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

Side by Side Diff: pkg/analysis_server/test/index/page_node_manager_test.dart

Issue 329633002: Some clean ups for caching tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« no previous file with comments | « pkg/analysis_server/test/index/lru_cache_test.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.index.page_node_manager; 5 library test.index.page_node_manager;
6 6
7 import 'dart:math'; 7 import 'dart:math';
8 import 'dart:typed_data'; 8 import 'dart:typed_data';
9 9
10 import 'package:analysis_server/src/index/b_plus_tree.dart'; 10 import 'package:analysis_server/src/index/b_plus_tree.dart';
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 76 }
77 // find every remaining key 77 // find every remaining key
78 for (int key in keys) { 78 for (int key in keys) {
79 expect(tree.find(key), 'V$key'); 79 expect(tree.find(key), 'V$key');
80 } 80 }
81 } 81 }
82 82
83 83
84 @ReflectiveTestCase() 84 @ReflectiveTestCase()
85 class _CachingNodeManagerTest { 85 class _CachingNodeManagerTest {
86 NodeManager<int, String, int> delegate = new _NodeManagerMock<int, String, int >(); 86 _NodeManagerMock<int, String, int> delegate = new _NodeManagerMock<int,
87 String, int>();
87 NodeManager<int, String, int> manager; 88 NodeManager<int, String, int> manager;
88 89
89 void setUp() { 90 void setUp() {
91 when(delegate.writeIndex).thenReturn((key, value) {
92 delegate.writeIndex(key, value);
93 });
94 when(delegate.writeLeaf).thenReturn((key, value) {
95 delegate.writeLeaf(key, value);
96 });
90 manager = new CachingNodeManager<int, String, int>(delegate, 4, 4); 97 manager = new CachingNodeManager<int, String, int>(delegate, 4, 4);
98 resetInteractions(delegate);
91 } 99 }
92 100
93 void test_maxIndexKeys() { 101 void test_maxIndexKeys() {
94 when(delegate.maxIndexKeys).thenReturn(42); 102 when(delegate.maxIndexKeys).thenReturn(42);
95 expect(manager.maxIndexKeys, 42); 103 expect(manager.maxIndexKeys, 42);
96 } 104 }
97 105
98 void test_maxLeafKeys() { 106 void test_maxLeafKeys() {
99 when(delegate.maxLeafKeys).thenReturn(42); 107 when(delegate.maxLeafKeys).thenReturn(42);
100 expect(manager.maxLeafKeys, 42); 108 expect(manager.maxLeafKeys, 42);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 expect(manager.readLeaf(2), data); 162 expect(manager.readLeaf(2), data);
155 } 163 }
156 164
157 void test_writeIndex() { 165 void test_writeIndex() {
158 var data = new IndexNodeData<int, int>([1], [10, 20]); 166 var data = new IndexNodeData<int, int>([1], [10, 20]);
159 manager.writeIndex(1, data); 167 manager.writeIndex(1, data);
160 manager.writeIndex(2, data); 168 manager.writeIndex(2, data);
161 manager.writeIndex(3, data); 169 manager.writeIndex(3, data);
162 manager.writeIndex(4, data); 170 manager.writeIndex(4, data);
163 manager.writeIndex(1, data); 171 manager.writeIndex(1, data);
164 // TODO(scheglov) method pointers don't work with mocks 172 verifyZeroInteractions(delegate);
165 // TODO(scheglov) add resetInteractions(mock)
166 // TODO(scheglov) verifyZeroInteractions() should accept 'dynamic'
167 // verifyZeroInteractions(delegate as TypedMock);
168 verify(delegate.writeIndex(anyInt, anyObject)).never();
169 // only 4 nodes can be cached, 5-th one cause write to the delegate 173 // only 4 nodes can be cached, 5-th one cause write to the delegate
170 manager.writeIndex(5, data); 174 manager.writeIndex(5, data);
171 verify(delegate.writeIndex(2, data)).once(); 175 verify(delegate.writeIndex(2, data)).once();
172 } 176 }
173 177
174 void test_writeLeaf() { 178 void test_writeLeaf() {
175 var data = new LeafNodeData<int, String>([1, 2], ['A', 'B']); 179 var data = new LeafNodeData<int, String>([1, 2], ['A', 'B']);
176 manager.writeLeaf(1, data); 180 manager.writeLeaf(1, data);
177 manager.writeLeaf(2, data); 181 manager.writeLeaf(2, data);
178 manager.writeLeaf(3, data); 182 manager.writeLeaf(3, data);
179 manager.writeLeaf(4, data); 183 manager.writeLeaf(4, data);
180 manager.writeLeaf(1, data); 184 manager.writeLeaf(1, data);
181 // TODO(scheglov) method pointers don't work with mocks 185 verifyZeroInteractions(delegate);
182 // TODO(scheglov) add resetInteractions(mock)
183 // TODO(scheglov) verifyZeroInteractions() should accept 'dynamic'
184 // verifyZeroInteractions(delegate as TypedMock);
185 verify(delegate.writeLeaf(anyInt, anyObject)).never();
186 // only 4 nodes can be cached, 5-th one cause write to the delegate 186 // only 4 nodes can be cached, 5-th one cause write to the delegate
187 manager.writeLeaf(5, data); 187 manager.writeLeaf(5, data);
188 verify(delegate.writeLeaf(2, data)).once(); 188 verify(delegate.writeLeaf(2, data)).once();
189 } 189 }
190 } 190 }
191 191
192 192
193 @ReflectiveTestCase() 193 @ReflectiveTestCase()
194 class _FixedStringCodecTest { 194 class _FixedStringCodecTest {
195 ByteData buffer; 195 ByteData buffer;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 test_write_doesNotExist() { 283 test_write_doesNotExist() {
284 expect(() { 284 expect(() {
285 Uint8List page = new Uint8List(PAGE_SIZE); 285 Uint8List page = new Uint8List(PAGE_SIZE);
286 manager.write(42, page); 286 manager.write(42, page);
287 }, throws); 287 }, throws);
288 } 288 }
289 } 289 }
290 290
291 291
292 292
293 class _NodeManagerMock<K, V, N> extends TypedMock implements NodeManager<K, V, N > { 293 class _NodeManagerMock<K, V, N> extends TypedMock implements NodeManager<K, V,
294 N> {
294 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 295 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
295 } 296 }
296 297
297 298
298 299
299 @ReflectiveTestCase() 300 @ReflectiveTestCase()
300 class _PageNodeManagerTest { 301 class _PageNodeManagerTest {
301 static const Codec KEY_CODEC = Uint32Codec.INSTANCE; 302 static const Codec KEY_CODEC = Uint32Codec.INSTANCE;
302 static const int PAGE_SIZE = 128; 303 static const int PAGE_SIZE = 128;
303 static const Codec VALUE_CODEC = const FixedStringCodec(4); 304 static const Codec VALUE_CODEC = const FixedStringCodec(4);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 385 }
385 386
386 test_all() { 387 test_all() {
387 // encode 388 // encode
388 codec.encode(buffer, 42); 389 codec.encode(buffer, 42);
389 expect(bytes, [0, 0, 0, 42]); 390 expect(bytes, [0, 0, 0, 42]);
390 // decode 391 // decode
391 expect(codec.decode(buffer), 42); 392 expect(codec.decode(buffer), 42);
392 } 393 }
393 } 394 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/index/lru_cache_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698