directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1227603 - in /directory/apacheds/branches/apacheds-txns/core-shared/src: main/java/org/apache/directory/server/core/shared/txn/logedit/ test/java/org/apache/directory/server/core/shared/txn/
Date Thu, 05 Jan 2012 14:17:24 GMT
Author: elecharny
Date: Thu Jan  5 14:17:23 2012
New Revision: 1227603

URL: http://svn.apache.org/viewvc?rev=1227603&view=rev
Log:
o Made the DataChangeContainer take only a partition as a parameter, so that we don't have
NPE in the tests when no partition is defined
o Modified the tests to run without any NPE : definded some mock object for that purpose.

Added:
    directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/AbstractPartitionTest.java
    directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockIndex.java
    directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockMasterTable.java
    directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockPartition.java
Removed:
    directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/LongComparator.java
    directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/LongSerializer.java
Modified:
    directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/DataChangeContainer.java
    directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/DefaultTxnManagerTest.java
    directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/EntryUpdateMergeTest.java
    directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapperTest.java
    directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnIndexCursorTest.java

Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/DataChangeContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/DataChangeContainer.java?rev=1227603&r1=1227602&r2=1227603&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/DataChangeContainer.java
(original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/DataChangeContainer.java
Thu Jan  5 14:17:23 2012
@@ -68,7 +68,6 @@ public class DataChangeContainer extends
     //For externalizable
     public DataChangeContainer()
     {
-
     }
 
 
@@ -79,12 +78,6 @@ public class DataChangeContainer extends
     }
 
 
-    public DataChangeContainer( Dn partitionDn )
-    {
-        this.partitionDn = partitionDn;
-    }
-
-
     public long getTxnID()
     {
         return txnID;

Added: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/AbstractPartitionTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/AbstractPartitionTest.java?rev=1227603&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/AbstractPartitionTest.java
(added)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/AbstractPartitionTest.java
Thu Jan  5 14:17:23 2012
@@ -0,0 +1,43 @@
+/*
+ *  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.server.core.shared.txn;
+
+
+import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.name.Dn;
+
+
+/**
+ * A base class used by the tests which need a partition.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AbstractPartitionTest
+{
+    /** A partition for this test */
+    protected Partition partition;
+
+
+    public void setup( Dn dn ) throws LdapInvalidDnException
+    {
+        partition = new MockPartition( dn );
+    }
+}

Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/DefaultTxnManagerTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/DefaultTxnManagerTest.java?rev=1227603&r1=1227602&r2=1227603&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/DefaultTxnManagerTest.java
(original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/DefaultTxnManagerTest.java
Thu Jan  5 14:17:23 2012
@@ -37,6 +37,7 @@ import org.junit.rules.TemporaryFolder;
 
 
 /**
+ * A test for the TxnManager class
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -54,6 +55,7 @@ public class DefaultTxnManagerTest
     /** Txn manager */
     private TxnManagerInternal txnManager;
 
+    /** Creates a temporary folder for each test */
     @Rule
     public TemporaryFolder folder = new TemporaryFolder();
 
@@ -100,19 +102,19 @@ public class DefaultTxnManagerTest
         {
             txnManager.beginTransaction( true );
 
-            assertTrue( txnManager.getCurTxn() != null );
-            assertTrue( txnManager.getCurTxn() instanceof ReadOnlyTxn );
+            Transaction transaction = txnManager.getCurTxn();
+
+            assertTrue( transaction != null );
+            assertTrue( transaction instanceof ReadOnlyTxn );
 
             txnManager.commitTransaction();
         }
         catch ( TxnConflictException e )
         {
-            e.printStackTrace();
             fail();
         }
         catch ( IOException e )
         {
-            e.printStackTrace();
             fail();
         }
     }
@@ -125,14 +127,15 @@ public class DefaultTxnManagerTest
         {
             txnManager.beginTransaction( true );
 
-            assertTrue( txnManager.getCurTxn() != null );
-            assertTrue( txnManager.getCurTxn() instanceof ReadOnlyTxn );
+            Transaction transaction = txnManager.getCurTxn();
+
+            assertTrue( transaction != null );
+            assertTrue( transaction instanceof ReadOnlyTxn );
 
             txnManager.abortTransaction();
         }
         catch ( Exception e )
         {
-            e.printStackTrace();
             fail();
         }
     }
@@ -145,19 +148,19 @@ public class DefaultTxnManagerTest
         {
             txnManager.beginTransaction( false );
 
-            assertTrue( txnManager.getCurTxn() != null );
-            assertTrue( txnManager.getCurTxn() instanceof ReadWriteTxn );
+            Transaction transaction = txnManager.getCurTxn();
+
+            assertTrue( transaction != null );
+            assertTrue( transaction instanceof ReadWriteTxn );
 
             txnManager.commitTransaction();
         }
         catch ( TxnConflictException e )
         {
-            e.printStackTrace();
             fail();
         }
         catch ( Exception e )
         {
-            e.printStackTrace();
             fail();
         }
     }
@@ -170,14 +173,15 @@ public class DefaultTxnManagerTest
         {
             txnManager.beginTransaction( false );
 
-            assertTrue( txnManager.getCurTxn() != null );
-            assertTrue( txnManager.getCurTxn() instanceof ReadWriteTxn );
+            Transaction transaction = txnManager.getCurTxn();
+
+            assertTrue( transaction != null );
+            assertTrue( transaction instanceof ReadWriteTxn );
 
             txnManager.abortTransaction();
         }
         catch ( Exception e )
         {
-            e.printStackTrace();
             fail();
         }
     }
@@ -189,49 +193,44 @@ public class DefaultTxnManagerTest
         List<ReadWriteTxn> dependentTxns;
         try
         {
-            Transaction txn1 = null;
             txnManager.beginTransaction( false );
-            txn1 = txnManager.getCurTxn();
+            Transaction txn1 = txnManager.getCurTxn();
             txnManager.commitTransaction();
 
-            Transaction txn2 = null;
             txnManager.beginTransaction( false );
-            txn2 = txnManager.getCurTxn();
+            Transaction txn2 = txnManager.getCurTxn();
             txnManager.commitTransaction();
 
-            Transaction txn3 = null;
             txnManager.beginTransaction( true );
-            txn3 = txnManager.getCurTxn();
+            Transaction txn3 = txnManager.getCurTxn();
 
             dependentTxns = txn3.getTxnsToCheck();
+
             assertTrue( dependentTxns.contains( txn1 ) );
             assertTrue( dependentTxns.contains( txn2 ) );
             assertTrue( dependentTxns.contains( txn3 ) == false );
 
             txnManager.commitTransaction();
 
-            Transaction txn4 = null;
             txnManager.beginTransaction( false );
-            txn4 = txnManager.getCurTxn();;
+            Transaction txn4 = txnManager.getCurTxn();
+
             dependentTxns = txn4.getTxnsToCheck();
+
             assertTrue( dependentTxns.contains( txn1 ) );
             assertTrue( dependentTxns.contains( txn2 ) );
             assertTrue( dependentTxns.contains( txn3 ) == false );
             assertTrue( dependentTxns.contains( txn4 ) );
 
             txnManager.commitTransaction();
-
         }
         catch ( TxnConflictException e )
         {
-            e.printStackTrace();
             fail();
         }
         catch ( Exception e )
         {
-            e.printStackTrace();
             fail();
         }
     }
-
 }

Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/EntryUpdateMergeTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/EntryUpdateMergeTest.java?rev=1227603&r1=1227602&r2=1227603&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/EntryUpdateMergeTest.java
(original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/EntryUpdateMergeTest.java
Thu Jan  5 14:17:23 2012
@@ -52,10 +52,11 @@ import org.junit.rules.TemporaryFolder;
 
 
 /**
- * 
+ * TODO Add header
+ *  
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class EntryUpdateMergeTest
+public class EntryUpdateMergeTest extends AbstractPartitionTest
 {
     /** Test partition Dn */
     private Dn dn;
@@ -118,15 +119,36 @@ public class EntryUpdateMergeTest
     }
 
 
+    /**
+     * Utility method to create a new entry
+     */
+    private Entry createEntry( UUID id ) throws Exception
+    {
+        String user = id.toString();
+
+        String dn = "cn=" + user + ",ou=department";
+
+        DefaultEntry entry = new DefaultEntry(
+            schemaManager,
+            dn,
+            "objectClass: person",
+            "cn", user,
+            "sn", user );
+
+        return entry;
+    }
+
+
     @Before
     public void setup() throws IOException, InvalidLogException
     {
         try
         {
+            schemaManager = new DefaultSchemaManager();
+
             // Init the partition dn
-            dn = new Dn( "ou=department" );
+            dn = new Dn( schemaManager, "ou=department" );
 
-            schemaManager = new DefaultSchemaManager();
             SN_AT = schemaManager.getAttributeType( "sn" );
             GN_AT = schemaManager.getAttributeType( "gn" );
 
@@ -139,54 +161,75 @@ public class EntryUpdateMergeTest
             toAdd = createEntry( addedEntryId );
             toDelete = createEntry( deletedEntryId );
 
-            // Begin a txn and do some entry changes.
-            DataChangeContainer changeContainer = new DataChangeContainer( dn );
+            super.setup( dn );
+
+            // Inject the entries in the Master table (except the entry that we will add)
+            partition.getMasterTable().put( updatedEntryId, toUpdate );
+            partition.getMasterTable().put( deletedEntryId, toDelete );
+
+            // Begin a txn and do some entry changes on the UpdatedEntry
+            DataChangeContainer changeContainer = new DataChangeContainer( partition );
             changeContainer.setEntryID( updatedEntryId );
-            txnManager.beginTransaction( false );
 
-            Attribute attribute = new DefaultAttribute( "sn", SN_AT );
-            attribute.add( "test2" );
+            {
+                txnManager.beginTransaction( false );
 
-            Modification redo = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE,
attribute );
-            Modification undo = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE,
attribute );
-            EntryChange eChange = new EntryChange( redo, undo );
+                // Add a SN value on an existing SN attribute
+                Attribute attribute = new DefaultAttribute( "sn", SN_AT );
+                attribute.add( "test2" );
 
-            changeContainer.getChanges().add( eChange );
+                Modification redo = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE,
attribute );
+                Modification undo = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE,
attribute );
+                EntryChange eChange = new EntryChange( redo, undo );
 
-            txnLogManager.log( changeContainer, false );
-            txnManager.commitTransaction();
+                changeContainer.getChanges().add( eChange );
 
-            txnManager.beginTransaction( false );
+                txnLogManager.log( changeContainer, false );
+                txnManager.commitTransaction();
+            }
 
-            changeContainer = new DataChangeContainer( dn );
-            changeContainer.setEntryID( updatedEntryId );
-            attribute = new DefaultAttribute( "gn", GN_AT );
-            attribute.add( "test3" );
+            // Do a second change on the UpdatedEntry
+            {
+                txnManager.beginTransaction( false );
 
-            redo = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attribute
);
-            undo = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attribute
);
-            eChange = new EntryChange( redo, undo );
-
-            changeContainer.getChanges().add( eChange );
-            txnLogManager.log( changeContainer, false );
-
-            changeContainer = new DataChangeContainer( dn );
-            changeContainer.setEntryID( addedEntryId );
-            EntryAddDelete eAdd = new EntryAddDelete( toAdd, EntryAddDelete.Type.ADD );
+                changeContainer = new DataChangeContainer( partition );
+                changeContainer.setEntryID( updatedEntryId );
 
-            changeContainer.getChanges().add( eAdd );
-            txnLogManager.log( changeContainer, false );
+                // Add a GN attribute
+                Attribute attribute = new DefaultAttribute( "gn", GN_AT );
+                attribute.add( "test3" );
 
-            txnManager.commitTransaction();
+                Modification redo = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE,
attribute );
+                Modification undo = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE,
attribute );
+                EntryChange eChange = new EntryChange( redo, undo );
 
-            txnManager.beginTransaction( false );
+                changeContainer.getChanges().add( eChange );
+                txnLogManager.log( changeContainer, false );
 
-            changeContainer = new DataChangeContainer( dn );
-            changeContainer.setEntryID( deletedEntryId );
-            EntryAddDelete eDelete = new EntryAddDelete( toDelete, EntryAddDelete.Type.DELETE
);
+                // Now, add a new entry (AddEntry)
+                changeContainer = new DataChangeContainer( partition );
+                changeContainer.setEntryID( addedEntryId );
+                EntryAddDelete eAdd = new EntryAddDelete( toAdd, EntryAddDelete.Type.ADD
);
 
-            changeContainer.getChanges().add( eDelete );
-            txnLogManager.log( changeContainer, false );
+                changeContainer.getChanges().add( eAdd );
+                txnLogManager.log( changeContainer, false );
+
+                txnManager.commitTransaction();
+            }
+
+            // Do a third change : delete an entry
+            {
+                txnManager.beginTransaction( false );
+
+                changeContainer = new DataChangeContainer( partition );
+                changeContainer.setEntryID( deletedEntryId );
+                EntryAddDelete eDelete = new EntryAddDelete( toDelete, EntryAddDelete.Type.DELETE
);
+
+                changeContainer.getChanges().add( eDelete );
+                txnLogManager.log( changeContainer, false );
+            }
+
+            // Note : the transaction remains open. It will be committed by the teardown
method.
 
         }
         catch ( Exception e )
@@ -205,7 +248,6 @@ public class EntryUpdateMergeTest
         }
         catch ( Exception e )
         {
-            e.printStackTrace();
             fail();
         }
 
@@ -220,18 +262,11 @@ public class EntryUpdateMergeTest
         {
             Entry updated = txnLogManager.mergeUpdates( dn, updatedEntryId, toUpdate );
 
-            String value = updated.get( SN_AT ).getString();
-
-            assertTrue( value.equals( "test2" ) );
-
-            value = updated.get( GN_AT ).getString();
-
-            assertTrue( value.equals( "test3" ) );
-
+            assertTrue( updated.contains( SN_AT, "test2", updatedEntryId.toString() ) );
+            assertTrue( updated.contains( GN_AT, "test3" ) );
         }
         catch ( Exception e )
         {
-            e.printStackTrace();
             fail();
         }
     }
@@ -248,7 +283,6 @@ public class EntryUpdateMergeTest
         }
         catch ( Exception e )
         {
-            e.printStackTrace();
             fail();
         }
     }
@@ -265,22 +299,7 @@ public class EntryUpdateMergeTest
         }
         catch ( Exception e )
         {
-            e.printStackTrace();
             fail();
         }
     }
-
-
-    private Entry createEntry( UUID id ) throws Exception
-    {
-        String user = id.toString();
-
-        String dn = "cn=" + user + ",ou=department";
-
-        DefaultEntry entry = new DefaultEntry( schemaManager, dn,
-            "objectClass", "person",
-            "cn", user );
-
-        return entry;
-    }
 }

Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapperTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapperTest.java?rev=1227603&r1=1227602&r2=1227603&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapperTest.java
(original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapperTest.java
Thu Jan  5 14:17:23 2012
@@ -32,14 +32,13 @@ import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.core.api.log.InvalidLogException;
 import org.apache.directory.server.core.api.partition.index.ForwardIndexComparator;
 import org.apache.directory.server.core.api.partition.index.ForwardIndexEntry;
-import org.apache.directory.server.core.api.partition.index.GenericIndex;
 import org.apache.directory.server.core.api.partition.index.IndexCursor;
 import org.apache.directory.server.core.api.partition.index.IndexEntry;
-import org.apache.directory.server.core.api.partition.index.ReverseIndexComparator;
 import org.apache.directory.server.core.api.txn.TxnLogManager;
 import org.apache.directory.server.core.shared.txn.logedit.DataChangeContainer;
 import org.apache.directory.server.core.shared.txn.logedit.IndexChange;
 import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.schema.comparators.LongComparator;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -48,10 +47,11 @@ import org.junit.rules.TemporaryFolder;
 
 
 /**
+ * TODO Add header
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class IndexCursorWrapperTest
+public class IndexCursorWrapperTest extends AbstractPartitionTest
 {
     /** Test partition Dn */
     private Dn dn;
@@ -60,7 +60,7 @@ public class IndexCursorWrapperTest
     private String attributeOid = "mockOid";
 
     /** Mock index with the mock attributeoid */
-    private MockIndex mockIndex = new MockIndex();
+    private MockIndex mockIndex;
 
     /** Log buffer size : 4096 bytes */
     private int logBufferSize = 1 << 12;
@@ -79,7 +79,7 @@ public class IndexCursorWrapperTest
 
     /** index entry comparator */
     private ForwardIndexComparator<?> comparator = new ForwardIndexComparator<Long>(
-        LongComparator.INSTANCE );
+        new LongComparator( null ) );
 
     /** sorted change set for the cursor */
     private TreeSet<IndexEntry<Object>> changedSet;
@@ -123,6 +123,11 @@ public class IndexCursorWrapperTest
             txnManager = txnManagerFactory.txnManagerInternalInstance();
             txnLogManager = txnManagerFactory.txnLogManagerInstance();
 
+            super.setup( dn );
+
+            MockIndex mockIndex = new MockIndex( attributeOid );
+            ( ( MockPartition ) partition ).addIndex( new MockIndex( attributeOid ) );
+
             // Prepare the to be wrapped cursor
             ForwardIndexEntry<Object> idxEntry;
             changedSet = new TreeSet<IndexEntry<Object>>( ( ForwardIndexComparator<Object>
) comparator );
@@ -151,7 +156,7 @@ public class IndexCursorWrapperTest
             IndexChange idxChange;
 
             // Begin a txn and do some index changes.
-            DataChangeContainer changeContainer = new DataChangeContainer( dn );
+            DataChangeContainer changeContainer = new DataChangeContainer( partition );
             txnManager.beginTransaction( false );
 
             // Add (5,5) missing in the original index 
@@ -175,7 +180,7 @@ public class IndexCursorWrapperTest
             txnManager.commitTransaction();
 
             // Begin another txn and do some more index changes
-            changeContainer = new DataChangeContainer( dn );
+            changeContainer = new DataChangeContainer( partition );
             txnManager.beginTransaction( false );
 
             // Add (4,5) already existing in the original index 
@@ -240,23 +245,23 @@ public class IndexCursorWrapperTest
     {
         try
         {
-            cursorWrapper.afterValue( getUUIDString( 0 ), new Long( 0 ) );
+            cursorWrapper.afterValue( getUUIDString( 0 ), 0L );
             assertTrue( cursorWrapper.next() );
 
             IndexEntry<?> next = cursorWrapper.get();
-            assertTrue( next.getValue().equals( new Long( 0 ) ) );
+            assertTrue( next.getValue().equals( 0L ) );
             assertTrue( next.getId().equals( getUUIDString( 1 ) ) );
 
             assertTrue( cursorWrapper.next() );
             next = cursorWrapper.get();
-            assertTrue( next.getValue().equals( new Long( 1 ) ) );
+            assertTrue( next.getValue().equals( 1L ) );
             assertTrue( next.getId().equals( getUUIDString( 1 ) ) );
 
-            cursorWrapper.afterValue( getUUIDString( 5 ), new Long( 4 ) );
+            cursorWrapper.afterValue( getUUIDString( 5 ), 4L );
             assertTrue( cursorWrapper.next() );
 
             next = cursorWrapper.get();
-            assertTrue( next.getValue().equals( new Long( 5 ) ) );
+            assertTrue( next.getValue().equals( 5L ) );
             assertTrue( next.getId().equals( getUUIDString( 5 ) ) );
         }
         catch ( Exception e )
@@ -394,25 +399,4 @@ public class IndexCursorWrapperTest
 
         return new UUID( high, low );
     }
-
-    class MockIndex extends GenericIndex<Long>
-    {
-        public MockIndex()
-        {
-            super( attributeOid );
-        }
-
-
-        public ForwardIndexComparator<Long> getForwardIndexEntryComparator()
-        {
-            return new ForwardIndexComparator<Long>( LongComparator.INSTANCE );
-        }
-
-
-        public ReverseIndexComparator<Long> getReverseIndexEntryComparator()
-        {
-            return new ReverseIndexComparator<Long>( LongComparator.INSTANCE );
-        }
-    }
-
 }

Added: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockIndex.java?rev=1227603&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockIndex.java
(added)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockIndex.java
Thu Jan  5 14:17:23 2012
@@ -0,0 +1,66 @@
+/*
+ *  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.server.core.shared.txn;
+
+
+import java.util.UUID;
+
+import org.apache.directory.server.core.api.partition.index.ForwardIndexComparator;
+import org.apache.directory.server.core.api.partition.index.GenericIndex;
+import org.apache.directory.server.core.api.partition.index.ReverseIndexComparator;
+import org.apache.directory.shared.ldap.model.schema.comparators.LongComparator;
+
+
+/**
+ * A Mock index
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+class MockIndex extends GenericIndex<Long>
+{
+    public MockIndex( String attributeOid )
+    {
+        super( attributeOid );
+    }
+
+
+    public ForwardIndexComparator<Long> getForwardIndexEntryComparator()
+    {
+        return new ForwardIndexComparator<Long>( new LongComparator( attributeId )
);
+    }
+
+
+    public ReverseIndexComparator<Long> getReverseIndexEntryComparator()
+    {
+        return new ReverseIndexComparator<Long>( new LongComparator( attributeId )
);
+    }
+
+
+    public void add( Long attrVal, UUID id ) throws Exception
+    {
+        // Do nothing
+    }
+
+
+    public void drop( Long attrVal, UUID id ) throws Exception
+    {
+        // Do nothing
+    }
+}

Added: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockMasterTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockMasterTable.java?rev=1227603&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockMasterTable.java
(added)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockMasterTable.java
Thu Jan  5 14:17:23 2012
@@ -0,0 +1,233 @@
+/*
+ *  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.server.core.shared.txn;
+
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.directory.server.core.api.partition.index.MasterTable;
+import org.apache.directory.shared.ldap.model.cursor.Cursor;
+import org.apache.directory.shared.ldap.model.cursor.Tuple;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+
+
+/**
+ * A Mock master table
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class MockMasterTable implements MasterTable
+{
+    private Map<UUID, Entry> entries = new HashMap<UUID, Entry>();
+
+
+    @Override
+    public Comparator<UUID> getKeyComparator()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    @Override
+    public Comparator<Entry> getValueComparator()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    @Override
+    public String getName()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    @Override
+    public boolean isDupsEnabled()
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    @Override
+    public boolean has( UUID key ) throws Exception
+    {
+        return entries.containsKey( key );
+    }
+
+
+    @Override
+    public boolean has( UUID key, Entry value ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    @Override
+    public boolean hasGreaterOrEqual( UUID key ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    @Override
+    public boolean hasLessOrEqual( UUID key ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    @Override
+    public boolean hasGreaterOrEqual( UUID key, Entry val ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    @Override
+    public boolean hasLessOrEqual( UUID key, Entry val ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    @Override
+    public Entry get( UUID key ) throws Exception
+    {
+        return entries.get( key );
+    }
+
+
+    @Override
+    public void put( UUID key, Entry value ) throws Exception
+    {
+        entries.put( key, value );
+    }
+
+
+    @Override
+    public void remove( UUID key ) throws Exception
+    {
+        entries.remove( key );
+    }
+
+
+    @Override
+    public void remove( UUID key, Entry value ) throws Exception
+    {
+        // TODO Auto-generated method stub
+    }
+
+
+    @Override
+    public Cursor<Tuple<UUID, Entry>> cursor() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    @Override
+    public Cursor<Tuple<UUID, Entry>> cursor( UUID key ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    @Override
+    public Cursor<Entry> valueCursor( UUID key ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    @Override
+    public int count() throws Exception
+    {
+        return entries.size();
+    }
+
+
+    @Override
+    public int count( UUID key ) throws Exception
+    {
+        if ( entries.containsKey( key ) )
+        {
+            return 1;
+        }
+        else
+        {
+            return 0;
+        }
+    }
+
+
+    @Override
+    public int greaterThanCount( UUID key ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    @Override
+    public int lessThanCount( UUID key ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    @Override
+    public void close() throws Exception
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    public UUID getNextId( Entry entry ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    @Override
+    public void resetCounter() throws Exception
+    {
+        // TODO Auto-generated method stub
+    }
+}

Added: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockPartition.java?rev=1227603&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockPartition.java
(added)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/MockPartition.java
Thu Jan  5 14:17:23 2012
@@ -0,0 +1,216 @@
+/*
+ *  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.server.core.shared.txn;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.naming.InvalidNameException;
+
+import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
+import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.DeleteOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.HasEntryOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.ListOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.MoveAndRenameOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.MoveOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.UnbindOperationContext;
+import org.apache.directory.server.core.api.partition.AbstractPartition;
+import org.apache.directory.server.core.api.partition.index.Index;
+import org.apache.directory.server.core.api.partition.index.IndexNotFoundException;
+import org.apache.directory.server.core.api.partition.index.MasterTable;
+import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.name.Dn;
+
+
+/**
+ * A mock partition
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class MockPartition extends AbstractPartition
+{
+    /** The MockMatserTable */
+    MasterTable master = new MockMasterTable();
+
+    /** The Mock indices */
+    private Map<String, Index<?>> indices = new HashMap<String, Index<?>>();
+
+
+    public MockPartition( Dn dn ) throws LdapInvalidDnException
+    {
+        //try
+        //{
+        setSuffixDn( dn );
+        //}
+    }
+
+
+    @Override
+    public void sync() throws Exception
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    public void delete( DeleteOperationContext deleteContext ) throws LdapException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    public void add( AddOperationContext addContext ) throws LdapException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    public void modify( ModifyOperationContext modifyContext ) throws LdapException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    public EntryFilteringCursor list( ListOperationContext listContext ) throws LdapException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    @Override
+    public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    @Override
+    public Entry lookup( LookupOperationContext lookupContext ) throws LdapException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    @Override
+    public boolean hasEntry( HasEntryOperationContext hasEntryContext ) throws LdapException
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    @Override
+    public void rename( RenameOperationContext renameContext ) throws LdapException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    public void move( MoveOperationContext moveContext ) throws LdapException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws
LdapException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    public void unbind( UnbindOperationContext unbindContext ) throws LdapException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    protected void doDestroy() throws Exception
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    protected void doInit() throws InvalidNameException, Exception
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public MasterTable getMasterTable() throws Exception
+    {
+        return master;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Index<?> getIndex( String oid ) throws IndexNotFoundException
+    {
+        if ( indices.containsKey( oid ) )
+        {
+            return indices.get( oid );
+        }
+
+        throw new IndexNotFoundException( I18n.err( I18n.ERR_3, oid, oid ) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addIndex( Index<?> index ) throws Exception
+    {
+        indices.put( index.getAttributeId(), index );
+    }
+}

Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnIndexCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnIndexCursorTest.java?rev=1227603&r1=1227602&r2=1227603&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnIndexCursorTest.java
(original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnIndexCursorTest.java
Thu Jan  5 14:17:23 2012
@@ -29,6 +29,7 @@ import java.util.UUID;
 import org.apache.directory.server.core.api.partition.index.ForwardIndexComparator;
 import org.apache.directory.server.core.api.partition.index.ForwardIndexEntry;
 import org.apache.directory.server.core.api.partition.index.IndexEntry;
+import org.apache.directory.shared.ldap.model.schema.comparators.LongComparator;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -41,7 +42,7 @@ import org.junit.Test;
 public class TxnIndexCursorTest
 {
     /** index entry comparator */
-    private ForwardIndexComparator<?> comparator = new ForwardIndexComparator<Long>(
LongComparator.INSTANCE );
+    private ForwardIndexComparator<?> comparator = new ForwardIndexComparator<Long>(
new LongComparator( null ) );
 
     /** sorted change set for the cursor */
     private TreeSet<IndexEntry<Object>> changedSet;



Mime
View raw message