directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r638209 - 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 04:35:14 GMT
Author: akarasulu
Date: Mon Mar 17 21:35:05 2008
New Revision: 638209

URL: http://svn.apache.org/viewvc?rev=638209&view=rev
Log:
adding start of JdbmStore test cases and fixing some minor issues found

Added:
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
Modified:
    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/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=638209&r1=638208&r2=638209&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 21:35:05 2008
@@ -46,6 +46,7 @@
 import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.NamespaceTools;
 import org.apache.directory.shared.ldap.NotImplementedException;
+import org.apache.directory.shared.ldap.MultiException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -70,7 +71,7 @@
     /** static logger */
     private static final Logger LOG = LoggerFactory.getLogger( JdbmStore.class );
     /** The default cache size is set to 10 000 objects */
-    private static final int DEFAULT_CACHE_SIZE = 10000;
+    static final int DEFAULT_CACHE_SIZE = 10000;
 
 
     /** the JDBM record manager used by this database */
@@ -138,7 +139,6 @@
 
     private ServerEntry contextEntry;
     private String suffixDn;
-    private boolean enableOptimizer;
     private int cacheSize = DEFAULT_CACHE_SIZE;
     private String name;
 
@@ -220,19 +220,6 @@
     }
 
 
-    public void setEnableOptimizer( boolean enableOptimizer )
-    {
-        protect( "enableOptimizer" );
-        this.enableOptimizer = enableOptimizer;
-    }
-
-
-    public boolean isEnableOptimizer()
-    {
-        return enableOptimizer;
-    }
-
-
     public void setCacheSize( int cacheSize )
     {
         protect( "cacheSize" );
@@ -448,7 +435,7 @@
     /**
      * Close the parttion : we have to close all the userIndices and the master table.
      */
-    public synchronized void destroy()
+    public synchronized void destroy() throws Exception
     {
         LOG.debug( "destroy() called on store for {}", this.suffixDn );
 
@@ -459,41 +446,8 @@
 
         List<JdbmIndex> array = new ArrayList<JdbmIndex>();
         array.addAll( userIndices.values() );
-
-        if ( null != ndnIdx )
-        {
-            array.add( ndnIdx );
-        }
-
-        if ( null != updnIdx )
-        {
-            array.add( updnIdx );
-        }
-
-        if ( null != aliasIdx )
-        {
-            array.add( aliasIdx );
-        }
-
-        if ( null != oneAliasIdx )
-        {
-            array.add( oneAliasIdx );
-        }
-
-        if ( null != subAliasIdx )
-        {
-            array.add( subAliasIdx );
-        }
-
-        if ( null != hierarchyIdx )
-        {
-            array.add( hierarchyIdx );
-        }
-
-        if ( null != existanceIdx )
-        {
-            array.add( existanceIdx );
-        }
+        array.addAll( systemIndices.values() );
+        MultiException errors = new MultiException( "Errors encountered on destroy()" );
 
         for ( JdbmIndex index:array )
         {
@@ -505,6 +459,7 @@
             catch ( Throwable t )
             {
                 LOG.error( "Failed to close an index.", t );
+                errors.addThrowable( t );
             }
         }
 
@@ -516,6 +471,7 @@
         catch ( Throwable t )
         {
             LOG.error( "Failed to close the master.", t );
+            errors.addThrowable( t );
         }
 
         try
@@ -526,6 +482,12 @@
         catch ( Throwable t )
         {
             LOG.error( "Failed to close the record manager", t );
+            errors.addThrowable( t );
+        }
+
+        if ( errors.size() > 0 )
+        {
+            throw errors;
         }
 
         initialized = false;
@@ -726,24 +688,9 @@
         {
             return userIndices.get( id );
         }
-        else
-        {
-            String name;
-            
-            try
-            {
-                name = oidRegistry.getPrimaryName( id );
-            }
-            catch ( NamingException e )
-            {
-                String msg = "Failed to resolve primary name for " + id + " in user index
lookup";
-                LOG.error( msg, e );
-                throw new IndexNotFoundException( msg, id, e );
-            }
-            
-            throw new IndexNotFoundException( "A user index on attribute " + id + " (" 
-                + name + ") does not exist!" );
-        }
+
+        throw new IndexNotFoundException( "A user index on attribute " + id + " ("
+            + name + ") does not exist!" );
     }
 
 
@@ -764,24 +711,9 @@
         {
             return systemIndices.get( id );
         }
-        else
-        {
-            String name;
-            
-            try
-            {
-                name = oidRegistry.getPrimaryName( id );
-            }
-            catch ( NamingException e )
-            {
-                String msg = "Failed to resolve primary name for " + id + " in user index
lookup";
-                LOG.error( msg, e );
-                throw new IndexNotFoundException( msg, id, e );
-            }
-            
-            throw new IndexNotFoundException( "A system index on attribute " + id + " ("

-                + name + ") does not exist!" );
-        }
+
+        throw new IndexNotFoundException( "A system index on attribute " + id + " ("
+            + name + ") does not exist!" );
     }
 
 

Added: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.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/JdbmStoreTest.java?rev=638209&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
Mon Mar 17 21:35:05 2008
@@ -0,0 +1,299 @@
+/*
+ *  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 org.apache.commons.io.FileUtils;
+import org.apache.directory.server.schema.bootstrap.*;
+import org.apache.directory.server.schema.registries.*;
+import org.apache.directory.server.schema.SerializableComparator;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.partition.impl.btree.IndexNotFoundException;
+import org.apache.directory.server.constants.CoreSchemaConstants;
+import org.apache.directory.server.constants.ApacheSchemaConstants;
+import org.apache.directory.server.constants.SystemSchemaConstants;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+
+import java.io.File;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
+
+
+/**
+ * Unit test cases for JdbmStore
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $$Rev$$
+ */
+public class JdbmStoreTest
+{
+    private static final Logger LOG = LoggerFactory.getLogger( JdbmStoreTest.class.getSimpleName()
);
+
+    File wkdir;
+    JdbmStore store;
+    Registries registries = null;
+    AttributeTypeRegistry attributeRegistry;
+
+
+    public JdbmStoreTest() throws Exception
+    {
+        // setup the standard registries
+        BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+        OidRegistry oidRegistry = new DefaultOidRegistry();
+        registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
+        SerializableComparator.setRegistry( registries.getComparatorRegistry() );
+
+        // load essential bootstrap schemas
+        Set<Schema> bootstrapSchemas = new HashSet<Schema>();
+        bootstrapSchemas.add( new ApachemetaSchema() );
+        bootstrapSchemas.add( new ApacheSchema() );
+        bootstrapSchemas.add( new CoreSchema() );
+        bootstrapSchemas.add( new SystemSchema() );
+        loader.loadWithDependencies( bootstrapSchemas, registries );
+        attributeRegistry = registries.getAttributeTypeRegistry();
+    }
+
+
+    @Before
+    public void createStore() throws Exception
+    {
+        destryStore();
+
+        // setup the working directory for the store
+        wkdir = File.createTempFile( getClass().getSimpleName(), "db" );
+        wkdir.delete();
+        wkdir = new File( wkdir.getParentFile(), getClass().getSimpleName() );
+        wkdir.mkdirs();
+
+        // initialize the store
+        store = new JdbmStore();
+        store.setName( "example" );
+        store.setCacheSize( 10 );
+        store.setSuffixDn( "dc=example,dc=com" );
+        store.setWorkingDirectory( wkdir );
+        store.setSyncOnWrite( false );
+
+        DefaultServerEntry contextEntry = new DefaultServerEntry( registries,
+            new LdapDN( "dc=example,dc=com" ) );
+        contextEntry.add( "objectClass", "domain" );
+        contextEntry.add( "dc", "example" );
+        store.setContextEntry( contextEntry );
+        store.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID ) );
+        store.addIndex( new JdbmIndex( SchemaConstants.UID_AT_OID ) );
+        store.init( registries.getOidRegistry(), attributeRegistry );
+        LOG.debug( "Created new store" );
+    }
+
+
+    @After
+    public void destryStore() throws Exception
+    {
+        if ( store != null )
+        {
+            store.destroy();
+        }
+
+        store = null;
+        if ( wkdir != null )
+        {
+            FileUtils.deleteDirectory( wkdir );
+        }
+
+        wkdir = null;
+    }
+
+
+    @Test
+    public void testSimplePropertiesUnlocked() throws Exception
+    {
+        JdbmStore store = new JdbmStore();
+
+        assertNull( store.getAliasIndex() );
+        store.setAliasIndex( new JdbmIndex<String>( "alias" ) );
+        assertNotNull( store.getAliasIndex() );
+
+        assertEquals( JdbmStore.DEFAULT_CACHE_SIZE, store.getCacheSize() );
+        store.setCacheSize( 24 );
+        assertEquals( 24, store.getCacheSize() );
+
+        assertNull( store.getContextEntry() );
+        store.setContextEntry( new DefaultServerEntry( registries, new LdapDN() ) );
+        assertNotNull( store.getContextEntry() );
+
+        assertNull( store.getExistanceIndex() );
+        store.setExistanceIndex( new JdbmIndex<String>( "existence" ) );
+        assertNotNull( store.getExistanceIndex() );
+
+        assertNull( store.getHierarchyIndex() );
+        store.setHierarchyIndex( new JdbmIndex<Long>( "hierarchy" ) );
+        assertNotNull( store.getHierarchyIndex() );
+
+        assertNull( store.getName() );
+        store.setName( "foo" );
+        assertEquals( "foo", store.getName() );
+
+        assertNull( store.getNdnIndex() );
+        store.setNdnIndex( new JdbmIndex<String>( "ndn" ) );
+        assertNotNull( store.getNdnIndex() );
+
+        assertNull( store.getOneAliasIndex() );
+        store.setOneAliasIndex( new JdbmIndex<Long>( "oneAlias" ) );
+        assertNotNull( store.getNdnIndex() );
+
+        assertNull( store.getSubAliasIndex() );
+        store.setSubAliasIndex( new JdbmIndex<Long>( "subAlias" ) );
+        assertNotNull( store.getSubAliasIndex() );
+
+        assertNull( store.getSuffixDn() );
+        store.setSuffixDn( "dc=example,dc=com" );
+        assertEquals( "dc=example,dc=com", store.getSuffixDn() );
+
+        assertNull( store.getUpdnIndex() );
+        store.setUpdnIndex( new JdbmIndex<String>( "updn" ) );
+        assertNotNull( store.getUpdnIndex() );
+
+        assertNull( store.getUpSuffix() );
+        assertNull( store.getSuffix() );
+
+        assertEquals( 0, store.getUserIndices().size() );
+        Set<JdbmIndex> set = new HashSet<JdbmIndex>();
+        set.add( new JdbmIndex( "foo" ) );
+        store.setUserIndices( set );
+        assertEquals( set.size(), store.getUserIndices().size() );
+
+        assertNull( store.getWorkingDirectory() );
+        store.setWorkingDirectory( new File( "." ) );
+        assertEquals( new File( "." ), store.getWorkingDirectory() );
+
+        assertFalse( store.isInitialized() );
+        assertTrue( store.isSyncOnWrite() );
+        store.setSyncOnWrite( false );
+        assertFalse( store.isSyncOnWrite() );
+
+        store.sync();
+        store.destroy();
+    }
+
+
+    @Test
+    public void testSimplePropertiesLocked() throws Exception
+    {
+        assertNotNull( store.getAliasIndex() );
+        try { store.setAliasIndex( new JdbmIndex<String>( "alias" ) ); fail(); }
+        catch( IllegalStateException e ) {}
+
+        assertEquals( 10, store.getCacheSize() );
+        try { store.setCacheSize( 24 ); }
+        catch( IllegalStateException e ) {}
+
+        assertNotNull( store.getContextEntry() );
+        try { store.setContextEntry( new DefaultServerEntry( registries, new LdapDN() ) );
fail(); }
+        catch( IllegalStateException e ) {}
+
+        assertNotNull( store.getExistanceIndex() );
+        try { store.setExistanceIndex( new JdbmIndex<String>( "existence" ) ); fail();
}
+        catch( IllegalStateException e ) {}
+
+        assertNotNull( store.getHierarchyIndex() );
+        try { store.setHierarchyIndex( new JdbmIndex<Long>( "hierarchy" ) ); fail();
}
+        catch( IllegalStateException e ) {}
+
+        assertNotNull( store.getName() );
+        try { store.setName( "foo" ); fail(); }
+        catch( IllegalStateException e ) {}
+
+        assertNotNull( store.getNdnIndex() );
+        try { store.setNdnIndex( new JdbmIndex<String>( "ndn" ) ); fail(); }
+        catch( IllegalStateException e ) {}
+
+        assertNotNull( store.getOneAliasIndex() );
+        try { store.setOneAliasIndex( new JdbmIndex<Long>( "oneAlias" ) ); fail();
}
+        catch( IllegalStateException e ) {}
+
+        assertNotNull( store.getSubAliasIndex() );
+        try { store.setSubAliasIndex( new JdbmIndex<Long>( "subAlias" ) ); fail();
}
+        catch( IllegalStateException e ) {}
+
+        assertNotNull( store.getSuffixDn() );
+        try { store.setSuffixDn( "dc=example,dc=com" ); fail(); }
+        catch( IllegalStateException e ) {}
+
+        assertNotNull( store.getUpdnIndex() );
+        try { store.setUpdnIndex( new JdbmIndex<String>( "updn" ) ); fail(); }
+        catch( IllegalStateException e ) {}
+        Iterator<String> systemIndices = store.systemIndices();
+        for ( int ii = 0; ii < 7; ii++ )
+        {
+            assertTrue( systemIndices.hasNext() );
+            assertNotNull( systemIndices.next() );
+        }
+        assertFalse( systemIndices.hasNext() );
+        assertNotNull( store.getSystemIndex( ApacheSchemaConstants.APACHE_ALIAS_AT ) );
+        try { store.getSystemIndex( "bogus" ); fail(); }
+        catch ( IndexNotFoundException e ) {}
+        try { store.getSystemIndex( "dc" ); fail(); }
+        catch ( IndexNotFoundException e ) {}
+
+        assertNotNull( store.getUpSuffix() );
+        assertNotNull( store.getSuffix() );
+
+        assertEquals( 2, store.getUserIndices().size() );
+        assertFalse( store.hasUserIndexOn( "dc" ) );
+        assertTrue( store.hasUserIndexOn( SchemaConstants.OU_AT ) );
+        assertTrue( store.hasSystemIndexOn( ApacheSchemaConstants.APACHE_ALIAS_AT ) );
+        Iterator<String> userIndices = store.userIndices();
+        assertTrue( userIndices.hasNext() );
+        assertNotNull( userIndices.next() );
+        assertTrue( userIndices.hasNext() );        
+        assertNotNull( userIndices.next() );
+        assertFalse( userIndices.hasNext() );        
+        assertNotNull( store.getUserIndex( SchemaConstants.OU_AT ) );
+        try { store.getUserIndex( "bogus" ); fail(); }
+        catch ( IndexNotFoundException e ) {}
+        try { store.getUserIndex( "dc" ); fail(); }
+        catch ( IndexNotFoundException e ) {}
+
+        assertNotNull( store.getWorkingDirectory() );
+        try { store.setWorkingDirectory( new File( "." ) ); fail(); }
+        catch( IllegalStateException e ) {}
+
+        assertTrue( store.isInitialized() );
+        assertFalse( store.isSyncOnWrite() );
+
+        store.sync();
+    }
+
+
+    @Test
+    public void testEmptyStore() throws Exception
+    {
+        LdapDN dn = new LdapDN( "dc=example,dc=com" );
+        dn.normalize( attributeRegistry.getNormalizerMapping() );
+        assertEquals( 1L, ( long ) store.getEntryId( dn.toNormName() ) );
+    }
+}



Mime
View raw message