You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by el...@apache.org on 2012/08/17 18:01:56 UTC
svn commit: r1374337 - in
/labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree:
BTreeConfigurationTest.java BTreeFlushTest.java MultiThreadedBtreeTest.java
Author: elecharny
Date: Fri Aug 17 16:01:56 2012
New Revision: 1374337
URL: http://svn.apache.org/viewvc?rev=1374337&view=rev
Log:
o Cleaned some files when the tests end
o Lowered the number of threads used for the write test
o Created the 5M element BTree only once
Modified:
labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java
labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java
labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/MultiThreadedBtreeTest.java
Modified: labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java?rev=1374337&r1=1374336&r2=1374337&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java (original)
+++ labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java Fri Aug 17 16:01:56 2012
@@ -160,6 +160,7 @@ public class BTreeConfigurationTest
config.setSerializer( new DefaultSerializer<Integer, String>( Integer.class, String.class ) );
config.setFilePath( parent );
+ config.setFileName( "mavibot" );
// Create the BTree
BTree<Integer, String> btree = new BTree<Integer, String>( config );
@@ -181,8 +182,6 @@ public class BTreeConfigurationTest
}
// Flush the data
- btree.flush();
-
btree.close();
// Now, create a new BTree using the same configuration
@@ -200,13 +199,21 @@ public class BTreeConfigurationTest
}
finally
{
- // Erase the mavibot.data file now
- File mavibotFile = new File( parent, "mavibot.data" );
+ // Erase the mavibot file now
+ File mavibotFile = new File( parent, "mavibot" );
if ( mavibotFile.exists() )
{
mavibotFile.delete();
}
+
+ // Erase the journal too
+ File mavibotJournal = new File( parent, "mavibot.log" );
+
+ if ( mavibotJournal.exists() )
+ {
+ mavibotJournal.delete();
+ }
}
}
}
Modified: labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java?rev=1374337&r1=1374336&r2=1374337&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java (original)
+++ labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java Fri Aug 17 16:01:56 2012
@@ -32,6 +32,7 @@ import java.util.Set;
import org.apache.mavibot.btree.comparator.IntComparator;
import org.apache.mavibot.btree.comparator.LongComparator;
import org.apache.mavibot.btree.serializer.DefaultSerializer;
+import org.junit.BeforeClass;
import org.junit.Test;
@@ -42,6 +43,9 @@ import org.junit.Test;
*/
public class BTreeFlushTest
{
+ /** A file containing 5 million elements */
+ private static String data5M;
+
// Some values to inject in a btree
private static int[] sortedValues = new int[]
{
@@ -111,87 +115,7 @@ public class BTreeFlushTest
};
- /**
- * Checks the created BTree contains the expected values
- */
- private boolean checkTreeLong( Set<Long> expected, BTree<Long, String> btree ) throws IOException
- {
- // We loop on all the expected value to see if they have correctly been inserted
- // into the btree
- for ( Long key : expected )
- {
- String value = btree.find( key );
-
- if ( value == null )
- {
- return false;
- }
- }
-
- return true;
- }
-
-
- /**
- * Test the browse method going backward
- * @throws Exception
- */
- @Test
- public void testFlushBTree() throws Exception
- {
- // Create a BTree with pages containing 8 elements
- DefaultSerializer<Integer, String> serializer = new DefaultSerializer<Integer, String>( Integer.class,
- String.class );
-
- // Create the file, it will be deleted on exit
- File file = File.createTempFile( "testFlush", "data" );
- file.deleteOnExit();
-
- BTree<Integer, String> btree = new BTree<Integer, String>( file, new IntComparator(), serializer );
- btree.setPageSize( 8 );
-
- // Inject the values
- for ( int value : sortedValues )
- {
- String strValue = "V" + value;
-
- btree.insert( value, strValue );
- }
-
- // Now, flush the btree
- btree.flush();
-
- // Load the data into a new tree
- BTree<Integer, String> btreeLoaded = new BTree<Integer, String>( file, new IntComparator(), serializer );
- btree.setPageSize( 8 );
-
- Cursor<Integer, String> cursor1 = btree.browse();
- Cursor<Integer, String> cursor2 = btree.browse();
-
- while ( cursor1.hasNext() )
- {
- assertTrue( cursor2.hasNext() );
-
- Tuple<Integer, String> tuple1 = cursor1.next();
- Tuple<Integer, String> tuple2 = cursor2.next();
-
- assertEquals( tuple1.getKey(), tuple2.getKey() );
- assertEquals( tuple1.getValue(), tuple2.getValue() );
- }
-
- assertFalse( cursor2.hasNext() );
-
- btree.close();
- btreeLoaded.close();
- }
-
-
- /**
- * Test the insertion of 5 million elements in a BTree
- * @throws Exception
- */
- @Test
- public void testPageInsert5M() throws Exception
+ private static void create5MElementsFile() throws IOException
{
Random random = new Random( System.nanoTime() );
@@ -202,8 +126,8 @@ public class BTreeFlushTest
long delta = l1;
int nbElems = 5000000;
- BTree<Long, String> btree = new BTree<Long, String>( new LongComparator(), new DefaultSerializer<Long, String>(
- Long.class, String.class ) );
+ BTree<Long, String> btree = new BTree<Long, String>( new LongComparator(),
+ new DefaultSerializer<Long, String>( Long.class, String.class ) );
btree.setPageSize( 32 );
for ( int i = 0; i < nbElems; i++ )
@@ -221,6 +145,7 @@ public class BTreeFlushTest
System.out.println( btree );
System.out.println( "Error while adding " + value );
nbError++;
+
return;
}
@@ -244,7 +169,7 @@ public class BTreeFlushTest
// Now, flush the btree
- File tempFile = File.createTempFile( "mavibot", "tmp" );
+ File tempFile = File.createTempFile( "mavibot", ".tmp" );
tempFile.deleteOnExit();
long t0 = System.currentTimeMillis();
@@ -253,7 +178,128 @@ public class BTreeFlushTest
long t1 = System.currentTimeMillis();
- System.out.println( "Time to flush 5 million elements : " + ( t1 - t0 ) );
+ System.out.println( "Time to flush 5 million elements : " + ( t1 - t0 ) + "ms" );
btree.close();
+
+ data5M = tempFile.getCanonicalPath();
+ }
+
+
+ @BeforeClass
+ public static void setup() throws IOException
+ {
+ create5MElementsFile();
+ }
+
+
+ /**
+ * Checks the created BTree contains the expected values
+ */
+ private boolean checkTreeLong( Set<Long> expected, BTree<Long, String> btree ) throws IOException
+ {
+ // We loop on all the expected value to see if they have correctly been inserted
+ // into the btree
+ for ( Long key : expected )
+ {
+ String value = btree.find( key );
+
+ if ( value == null )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * Test the browse method going backward
+ * @throws Exception
+ */
+ @Test
+ public void testFlushBTree() throws Exception
+ {
+ // Create a BTree with pages containing 8 elements
+ DefaultSerializer<Integer, String> serializer = new DefaultSerializer<Integer, String>( Integer.class,
+ String.class );
+
+ // Create the file, it will be deleted on exit
+ File tempFile = File.createTempFile( "testFlush", null );
+ String path = tempFile.getParent();
+ String fileName = "mavibot";
+ tempFile.delete();
+ File journal = new File( path, fileName + BTree.JOURNAL_SUFFIX );
+ File data = new File( path, fileName + BTree.DATA_SUFFIX );
+
+ try
+ {
+ BTree<Integer, String> btree = new BTree<Integer, String>( path, fileName, new IntComparator(), serializer );
+ btree.setPageSize( 8 );
+
+ // Inject the values
+ for ( int value : sortedValues )
+ {
+ String strValue = "V" + value;
+
+ btree.insert( value, strValue );
+ }
+
+ // The journal must be full
+ assertTrue( journal.length() > 0 );
+
+ // Now, flush the btree
+ btree.flush();
+
+ // The journal must be empty
+ assertEquals( 0, journal.length() );
+
+ // Load the data into a new tree
+ BTree<Integer, String> btreeLoaded = new BTree<Integer, String>( path, fileName, new IntComparator(),
+ serializer );
+ btree.setPageSize( 8 );
+
+ Cursor<Integer, String> cursor1 = btree.browse();
+ Cursor<Integer, String> cursor2 = btree.browse();
+
+ while ( cursor1.hasNext() )
+ {
+ assertTrue( cursor2.hasNext() );
+
+ Tuple<Integer, String> tuple1 = cursor1.next();
+ Tuple<Integer, String> tuple2 = cursor2.next();
+
+ assertEquals( tuple1.getKey(), tuple2.getKey() );
+ assertEquals( tuple1.getValue(), tuple2.getValue() );
+ }
+
+ assertFalse( cursor2.hasNext() );
+
+ btree.close();
+ btreeLoaded.close();
+ }
+ finally
+ {
+ data.delete();
+ journal.delete();
+ }
+ }
+
+
+ /**
+ * Test the insertion of 5 million elements in a BTree
+ * @throws Exception
+ */
+ @Test
+ public void testLoadBTreeFromFile() throws Exception
+ {
+ File dataFile = new File( data5M );
+ BTree<Long, String> btree = new BTree<Long, String>(
+ dataFile.getParent(),
+ dataFile.getName(),
+ new LongComparator(),
+ new DefaultSerializer<Long, String>( Long.class, String.class ) );
+ btree.setPageSize( 32 );
+
}
}
Modified: labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/MultiThreadedBtreeTest.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/MultiThreadedBtreeTest.java?rev=1374337&r1=1374336&r2=1374337&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/MultiThreadedBtreeTest.java (original)
+++ labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/MultiThreadedBtreeTest.java Fri Aug 17 16:01:56 2012
@@ -214,9 +214,11 @@ public class MultiThreadedBtreeTest
@Test
public void testInsertMultiThreads() throws InterruptedException, IOException
{
- int nbThreads = 100;
+ int nbThreads = 20;
final CountDownLatch latch = new CountDownLatch( nbThreads );
+ //Thread.sleep( 60000L );
+
long t0 = System.currentTimeMillis();
for ( int i = 0; i < nbThreads; i++ )
@@ -233,6 +235,14 @@ public class MultiThreadedBtreeTest
{
long value = prefix * 100000 + j;
btree.insert( value, Long.toString( value ) );
+
+ /*
+ if ( j % 10000 == 0 )
+ {
+ System.out.println( "Thread " + Thread.currentThread().getName() + " flushed " + j
+ + " elements" );
+ }
+ */
}
latch.countDown();
@@ -258,7 +268,7 @@ public class MultiThreadedBtreeTest
assertEquals( Long.toString( i ), btree.find( i ) );
}
- System.out.println( " Time to create 10M entries : "
+ System.out.println( " Time to create 1M entries : "
+ ( ( t1 - t0 ) / 1000 ) + " seconds" );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org