directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1811998 - in /directory/mavibot/branches/single-value/mavibot/src: main/java/org/apache/directory/mavibot/btree/ test/java/org/apache/directory/mavibot/btree/
Date Thu, 12 Oct 2017 19:14:09 GMT
Author: elecharny
Date: Thu Oct 12 19:14:09 2017
New Revision: 1811998

URL: http://svn.apache.org/viewvc?rev=1811998&view=rev
Log:
o Fixed tests compilation errors
o Fixes in the MavibotInspector class

Modified:
    directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java
    directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeBuilderTest.java
    directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeTransactionTest.java
    directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerPrivateMethodTest.java

Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java?rev=1811998&r1=1811997&r2=1811998&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java
(original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java
Thu Oct 12 19:14:09 2017
@@ -40,7 +40,6 @@ import org.apache.directory.mavibot.btre
 import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
 import org.apache.directory.mavibot.btree.serializer.LongArraySerializer;
 import org.apache.directory.mavibot.btree.serializer.LongSerializer;
-import org.apache.directory.mavibot.btree.serializer.StringSerializer;
 import org.apache.directory.mavibot.btree.util.Strings;
 
 
@@ -194,7 +193,7 @@ public class MavibotInspector
     /**
      * Check a B-tree
      */
-    public void inspectBTree( RecordManager recordManager, String btree )
+    public void inspectBTree( RecordManager recordManager ) throws IOException
     {
         if ( recordManager == null )
         {
@@ -205,23 +204,26 @@ public class MavibotInspector
         System.out.print( "BTree Name: " );
         String name = readLine();
 
-        BTree<?, ?> pb = ( BTree<?, ?> ) rm.getBtree( recordManagerHeader, name
);
-
-        if ( pb == null )
+        try ( Transaction transaction = rm.beginReadTransaction() )
         {
-            System.out.println( "No BTree exists with the name '" + name + "'" );
-            return;
+            BTree<?, ?> pb = ( BTree<?, ?> ) rm.getBtree( transaction, name,
Long.MAX_VALUE - 1 );
+    
+            if ( pb == null )
+            {
+                System.out.println( "No BTree exists with the name '" + name + "'" );
+                return;
+            }
+    
+            System.out.println( "\nBTree offset: " + String.format( "0x%1$08x", pb.getBtreeOffset()
) );
+            System.out.println( "BTree _info_ offset: " + String.format( "0x%1$08x", pb.getBtreeInfoOffset()
) );
+            System.out.println( "BTree root page offset: " + String.format( "0x%1$08x", pb.getRootPageOffset()
) );
+            System.out.println( "Number of elements present: " + pb.getNbElems() );
+            System.out.println( "BTree Page size: " + pb.getNbElems() );
+            System.out.println( "BTree revision: " + pb.getBtreeHeader().getRevision() );
+            System.out.println( "Key serializer: " + pb.getKeySerializerFQCN() );
+            System.out.println( "Value serializer: " + pb.getValueSerializerFQCN() );
+            System.out.println();
         }
-
-        System.out.println( "\nBTree offset: " + String.format( "0x%1$08x", pb.getBtreeOffset()
) );
-        System.out.println( "BTree _info_ offset: " + String.format( "0x%1$08x", pb.getBtreeInfoOffset()
) );
-        System.out.println( "BTree root page offset: " + String.format( "0x%1$08x", pb.getRootPageOffset()
) );
-        System.out.println( "Number of elements present: " + pb.getNbElems() );
-        System.out.println( "BTree Page size: " + pb.getNbElems() );
-        System.out.println( "BTree revision: " + pb.getRevision() );
-        System.out.println( "Key serializer: " + pb.getKeySerializerFQCN() );
-        System.out.println( "Value serializer: " + pb.getValueSerializerFQCN() );
-        System.out.println();
     }
 
 
@@ -252,7 +254,7 @@ public class MavibotInspector
 
 
     /**
-     * Check the whole file
+     * Check the whole file.
      */
     /* no qualifier */static void check( RecordManager recordManager )
     {
@@ -362,6 +364,17 @@ public class MavibotInspector
     }
     
     
+    /**
+     * Dump the Mavibot file infos :
+     * <ul>
+     *   <li>The recordManager header</li>
+     *   <li><The copiedPages B-tree/li>
+     *   <li>The B-tree of B-trees</li>
+     * </ul>
+     * @param recordManager The recordMnaager instance
+     * @param recordManagerHeader The current RecordManagerHeader 
+     * @throws Exception
+     */
     public static void dumpInfos( RecordManager recordManager, RecordManagerHeader recordManagerHeader
) throws Exception
     {
         StringBuilder sb = new StringBuilder();
@@ -1988,7 +2001,7 @@ public class MavibotInspector
             switch ( c )
             {
                 case 'n':
-                    printNumberOfBTrees();
+                    printNumberOfBTrees( rm.getCurrentRecordManagerHeader() );
                     break;
 
                 case 'b':
@@ -1996,7 +2009,7 @@ public class MavibotInspector
                     break;
 
                 case 'i':
-                    inspectBTree();
+                    inspectBTree( rm );
                     break;
 
                 case 'c':
@@ -2125,17 +2138,13 @@ public class MavibotInspector
             return;
         }
         
-        PageIO io = rm.fetchPage( recordManagerHeader.pageSize, offset );
+        PageIO io = rm.fetchPageIO( recordManagerHeader.pageSize, offset );
 
         List<Long> ll = new ArrayList<Long>();
         ll.add( offset );
         
         do
         {
-//            System.out.println( "Next Page: " + next );
-//            System.out.println( "Size: " + io.getSize() );
-//            ByteBuffer data = io.getData();
-            
             long next = io.getNextPage();
             ll.add( next );
             if ( next == -1 )
@@ -2143,7 +2152,7 @@ public class MavibotInspector
                 break;
             }
             
-            io = rm.fetchPage( recordManagerHeader.pageSize, next );
+            io = rm.fetchPageIO( recordManagerHeader.pageSize, next );
         }
         while( true );
         

Modified: directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeBuilderTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeBuilderTest.java?rev=1811998&r1=1811997&r2=1811998&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeBuilderTest.java
(original)
+++ directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeBuilderTest.java
Thu Oct 12 19:14:09 2017
@@ -28,7 +28,6 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.directory.mavibot.btree.serializer.IntSerializer;
-import org.junit.Ignore;
 import org.junit.Test;
 
 
@@ -60,16 +59,10 @@ public class BTreeBuilderTest
             RecordManager rm = new RecordManager( file.getAbsolutePath() );
 
             IntSerializer ser = IntSerializer.INSTANCE;
-            /*
-            BTreeBuilder<Integer, Integer> bb = new BTreeBuilder<Integer, Integer>(
rm, "master", 4,
-                ser,
-                ser );
-                */
-
             System.out.println( "Init" );
             System.out.println( "-----------------------------------------------------------"
);
 
-            MavibotInspector.dumpInfos( rm, rm.getRecordManagerHeader() );
+            MavibotInspector.dumpInfos( rm, rm.getCurrentRecordManagerHeader() );
 
             System.out.println( "-----------------------------------------------------------"
);
             System.out.println();
@@ -84,7 +77,7 @@ public class BTreeBuilderTest
                 btree = rm.addBTree( writeTxn, "master", IntSerializer.INSTANCE, IntSerializer.INSTANCE,
true );
             }
 
-            MavibotInspector.dumpInfos( rm, rm.getRecordManagerHeader() );
+            MavibotInspector.dumpInfos( rm, rm.getCurrentRecordManagerHeader() );
             
             System.out.println( "-----------------------------------------------------------"
);
             System.out.println();
@@ -101,14 +94,14 @@ public class BTreeBuilderTest
                 //btree = bb.build( writeTxn, sortedTuple.iterator() );
             }
 
-            MavibotInspector.dumpInfos( rm, rm.getRecordManagerHeader() );
+            MavibotInspector.dumpInfos( rm, rm.getCurrentRecordManagerHeader() );
             
             System.out.println( "-----------------------------------------------------------"
);
             rm.close();
 
             rm = new RecordManager( file.getAbsolutePath() );
             
-            MavibotInspector.dumpInfos( rm, rm.getRecordManagerHeader() );
+            MavibotInspector.dumpInfos( rm, rm.getCurrentRecordManagerHeader() );
             
             try ( Transaction txn = rm.beginReadTransaction() )
             {
@@ -116,9 +109,9 @@ public class BTreeBuilderTest
     
                 assertEquals( 7, btree.getRootPage().getPageNbElems() );
     
-                assertEquals( 7, btree.getRootPage().findRightMost().getKey().intValue()
);
+                assertEquals( 7, btree.getRootPage().findRightMost( txn ).getKey().intValue()
);
     
-                assertEquals( 1, btree.getRootPage().findLeftMost().getKey().intValue() );
+                assertEquals( 1, btree.getRootPage().findLeftMost( txn ).getKey().intValue()
);
     
                 TupleCursor<Integer, Integer> cursor = btree.browse( txn );
                 int i = 0;

Modified: directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeTransactionTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeTransactionTest.java?rev=1811998&r1=1811997&r2=1811998&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeTransactionTest.java
(original)
+++ directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeTransactionTest.java
Thu Oct 12 19:14:09 2017
@@ -19,8 +19,6 @@
  */
 package org.apache.directory.mavibot.btree;
 
-import static org.junit.Assert.assertTrue;
-
 import java.io.File;
 import java.io.IOException;
 import java.util.UUID;
@@ -56,10 +54,10 @@ public class BTreeTransactionTest
 
         openRecordManagerAndBtrees();
 
-        try
+        try ( WriteTransaction writeTransaction = recordManager.beginWriteTransaction() )
         {
             // Create a new BTree with transaction and another one without
-            btree = recordManager.addBTree( "testWithTxn", LongSerializer.INSTANCE, StringSerializer.INSTANCE,
false );
+            btree = recordManager.addBTree( writeTransaction, "testWithTxn", LongSerializer.INSTANCE,
StringSerializer.INSTANCE, false );
         }
         catch ( Exception e )
         {
@@ -111,7 +109,6 @@ public class BTreeTransactionTest
 
 
     @Test
-    @Ignore("Fails atm")
     public void testWithTransaction() throws IOException
     {
         long nbIteration = 100_000L;

Modified: directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerPrivateMethodTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerPrivateMethodTest.java?rev=1811998&r1=1811997&r2=1811998&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerPrivateMethodTest.java
(original)
+++ directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerPrivateMethodTest.java
Thu Oct 12 19:14:09 2017
@@ -65,7 +65,10 @@ public class RecordManagerPrivateMethodT
         recordManager = new RecordManager( dataDir.getAbsolutePath(), 32 );
 
         // Create a new BTree
-        btree = recordManager.addBTree( "test", LongSerializer.INSTANCE, StringSerializer.INSTANCE,
false );
+        try ( WriteTransaction writeTransaction = recordManager.beginWriteTransaction() )
+        { 
+            btree = recordManager.addBTree( writeTransaction, "test", LongSerializer.INSTANCE,
StringSerializer.INSTANCE, false );
+        }
     }
 
 
@@ -83,28 +86,32 @@ public class RecordManagerPrivateMethodT
     public void testGetFreePageIos() throws IOException, NoSuchMethodException, InvocationTargetException,
         IllegalAccessException
     {
-        Method getFreePageIOsMethod = RecordManager.class.getDeclaredMethod( "getFreePageIOs",
int.class );
+        Method getFreePageIOsMethod = RecordManager.class.getDeclaredMethod( "getFreePageIOs",
RecordManagerHeader.class, int.class );
         getFreePageIOsMethod.setAccessible( true );
 
-        PageIO[] pages = ( org.apache.directory.mavibot.btree.PageIO[] ) getFreePageIOsMethod.invoke(
recordManager, 0 );
+        PageIO[] pages = ( org.apache.directory.mavibot.btree.PageIO[] ) getFreePageIOsMethod.invoke(
recordManager, 
+            recordManager.getCurrentRecordManagerHeader(), 0 );
 
         assertEquals( 0, pages.length );
 
         for ( int i = 1; i <= 52; i++ )
         {
-            pages = ( org.apache.directory.mavibot.btree.PageIO[] ) getFreePageIOsMethod.invoke(
recordManager, i );
+            pages = ( org.apache.directory.mavibot.btree.PageIO[] ) getFreePageIOsMethod.invoke(
recordManager, 
+                recordManager.getCurrentRecordManagerHeader(), i );
             assertEquals( 1, pages.length );
         }
 
         for ( int i = 53; i <= 108; i++ )
         {
-            pages = ( org.apache.directory.mavibot.btree.PageIO[] ) getFreePageIOsMethod.invoke(
recordManager, i );
+            pages = ( org.apache.directory.mavibot.btree.PageIO[] ) getFreePageIOsMethod.invoke(
recordManager, 
+                recordManager.getCurrentRecordManagerHeader(), i );
             assertEquals( 2, pages.length );
         }
 
         for ( int i = 109; i <= 164; i++ )
         {
-            pages = ( org.apache.directory.mavibot.btree.PageIO[] ) getFreePageIOsMethod.invoke(
recordManager, i );
+            pages = ( org.apache.directory.mavibot.btree.PageIO[] ) getFreePageIOsMethod.invoke(
recordManager, 
+                recordManager.getCurrentRecordManagerHeader(), i );
             assertEquals( 3, pages.length );
         }
 
@@ -119,24 +126,28 @@ public class RecordManagerPrivateMethodT
     public void testComputeNbPages() throws IOException, SecurityException, NoSuchMethodException,
         IllegalArgumentException, IllegalAccessException, InvocationTargetException
     {
-        Method computeNbPagesMethod = RecordManager.class.getDeclaredMethod( "computeNbPages",
int.class );
+        Method computeNbPagesMethod = RecordManager.class.getDeclaredMethod( "computeNbPages",
RecordManagerHeader.class, int.class );
         computeNbPagesMethod.setAccessible( true );
 
-        assertEquals( 0, ( ( Integer ) computeNbPagesMethod.invoke( recordManager, 0 ) ).intValue()
);
+        assertEquals( 0, ( ( Integer ) computeNbPagesMethod.invoke( recordManager, 
+            recordManager.getCurrentRecordManagerHeader(), 0 ) ).intValue() );
 
         for ( int i = 1; i < 53; i++ )
         {
-            assertEquals( 1, ( ( Integer ) computeNbPagesMethod.invoke( recordManager, i
) ).intValue() );
+            assertEquals( 1, ( ( Integer ) computeNbPagesMethod.invoke( recordManager, 
+                recordManager.getCurrentRecordManagerHeader(), i ) ).intValue() );
         }
 
         for ( int i = 53; i < 109; i++ )
         {
-            assertEquals( 2, ( ( Integer ) computeNbPagesMethod.invoke( recordManager, i
) ).intValue() );
+            assertEquals( 2, ( ( Integer ) computeNbPagesMethod.invoke( recordManager, 
+                recordManager.getCurrentRecordManagerHeader(), i ) ).intValue() );
         }
 
         for ( int i = 109; i < 164; i++ )
         {
-            assertEquals( 3, ( ( Integer ) computeNbPagesMethod.invoke( recordManager, i
) ).intValue() );
+            assertEquals( 3, ( ( Integer ) computeNbPagesMethod.invoke( recordManager, 
+                recordManager.getCurrentRecordManagerHeader(), i ) ).intValue() );
         }
 
         btree.close();



Mime
View raw message