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 2014/03/14 01:26:23 UTC
svn commit: r1577389 - in /directory/mavibot/branches/with-txns/mavibot/src:
main/java/org/apache/directory/mavibot/btree/
test/java/org/apache/directory/mavibot/btree/
Author: elecharny
Date: Fri Mar 14 00:26:22 2014
New Revision: 1577389
URL: http://svn.apache.org/r1577389
Log:
o Fixed some tests
o Added the EmptyValueCursor cursor for when we don't have any value to return
o Managed the missing revisions i various method in AbstracBtree
Added:
directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/EmptyValueCursor.java
Modified:
directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java
directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeTestOps.java
directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerTest.java
Modified: directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java?rev=1577389&r1=1577388&r2=1577389&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java (original)
+++ directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java Fri Mar 14 00:26:22 2014
@@ -142,14 +142,21 @@ import org.apache.directory.mavibot.btre
{
ReadTransaction<K, V> transaction = beginReadTransaction();
- ParentPos<K, V>[] stack = (ParentPos<K, V>[]) Array.newInstance( ParentPos.class, 32 );
+ if ( transaction == null )
+ {
+ return new EmptyTupleCursor<K, V>( 0L );
+ }
+ else
+ {
+ ParentPos<K, V>[] stack = (ParentPos<K, V>[]) Array.newInstance( ParentPos.class, 32 );
- TupleCursor<K, V> cursor = transaction.getRootPage().browse( transaction, stack, 0 );
+ TupleCursor<K, V> cursor = transaction.getRootPage().browse( transaction, stack, 0 );
- // Set the position before the first element
- cursor.beforeFirst();
+ // Set the position before the first element
+ cursor.beforeFirst();
- return cursor;
+ return cursor;
+ }
}
@@ -221,13 +228,20 @@ import org.apache.directory.mavibot.btre
{
ReadTransaction<K, V> transaction = beginReadTransaction();
- try
+ if ( transaction == null )
{
- return transaction.getRootPage().contains( key, value );
+ return false;
}
- finally
+ else
{
- transaction.close();
+ try
+ {
+ return transaction.getRootPage().contains( key, value );
+ }
+ finally
+ {
+ transaction.close();
+ }
}
}
@@ -240,13 +254,20 @@ import org.apache.directory.mavibot.btre
// Fetch the root page for this revision
ReadTransaction<K, V> transaction = beginReadTransaction( revision );
- try
+ if ( transaction == null )
{
- return transaction.getRootPage().contains( key, value );
+ return false;
}
- finally
+ else
{
- transaction.close();
+ try
+ {
+ return transaction.getRootPage().contains( key, value );
+ }
+ finally
+ {
+ transaction.close();
+ }
}
}
@@ -344,13 +365,20 @@ import org.apache.directory.mavibot.btre
{
ReadTransaction<K, V> transaction = beginReadTransaction();
- try
+ if ( transaction == null )
{
- return transaction.getRootPage().get( key );
+ return null;
}
- finally
+ else
{
- transaction.close();
+ try
+ {
+ return transaction.getRootPage().get( key );
+ }
+ finally
+ {
+ transaction.close();
+ }
}
}
@@ -399,13 +427,20 @@ import org.apache.directory.mavibot.btre
{
ReadTransaction<K, V> transaction = beginReadTransaction();
- try
+ if ( transaction == null )
{
- return transaction.getRootPage().getValues( key );
+ return new EmptyValueCursor<V>( 0L );
}
- finally
+ else
{
- transaction.close();
+ try
+ {
+ return transaction.getRootPage().getValues( key );
+ }
+ finally
+ {
+ transaction.close();
+ }
}
}
@@ -422,13 +457,20 @@ import org.apache.directory.mavibot.btre
ReadTransaction<K, V> transaction = beginReadTransaction();
- try
+ if ( transaction == null )
{
- return transaction.getRootPage().hasKey( key );
+ return false;
}
- finally
+ else
{
- transaction.close();
+ try
+ {
+ return transaction.getRootPage().hasKey( key );
+ }
+ finally
+ {
+ transaction.close();
+ }
}
}
@@ -445,13 +487,20 @@ import org.apache.directory.mavibot.btre
ReadTransaction<K, V> transaction = beginReadTransaction( revision );
- try
+ if ( transaction == null )
{
- return transaction.getRootPage().hasKey( key );
+ return false;
}
- finally
+ else
{
- transaction.close();
+ try
+ {
+ return transaction.getRootPage().hasKey( key );
+ }
+ finally
+ {
+ transaction.close();
+ }
}
}
@@ -519,13 +568,20 @@ import org.apache.directory.mavibot.btre
{
ReadTransaction<K, V> transaction = beginReadTransaction();
- try
+ if ( transaction == null )
{
- return transaction.getRevision();
+ return -1L;
}
- finally
+ else
{
- transaction.close();
+ try
+ {
+ return transaction.getRevision();
+ }
+ finally
+ {
+ transaction.close();
+ }
}
}
@@ -580,13 +636,20 @@ import org.apache.directory.mavibot.btre
{
ReadTransaction<K, V> transaction = beginReadTransaction();
- try
+ if ( transaction == null )
{
- return transaction.getBtreeHeader().getNbElems();
+ return -1L;
}
- finally
+ else
{
- transaction.close();
+ try
+ {
+ return transaction.getBtreeHeader().getNbElems();
+ }
+ finally
+ {
+ transaction.close();
+ }
}
}
Added: directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/EmptyValueCursor.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/EmptyValueCursor.java?rev=1577389&view=auto
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/EmptyValueCursor.java (added)
+++ directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/EmptyValueCursor.java Fri Mar 14 00:26:22 2014
@@ -0,0 +1,188 @@
+/*
+ * 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.directory.mavibot.btree;
+
+
+import java.io.IOException;
+
+import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
+
+
+/**
+ * A Cursor which is used when we have no value to return
+ * <p>
+ *
+ * @param <K> The type for the Key
+ * @param <V> The type for the stored value
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EmptyValueCursor<V> implements ValueCursor<V>
+{
+ private long revision;
+ private long creationDate;
+
+ /**
+ * Creates a new instance of Cursor, starting on a page at a given position.
+ *
+ * @param transaction The transaction this operation is protected by
+ * @param stack The stack of parent's from root to this page
+ */
+ public EmptyValueCursor( long revision )
+ {
+ super();
+
+ this.revision = revision;
+ creationDate = System.currentTimeMillis();
+ }
+
+
+ /**
+ * Change the position in the current cursor to set it after the last key
+ */
+ public void afterLast() throws IOException
+ {
+ }
+
+
+ /**
+ * Change the position in the current cursor before the first key
+ */
+ public void beforeFirst() throws IOException
+ {
+ }
+
+
+ /**
+ * Tells if the cursor can return a next element
+ *
+ * @return true if there are some more elements
+ * @throws IOException
+ * @throws EndOfFileExceededException
+ */
+ public boolean hasNext() throws EndOfFileExceededException, IOException
+ {
+ return false;
+ }
+
+
+ /**
+ * Tells if the cursor can return a next key
+ *
+ * @return true if there are some more keys
+ * @throws IOException
+ * @throws EndOfFileExceededException
+ */
+ public boolean hasNextKey() throws EndOfFileExceededException, IOException
+ {
+ return false;
+ }
+
+
+ /**
+ * Tells if the cursor can return a previous element
+ *
+ * @return true if there are some more elements
+ * @throws IOException
+ * @throws EndOfFileExceededException
+ */
+ public boolean hasPrev() throws EndOfFileExceededException, IOException
+ {
+ return false;
+ }
+
+
+ /**
+ * Tells if the cursor can return a previous key
+ *
+ * @return true if there are some more keys
+ * @throws IOException
+ * @throws EndOfFileExceededException
+ */
+ public boolean hasPrevKey() throws EndOfFileExceededException, IOException
+ {
+ return false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public V prev() throws EndOfFileExceededException, IOException
+ {
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public V next() throws EndOfFileExceededException, IOException
+ {
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void close()
+ {
+ }
+
+
+ /**
+ * Get the creation date
+ * @return The creation date for this cursor
+ */
+ public long getCreationDate()
+ {
+ return creationDate;
+ }
+
+
+ /**
+ * Get the current revision
+ *
+ * @return The revision this cursor is based on
+ */
+ public long getRevision()
+ {
+ return revision;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int size()
+ {
+ return 0;
+ }
+
+
+ public String toString()
+ {
+ return "EmptyValueCursor";
+ }
+}
Modified: directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeTestOps.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeTestOps.java?rev=1577389&r1=1577388&r2=1577389&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeTestOps.java (original)
+++ directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeTestOps.java Fri Mar 14 00:26:22 2014
@@ -70,7 +70,7 @@ public class InMemoryBTreeTestOps
{
Random random = new Random( System.nanoTime() );
- int nbElems = 500000;
+ int nbElems = 50000;
// Create a BTree with 500 000 entries
btree.setPageSize( 32 );
Modified: directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerTest.java?rev=1577389&r1=1577388&r2=1577389&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerTest.java (original)
+++ directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerTest.java Fri Mar 14 00:26:22 2014
@@ -713,18 +713,18 @@ public class RecordManagerTest
// Check that we can get a value from each revision
// revision 1
assertFalse( btree.contains( rev1, 1L, "V1" ) );
- assertTrue( btree.contains( rev1, 3L, "V3" ) );
+ assertFalse( btree.contains( rev1, 3L, "V3" ) );
assertFalse( btree.contains( rev1, 5L, "V5" ) );
// revision 2
- assertTrue( btree.contains( rev2, 1L, "V1" ) );
- assertTrue( btree.contains( rev2, 3L, "V3" ) );
+ assertFalse( btree.contains( rev2, 1L, "V1" ) );
+ assertFalse( btree.contains( rev2, 3L, "V3" ) );
assertFalse( btree.contains( rev2, 5L, "V5" ) );
// revision 3
- assertTrue( btree.contains( rev3, 1L, "V1" ) );
- assertTrue( btree.contains( rev3, 3L, "V3" ) );
- assertTrue( btree.contains( rev3, 5L, "V5" ) );
+ assertFalse( btree.contains( rev3, 1L, "V1" ) );
+ assertFalse( btree.contains( rev3, 3L, "V3" ) );
+ assertFalse( btree.contains( rev3, 5L, "V5" ) );
// revision 4
assertTrue( btree.contains( rev4, 1L, "V1" ) );
@@ -808,18 +808,18 @@ public class RecordManagerTest
// Check that we can get a value from each revision
// revision 1
assertFalse( btree.hasKey( rev1, 1L ) );
- assertTrue( btree.hasKey( rev1, 3L ) );
+ assertFalse( btree.hasKey( rev1, 3L ) );
assertFalse( btree.hasKey( rev1, 5L ) );
// revision 2
- assertTrue( btree.hasKey( rev2, 1L ) );
- assertTrue( btree.hasKey( rev2, 3L ) );
+ assertFalse( btree.hasKey( rev2, 1L ) );
+ assertFalse( btree.hasKey( rev2, 3L ) );
assertFalse( btree.hasKey( rev2, 5L ) );
// revision 3
- assertTrue( btree.hasKey( rev3, 1L ) );
- assertTrue( btree.hasKey( rev3, 3L ) );
- assertTrue( btree.hasKey( rev3, 5L ) );
+ assertFalse( btree.hasKey( rev3, 1L ) );
+ assertFalse( btree.hasKey( rev3, 3L ) );
+ assertFalse( btree.hasKey( rev3, 5L ) );
// revision 4
assertTrue( btree.hasKey( rev4, 1L ) );