1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.directory.mavibot.btree;
22
23
24 import static org.junit.Assert.assertEquals;
25
26 import java.io.File;
27 import java.util.ArrayList;
28 import java.util.List;
29
30 import org.apache.directory.mavibot.btree.serializer.IntSerializer;
31 import org.junit.Ignore;
32 import org.junit.Test;
33
34
35
36
37
38
39
40 @Ignore( "until ApacheDS works with mavibot" )
41 public class PersistedBTreeBuilderTest
42 {
43
44 @Test
45 public void testManagedBTreeBuilding() throws Exception
46 {
47 List<Tuple<Integer, Integer>> sortedTuple = new ArrayList<Tuple<Integer, Integer>>();
48
49 for ( int i = 1; i < 8; i++ )
50 {
51 Tuple<Integer, Integer> t = new Tuple<Integer, Integer>( i, i );
52 sortedTuple.add( t );
53 }
54
55 File file = File.createTempFile( "managedbtreebuilder", ".data" );
56 file.deleteOnExit();
57
58 RecordManager rm = new RecordManager( file.getAbsolutePath() );
59
60 IntSerializer ser = IntSerializer.INSTANCE;
61 PersistedBTreeBuilder<Integer, Integer> bb = new PersistedBTreeBuilder<Integer, Integer>( rm, "master", 4, ser,
62 ser );
63
64
65 BTree<Integer, Integer> btree = bb.build( sortedTuple.iterator() );
66
67 rm.close();
68
69 rm = new RecordManager( file.getAbsolutePath() );
70 btree = rm.getManagedTree( "master" );
71
72 assertEquals( 1, btree.getRootPage().getNbElems() );
73
74 assertEquals( 7, btree.getRootPage().findRightMost().getKey().intValue() );
75
76 assertEquals( 1, btree.getRootPage().findLeftMost().getKey().intValue() );
77
78 TupleCursor<Integer, Integer> cursor = btree.browse();
79 int i = 0;
80
81 while ( cursor.hasNext() )
82 {
83 Tuple<Integer, Integer> expected = sortedTuple.get( i++ );
84 Tuple<Integer, Integer> actual = cursor.next();
85 assertEquals( expected.getKey(), actual.getKey() );
86 assertEquals( expected.getValue(), actual.getValue() );
87 }
88
89 cursor.close();
90 btree.close();
91 }
92 }