directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1638068 - in /directory/mavibot/trunk/mavibot/src: main/java/org/apache/directory/mavibot/btree/BulkLoader.java test/java/org/apache/directory/mavibot/btree/BulkLoaderTest.java
Date Tue, 11 Nov 2014 11:37:26 GMT
Author: elecharny
Date: Tue Nov 11 11:37:26 2014
New Revision: 1638068

URL: http://svn.apache.org/r1638068
Log:
o Bulkloader code cleanup
o Deleting the temprorary files when quiting the tests

Modified:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BulkLoader.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/BulkLoaderTest.java

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BulkLoader.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BulkLoader.java?rev=1638068&r1=1638067&r2=1638068&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BulkLoader.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BulkLoader.java
Tue Nov 11 11:37:26 2014
@@ -130,41 +130,25 @@ public class BulkLoader<K, V>
 
 
     /**
-     * Bulk Load data into a persisted BTree
+     * Process the data, and creates files to store them sorted if necessary, or store them
+     * TODO readElements.
      *
-     * @param btree The persisted BTree in which we want to load the data
-     * @param iterator The iterator over the data to bulkload
-     * @param chunkSize The number of elements we may store in memory at each iteration
-     * @throws IOException If there is a problem while processing the data
+     * @param btree
+     * @param iterator
+     * @param sortedFiles
+     * @param tuples
+     * @param chunkSize
+     * @return
+     * @throws IOException
      */
-    public BTree<K, V> load( PersistedBTree<K, V> btree, Iterator<Tuple<K,
V>> iterator, int chunkSize )
-        throws IOException
+    private int readElements( BTree<K, V> btree, Iterator<Tuple<K, V>>
iterator, List<File> sortedFiles,
+        List<Tuple<K, V>> tuples, int chunkSize ) throws IOException
     {
-        if ( btree == null )
-        {
-            throw new RuntimeException( "Invalid BTree : it's null" );
-        }
-
-        if ( iterator == null )
-        {
-            // Nothing to do...
-            return null;
-        }
-
-        // Iterate through the elements by chunk
         int nbRead = 0;
         int nbIteration = 0;
-        boolean inMemory = true;
         int nbElems = 0;
+        boolean inMemory = true;
 
-        // An array of chukSize tuple max
-        List<Tuple<K, V>> tuples = new ArrayList<Tuple<K, V>>( chunkSize
);
-
-        // The list of files we will use to store the sorted chunks
-        List<File> sortedFiles = new ArrayList<File>();
-
-        // Now, start to read all the tuples to sort them. We may use intermediate files
-        // for that purpose if we hit the threshold.
         while ( true )
         {
             nbIteration++;
@@ -184,7 +168,7 @@ public class BulkLoader<K, V>
                 {
                     // We have read all the data in one round trip, let's get out, no need
                     // to store the data on disk
-                    sortedFiles.add( flushToDisk( nbIteration, tuples, btree ) );
+                    ;
                 }
                 else
                 {
@@ -227,6 +211,56 @@ public class BulkLoader<K, V>
             }
         }
 
+        if ( !inMemory )
+        {
+            tuples.clear();
+        }
+
+        return nbElems;
+    }
+
+
+    /**
+     * Bulk Load data into a persisted BTree
+     *
+     * @param btree The persisted BTree in which we want to load the data
+     * @param iterator The iterator over the data to bulkload
+     * @param chunkSize The number of elements we may store in memory at each iteration
+     * @throws IOException If there is a problem while processing the data
+     */
+    public BTree<K, V> load( PersistedBTree<K, V> btree, Iterator<Tuple<K,
V>> iterator, int chunkSize )
+        throws IOException
+    {
+        if ( btree == null )
+        {
+            throw new RuntimeException( "Invalid BTree : it's null" );
+        }
+
+        if ( iterator == null )
+        {
+            // Nothing to do...
+            return null;
+        }
+
+        // Iterate through the elements by chunk
+        boolean inMemory = true;
+
+        // The list of files we will use to store the sorted chunks
+        List<File> sortedFiles = new ArrayList<File>();
+
+        // An array of chukSize tuple max
+        List<Tuple<K, V>> tuples = new ArrayList<Tuple<K, V>>( chunkSize
);
+
+        // Now, start to read all the tuples to sort them. We may use intermediate files
+        // for that purpose if we hit the threshold.
+        int nbElems = readElements( btree, iterator, sortedFiles, tuples, chunkSize );
+
+        // If the tuple list is empty, we have to process the load based on files, not in
memory
+        if ( nbElems > 0 )
+        {
+            inMemory = tuples.size() > 0;
+        }
+
         // Now that we have processed all the data, we can start storing them in the btree
         Iterator<Tuple<K, Set<V>>> dataIterator = null;
         FileInputStream[] streams = null;
@@ -236,7 +270,6 @@ public class BulkLoader<K, V>
             // Here, we have all the data in memory, no need to merge files
             // We will build a simple iterator over the data
             dataIterator = createTupleIterator( btree, tuples );
-
         }
         else
         {
@@ -256,7 +289,7 @@ public class BulkLoader<K, V>
         // target btree.
         BTree<K, V> resultBTree = bulkLoad( btree, dataIterator, nbElems );
 
-        // Now, close the FileInputStream if we have some
+        // Now, close the FileInputStream, and delete them if we have some
         if ( !inMemory )
         {
             int nbFiles = sortedFiles.size();
@@ -264,6 +297,7 @@ public class BulkLoader<K, V>
             for ( int i = 0; i < nbFiles; i++ )
             {
                 streams[i].close();
+                sortedFiles.get( i ).delete();
             }
         }
 
@@ -775,19 +809,9 @@ public class BulkLoader<K, V>
 
         // Now, let's fill the levels
         LevelInfo leafLevel = levels.get( 0 );
-        int nbRead = 0;
 
         while ( dataIterator.hasNext() )
         {
-            nbRead++;
-            //System.out.println( "Adding #" + nbRead );
-            //System.out.println( "--------------------------------------------------------"
);
-
-            //for ( int i = 0; i < leafLevel.currentPage.getNbElems(); i++ )
-            //{
-            //    System.out.println( "Key[" + i + "] = " + leafLevel.currentPage.getKey(
i ) );
-            //}
-
             // let's fill page up to the point all the complete pages have been filled
             if ( leafLevel.nbAddedElems < leafLevel.nbElemsLimit )
             {
@@ -800,7 +824,6 @@ public class BulkLoader<K, V>
                 // The page is completed, update the parent's node and create a new current
page
                 if ( leafLevel.currentPos == pageSize )
                 {
-                    //System.out.println( leafLevel.currentPage );
                     injectInNode( btree, leafLevel.currentPage, levels, 1 );
 
                     // The page is full, we have to create a new one
@@ -838,7 +861,6 @@ public class BulkLoader<K, V>
 
                     // Now inject the page into the node
                     injectInNode( btree, leafLevel.currentPage, levels, 1 );
-                    //System.out.println( leafLevel.currentPage );
 
                     // Create a new page for the remaining elements
                     nbToAdd = pageSize / 2;
@@ -859,7 +881,6 @@ public class BulkLoader<K, V>
                     injectInNode( btree, leafLevel.currentPage, levels, 1 );
 
                     // We are done
-                    //System.out.println( leafLevel.currentPage );
                     break;
                 }
                 else
@@ -882,7 +903,6 @@ public class BulkLoader<K, V>
                     injectInNode( btree, leafLevel.currentPage, levels, 1 );
 
                     // and we are done
-                    //System.out.println( leafLevel.currentPage );
                     break;
                 }
             }
@@ -899,28 +919,9 @@ public class BulkLoader<K, V>
      */
     private File flushToDisk( int fileNb, List<Tuple<K, V>> tuples, BTree<K,
V> btree ) throws IOException
     {
-        //System.out.println( "Sorted values for file nb[" + fileNb + "] : " );
-
         // Sort the tuples. 
         Tuple<K, Set<V>>[] sortedTuples = sort( btree, tuples );
 
-        boolean isFirst = true;
-        for ( Tuple<K, Set<V>> tuple : sortedTuples )
-        {
-            if ( isFirst )
-            {
-                isFirst = false;
-            }
-            else
-            {
-                //System.out.print( ", " );
-            }
-
-            //System.out.print( tuple.getKey() );
-        }
-
-        //System.out.println();
-
         File file = File.createTempFile( "sorted", Integer.toString( fileNb ) );
         file.deleteOnExit();
         FileOutputStream fos = new FileOutputStream( file );
@@ -1130,7 +1131,6 @@ public class BulkLoader<K, V>
             while ( true )
             {
                 readTuples[i] = fetchTuple( btree, streams[i] );
-                //System.out.println( "Fetched tuple " + readTuples[i] + " from file " +
i );
 
                 if ( readTuples[i] != null )
                 {
@@ -1139,7 +1139,6 @@ public class BulkLoader<K, V>
 
                     if ( !candidateSet.contains( candidate ) )
                     {
-                        //System.out.println( "Added candidate " + candidate + " to the set
of candidates" );
                         candidateSet.add( candidate );
                         break;
                     }
@@ -1151,21 +1150,8 @@ public class BulkLoader<K, V>
             }
         }
 
-        int pos = 0;
-        Iterator<Tuple<K, Integer>> iterator = candidateSet.iterator();
-
-        while ( iterator.hasNext() )
-        {
-            Tuple<K, Integer> candidate = iterator.next();
-            //System.out.println( "candidate[" + pos + "] = " + candidate.getKey() );
-            pos++;
-        }
-
         Iterator<Tuple<K, Set<V>>> tupleIterator = new Iterator<Tuple<K,
Set<V>>>()
         {
-            private int pos = 0;
-
-
             @Override
             public Tuple<K, Set<V>> next()
             {
@@ -1180,8 +1166,6 @@ public class BulkLoader<K, V>
 
                 // fetch it from the disk and store it into its reader
                 readTuples[tupleCandidate.value] = fetchTuple( btree, streams[tupleCandidate.value]
);
-                //System.out.println( "Next : fetched new tuple from file nb " + tupleCandidate.value
+ " : "
-                //    + readTuples[tupleCandidate.value] );
 
                 if ( readTuples[tupleCandidate.value] != null )
                 {
@@ -1191,18 +1175,7 @@ public class BulkLoader<K, V>
                     candidateSet.add( newTuple );
                 }
 
-                int pos = 0;
-                Iterator<Tuple<K, Integer>> iterator = candidateSet.iterator();
-
-                while ( iterator.hasNext() )
-                {
-                    Tuple<K, Integer> candidate = iterator.next();
-                    //System.out.println( "candidate[" + pos + "] = " + candidate.getKey()
);
-                    pos++;
-                }
-
                 // We can now return the found value
-                //System.out.println( "Returning selected tuple : " + tuple );
                 return tuple;
             }
 

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/BulkLoaderTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/BulkLoaderTest.java?rev=1638068&r1=1638067&r2=1638068&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/BulkLoaderTest.java
(original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/BulkLoaderTest.java
Tue Nov 11 11:37:26 2014
@@ -149,128 +149,118 @@ public class BulkLoaderTest
     public void testPersistedBulkLoad10Elements() throws IOException, KeyNotFoundException,
         BTreeAlreadyManagedException
     {
-        for ( int i = 1000; i < 1001; i++ )
+        for ( int i = 0; i < 1001; i++ )
         {
-            System.out.println( "=======================================" );
-            System.out.println( "== Iteration #" + i );
-            System.out.println( "=======================================" );
             Random random = new Random( System.currentTimeMillis() );
             File file = File.createTempFile( "managedbtreebuilder", ".data" );
             file.deleteOnExit();
 
-            RecordManager rm = new RecordManager( file.getAbsolutePath() );
-            PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String>
) rm.addBTree( "test",
-                LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
-
-            BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
-            int nbElems = i;
-            int addedElems = 0;
-
-            final Tuple<Long, String>[] elems = new Tuple[nbElems];
-            Map<Long, Tuple<Long, Set<String>>> expected = new HashMap<Long,
Tuple<Long, Set<String>>>();
-
-            long t00 = System.currentTimeMillis();
-
-            while ( addedElems < nbElems )
+            try
             {
-                long key = random.nextLong() % 3333333L;
-
-                if ( expected.containsKey( key ) )
-                {
-                    continue;
-                }
+                RecordManager rm = new RecordManager( file.getAbsolutePath() );
+                PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String>
) rm.addBTree( "test",
+                    LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
 
-                long w = random.nextLong() % 3333333L;
-                String value = "V" + w;
-                elems[addedElems] = new Tuple<Long, String>( key, value );
+                BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
+                int nbElems = i;
+                int addedElems = 0;
 
-                //System.out.println( "Adding tuple : " + elems[i] );
+                final Tuple<Long, String>[] elems = new Tuple[nbElems];
+                Map<Long, Tuple<Long, Set<String>>> expected = new HashMap<Long,
Tuple<Long, Set<String>>>();
 
-                Tuple<Long, Set<String>> expectedTuple = expected.get( key );
+                long t00 = System.currentTimeMillis();
 
-                if ( expectedTuple == null )
+                while ( addedElems < nbElems )
                 {
-                    expectedTuple = new Tuple<Long, Set<String>>( key, new TreeSet<String>()
);
-                }
+                    long key = random.nextLong() % 3333333L;
 
-                expectedTuple.value.add( value );
-                expected.put( key, expectedTuple );
-                addedElems++;
-
-                if ( addedElems % 100 == 0 )
-                {
-                    //System.out.println( "Nb added elements = " + addedElems );
+                    if ( expected.containsKey( key ) )
+                    {
+                        continue;
+                    }
+
+                    long w = random.nextLong() % 3333333L;
+                    String value = "V" + w;
+                    elems[addedElems] = new Tuple<Long, String>( key, value );
+
+                    Tuple<Long, Set<String>> expectedTuple = expected.get( key
);
+
+                    if ( expectedTuple == null )
+                    {
+                        expectedTuple = new Tuple<Long, Set<String>>( key, new
TreeSet<String>() );
+                    }
+
+                    expectedTuple.value.add( value );
+                    expected.put( key, expectedTuple );
+                    addedElems++;
+
+                    if ( addedElems % 100 == 0 )
+                    {
+                        //System.out.println( "Nb added elements = " + addedElems );
+                    }
                 }
-            }
-            long t01 = System.currentTimeMillis();
-
-            System.out.println( "Time to create the " + nbElems + " elements " + ( ( t01
- t00 ) / 1 ) );
-
-            Iterator<Tuple<Long, String>> tupleIterator = new Iterator<Tuple<Long,
String>>()
-            {
-                private int pos = 0;
+                long t01 = System.currentTimeMillis();
 
+                // System.out.println( "Time to create the " + nbElems + " elements " + (
( t01 - t00 ) / 1 ) );
 
-                @Override
-                public Tuple<Long, String> next()
+                Iterator<Tuple<Long, String>> tupleIterator = new Iterator<Tuple<Long,
String>>()
                 {
-                    return elems[pos++];
-                }
+                    private int pos = 0;
 
 
-                @Override
-                public boolean hasNext()
-                {
-                    return pos < elems.length;
-                }
+                    @Override
+                    public Tuple<Long, String> next()
+                    {
+                        return elems[pos++];
+                    }
 
 
-                @Override
-                public void remove()
-                {
-                }
-            };
+                    @Override
+                    public boolean hasNext()
+                    {
+                        return pos < elems.length;
+                    }
 
-            long t0 = System.currentTimeMillis();
-            BTree<Long, String> result = bulkLoader.load( btree, tupleIterator, 65536
);
-            //rm.close();
-            //rm = new RecordManager( file.getAbsolutePath() );
-            //result.close();
 
-            //result = rm.getManagedTree( btree.getName() );
-            long t1 = System.currentTimeMillis();
+                    @Override
+                    public void remove()
+                    {
+                    }
+                };
 
-            System.out.println( "Time to bulkoad the " + nbElems + " elements " + ( ( t1
- t0 ) / 1 ) );
+                long t0 = System.currentTimeMillis();
+                BTree<Long, String> result = bulkLoader.load( btree, tupleIterator,
128 );
+                long t1 = System.currentTimeMillis();
 
-            TupleCursor<Long, String> cursor = result.browse();
-            int nbFetched = 0;
+                System.out.println( "== Btree #" + i + ", Time to bulkoad the " + nbElems
+ " elements "
+                    + ( t1 - t0 ) + "ms" );
 
-            long t2 = System.currentTimeMillis();
+                TupleCursor<Long, String> cursor = result.browse();
+                int nbFetched = 0;
 
-            while ( cursor.hasNext() )
-            {
-                Tuple<Long, String> elem = cursor.next();
+                long t2 = System.currentTimeMillis();
 
-                assertTrue( expected.containsKey( elem.key ) );
-                Tuple<Long, Set<String>> tuple = expected.get( elem.key );
-                assertNotNull( tuple );
-                nbFetched++;
-
-                //System.out.println( "Read tuple : " + tuple );
-                /*
-                for ( String value : elem.value )
+                while ( cursor.hasNext() )
                 {
-                    assertTrue( tuple.value.contains( value ) );
+                    Tuple<Long, String> elem = cursor.next();
+
+                    assertTrue( expected.containsKey( elem.key ) );
+                    Tuple<Long, Set<String>> tuple = expected.get( elem.key );
+                    assertNotNull( tuple );
+                    nbFetched++;
                 }
-                */
-            }
 
-            long t3 = System.currentTimeMillis();
+                long t3 = System.currentTimeMillis();
 
-            System.out.println( "Time to read the " + nbElems + " elements " + ( t3 - t2
) );
-            assertEquals( nbElems, nbFetched );
+                //System.out.println( "Time to read the " + nbElems + " elements " + ( t3
- t2 ) );
+                assertEquals( nbElems, nbFetched );
 
-            checkBtree( btree, result );
+                checkBtree( btree, result );
+            }
+            finally
+            {
+                file.delete();
+            }
         }
     }
 
@@ -426,47 +416,54 @@ public class BulkLoaderTest
         File file = File.createTempFile( "managedbtreebuilder", ".data" );
         file.deleteOnExit();
 
-        RecordManager rm = new RecordManager( file.getAbsolutePath() );
-        PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String> )
rm.addBTree( "test",
-            LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
+        try
+        {
+            RecordManager rm = new RecordManager( file.getAbsolutePath() );
+            PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String>
) rm.addBTree( "test",
+                LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
+
+            BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
 
-        BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
+            int[] expectedNbPages = new int[]
+                {
+                    0,
+                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+                    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+                    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
+            };
 
-        int[] expectedNbPages = new int[]
-            {
-                0,
-                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
-        };
+            int[] expectedLimit = new int[]
+                {
+                    0,
+                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+                    0, 0, 0, 0, 0, 0, 0, 16, 16, 16, 16, 16, 16, 16, 16, 32,
+                    16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 48
+            };
 
-        int[] expectedLimit = new int[]
-            {
-                0,
-                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
-                0, 0, 0, 0, 0, 0, 0, 16, 16, 16, 16, 16, 16, 16, 16, 32,
-                16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 48
-        };
+            int[] expectedKeys = new int[]
+                {
+                    0,
+                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+                    9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+                    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
+            };
 
-        int[] expectedKeys = new int[]
+            for ( int i = 0; i < 49; i++ )
             {
-                0,
-                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
-                9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-                16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
-        };
-
-        for ( int i = 0; i < 49; i++ )
-        {
-            System.out.println( "=======================================" );
-            System.out.println( "== Iteration n#" + i );
-            System.out.println( "=======================================" );
-
-            BulkLoader<Long, String>.LevelInfo leafInfo = bulkLoader.computeLevel(
btree, i, LevelEnum.LEAF );
-
-            assertEquals( expectedNbPages[i], leafInfo.nbPages );
-            assertEquals( expectedLimit[i], leafInfo.nbElemsLimit );
-            assertEquals( expectedKeys[i], leafInfo.currentPage.getNbElems() );
+                System.out.println( "=======================================" );
+                System.out.println( "== Iteration n#" + i );
+                System.out.println( "=======================================" );
+
+                BulkLoader<Long, String>.LevelInfo leafInfo = bulkLoader.computeLevel(
btree, i, LevelEnum.LEAF );
+
+                assertEquals( expectedNbPages[i], leafInfo.nbPages );
+                assertEquals( expectedLimit[i], leafInfo.nbElemsLimit );
+                assertEquals( expectedKeys[i], leafInfo.currentPage.getNbElems() );
+            }
+        }
+        finally
+        {
+            file.delete();
         }
     }
 
@@ -482,45 +479,52 @@ public class BulkLoaderTest
         File file = File.createTempFile( "managedbtreebuilder", ".data" );
         file.deleteOnExit();
 
-        RecordManager rm = new RecordManager( file.getAbsolutePath() );
-        PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String> )
rm.addBTree( "test",
-            LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
+        try
+        {
+            RecordManager rm = new RecordManager( file.getAbsolutePath() );
+            PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String>
) rm.addBTree( "test",
+                LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
 
-        BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
+            BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
 
-        int[] expectedNbPages = new int[]
-            {
-                -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
-        };
+            int[] expectedNbPages = new int[]
+                {
+                    -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+                    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+                    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
+            };
 
-        int[] expectedLimit = new int[]
-            {
-                -1,
-                -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
-                0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 34,
-                17, 17, 17, 17, 17, 17, 17, 17, 34, 34, 34, 34, 34, 34, 34, 34, 51
-        };
+            int[] expectedLimit = new int[]
+                {
+                    -1,
+                    -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
+                    0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 34,
+                    17, 17, 17, 17, 17, 17, 17, 17, 34, 34, 34, 34, 34, 34, 34, 34, 51
+            };
 
-        int[] expectedKeys = new int[]
+            int[] expectedKeys = new int[]
+                {
+                    -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+                    8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+                    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
+            };
+
+            for ( int i = 2; i < 52; i++ )
             {
-                -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
-                8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-                16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
-        };
-
-        for ( int i = 2; i < 52; i++ )
-        {
-            System.out.println( "=======================================" );
-            System.out.println( "== Iteration n#" + i );
-            System.out.println( "=======================================" );
-
-            BulkLoader<Long, String>.LevelInfo nodeInfo = bulkLoader.computeLevel(
btree, i, LevelEnum.NODE );
-
-            assertEquals( expectedNbPages[i], nodeInfo.nbPages );
-            assertEquals( expectedLimit[i], nodeInfo.nbElemsLimit );
-            assertEquals( expectedKeys[i], nodeInfo.currentPage.getNbElems() );
+                System.out.println( "=======================================" );
+                System.out.println( "== Iteration n#" + i );
+                System.out.println( "=======================================" );
+
+                BulkLoader<Long, String>.LevelInfo nodeInfo = bulkLoader.computeLevel(
btree, i, LevelEnum.NODE );
+
+                assertEquals( expectedNbPages[i], nodeInfo.nbPages );
+                assertEquals( expectedLimit[i], nodeInfo.nbElemsLimit );
+                assertEquals( expectedKeys[i], nodeInfo.currentPage.getNbElems() );
+            }
+        }
+        finally
+        {
+            file.delete();
         }
     }
 
@@ -536,46 +540,53 @@ public class BulkLoaderTest
         File file = File.createTempFile( "managedbtreebuilder", ".data" );
         file.deleteOnExit();
 
-        RecordManager rm = new RecordManager( file.getAbsolutePath() );
-        PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String> )
rm.addBTree( "test",
-            LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
+        try
+        {
+            RecordManager rm = new RecordManager( file.getAbsolutePath() );
+            PersistedBTree<Long, String> btree = ( PersistedBTree<Long, String>
) rm.addBTree( "test",
+                LongSerializer.INSTANCE, StringSerializer.INSTANCE, false );
 
-        BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
+            BulkLoader<Long, String> bulkLoader = new BulkLoader<Long, String>();
 
-        int[] expectedNbPages = new int[]
-            {
-                -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
-        };
+            int[] expectedNbPages = new int[]
+                {
+                    -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+                    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+                    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
+            };
 
-        int[] expectedLimit = new int[]
-            {
-                -1,
-                -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
-                0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 34,
-                17, 17, 17, 17, 17, 17, 17, 17, 34, 34, 34, 34, 34, 34, 34, 34, 51
-        };
+            int[] expectedLimit = new int[]
+                {
+                    -1,
+                    -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
+                    0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 34,
+                    17, 17, 17, 17, 17, 17, 17, 17, 34, 34, 34, 34, 34, 34, 34, 34, 51
+            };
 
-        int[] expectedKeys = new int[]
-            {
-                -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
-                8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-                16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
-        };
+            int[] expectedKeys = new int[]
+                {
+                    -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+                    8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+                    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
+            };
 
-        for ( int i = 2599; i <= 2599; i++ )
-        {
-            System.out.println( "=======================================" );
-            System.out.println( "== Iteration #" + i );
-            System.out.println( "=======================================" );
+            for ( int i = 2599; i <= 2599; i++ )
+            {
+                System.out.println( "=======================================" );
+                System.out.println( "== Iteration #" + i );
+                System.out.println( "=======================================" );
 
-            List<BulkLoader<Long, String>.LevelInfo> levels = bulkLoader.computeLevels(
btree, i );
+                List<BulkLoader<Long, String>.LevelInfo> levels = bulkLoader.computeLevels(
btree, i );
 
-            for ( BulkLoader<Long, String>.LevelInfo level : levels )
-            {
-                System.out.println( level );
+                for ( BulkLoader<Long, String>.LevelInfo level : levels )
+                {
+                    System.out.println( level );
+                }
             }
         }
+        finally
+        {
+            file.delete();
+        }
     }
 }



Mime
View raw message