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

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

Issue 321953002: FilePageManager - disk based PageManager. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Improved tests. 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.index.file_page_manager;
6
7 import 'dart:io';
8 import 'dart:math';
9 import 'dart:typed_data';
10
11 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/page_node_manager.dart';
14 import 'package:path/path.dart' as pathos;
15 import 'package:unittest/unittest.dart';
16
17 import '../reflective_tests.dart';
18
19
20 main() {
21 groupSep = ' | ';
22 group('FixedStringCodecTest', () {
23 runReflectiveTests(_FilePageManagerTest);
24 });
25 }
26
27
28 int _intComparator(int a, int b) => a - b;
29
30
31 @ReflectiveTestCase()
32 class _FilePageManagerTest {
33 FilePageManager manager;
34 int pageSize = 256;
35 Directory tempDir;
36
37 void setUp() {
38 tempDir = Directory.systemTemp.createTempSync('testIndex_');
39 String path = pathos.join(tempDir.path, 'my.index');
40 manager = new FilePageManager(pageSize, path);
41 }
42
43 void tearDown() {
44 manager.close();
45 manager.delete();
46 tempDir.deleteSync(recursive: true);
47 }
48
49 void test_alloc_reuseFree() {
50 int id = manager.alloc();
51 manager.free(id);
52 int newId = manager.alloc();
53 expect(newId, id);
54 }
55
56 void test_alloc_unique() {
57 int idA = manager.alloc();
58 int idB = manager.alloc();
59 expect(idB, isNot(idA));
60 }
61
62 void test_btree_stress_random() {
63 NodeManager<int, String, int> nodeManager = new PageNodeManager<int,
64 String>(manager, Uint32Codec.INSTANCE, new FixedStringCodec(7));
65 print('maxIndexKeys: ${nodeManager.maxIndexKeys} '
66 'maxLeafKeys: ${nodeManager.maxLeafKeys}');
67 BPlusTree<int, String, int> tree = new BPlusTree(_intComparator,
68 nodeManager);
69 int maxKey = 1000000;
70 int tryCount = 1000;
71 Set<int> keys = new Set<int>();
72 {
73 Random random = new Random();
74 for (int i = 0; i < tryCount; i++) {
75 int key = random.nextInt(maxKey);
76 keys.add(key);
77 tree.insert(key, 'V$key');
78 }
79 }
80 // find every
81 for (int key in keys) {
82 expect(tree.find(key), 'V$key');
83 }
84 // remove random keys
85 {
86 Random random = new Random();
87 for (int key in new Set<int>.from(keys)) {
88 if (random.nextBool()) {
89 keys.remove(key);
90 expect(tree.remove(key), 'V$key');
91 }
92 }
93 }
94 // find every remaining key
95 for (int key in keys) {
96 expect(tree.find(key), 'V$key');
97 }
98 }
99
100 void test_free_double() {
101 int id = manager.alloc();
102 manager.free(id);
103 expect(() {
104 manager.free(id);
105 }, throws);
106 }
107
108 void test_writeRead() {
109 // write
110 int id1 = manager.alloc();
111 int id2 = manager.alloc();
112 manager.write(id1, new Uint8List.fromList(new List.filled(pageSize, 1)));
113 manager.write(id2, new Uint8List.fromList(new List.filled(pageSize, 2)));
114 // read
115 expect(manager.read(id1), everyElement(1));
116 expect(manager.read(id2), everyElement(2));
117 }
118 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/index/b_plus_tree_test.dart ('k') | pkg/analysis_server/test/index/page_node_manager_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698