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

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

Issue 308003009: Add ServerOperation and queue. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweaks for review comments Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.operation.queue;
6
7 import 'package:analysis_server/src/analysis_server.dart';
8 import 'package:analysis_server/src/operation/operation.dart';
9 import 'package:analysis_server/src/operation/operation_queue.dart';
10 import 'package:analyzer/src/generated/engine.dart';
11 import 'package:typed_mock/typed_mock.dart';
12 import 'package:unittest/unittest.dart';
13
14 main() {
15 groupSep = ' | ';
16
17 group('ServerOperationQueue', () {
18 AnalysisServer server;
19 ServerOperationQueue queue;
20
21 setUp(() {
22 server = new AnalysisServerMock();
23 queue = new ServerOperationQueue(server);
24 });
25
26 test('clear', () {
27 var operationA = mockOperation(ServerOperationPriority.SEARCH);
28 var operationB = mockOperation(ServerOperationPriority.REFACTORING);
29 queue.add(operationA);
30 queue.add(operationB);
31 // there are some operations
32 expect(queue.isEmpty, false);
33 // clear - no operations
34 queue.clear();
35 expect(queue.isEmpty, true);
36 });
37
38 group('isEmpty', () {
39 test('true', () {
40 expect(queue.isEmpty, isTrue);
41 });
42
43 test('false', () {
44 var operation = mockOperation(ServerOperationPriority.SEARCH);
45 queue.add(operation);
46 expect(queue.isEmpty, isFalse);
47 });
48 });
49
50 group('take', () {
51 test('empty', () {
52 expect(queue.take(), isNull);
53 });
54
55 test('use operation priorities', () {
56 // TODO(scheglov) update 'typed_mock' to make 'any*' fields dynamic
57 when(server.isPriorityContext(anyObject as dynamic)).thenReturn(false);
58 var analysisContext = new AnalysisContextMock();
59 var operationA = mockOperation(ServerOperationPriority.SEARCH);
60 var operationB = mockOperation(ServerOperationPriority.REFACTORING);
61 var operationC = new PerformAnalysisOperation(analysisContext, false);
62 queue.add(operationA);
63 queue.add(operationB);
64 queue.add(operationC);
65 expect(queue.take(), operationC);
66 expect(queue.take(), operationA);
67 expect(queue.take(), operationB);
68 expect(queue.take(), isNull);
69 });
70
71 test('continue analysis first', () {
72 // TODO(scheglov) update 'typed_mock' to make 'any*' fields dynamic
73 when(server.isPriorityContext(anyObject as dynamic)).thenReturn(false);
74 var analysisContext = new AnalysisContextMock();
75 var operationA = new PerformAnalysisOperation(analysisContext, false);
76 var operationB = new PerformAnalysisOperation(analysisContext, true);
77 queue.add(operationA);
78 queue.add(operationB);
79 expect(queue.take(), operationB);
80 expect(queue.take(), operationA);
81 expect(queue.take(), isNull);
82 });
83
84 test('priority context first', () {
85 var analysisContextA = new AnalysisContextMock();
86 var analysisContextB = new AnalysisContextMock();
87 var operationA = new PerformAnalysisOperation(analysisContextA, false);
88 var operationB = new PerformAnalysisOperation(analysisContextB, false);
89 queue.add(operationA);
90 queue.add(operationB);
91 when(server.isPriorityContext(analysisContextA)).thenReturn(false);
92 when(server.isPriorityContext(analysisContextB)).thenReturn(true);
93 expect(queue.take(), operationB);
94 expect(queue.take(), operationA);
95 expect(queue.take(), isNull);
96 });
97 });
98 });
99 }
100
101
102 /**
103 * Return a [ServerOperation] mock with the given priority.
104 */
105 ServerOperation mockOperation(ServerOperationPriority priority) {
106 ServerOperation operation = new ServerOperationMock();
107 when(operation.priority).thenReturn(priority);
108 return operation;
109 }
110
111
112 class AnalysisContextMock extends TypedMock implements AnalysisContext {
113 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
114 }
115
116 class ServerOperationMock extends TypedMock implements ServerOperation {
117 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
118 }
119
120 class AnalysisServerMock extends TypedMock implements AnalysisServer {
121 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
122 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/mocks.dart ('k') | pkg/analysis_server/test/operation/operation_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698