You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2015/03/01 07:10:41 UTC
svn commit: r1663028 -
/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java
Author: elecharny
Date: Sun Mar 1 06:10:41 2015
New Revision: 1663028
URL: http://svn.apache.org/r1663028
Log:
The browse test with 500 random btrees now test the backward browse too.
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=1663028&r1=1663027&r2=1663028&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 Sun Mar 1 06:10:41 2015
@@ -80,7 +80,6 @@ public class PersistedBTreeBrowseTest
{
// Create a new BTree which allows duplicate values
btree = recordManager1.addBTree( "test", LongSerializer.INSTANCE, StringSerializer.INSTANCE, true );
- //btree.setPageSize( 4 );
}
catch ( Exception e )
{
@@ -1222,6 +1221,7 @@ public class PersistedBTreeBrowseTest
}
long t0 = System.currentTimeMillis();
+
// Now, browse the BTree starting from 0 to the end
for ( Long i = 0L; i < nbKeys; i++ )
{
@@ -1249,93 +1249,45 @@ public class PersistedBTreeBrowseTest
}
long t1 = System.currentTimeMillis();
- System.out.println( " Delta for " + nbValues + " = " + ( t1 - t0 ) );
- }
- finally
- {
- btreeLong.close();
- }
- }
-
-
- /**
- * Test the browse methods on a btree containing 500 random entries, with multiple values, and
- * try to browse it. The key is a complex one
- */
- @Test
- public void testBrowseBTreeComplexKey() throws IOException, BTreeAlreadyManagedException,
- KeyNotFoundException
- {
- /*
- int nbKeys = 500;
- List<Long> values = new ArrayList<Long>( nbKeys );
- long[] randomVals = new long[nbKeys];
- Random r = new Random( System.currentTimeMillis() );
-
- // Create the data to inject into the btree
- for ( long i = 0L; i < nbKeys; i++ )
- {
- values.add( i );
- }
-
- for ( int i = 0; i < nbKeys; i++ )
- {
- int index = r.nextInt( nbKeys - i );
- randomVals[i] = values.get( index );
- values.remove( index );
- }
-
- long sum = 0L;
-
- for ( int i = 0; i < nbKeys; i++ )
- {
- sum += randomVals[i];
- }
+ System.out.println( "Browse Forward for " + nbValues + " = " + ( t1 - t0 ) );
- assertEquals( ( nbKeys * ( nbKeys - 1 ) ) / 2, sum );
+ long t00 = System.currentTimeMillis();
- int nbValues = 9;
-
- // Inject some data
- for ( int i = 0; i < nbKeys; i++ )
- {
- Long value = randomVals[i];
-
- for ( Long j = 0L; j < nbValues; j++ )
+ // Now, browse the BTree starting from 0 to the end
+ for ( Long i = nbKeys - 1L; i >= 0; i-- )
{
- btreeLong.insert( randomVals[i], value + j );
- }
- }
+ // Create the cursor
+ TupleCursor<Long, Long> cursor = btreeLong.browseFrom( i );
- long t0 = System.currentTimeMillis();
- // Now, browse the BTree starting from 0 to the end
- for ( Long i = 0L; i < nbKeys; i++ )
- {
- //System.out.println( "Browsing from " + i );
- // Create the cursor
- TupleCursor<Long, Long> cursor = btreeLong.browseFrom( i );
+ if ( i > 0 )
+ {
+ assertTrue( cursor.hasPrev() );
+ }
- assertTrue( cursor.hasNext() );
- Long expected = i;
+ Long expected = i;
- while ( cursor.hasNext() )
- {
- for ( Long j = 0L; j < nbValues; j++ )
+ while ( cursor.hasPrev() )
{
- Tuple<Long, Long> tuple1 = cursor.next();
+ for ( Long j = Long.valueOf( nbValues - 1 ); j >= 0L; j-- )
+ {
+ Tuple<Long, Long> tuple1 = cursor.prev();
+
+ assertEquals( Long.valueOf( expected - 1L ), tuple1.getKey() );
+ assertEquals( ( Long ) ( expected - 1L + j ), tuple1.getValue() );
+ }
- assertEquals( expected, tuple1.getKey() );
- assertEquals( ( Long ) ( expected + j ), tuple1.getValue() );
+ expected--;
}
- expected++;
+ cursor.close();
}
+ long t11 = System.currentTimeMillis();
- cursor.close();
+ System.out.println( "Browe backward for " + nbValues + " = " + ( t11 - t00 ) );
+ }
+ finally
+ {
+ btreeLong.close();
}
- long t1 = System.currentTimeMillis();
-
- System.out.println( " Delta for " + nbValues + " = " + ( t1 - t0 ) );
- */
}
}
\ No newline at end of file