Author: kayyagari
Date: Mon Jun  3 17:54:08 2013
New Revision: 1489080

URL: http://svn.apache.org/r1489080
Log:
o added commons-io to use the FileUtils in tests
o added a test for freepage management code

Added:
    
labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/RecordManagerFreePageTest.java
Modified:
    labs/mavibot/trunk/mavibot/pom.xml

Modified: labs/mavibot/trunk/mavibot/pom.xml
URL: 
http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/pom.xml?rev=1489080&r1=1489079&r2=1489080&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/pom.xml (original)
+++ labs/mavibot/trunk/mavibot/pom.xml Mon Jun  3 17:54:08 2013
@@ -51,6 +51,14 @@
       <artifactId>commons-collections</artifactId>
       <version>${commons.collections.version}</version>
     </dependency>
+
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>2.4</version>
+      <scope>test</scope>
+    </dependency>
+    
   </dependencies>
   
   <build>

Added: 
labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/RecordManagerFreePageTest.java
URL: 
http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/RecordManagerFreePageTest.java?rev=1489080&view=auto
==============================================================================
--- 
labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/RecordManagerFreePageTest.java
 (added)
+++ 
labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/RecordManagerFreePageTest.java
 Mon Jun  3 17:54:08 2013
@@ -0,0 +1,181 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.mavibot.btree;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Set;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.mavibot.btree.exception.BTreeAlreadyManagedException;
+import org.apache.mavibot.btree.serializer.LongSerializer;
+import org.apache.mavibot.btree.serializer.StringSerializer;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * test the RecordManager's free page management
+ * 
+ * @author <a href="mailto:[email protected]";>Mavibot labs Project</a>
+ */
+public class RecordManagerFreePageTest
+{
+    private BTree<Long, String> btree = null;
+
+    private RecordManager recordManager1 = null;
+
+    private File dataDir = null;
+
+
+    @Before
+    public void createBTree() throws IOException
+    {
+        dataDir = new File( System.getProperty( "java.io.tmpdir" ) + 
"/recordman" );
+
+        if( dataDir.exists() )
+        {
+            FileUtils.deleteDirectory( dataDir );
+        }
+        
+        dataDir.mkdirs();
+        
+        openRecordManagerAndBtree();
+
+        try
+        {
+            // Create a new BTree
+            btree = ( BTree<Long, String> ) recordManager1.addBTree( "test", 
new LongSerializer(), new StringSerializer(), false );
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( e );
+        }
+    }
+
+
+    private void openRecordManagerAndBtree()
+    {
+        try
+        {
+            if( recordManager1 != null )
+            {
+                recordManager1.close();
+            }
+            
+            // Now, try to reload the file back
+            recordManager1 = new RecordManager( dataDir.getAbsolutePath() );
+            
+            // load the last created btree
+            if( btree != null )
+            {
+                btree = recordManager1.getManagedTree( btree.getName() );
+            }
+        }
+        catch( Exception e )
+        {
+            throw new RuntimeException( e );
+        }
+    }
+
+
+    private int nbElems = 200;//00;
+    
+    /**
+     * Test the creation of a RecordManager, and that we can read it back.  
+     */
+    @Test
+    public void testRecordManager() throws IOException, 
BTreeAlreadyManagedException
+    {
+        assertEquals( 1, recordManager1.getNbManagedTrees() );
+
+        Set<String> managedBTrees = recordManager1.getManagedTrees();
+
+        assertEquals( 1, managedBTrees.size() );
+        assertTrue( managedBTrees.contains( "test" ) );
+
+        int nbError = 0;
+
+        long l1 = System.currentTimeMillis();
+        int n = 0;
+        long delta = l1;
+
+        for ( int i = 0; i < nbElems; i++ )
+        {
+            Long key = ( long ) i;
+            String value = Long.toString( key );
+
+            btree.insert( key, value );
+            if ( i % 10000 == 0 )
+            {
+                if ( n > 0 )
+                {
+                    long t0 = System.currentTimeMillis();
+                    System.out.println( "Written " + i + " elements in : " + ( 
t0 - delta ) + "ms" );
+                    delta = t0;
+                }
+
+                n++;
+            }
+        }
+
+        long l2 = System.currentTimeMillis();
+
+        System.out.println( "Delta : " + ( l2 - l1 ) + ", nbError = " + nbError
+            + ", Nb insertion per second : " + ( ( nbElems ) / ( l2 - l1 ) ) * 
1000 );
+
+        long length = new File( dataDir, "mavibot.db").length();
+        String units = "MB";
+
+        long size = length / (1024 * 1024 );
+
+        if( size == 0 )
+        {
+            size = length / 1024;
+            units = "KB";
+        }
+        
+        System.out.println( size + units );
+        
+        openRecordManagerAndBtree();
+        
+        assertTrue( nbElems == btree.getNbElems() );
+        
+        //FIXME the total number of elements read are not same as the number 
of elements stored
+        Cursor<Long, String> cursor = btree.browse();
+        
+        long i = 0;
+        while( cursor.hasNext() )
+        {
+            Tuple<Long, String> t = cursor.next();
+//            assertEquals( ( Long ) i, t.getKey() );
+//            assertEquals( String.valueOf( i ), t.getValue() );
+            i++;
+        }
+
+        cursor.close();
+
+        System.out.println( "Total number of tuples " + i);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to