directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1659120 - /directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java
Date Thu, 12 Feb 2015 01:30:14 GMT
Author: elecharny
Date: Thu Feb 12 01:30:14 2015
New Revision: 1659120

URL: http://svn.apache.org/r1659120
Log:
Adding a test that checks we can browse a btree with random keys. Currently, this test is
failing, we have some issue in teh way we build the browser.

Modified:
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java?rev=1659120&r1=1659119&r2=1659120&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java
(original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java
Thu Feb 12 01:30:14 2015
@@ -28,8 +28,11 @@ import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
+import java.util.Random;
 import java.util.UUID;
 
 import org.apache.commons.io.FileUtils;
@@ -1162,4 +1165,55 @@ public class PersistedBTreeBrowseTest
             System.out.println( cursor.nextKey() );
         }
     }
+
+
+    /**
+     * Test the browse methods on a btree containing 500 random entries, and 
+     * try to browse it.
+     */
+    @Test
+    public void testBrowseBTree500() throws IOException, BTreeAlreadyManagedException, KeyNotFoundException
+    {
+        List<Long> values = new ArrayList<Long>( 500 );
+        long[] randomVals = new long[500];
+        Random r = new Random( System.currentTimeMillis() );
+
+        // Inject some data
+        for ( long i = 0L; i < 5000L; i++ )
+        {
+            values.add( i );
+        }
+
+        for ( int i = 0; i < 500; i++ )
+        {
+            int index = r.nextInt( 500 - i );
+            randomVals[i] = values.get( index );
+        }
+
+        // Inject some data
+        for ( int i = 0; i < 500; i++ )
+        {
+            btree.insert( randomVals[i], Long.toString( randomVals[i] ) );
+        }
+
+        // Now, browse the BTree starting from 0 to the end
+        for ( long i = 0L; i < 500L; i++ )
+        {
+            System.out.println( "Browsing from " + i );
+            // Create the cursor
+            TupleCursor<Long, String> cursor = btree.browseFrom( i );
+
+            assertTrue( cursor.hasNext() );
+            Long expected = i;
+
+            while ( cursor.hasNext() )
+            {
+                Tuple<Long, String> tuple = cursor.next();
+                assertEquals( expected, tuple.getKey() );
+                expected++;
+            }
+
+            cursor.close();
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message