Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: pkg/analysis_server/test/operation/operation_queue_test.dart

Issue 1327173002: Make NavigationOperation a MergeableOperation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/operation/operation_queue.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.operation.queue; 5 library test.operation.queue;
6 6
7 import 'package:analysis_server/src/analysis_server.dart'; 7 import 'package:analysis_server/src/analysis_server.dart';
8 import 'package:analysis_server/src/context_manager.dart'; 8 import 'package:analysis_server/src/context_manager.dart';
9 import 'package:analysis_server/src/operation/operation.dart'; 9 import 'package:analysis_server/src/operation/operation.dart';
10 import 'package:analysis_server/src/operation/operation_analysis.dart'; 10 import 'package:analysis_server/src/operation/operation_analysis.dart';
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 54
55 class ServerContextManagerMock extends TypedMock implements ContextManager { 55 class ServerContextManagerMock extends TypedMock implements ContextManager {
56 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 56 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
57 } 57 }
58 58
59 @reflectiveTest 59 @reflectiveTest
60 class ServerOperationQueueTest { 60 class ServerOperationQueueTest {
61 ServerOperationQueue queue = new ServerOperationQueue(); 61 ServerOperationQueue queue = new ServerOperationQueue();
62 62
63 void test_add_withMerge() {
64 var opA = new _MergeableOperationMock();
65 var opB = new _MergeableOperationMock();
66 var opC = new _MergeableOperationMock();
67 when(opA.merge(opC)).thenReturn(true);
68 when(opA.merge(anyObject)).thenReturn(false);
69 when(opB.merge(anyObject)).thenReturn(false);
70 when(opC.merge(anyObject)).thenReturn(false);
71 queue.add(opA);
72 queue.add(opB);
73 queue.add(opC);
74 expect(queue.take(), same(opA));
75 expect(queue.take(), same(opB));
76 // no opC, it was merged into opA
77 expect(queue.isEmpty, isTrue);
78 }
79
63 void test_clear() { 80 void test_clear() {
64 var operationA = mockOperation(ServerOperationPriority.ANALYSIS); 81 var operationA = mockOperation(ServerOperationPriority.ANALYSIS);
65 var operationB = mockOperation(ServerOperationPriority.ANALYSIS_CONTINUE); 82 var operationB = mockOperation(ServerOperationPriority.ANALYSIS_CONTINUE);
66 queue.add(operationA); 83 queue.add(operationA);
67 queue.add(operationB); 84 queue.add(operationB);
68 // there are some operations 85 // there are some operations
69 expect(queue.isEmpty, false); 86 expect(queue.isEmpty, false);
70 // clear - no operations 87 // clear - no operations
71 queue.clear(); 88 queue.clear();
72 expect(queue.isEmpty, true); 89 expect(queue.isEmpty, true);
(...skipping 26 matching lines...) Expand all
99 void test_isEmpty_false() { 116 void test_isEmpty_false() {
100 var operation = mockOperation(ServerOperationPriority.ANALYSIS); 117 var operation = mockOperation(ServerOperationPriority.ANALYSIS);
101 queue.add(operation); 118 queue.add(operation);
102 expect(queue.isEmpty, isFalse); 119 expect(queue.isEmpty, isFalse);
103 } 120 }
104 121
105 void test_isEmpty_true() { 122 void test_isEmpty_true() {
106 expect(queue.isEmpty, isTrue); 123 expect(queue.isEmpty, isTrue);
107 } 124 }
108 125
126 void test_peek() {
127 var operationA = mockOperation(ServerOperationPriority.ANALYSIS);
128 var operationB = mockOperation(ServerOperationPriority.ANALYSIS);
129 queue.add(operationA);
130 queue.add(operationB);
131 expect(queue.peek(), operationA);
132 expect(queue.peek(), operationA);
133 expect(queue.peek(), operationA);
134 }
135
136 void test_peek_empty() {
137 expect(queue.peek(), isNull);
138 }
139
109 void test_reschedule() { 140 void test_reschedule() {
110 var prioritySource = new MockSource(); 141 var prioritySource = new MockSource();
111 var analysisContextA = new AnalysisContextMock(); 142 var analysisContextA = new AnalysisContextMock();
112 var analysisContextB = new AnalysisContextMock(); 143 var analysisContextB = new AnalysisContextMock();
113 var operationA = new PerformAnalysisOperation(analysisContextA, false); 144 var operationA = new PerformAnalysisOperation(analysisContextA, false);
114 var operationB = new PerformAnalysisOperation(analysisContextB, false); 145 var operationB = new PerformAnalysisOperation(analysisContextB, false);
115 queue.add(operationA); 146 queue.add(operationA);
116 queue.add(operationB); 147 queue.add(operationB);
117 // update priority sources and reschedule 148 // update priority sources and reschedule
118 analysisContextB.prioritySources = [prioritySource]; 149 analysisContextB.prioritySources = [prioritySource];
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 var operationB = mockOperation(ServerOperationPriority.ANALYSIS_CONTINUE); 204 var operationB = mockOperation(ServerOperationPriority.ANALYSIS_CONTINUE);
174 var operationC = mockOperation(ServerOperationPriority.PRIORITY_ANALYSIS); 205 var operationC = mockOperation(ServerOperationPriority.PRIORITY_ANALYSIS);
175 queue.add(operationA); 206 queue.add(operationA);
176 queue.add(operationB); 207 queue.add(operationB);
177 queue.add(operationC); 208 queue.add(operationC);
178 expect(queue.take(), operationC); 209 expect(queue.take(), operationC);
179 expect(queue.take(), operationB); 210 expect(queue.take(), operationB);
180 expect(queue.take(), operationA); 211 expect(queue.take(), operationA);
181 expect(queue.take(), isNull); 212 expect(queue.take(), isNull);
182 } 213 }
214
215 void test_takeIf() {
216 var operationA = mockOperation(ServerOperationPriority.ANALYSIS);
217 var operationB = mockOperation(ServerOperationPriority.ANALYSIS);
218 queue.add(operationA);
219 queue.add(operationB);
220 expect(queue.takeIf((_) => false), isNull);
221 expect(queue.takeIf((operation) => operation == operationB), operationB);
222 expect(queue.takeIf((operation) => operation == operationB), isNull);
223 expect(queue.takeIf((operation) => operation == operationA), operationA);
224 expect(queue.isEmpty, isTrue);
225 }
226 }
227
228 class _MergeableOperationMock extends TypedMock implements MergeableOperation {
229 @override
230 ServerOperationPriority get priority {
231 return ServerOperationPriority.ANALYSIS_NOTIFICATION;
232 }
233
234 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
183 } 235 }
184 236
185 class _ServerOperationMock extends TypedMock implements ServerOperation { 237 class _ServerOperationMock extends TypedMock implements ServerOperation {
186 final AnalysisContext context; 238 final AnalysisContext context;
187 239
188 _ServerOperationMock([this.context]); 240 _ServerOperationMock([this.context]);
189 241
190 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 242 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
191 } 243 }
192 244
(...skipping 12 matching lines...) Expand all
205 return ServerOperationPriority.ANALYSIS_NOTIFICATION; 257 return ServerOperationPriority.ANALYSIS_NOTIFICATION;
206 } 258 }
207 259
208 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 260 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
209 261
210 @override 262 @override
211 bool shouldBeDiscardedOnSourceChange(Source source) { 263 bool shouldBeDiscardedOnSourceChange(Source source) {
212 return source == this.source; 264 return source == this.source;
213 } 265 }
214 } 266 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/operation/operation_queue.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698