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

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

Issue 326123002: Node cache, binary search. (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
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.file_page_manager; 5 library test.index.file_page_manager;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:math'; 8 import 'dart:math';
9 import 'dart:typed_data'; 9 import 'dart:typed_data';
10 10
(...skipping 13 matching lines...) Expand all
24 }); 24 });
25 } 25 }
26 26
27 27
28 int _intComparator(int a, int b) => a - b; 28 int _intComparator(int a, int b) => a - b;
29 29
30 30
31 @ReflectiveTestCase() 31 @ReflectiveTestCase()
32 class _FilePageManagerTest { 32 class _FilePageManagerTest {
33 FilePageManager manager; 33 FilePageManager manager;
34 int pageSize = 256; 34 int pageSize = 1024;
35 Directory tempDir; 35 Directory tempDir;
36 36
37 void setUp() { 37 void setUp() {
38 tempDir = Directory.systemTemp.createTempSync('testIndex_'); 38 tempDir = Directory.systemTemp.createTempSync('testIndex_');
39 String path = pathos.join(tempDir.path, 'my.index'); 39 String path = pathos.join(tempDir.path, 'my.index');
40 manager = new FilePageManager(pageSize, path); 40 manager = new FilePageManager(pageSize, path);
41 } 41 }
42 42
43 void tearDown() { 43 void tearDown() {
44 manager.close(); 44 manager.close();
(...skipping 10 matching lines...) Expand all
55 55
56 void test_alloc_unique() { 56 void test_alloc_unique() {
57 int idA = manager.alloc(); 57 int idA = manager.alloc();
58 int idB = manager.alloc(); 58 int idB = manager.alloc();
59 expect(idB, isNot(idA)); 59 expect(idB, isNot(idA));
60 } 60 }
61 61
62 void test_btree_stress_random() { 62 void test_btree_stress_random() {
63 NodeManager<int, String, int> nodeManager = new PageNodeManager<int, 63 NodeManager<int, String, int> nodeManager = new PageNodeManager<int,
64 String>(manager, Uint32Codec.INSTANCE, new FixedStringCodec(7)); 64 String>(manager, Uint32Codec.INSTANCE, new FixedStringCodec(7));
65 print('maxIndexKeys: ${nodeManager.maxIndexKeys} ' 65 nodeManager = new CachingNodeManager(nodeManager, 32, 32);
66 'maxLeafKeys: ${nodeManager.maxLeafKeys}');
67 BPlusTree<int, String, int> tree = new BPlusTree(_intComparator, 66 BPlusTree<int, String, int> tree = new BPlusTree(_intComparator,
68 nodeManager); 67 nodeManager);
68 // insert
69 int maxKey = 1000000; 69 int maxKey = 1000000;
70 int tryCount = 1000; 70 int tryCount = 1000;
71 Set<int> keys = new Set<int>(); 71 Set<int> keys = new Set<int>();
72 { 72 {
73 Random random = new Random(); 73 Random random = new Random();
74 for (int i = 0; i < tryCount; i++) { 74 for (int i = 0; i < tryCount; i++) {
75 int key = random.nextInt(maxKey); 75 int key = random.nextInt(maxKey);
76 keys.add(key); 76 keys.add(key);
77 tree.insert(key, 'V$key'); 77 tree.insert(key, 'V$key');
78 } 78 }
(...skipping 30 matching lines...) Expand all
109 // write 109 // write
110 int id1 = manager.alloc(); 110 int id1 = manager.alloc();
111 int id2 = manager.alloc(); 111 int id2 = manager.alloc();
112 manager.write(id1, new Uint8List.fromList(new List.filled(pageSize, 1))); 112 manager.write(id1, new Uint8List.fromList(new List.filled(pageSize, 1)));
113 manager.write(id2, new Uint8List.fromList(new List.filled(pageSize, 2))); 113 manager.write(id2, new Uint8List.fromList(new List.filled(pageSize, 2)));
114 // read 114 // read
115 expect(manager.read(id1), everyElement(1)); 115 expect(manager.read(id1), everyElement(1));
116 expect(manager.read(id2), everyElement(2)); 116 expect(manager.read(id2), everyElement(2));
117 } 117 }
118 } 118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698