directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r638165 - in /directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src: main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/
Date Tue, 18 Mar 2008 01:33:33 GMT
Author: akarasulu
Date: Mon Mar 17 18:33:32 2008
New Revision: 638165

URL: http://svn.apache.org/viewvc?rev=638165&view=rev
Log:
added test case for master table and cleaned it up a bit

Added:
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTableTest.java
Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java?rev=638165&r1=638164&r2=638165&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java
Mon Mar 17 18:33:32 2008
@@ -23,6 +23,7 @@
 import jdbm.RecordManager;
 import jdbm.helper.LongSerializer;
 import jdbm.helper.StringComparator;
+import jdbm.helper.Serializer;
 import org.apache.directory.server.core.partition.impl.btree.MasterTable;
 import org.apache.directory.server.schema.SerializableComparator;
 
@@ -81,11 +82,12 @@
      * Creates the master table using JDBM B+Trees for the backing store.
      *
      * @param recMan the JDBM record manager
+     * @param serializer the serializer to use for persisting objects
      * @throws Exception if there is an error opening the Db file.
      */
-    public JdbmMasterTable( RecordManager recMan ) throws Exception
+    public JdbmMasterTable( RecordManager recMan, Serializer serializer ) throws Exception
     {
-        super( DBF, recMan, LONG_COMPARATOR, LongSerializer.INSTANCE, new AttributesSerializer()
);
+        super( DBF, recMan, LONG_COMPARATOR, LongSerializer.INSTANCE, serializer );
         adminTbl = new JdbmTable<String,String>( "admin", recMan, STRING_COMPARATOR,
null, null );
         String seqValue = adminTbl.get( SEQPROP_KEY );
 
@@ -102,7 +104,7 @@
     }
 
 
-    public E put( E entry, Long id ) throws Exception
+    public E put( Long id, E entry ) throws Exception
     {
         return super.put( id, entry );
     }
@@ -121,13 +123,6 @@
         synchronized ( adminTbl )
         {
             id = new Long( adminTbl.get( SEQPROP_KEY ) );
-
-            //noinspection ConstantConditions
-            if ( null == id )
-            {
-                adminTbl.put( SEQPROP_KEY, "0" );
-                id = 0L;
-            }
         }
 
         return id;
@@ -142,18 +137,8 @@
         synchronized ( adminTbl )
         {
             lastVal = new Long( adminTbl.get( SEQPROP_KEY ) );
-
-            //noinspection ConstantConditions
-            if ( null == lastVal )
-            {
-                adminTbl.put( SEQPROP_KEY, "1" );
-                return 1L;
-            }
-            else
-            {
-                nextVal = lastVal + 1L;
-                adminTbl.put( SEQPROP_KEY, nextVal.toString() );
-            }
+            nextVal = lastVal + 1L;
+            adminTbl.put( SEQPROP_KEY, nextVal.toString() );
         }
 
         return nextVal;

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java?rev=638165&r1=638164&r2=638165&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
Mon Mar 17 18:33:32 2008
@@ -312,7 +312,7 @@
         recMan = new CacheRecordManager( base, new MRU( cacheSize ) );
 
         // Create the master table (the table wcontaining all the entries)
-        master = new JdbmMasterTable<Attributes>( recMan );
+        master = new JdbmMasterTable<Attributes>( recMan, new AttributesSerializer()
);
 
         // -------------------------------------------------------------------
         // Initializes the user and system indices
@@ -1095,7 +1095,7 @@
             }
         }
 
-        master.put( entry, id );
+        master.put( id, entry );
         
         if ( isSyncOnWrite )
         {
@@ -1523,7 +1523,7 @@
                 throw new NamingException( "Unidentified modification operation" );
         }
 
-        master.put( entry, id );
+        master.put( id, entry );
         
         if ( isSyncOnWrite )
         {
@@ -1560,7 +1560,7 @@
             }
         }
 
-        master.put( entry, id );
+        master.put( id, entry );
         
         if ( isSyncOnWrite )
         {

Added: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTableTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTableTest.java?rev=638165&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTableTest.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTableTest.java
Mon Mar 17 18:33:32 2008
@@ -0,0 +1,121 @@
+/*
+ *  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.partition.impl.btree.jdbm;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import java.io.File;
+
+import jdbm.RecordManager;
+import jdbm.helper.IntegerSerializer;
+import jdbm.recman.BaseRecordManager;
+
+
+/**
+ * Test cases for JdbmMasterTable.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $$Rev$$
+ */
+public class JdbmMasterTableTest
+{
+    private static final Logger LOG = LoggerFactory.getLogger( JdbmMasterTableTest.class.getSimpleName()
);
+    private static final String TEST_OUTPUT_PATH = "test.output.path";
+
+    transient JdbmMasterTable<Integer> table;
+    transient File dbFile;
+    transient RecordManager recman;
+
+
+    @Before
+    public void createTable() throws Exception
+    {
+        destryTable();
+        File tmpDir = null;
+        if ( System.getProperty( TEST_OUTPUT_PATH, null ) != null )
+        {
+            tmpDir = new File( System.getProperty( TEST_OUTPUT_PATH ) );
+        }
+
+        dbFile = File.createTempFile( getClass().getSimpleName(), "db", tmpDir );
+        recman = new BaseRecordManager( dbFile.getAbsolutePath() );
+
+        table = new JdbmMasterTable<Integer>( recman, new IntegerSerializer() );
+        LOG.debug( "Created new table and populated it with data" );
+
+        JdbmMasterTable t2 = new JdbmMasterTable<Integer>( recman, new IntegerSerializer()
);
+        t2.close();
+    }
+
+
+    @After
+    public void destryTable() throws Exception
+    {
+        if ( table != null )
+        {
+            table.close();
+        }
+
+        table = null;
+
+        if ( recman != null )
+        {
+            recman.close();
+        }
+
+        recman = null;
+
+        if ( dbFile != null )
+        {
+            dbFile.delete();
+        }
+
+        dbFile = null;
+    }
+
+
+    @Test
+    public void testAll() throws Exception
+    {
+        assertNull( table.get( 0L ) );
+
+        assertEquals( 0, ( long ) table.getCurrentId() );
+        assertEquals( 1, ( long ) table.getNextId() );
+        assertEquals( 1, ( long ) table.getCurrentId() );
+        assertNull( table.put( 1L, 5 ) );
+        assertEquals( 5, ( int ) table.get( 1L ) );
+
+        assertEquals( 1, ( long ) table.getCurrentId() );
+        assertEquals( 2, ( long ) table.getNextId() );
+        assertEquals( 2, ( long ) table.getCurrentId() );
+        assertNull( table.put( 2L, 6 ) );
+        assertEquals( 6, ( int ) table.get( 2L ) );
+
+        assertNull( table.getProperty( "foo" ) );
+        table.setProperty( "foo", "bar" );
+        assertEquals( "bar", table.getProperty( "foo" ) );
+    }
+}



Mime
View raw message