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

Unified 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: Remove some priorities Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/test/operation/operation_queue_test.dart
diff --git a/pkg/analysis_server/test/operation/operation_queue_test.dart b/pkg/analysis_server/test/operation/operation_queue_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..19483f29e0d190a5dee927006380467a180c9637
--- /dev/null
+++ b/pkg/analysis_server/test/operation/operation_queue_test.dart
@@ -0,0 +1,114 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library test.operation.queue;
+
+import 'package:analysis_server/src/operation/operation.dart';
+import 'package:analysis_server/src/operation/operation_queue.dart';
+import 'package:typed_mock/typed_mock.dart';
+import 'package:unittest/unittest.dart';
+
+main() {
+ groupSep = ' | ';
+
+ group('ServerOperationQueue', () {
+ ServerOperationQueue queue;
+
+ setUp(() {
+ queue = new ServerOperationQueue();
+ });
+
+ group('add', () {
+ group('MergeableOperation', () {
+ test('false', () {
+ var operationA = mockMergeableOperation(ServerOperationPriority.SEARCH);
+ var operationB = mockMergeableOperation(ServerOperationPriority.SEARCH);
+ when(operationA.mergeWith(operationB)).thenReturn(false);
+ queue.add(operationA);
+ queue.add(operationB);
+ expect(queue.take(), operationA);
+ expect(queue.take(), operationB);
+ expect(queue.take(), null);
Brian Wilkerson 2014/06/02 14:32:18 Should this (and line 42) be "isNull"?
scheglov 2014/06/02 17:56:59 As I see it now, we actually don't need mergeable
+ });
+
+ test('true', () {
+ var operationA = mockMergeableOperation(ServerOperationPriority.SEARCH);
+ var operationB = mockMergeableOperation(ServerOperationPriority.SEARCH);
+ when(operationA.mergeWith(operationB)).thenReturn(true);
+ queue.add(operationA);
+ queue.add(operationB);
+ expect(queue.take(), operationA);
+ expect(queue.take(), null);
+ });
+ });
+
+ test('false', () {
Brian Wilkerson 2014/06/02 14:32:18 This test is duplicated on line 58.
scheglov 2014/06/02 17:56:59 Removed.
+ var operation = mockOperation(ServerOperationPriority.SEARCH);
+ queue.add(operation);
+ expect(queue.isEmpty, isFalse);
+ });
+ });
+
+ group('isEmpty', () {
+ test('true', () {
+ expect(queue.isEmpty, isTrue);
+ });
+
+ test('false', () {
+ var operation = mockOperation(ServerOperationPriority.SEARCH);
+ queue.add(operation);
+ expect(queue.isEmpty, isFalse);
+ });
+ });
+
+ group('take', () {
+ test('empty', () {
+ expect(queue.take(), isNull);
+ });
+
+ test('use priorities', () {
+ var operationA = mockOperation(ServerOperationPriority.SEARCH);
+ var operationB = mockOperation(ServerOperationPriority.REFACTORING);
+ var operationC = mockOperation(ServerOperationPriority.ANALYSIS);
+ queue.add(operationA);
+ queue.add(operationB);
+ queue.add(operationC);
+ expect(queue.take(), operationC);
+ expect(queue.take(), operationA);
+ expect(queue.take(), operationB);
+ expect(queue.take(), isNull);
+ });
+ });
+ });
+}
+
+
+/**
+ * Return a [ServerOperation] mock with the given priority.
+ */
+ServerOperation mockOperation(ServerOperationPriority priority) {
+ ServerOperation operation = new ServerOperationMock();
+ when(operation.priority).thenReturn(priority);
+ return operation;
+}
+
+
+/**
+ * Return a [MergeableOperation] mock with the given priority.
+ */
+MergeableOperation mockMergeableOperation(ServerOperationPriority priority) {
+ MergeableOperation operation = new MergeableOperationMock();
+ when(operation.priority).thenReturn(priority);
+ return operation;
+}
+
+
+class ServerOperationMock extends TypedMock implements ServerOperation {
+ noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
+}
+
+
+class MergeableOperationMock extends TypedMock implements MergeableOperation {
+ noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
+}

Powered by Google App Engine
This is Rietveld 408576698