Delete the temporary file after the end of the test
authorEmmanuel Lécharny <elecharny@apache.org>
Tue, 11 Nov 2014 23:12:02 +0000 (23:12 +0000)
committerEmmanuel Lécharny <elecharny@apache.org>
Tue, 11 Nov 2014 23:12:02 +0000 (23:12 +0000)
mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBuilderTest.java

index 6552d8d..44f4eb1 100644 (file)
@@ -37,7 +37,7 @@ import org.junit.Test;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-@Ignore( "until ApacheDS works with mavibot" )
+@Ignore("until ApacheDS works with mavibot")
 public class PersistedBTreeBuilderTest
 {
 
@@ -55,38 +55,46 @@ public class PersistedBTreeBuilderTest
         File file = File.createTempFile( "managedbtreebuilder", ".data" );
         file.deleteOnExit();
 
-        RecordManager rm = new RecordManager( file.getAbsolutePath() );
+        try
+        {
+            RecordManager rm = new RecordManager( file.getAbsolutePath() );
+
+            IntSerializer ser = IntSerializer.INSTANCE;
+            PersistedBTreeBuilder<Integer, Integer> bb = new PersistedBTreeBuilder<Integer, Integer>( rm, "master", 4,
+                ser,
+                ser );
 
-        IntSerializer ser = IntSerializer.INSTANCE;
-        PersistedBTreeBuilder<Integer, Integer> bb = new PersistedBTreeBuilder<Integer, Integer>( rm, "master", 4, ser,
-            ser );
+            // contains 1, 2, 3, 4, 5, 6, 7
+            BTree<Integer, Integer> btree = bb.build( sortedTuple.iterator() );
 
-        // contains 1, 2, 3, 4, 5, 6, 7
-        BTree<Integer, Integer> btree = bb.build( sortedTuple.iterator() );
+            rm.close();
 
-        rm.close();
+            rm = new RecordManager( file.getAbsolutePath() );
+            btree = rm.getManagedTree( "master" );
 
-        rm = new RecordManager( file.getAbsolutePath() );
-        btree = rm.getManagedTree( "master" );
+            assertEquals( 1, btree.getRootPage().getNbElems() );
 
-        assertEquals( 1, btree.getRootPage().getNbElems() );
+            assertEquals( 7, btree.getRootPage().findRightMost().getKey().intValue() );
 
-        assertEquals( 7, btree.getRootPage().findRightMost().getKey().intValue() );
+            assertEquals( 1, btree.getRootPage().findLeftMost().getKey().intValue() );
 
-        assertEquals( 1, btree.getRootPage().findLeftMost().getKey().intValue() );
+            TupleCursor<Integer, Integer> cursor = btree.browse();
+            int i = 0;
 
-        TupleCursor<Integer, Integer> cursor = btree.browse();
-        int i = 0;
+            while ( cursor.hasNext() )
+            {
+                Tuple<Integer, Integer> expected = sortedTuple.get( i++ );
+                Tuple<Integer, Integer> actual = cursor.next();
+                assertEquals( expected.getKey(), actual.getKey() );
+                assertEquals( expected.getValue(), actual.getValue() );
+            }
 
-        while ( cursor.hasNext() )
+            cursor.close();
+            btree.close();
+        }
+        finally
         {
-            Tuple<Integer, Integer> expected = sortedTuple.get( i++ );
-            Tuple<Integer, Integer> actual = cursor.next();
-            assertEquals( expected.getKey(), actual.getKey() );
-            assertEquals( expected.getValue(), actual.getValue() );
+            file.delete();
         }
-
-        cursor.close();
-        btree.close();
     }
 }