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

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

Issue 327003004: Tweaks for review comments. (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:collection';
7 import 'dart:io'; 8 import 'dart:io';
8 import 'dart:math'; 9 import 'dart:math';
9 import 'dart:typed_data'; 10 import 'dart:typed_data';
10 11
11 import 'package:analysis_server/src/index/b_plus_tree.dart'; 12 import 'package:analysis_server/src/index/b_plus_tree.dart';
12 import 'package:analysis_server/src/index/file_page_manager.dart'; 13 import 'package:analysis_server/src/index/file_page_manager.dart';
13 import 'package:analysis_server/src/index/page_node_manager.dart'; 14 import 'package:analysis_server/src/index/page_node_manager.dart';
14 import 'package:path/path.dart' as pathos; 15 import 'package:path/path.dart' as pathos;
15 import 'package:unittest/unittest.dart'; 16 import 'package:unittest/unittest.dart';
16 17
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 NodeManager<int, String, int> nodeManager = new PageNodeManager<int, 64 NodeManager<int, String, int> nodeManager = new PageNodeManager<int,
64 String>(manager, Uint32Codec.INSTANCE, new FixedStringCodec(7)); 65 String>(manager, Uint32Codec.INSTANCE, new FixedStringCodec(7));
65 nodeManager = new CachingNodeManager(nodeManager, 32, 32); 66 nodeManager = new CachingNodeManager(nodeManager, 32, 32);
66 BPlusTree<int, String, int> tree = new BPlusTree(_intComparator, 67 BPlusTree<int, String, int> tree = new BPlusTree(_intComparator,
67 nodeManager); 68 nodeManager);
68 // insert 69 // insert
69 int maxKey = 1000000; 70 int maxKey = 1000000;
70 int tryCount = 1000; 71 int tryCount = 1000;
71 Set<int> keys = new Set<int>(); 72 Set<int> keys = new Set<int>();
72 { 73 {
73 Random random = new Random(); 74 Random random = new Random(37);
74 for (int i = 0; i < tryCount; i++) { 75 for (int i = 0; i < tryCount; i++) {
75 int key = random.nextInt(maxKey); 76 int key = random.nextInt(maxKey);
76 keys.add(key); 77 keys.add(key);
77 tree.insert(key, 'V$key'); 78 tree.insert(key, 'V$key');
78 } 79 }
79 } 80 }
80 // find every 81 // find every
81 for (int key in keys) { 82 for (int key in keys) {
82 expect(tree.find(key), 'V$key'); 83 expect(tree.find(key), 'V$key');
83 } 84 }
84 // remove random keys 85 // remove random keys
85 { 86 {
86 Random random = new Random(); 87 Random random = new Random(37);
88 Set<int> removedKeys = new HashSet<int>();
87 for (int key in new Set<int>.from(keys)) { 89 for (int key in new Set<int>.from(keys)) {
88 if (random.nextBool()) { 90 if (random.nextBool()) {
91 removedKeys.add(key);
89 keys.remove(key); 92 keys.remove(key);
90 expect(tree.remove(key), 'V$key'); 93 expect(tree.remove(key), 'V$key');
91 } 94 }
92 } 95 }
96 // check the removed keys are actually gone
97 for (int key in removedKeys) {
98 expect(tree.find(key), isNull);
99 }
93 } 100 }
94 // find every remaining key 101 // find every remaining key
95 for (int key in keys) { 102 for (int key in keys) {
96 expect(tree.find(key), 'V$key'); 103 expect(tree.find(key), 'V$key');
97 } 104 }
98 } 105 }
99 106
100 void test_free_double() { 107 void test_free_double() {
101 int id = manager.alloc(); 108 int id = manager.alloc();
102 manager.free(id); 109 manager.free(id);
103 expect(() { 110 expect(() {
104 manager.free(id); 111 manager.free(id);
105 }, throws); 112 }, throws);
106 } 113 }
107 114
108 void test_writeRead() { 115 void test_writeRead() {
109 // write 116 // write
110 int id1 = manager.alloc(); 117 int id1 = manager.alloc();
111 int id2 = manager.alloc(); 118 int id2 = manager.alloc();
112 manager.write(id1, new Uint8List.fromList(new List.filled(pageSize, 1))); 119 manager.write(id1, new Uint8List.fromList(new List.filled(pageSize, 1)));
113 manager.write(id2, new Uint8List.fromList(new List.filled(pageSize, 2))); 120 manager.write(id2, new Uint8List.fromList(new List.filled(pageSize, 2)));
114 // read 121 // read
115 expect(manager.read(id1), everyElement(1)); 122 expect(manager.read(id1), everyElement(1));
116 expect(manager.read(id2), everyElement(2)); 123 expect(manager.read(id2), everyElement(2));
117 } 124 }
118 } 125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698