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 2010/01/06 19:27:19 UTC
svn commit: r896599 [21/30] - in /directory/apacheds/trunk: ./
avl-partition/ avl-partition/src/ avl-partition/src/main/
avl-partition/src/main/java/ avl-partition/src/main/java/org/
avl-partition/src/main/java/org/apache/ avl-partition/src/main/java/o...
Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTableTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTableTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTableTest.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTableTest.java Wed Jan 6 18:26:43 2010
@@ -20,23 +20,27 @@
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.directory.server.schema.bootstrap.*;
-import org.apache.directory.server.schema.registries.*;
-import org.apache.directory.server.schema.SerializableComparator;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
import java.io.File;
-import java.util.Set;
-import java.util.HashSet;
import jdbm.RecordManager;
import jdbm.recman.BaseRecordManager;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Test cases for JdbmMasterTable.
@@ -52,26 +56,33 @@
transient JdbmMasterTable<Integer> table;
transient File dbFile;
transient RecordManager recman;
- transient Registries registries = null;
- transient AttributeTypeRegistry attributeRegistry;
+ transient SchemaManager schemaManager = null;
public JdbmMasterTableTest() 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();
+ String workingDirectory = System.getProperty( "workingDirectory" );
+
+ if ( workingDirectory == null )
+ {
+ String path = JdbmMasterTableTest.class.getResource( "" ).getPath();
+ int targetPos = path.indexOf( "target" );
+ workingDirectory = path.substring( 0, targetPos + 6 );
+ }
+
+ File schemaRepository = new File( workingDirectory, "schema" );
+ SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
+ extractor.extractOrCopy( true );
+ LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+
+ schemaManager = new DefaultSchemaManager( loader );
+
+ boolean loaded = schemaManager.loadAllEnabled();
+
+ if ( !loaded )
+ {
+ fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+ }
}
@@ -88,10 +99,10 @@
dbFile = File.createTempFile( getClass().getSimpleName(), "db", tmpDir );
recman = new BaseRecordManager( dbFile.getAbsolutePath() );
- table = new JdbmMasterTable<Integer>( recman, registries );
+ table = new JdbmMasterTable<Integer>( recman, schemaManager );
LOG.debug( "Created new table and populated it with data" );
- JdbmMasterTable<Integer> t2 = new JdbmMasterTable<Integer>( recman, registries );
+ JdbmMasterTable<Integer> t2 = new JdbmMasterTable<Integer>( recman, schemaManager );
t2.close();
}
Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java Wed Jan 6 18:26:43 2010
@@ -20,48 +20,59 @@
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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.naming.directory.Attributes;
+
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.constants.ApacheSchemaConstants;
+import org.apache.directory.server.core.entry.DefaultServerAttribute;
import org.apache.directory.server.core.entry.DefaultServerEntry;
-import org.apache.directory.server.xdbm.IndexNotFoundException;
-import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.core.entry.ServerAttribute;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.entry.ServerModification;
import org.apache.directory.server.xdbm.Index;
import org.apache.directory.server.xdbm.IndexCursor;
+import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.IndexNotFoundException;
import org.apache.directory.server.xdbm.tools.StoreUtils;
-import org.apache.directory.server.core.entry.ServerEntry;
-import org.apache.directory.server.core.entry.ServerModification;
-import org.apache.directory.server.core.entry.DefaultServerAttribute;
-import org.apache.directory.server.core.entry.ServerAttribute;
-import org.apache.directory.server.constants.ApacheSchemaConstants;
-import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.csn.CsnFactory;
import org.apache.directory.shared.ldap.cursor.Cursor;
-import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.schema.SchemaUtils;
-import org.apache.directory.shared.ldap.entry.ModificationOperation;
import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
+import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.name.Rdn;
-
-import javax.naming.directory.Attributes;
-import java.lang.reflect.Method;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.UUID;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.SchemaUtils;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -77,26 +88,34 @@
File wkdir;
JdbmStore<ServerEntry> store;
- Registries registries = null;
- AttributeTypeRegistry attributeRegistry;
+ private static SchemaManager schemaManager = null;
+ private static LdifSchemaLoader loader;
- public JdbmStoreTest() throws Exception
+ @BeforeClass
+ public static void setup() 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();
+ String workingDirectory = System.getProperty( "workingDirectory" );
+
+ if ( workingDirectory == null )
+ {
+ String path = JdbmStoreTest.class.getResource( "" ).getPath();
+ int targetPos = path.indexOf( "target" );
+ workingDirectory = path.substring( 0, targetPos + 6 );
+ }
+
+ File schemaRepository = new File( workingDirectory, "schema" );
+ SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
+ extractor.extractOrCopy( true );
+ loader = new LdifSchemaLoader( schemaRepository );
+ schemaManager = new DefaultSchemaManager( loader );
+
+ boolean loaded = schemaManager.loadAllEnabled();
+
+ if ( !loaded )
+ {
+ fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+ }
}
@@ -117,10 +136,10 @@
store.setCacheSize( 10 );
store.setWorkingDirectory( wkdir );
store.setSyncOnWrite( false );
-
store.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID ) );
store.addIndex( new JdbmIndex( SchemaConstants.UID_AT_OID ) );
- StoreUtils.loadExampleData( store, registries );
+
+ StoreUtils.loadExampleData( store, schemaManager );
LOG.debug( "Created new store" );
}
@@ -321,12 +340,12 @@
public void testFreshStore() throws Exception
{
LdapDN dn = new LdapDN( "o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
assertEquals( 1L, ( long ) store.getEntryId( dn.toNormName() ) );
assertEquals( 11, store.count() );
assertEquals( "o=Good Times Co.", store.getEntryUpdn( dn.toNormName() ) );
assertEquals( dn.toNormName(), store.getEntryDn( 1L ) );
- assertEquals( dn.getUpName(), store.getEntryUpdn( 1L ) );
+ assertEquals( dn.getName(), store.getEntryUpdn( 1L ) );
// note that the suffix entry returns 0 for it's parent which does not exist
assertEquals( 0L, ( long ) store.getParentId( dn.toNormName() ) );
@@ -356,8 +375,8 @@
// add an alias and delete to test dropAliasIndices method
LdapDN dn = new LdapDN( "commonName=Jack Daniels,ou=Apache,ou=Board of Directors,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "objectClass", "top", "alias", "extensibleObject" );
entry.add( "ou", "Apache" );
entry.add( "commonName", "Jack Daniels");
@@ -405,8 +424,8 @@
// dn id 12
LdapDN martinDn = new LdapDN( "cn=Marting King,ou=Sales,o=Good Times Co." );
- martinDn.normalize( attributeRegistry.getNormalizerMapping() );
- DefaultServerEntry entry = new DefaultServerEntry( registries, martinDn );
+ martinDn.normalize( schemaManager.getNormalizerMapping() );
+ DefaultServerEntry entry = new DefaultServerEntry( schemaManager, martinDn );
entry.add( "objectClass", "top", "person", "organizationalPerson" );
entry.add( "ou", "Sales" );
entry.add( "cn", "Martin King");
@@ -420,7 +439,7 @@
assertEquals( 12, ( long ) cursor.get().getId() );
LdapDN newParentDn = new LdapDN( "ou=Board of Directors,o=Good Times Co." );
- newParentDn.normalize( attributeRegistry.getNormalizerMapping() );
+ newParentDn.normalize( schemaManager.getNormalizerMapping() );
store.move( martinDn, newParentDn );
cursor = idx.forwardCursor( 3L);
@@ -430,8 +449,8 @@
// dn id 13
LdapDN marketingDn = new LdapDN( "ou=Marketing,ou=Sales,o=Good Times Co." );
- marketingDn.normalize( attributeRegistry.getNormalizerMapping() );
- entry = new DefaultServerEntry( registries, marketingDn );
+ marketingDn.normalize( schemaManager.getNormalizerMapping() );
+ entry = new DefaultServerEntry( schemaManager, marketingDn );
entry.add( "objectClass", "top", "organizationalUnit" );
entry.add( "ou", "Marketing" );
entry.add( "entryCSN", new CsnFactory( 1 ).newInstance().toString() );
@@ -440,8 +459,8 @@
// dn id 14
LdapDN jimmyDn = new LdapDN( "cn=Jimmy Wales,ou=Marketing, ou=Sales,o=Good Times Co." );
- jimmyDn.normalize( attributeRegistry.getNormalizerMapping() );
- entry = new DefaultServerEntry( registries, jimmyDn );
+ jimmyDn.normalize( schemaManager.getNormalizerMapping() );
+ entry = new DefaultServerEntry( schemaManager, jimmyDn );
entry.add( "objectClass", "top", "person", "organizationalPerson" );
entry.add( "ou", "Marketing" );
entry.add( "cn", "Jimmy Wales");
@@ -679,8 +698,8 @@
public void testAddWithoutParentId() throws Exception
{
LdapDN dn = new LdapDN( "cn=Marting King,ou=Not Present,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "objectClass", "top", "person", "organizationalPerson" );
entry.add( "ou", "Not Present" );
entry.add( "cn", "Martin King");
@@ -692,8 +711,8 @@
public void testAddWithoutObjectClass() throws Exception
{
LdapDN dn = new LdapDN( "cn=Martin King,ou=Sales,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "ou", "Sales" );
entry.add( "cn", "Martin King");
store.add( entry );
@@ -704,11 +723,11 @@
public void testModifyAddOUAttrib() throws Exception
{
LdapDN dn = new LdapDN( "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
List<Modification> mods = new ArrayList<Modification>();
ServerAttribute attrib = new DefaultServerAttribute( SchemaConstants.OU_AT,
- attributeRegistry.lookup( SchemaConstants.OU_AT_OID ) );
+ schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OU_AT_OID ) );
attrib.add( "Engineering" );
Modification add = new ServerModification( ModificationOperation.ADD_ATTRIBUTE, attrib );
@@ -723,8 +742,8 @@
public void testRename() throws Exception
{
LdapDN dn = new LdapDN( "cn=Pivate Ryan,ou=Engineering,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "objectClass", "top", "person", "organizationalPerson" );
entry.add( "ou", "Engineering" );
entry.add( "cn", "Private Ryan");
@@ -740,11 +759,38 @@
@Test
+ public void testRenameEscaped() throws Exception
+ {
+ LdapDN dn = new LdapDN( "cn=Pivate Ryan,ou=Engineering,o=Good Times Co." );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );
+ entry.add( "objectClass", "top", "person", "organizationalPerson" );
+ entry.add( "ou", "Engineering" );
+ entry.add( "cn", "Private Ryan");
+ entry.add( "entryCSN", new CsnFactory( 1 ).newInstance().toString() );
+ entry.add( "entryUUID", SchemaUtils.uuidToBytes( UUID.randomUUID() ) );
+
+ store.add( entry );
+
+ Rdn rdn = new Rdn("sn=Ja\\+es");
+
+ store.rename( dn, rdn, true );
+
+ LdapDN dn2 = new LdapDN( "sn=Ja\\+es,ou=Engineering,o=Good Times Co." );
+ dn2.normalize( schemaManager.getNormalizerMapping() );
+ Long id = store.getEntryId( dn2.getNormName() );
+ assertNotNull( id );
+ ServerEntry entry2 = store.lookup( id );
+ assertEquals("Ja+es", entry2.get( "sn" ).getString());
+ }
+
+
+ @Test
public void testMove() throws Exception
{
LdapDN childDn = new LdapDN( "cn=Pivate Ryan,ou=Engineering,o=Good Times Co." );
- childDn.normalize( attributeRegistry.getNormalizerMapping() );
- DefaultServerEntry childEntry = new DefaultServerEntry( registries, childDn );
+ childDn.normalize( schemaManager.getNormalizerMapping() );
+ DefaultServerEntry childEntry = new DefaultServerEntry( schemaManager, childDn );
childEntry.add( "objectClass", "top", "person", "organizationalPerson" );
childEntry.add( "ou", "Engineering" );
childEntry.add( "cn", "Private Ryan");
@@ -754,7 +800,7 @@
store.add( childEntry );
LdapDN parentDn = new LdapDN( "ou=Sales,o=Good Times Co." );
- parentDn.normalize( attributeRegistry.getNormalizerMapping() );
+ parentDn.normalize( schemaManager.getNormalizerMapping() );
Rdn rdn = new Rdn("cn=Ryan");
@@ -762,10 +808,10 @@
// to drop the alias indices
childDn = new LdapDN( "commonName=Jim Bean,ou=Apache,ou=Board of Directors,o=Good Times Co." );
- childDn.normalize( attributeRegistry.getNormalizerMapping() );
+ childDn.normalize( schemaManager.getNormalizerMapping() );
parentDn = new LdapDN( "ou=Engineering,o=Good Times Co." );
- parentDn.normalize( attributeRegistry.getNormalizerMapping() );
+ parentDn.normalize( schemaManager.getNormalizerMapping() );
assertEquals( 3, store.getSubAliasIndex().count() );
@@ -779,11 +825,11 @@
public void testModifyAdd() throws Exception
{
LdapDN dn = new LdapDN( "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
List<Modification> mods = new ArrayList<Modification>();
ServerAttribute attrib = new DefaultServerAttribute( SchemaConstants.SURNAME_AT,
- attributeRegistry.lookup( SchemaConstants.SURNAME_AT ) );
+ schemaManager.lookupAttributeTypeRegistry( SchemaConstants.SURNAME_AT ) );
String attribVal = "Walker";
attrib.add( attribVal );
@@ -797,7 +843,7 @@
assertTrue( lookedup.get( "sn" ).contains( attribVal ) );
// testing the store.modify( dn, mod, entry ) API
- ServerEntry entry = new DefaultServerEntry( registries, dn );
+ ServerEntry entry = new DefaultServerEntry( schemaManager, dn );
attribVal = "+1974045779";
entry.add( "telephoneNumber", attribVal );
@@ -811,11 +857,11 @@
public void testModifyReplace() throws Exception
{
LdapDN dn = new LdapDN( "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
List<Modification> mods = new ArrayList<Modification>();
ServerAttribute attrib = new DefaultServerAttribute( SchemaConstants.SN_AT,
- attributeRegistry.lookup( SchemaConstants.SN_AT_OID ) );
+ schemaManager.lookupAttributeTypeRegistry( SchemaConstants.SN_AT_OID ) );
String attribVal = "Johnny";
attrib.add( attribVal );
@@ -831,7 +877,7 @@
assertEquals( attribVal, lookedup.get( "sn" ).get().getString() );
// testing the store.modify( dn, mod, entry ) API
- ServerEntry entry = new DefaultServerEntry( registries, dn );
+ ServerEntry entry = new DefaultServerEntry( schemaManager, dn );
attribVal = "JWalker";
entry.add( "sn", attribVal );
@@ -844,11 +890,11 @@
public void testModifyRemove() throws Exception
{
LdapDN dn = new LdapDN( "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
List<Modification> mods = new ArrayList<Modification>();
ServerAttribute attrib = new DefaultServerAttribute( SchemaConstants.SN_AT,
- attributeRegistry.lookup( SchemaConstants.SN_AT_OID ) );
+ schemaManager.lookupAttributeTypeRegistry( SchemaConstants.SN_AT_OID ) );
Modification add = new ServerModification( ModificationOperation.REMOVE_ATTRIBUTE, attrib );
mods.add( add );
@@ -861,7 +907,7 @@
assertNull( lookedup.get( "sn" ) );
// testing the store.modify( dn, mod, entry ) API
- ServerEntry entry = new DefaultServerEntry( registries, dn );
+ ServerEntry entry = new DefaultServerEntry( schemaManager, dn );
// add an entry for the sake of testing the remove operation
entry.add( "sn", "JWalker" );
@@ -877,8 +923,8 @@
public void testModifyReplaceNonExistingIndexAttribute() throws Exception
{
LdapDN dn = new LdapDN( "cn=Tim B,ou=Sales,o=Good Times Co." );
- dn.normalize( attributeRegistry.getNormalizerMapping() );
- DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+ dn.normalize( schemaManager.getNormalizerMapping() );
+ DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );
entry.add( "objectClass", "top", "person", "organizationalPerson" );
entry.add( "cn", "Tim B");
entry.add( "entryCSN", new CsnFactory( 1 ).newInstance().toString() );
@@ -888,7 +934,7 @@
List<Modification> mods = new ArrayList<Modification>();
ServerAttribute attrib = new DefaultServerAttribute( SchemaConstants.OU_AT,
- attributeRegistry.lookup( SchemaConstants.OU_AT_OID ) );
+ schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OU_AT_OID ) );
String attribVal = "Marketing";
attrib.add( attribVal );
Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java Wed Jan 6 18:26:43 2010
@@ -19,26 +19,33 @@
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.directory.server.xdbm.Table;
-import org.apache.directory.server.schema.SerializableComparator;
-import org.apache.directory.server.schema.registries.ComparatorRegistry;
-import org.apache.directory.shared.ldap.schema.parsers.ComparatorDescription;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
-import java.util.Comparator;
-import java.util.Iterator;
import jdbm.RecordManager;
import jdbm.recman.BaseRecordManager;
-import javax.naming.NamingException;
+import org.apache.directory.server.xdbm.Table;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.comparators.SerializableComparator;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -52,16 +59,45 @@
private static final Logger LOG = LoggerFactory.getLogger( JdbmTableNoDuplicatesTest.class.getSimpleName() );
private static final String TEST_OUTPUT_PATH = "test.output.path";
- transient Table<Integer,Integer> table;
+ transient Table<String,String> table;
transient File dbFile;
transient RecordManager recman;
+ private static SchemaManager schemaManager;
+
+
+ @BeforeClass
+ public static void init() throws Exception
+ {
+ String workingDirectory = System.getProperty( "workingDirectory" );
+
+ if ( workingDirectory == null )
+ {
+ String path = DupsContainerCursorTest.class.getResource( "" ).getPath();
+ int targetPos = path.indexOf( "target" );
+ workingDirectory = path.substring( 0, targetPos + 6 );
+ }
+
+ File schemaRepository = new File( workingDirectory, "schema" );
+ SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
+ extractor.extractOrCopy( true );
+ LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+ schemaManager = new DefaultSchemaManager( loader );
+ boolean loaded = schemaManager.loadAllEnabled();
+ if ( !loaded )
+ {
+ fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+ }
+ }
+
+
@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 ) );
@@ -70,9 +106,9 @@
dbFile = File.createTempFile( getClass().getSimpleName(), "db", tmpDir );
recman = new BaseRecordManager( dbFile.getAbsolutePath() );
- // gosh this is a terrible use of a global static variable
- SerializableComparator.setRegistry( new MockComparatorRegistry() );
- table = new JdbmTable<Integer,Integer>( "test", recman, new SerializableComparator<Integer>( "" ), null, null );
+ SerializableComparator<String> comparator = new SerializableComparator<String>( SchemaConstants.INTEGER_ORDERING_MATCH_MR_OID );
+ comparator.setSchemaManager( schemaManager );
+ table = new JdbmTable<String,String>( schemaManager, "test", recman, comparator, null, null );
LOG.debug( "Created new table and populated it with data" );
}
@@ -110,10 +146,12 @@
@Test
public void testCloseReopen() throws Exception
{
- table.put( 1, 2 );
+ table.put( "1", "2" );
table.close();
- table = new JdbmTable<Integer,Integer>( "test", recman, new SerializableComparator<Integer>( "" ), null, null );
- assertTrue( 2 == table.get( 1 ) );
+ SerializableComparator<String> comparator = new SerializableComparator<String>( SchemaConstants.INTEGER_ORDERING_MATCH_MR_OID );
+ comparator.setSchemaManager( schemaManager );
+ table = new JdbmTable<String,String>( schemaManager, "test", recman, comparator, null, null );
+ assertEquals( "2", table.get( "1" ) );
}
@@ -131,24 +169,24 @@
{
// Test the count methods
assertEquals( 0, table.count() );
- assertEquals( 0, table.count( 1 ) );
+ assertEquals( 0, table.count( "1" ) );
// Test get method
- assertNull( table.get( 0 ) );
+ assertNull( table.get( "0" ) );
// Test remove methods
- table.remove( 1 );
- assertNull( table.get( 1 ) );
+ table.remove( "1" );
+ assertNull( table.get( "1" ) );
// Test has operations
- assertFalse( table.has( 1 ) );
- assertFalse( table.has( 1, 0 ) );
- assertFalse( table.hasGreaterOrEqual( 1 ) );
- assertFalse( table.hasLessOrEqual( 1 ) );
+ assertFalse( table.has( "1" ) );
+ assertFalse( table.has( "1", "0" ) );
+ assertFalse( table.hasGreaterOrEqual( "1" ) );
+ assertFalse( table.hasLessOrEqual( "1" ) );
try
{
- assertFalse( table.hasGreaterOrEqual( 1, 0 ) );
+ assertFalse( table.hasGreaterOrEqual( "1", "0" ) );
fail( "Should never get here." );
}
catch ( UnsupportedOperationException e )
@@ -157,7 +195,7 @@
try
{
- assertFalse( table.hasLessOrEqual( 1, 0 ) );
+ assertFalse( table.hasLessOrEqual( "1", "0" ) );
fail( "Should never get here." );
}
catch ( UnsupportedOperationException e )
@@ -170,13 +208,14 @@
public void testLoadData() throws Exception
{
// add some data to it
- for ( int ii = 0; ii < 10; ii++ )
+ for ( int i = 0; i < 10; i++ )
{
- table.put( ii, ii );
+ String istr = Integer.toString( i );
+ table.put( istr, istr );
}
assertEquals( 10, table.count() );
- assertEquals( 1, table.count( 0 ) );
+ assertEquals( 1, table.count( "0" ) );
/*
* If counts are exact then we can test for exact values. Again this
@@ -186,13 +225,13 @@
if ( table.isCountExact() )
{
- assertEquals( 5, table.lessThanCount( 5 ) );
- assertEquals( 4, table.greaterThanCount( 5 ) );
+ assertEquals( 5, table.lessThanCount( "5" ) );
+ assertEquals( 4, table.greaterThanCount( "5" ) );
}
else
{
- assertEquals( 10, table.lessThanCount( 5 ) );
- assertEquals( 10, table.greaterThanCount( 5 ) );
+ assertEquals( 10, table.lessThanCount( "5" ) );
+ assertEquals( 10, table.greaterThanCount( "5" ) );
}
}
@@ -208,7 +247,7 @@
try
{
- table.put( 1, null );
+ table.put( "1", null );
fail( "should never get here due to IllegalArgumentException" );
}
catch( IllegalArgumentException e )
@@ -218,7 +257,7 @@
try
{
- table.put( null, 2 );
+ table.put( null, "2" );
fail( "should never get here due to IllegalArgumentException" );
}
catch( IllegalArgumentException e )
@@ -227,32 +266,32 @@
}
assertEquals( 0, table.count() );
- assertEquals( null, table.get( 1 ) );
+ assertEquals( null, table.get( "1" ) );
// Let's add the key with a valid value and remove just the value
- assertEquals( 0, table.count( 1 ) );
- table.remove( 1 );
- assertEquals( 0, table.count( 1 ) );
- table.put( 1, 1 );
- assertEquals( 1, table.count( 1 ) );
- table.remove( 1, 1 );
- assertEquals( 0, table.count( 1 ) );
- assertNull( table.get( 1 ) );
- assertFalse( table.has( 1 ) );
+ assertEquals( 0, table.count( "1" ) );
+ table.remove( "1" );
+ assertEquals( 0, table.count( "1" ) );
+ table.put( "1", "1" );
+ assertEquals( 1, table.count( "1" ) );
+ table.remove( "1", "1" );
+ assertEquals( 0, table.count( "1" ) );
+ assertNull( table.get( "1" ) );
+ assertFalse( table.has( "1" ) );
}
@Test
public void testRemove() throws Exception
{
- table.put( 1, 1 );
- table.remove( 1 );
- assertNull( table.get( 1 ) );
+ table.put( "1", "1" );
+ table.remove( "1" );
+ assertNull( table.get( "1" ) );
- table.put( 10, 10 );
+ table.put( "10", "10" );
- table.remove( 10, 11 );
- assertFalse( table.has( 10, 11 ) );
+ table.remove( "10", "11" );
+ assertFalse( table.has( "10", "11" ) );
// assertNull( table.remove( null ) );
// assertNull( table.remove( null, null ) );
@@ -264,50 +303,53 @@
{
final int SIZE = 15;
- for ( int ii = 0; ii < SIZE; ii++ )
+ for ( int i = 0; i < SIZE; i++ )
{
- table.put( ii, ii );
+ String istr = Integer.toString( i );
+ table.put( istr, istr );
}
+
assertEquals( SIZE, table.count() );
- table.put( 0, 0 );
- assertTrue( table.has( 0, 0 ) );
+ table.put( "0", "0" );
+ assertTrue( table.has( "0", "0" ) );
}
@Test
public void testHas() throws Exception
{
- assertFalse( table.has( 1 ) );
+ assertFalse( table.has( "1" ) );
final int SIZE = 15;
- for ( int ii = 0; ii < SIZE; ii++ )
+ for ( int i = 0; i < SIZE; i++ )
{
- table.put( ii, ii );
+ String istr = Integer.toString( i );
+ table.put( istr, istr );
}
assertEquals( SIZE, table.count() );
- assertFalse( table.has( -1 ) );
- assertTrue( table.hasGreaterOrEqual( -1 ) );
- assertFalse( table.hasLessOrEqual( -1 ) );
-
- assertTrue( table.has( 0 ) );
- assertTrue( table.hasGreaterOrEqual( 0 ) );
- assertTrue( table.hasLessOrEqual( 0 ) );
-
- assertTrue( table.has( SIZE - 1 ) );
- assertTrue( table.hasGreaterOrEqual( SIZE - 1 ) );
- assertTrue( table.hasLessOrEqual( SIZE - 1 ) );
-
- assertFalse( table.has( SIZE ) );
- assertFalse( table.hasGreaterOrEqual( SIZE ) );
- assertTrue( table.hasLessOrEqual( SIZE ) );
- table.remove( 10 );
- table.remove( 11 );
- assertTrue( table.hasLessOrEqual( 11 ) );
+ assertFalse( table.has( "-1" ) );
+ assertTrue( table.hasGreaterOrEqual( "-1" ) );
+ assertFalse( table.hasLessOrEqual( "-1" ) );
+
+ assertTrue( table.has( "0" ) );
+ assertTrue( table.hasGreaterOrEqual( "0" ) );
+ assertTrue( table.hasLessOrEqual( "0" ) );
+
+ assertTrue( table.has( Integer.toString( SIZE - 1 ) ) );
+ assertTrue( table.hasGreaterOrEqual( Integer.toString( SIZE - 1 ) ) );
+ assertTrue( table.hasLessOrEqual( Integer.toString( SIZE - 1 ) ) );
+
+ assertFalse( table.has( Integer.toString( SIZE ) ) );
+ assertFalse( table.hasGreaterOrEqual( Integer.toString( SIZE ) ) );
+ assertTrue( table.hasLessOrEqual( Integer.toString( SIZE ) ) );
+ table.remove( "10" );
+ table.remove( "11" );
+ assertTrue( table.hasLessOrEqual( "11" ) );
try
{
- assertFalse( table.hasGreaterOrEqual( 1, 1 ) );
+ assertFalse( table.hasGreaterOrEqual( "1", "1" ) );
fail( "Should never get here." );
}
catch ( UnsupportedOperationException e )
@@ -316,7 +358,7 @@
try
{
- assertFalse( table.hasLessOrEqual( 1, 1 ) );
+ assertFalse( table.hasLessOrEqual( "1", "1" ) );
fail( "Should never get here." );
}
catch ( UnsupportedOperationException e )
@@ -325,7 +367,7 @@
try
{
- assertTrue( table.hasLessOrEqual( 1, 2 ) );
+ assertTrue( table.hasLessOrEqual( "1", "2" ) );
fail( "Should never get here since no dups tables " +
"freak when they cannot find a value comparator" );
}
@@ -334,66 +376,4 @@
assertNotNull( e );
}
}
-
-
- private class MockComparatorRegistry implements ComparatorRegistry
- {
- private Comparator comparator = new Comparator<Integer>()
- {
- public int compare( Integer i1, Integer i2 )
- {
- return i1.compareTo( i2 );
- }
- };
-
-
- public String getSchemaName( String oid ) throws NamingException
- {
- return null;
- }
-
-
- public void register( ComparatorDescription description, Comparator comparator ) throws NamingException
- {
- }
-
-
- public Comparator lookup( String oid ) throws NamingException
- {
- return comparator;
- }
-
-
- public boolean hasComparator( String oid )
- {
- return true;
- }
-
-
- public Iterator<String> iterator()
- {
- return null;
- }
-
-
- public Iterator<ComparatorDescription> comparatorDescriptionIterator()
- {
- return null;
- }
-
-
- public void unregister( String oid ) throws NamingException
- {
- }
-
-
- public void unregisterSchemaElements( String schemaName )
- {
- }
-
-
- public void renameSchema( String originalSchemaName, String newSchemaName )
- {
- }
- }
}
Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java Wed Jan 6 18:26:43 2010
@@ -19,29 +19,37 @@
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.directory.server.xdbm.Table;
-import org.apache.directory.server.xdbm.Tuple;
-import org.apache.directory.server.schema.SerializableComparator;
-import org.apache.directory.server.schema.registries.ComparatorRegistry;
-import org.apache.directory.shared.ldap.cursor.Cursor;
-import org.apache.directory.shared.ldap.schema.parsers.ComparatorDescription;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
-import java.util.Comparator;
-import java.util.Iterator;
import jdbm.RecordManager;
+import jdbm.helper.DefaultSerializer;
import jdbm.helper.IntegerSerializer;
import jdbm.recman.BaseRecordManager;
-import javax.naming.NamingException;
+import org.apache.directory.server.xdbm.Table;
+import org.apache.directory.server.xdbm.Tuple;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.comparators.SerializableComparator;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -55,10 +63,48 @@
private static final Logger LOG = LoggerFactory.getLogger( JdbmTableWithDuplicatesTest.class.getSimpleName() );
private static final String TEST_OUTPUT_PATH = "test.output.path";
private static final int SIZE = 15;
+ private static final int SIZE2 = 30;
+
+ private static final String SIZE_MINUS_ONE_STR = "14";
+ private static final String SIZE_STR = "15";
+ private static final String SIZE_PLUS_ONE_STR = "16";
+ private static final String SIZE_PLUS_TWO_STR = "17";
+
+ private static final String SIZE2_MINUS_ONE_STR = "29";
+ private static final String SIZE2_STR = "30";
+ private static final String SIZE2_PLUS_ONE_STR = "31";
- transient Table<Integer,Integer> table;
+ transient Table<String,String> table;
transient File dbFile;
transient RecordManager recman;
+ private static SchemaManager schemaManager;
+
+
+ @BeforeClass
+ public static void init() throws Exception
+ {
+ String workingDirectory = System.getProperty( "workingDirectory" );
+
+ if ( workingDirectory == null )
+ {
+ String path = DupsContainerCursorTest.class.getResource( "" ).getPath();
+ int targetPos = path.indexOf( "target" );
+ workingDirectory = path.substring( 0, targetPos + 6 );
+ }
+
+ File schemaRepository = new File( workingDirectory, "schema" );
+ SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
+ extractor.extractOrCopy( true );
+ LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+ schemaManager = new DefaultSchemaManager( loader );
+
+ boolean loaded = schemaManager.loadAllEnabled();
+
+ if ( !loaded )
+ {
+ fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+ }
+ }
@Before
@@ -66,6 +112,7 @@
{
destryTable();
File tmpDir = null;
+
if ( System.getProperty( TEST_OUTPUT_PATH, null ) != null )
{
tmpDir = new File( System.getProperty( TEST_OUTPUT_PATH ) );
@@ -74,13 +121,11 @@
dbFile = File.createTempFile( getClass().getSimpleName(), "db", tmpDir );
recman = new BaseRecordManager( dbFile.getAbsolutePath() );
- // gosh this is a terrible use of a global static variable
- SerializableComparator.setRegistry( new MockComparatorRegistry() );
+ SerializableComparator<String> comparator = new SerializableComparator<String>( SchemaConstants.INTEGER_ORDERING_MATCH_MR_OID );
+ comparator.setSchemaManager( schemaManager );
- table = new JdbmTable<Integer,Integer>( "test", SIZE, recman,
- new SerializableComparator<Integer>( "" ),
- new SerializableComparator<Integer>( "" ),
- new IntegerSerializer(), new IntegerSerializer() );
+ table = new JdbmTable<String,String>( schemaManager, "test", SIZE, recman,
+ comparator, comparator, new DefaultSerializer(), new DefaultSerializer() );
LOG.debug( "Created new table and populated it with data" );
}
@@ -126,7 +171,7 @@
@Test
public void testCountOneArg() throws Exception
{
- assertEquals( 0, table.count( 3 ) );
+ assertEquals( 0, table.count( "3" ) );
assertEquals( 0, table.count( null ) );
}
@@ -135,10 +180,12 @@
public void testNullKeyComparator() throws Exception
{
assertNotNull( ( ( JdbmTable ) table ).getKeyComparator() );
- new JdbmTable<Integer,Integer>( "test", SIZE, recman,
- null,
- new SerializableComparator<Integer>( "" ),
- null, new IntegerSerializer() );
+
+ SerializableComparator<String> comparator = new SerializableComparator<String>( SchemaConstants.INTEGER_ORDERING_MATCH_MR_OID );
+ comparator.setSchemaManager( schemaManager );
+
+ new JdbmTable<String,String>( schemaManager, "test", SIZE, recman,
+ null, comparator, null, new IntegerSerializer() );
}
@@ -146,24 +193,27 @@
public void testNullValueComparator() throws Exception
{
assertNotNull( ( ( JdbmTable ) table ).getValueComparator() );
- new JdbmTable<Integer,Integer>( "test", SIZE, recman,
- new SerializableComparator<Integer>( "" ),
- null,
- null, new IntegerSerializer() );
+
+ SerializableComparator<String> comparator = new SerializableComparator<String>( SchemaConstants.INTEGER_ORDERING_MATCH_MR_OID );
+ comparator.setSchemaManager( schemaManager );
+
+ new JdbmTable<String,String>( schemaManager, "test", SIZE, recman,
+ comparator, null, null, new IntegerSerializer() );
}
@Test
public void testCloseReopen() throws Exception
{
- table.put( 1, 2 );
- assertTrue( 2 == table.get( 1 ) );
+ table.put( "1", "2" );
+ assertEquals( "2", table.get( "1" ) );
table.close();
- table = new JdbmTable<Integer,Integer>( "test", SIZE, recman,
- new SerializableComparator<Integer>( "" ),
- new SerializableComparator<Integer>( "" ),
- new IntegerSerializer(), new IntegerSerializer() );
- assertTrue( 2 == table.get( 1 ) );
+ SerializableComparator<String> comparator = new SerializableComparator<String>( SchemaConstants.INTEGER_ORDERING_MATCH_MR_OID );
+ comparator.setSchemaManager( schemaManager );
+
+ table = new JdbmTable<String,String>( schemaManager, "test", SIZE, recman,
+ comparator, comparator, new DefaultSerializer(), new DefaultSerializer() );
+ assertEquals( "2", table.get( "1" ) );
}
@@ -181,23 +231,23 @@
{
// Test the count methods
assertEquals( 0, table.count() );
- assertEquals( 0, table.count( 1 ) );
+ assertEquals( 0, table.count( "1" ) );
// Test get method
- assertNull( table.get( 0 ) );
+ assertNull( table.get( "0" ) );
assertNull( table.get( null ) );
// Test remove methods
- table.remove( 1 );
- assertFalse( table.has( 1 ) );
+ table.remove( "1" );
+ assertFalse( table.has( "1" ) );
// Test has operations
- assertFalse( table.has( 1 ) );
- assertFalse( table.has( 1, 0 ) );
- assertFalse( table.hasGreaterOrEqual( 1 ) );
- assertFalse( table.hasLessOrEqual( 1 ) );
- assertFalse( table.hasGreaterOrEqual( 1, 0 ) );
- assertFalse( table.hasLessOrEqual( 1, 0 ) );
+ assertFalse( table.has( "1" ) );
+ assertFalse( table.has( "1", "0" ) );
+ assertFalse( table.hasGreaterOrEqual( "1" ) );
+ assertFalse( table.hasLessOrEqual( "1" ) );
+ assertFalse( table.hasGreaterOrEqual( "1", "0" ) );
+ assertFalse( table.hasLessOrEqual( "1", "0" ) );
}
@@ -206,128 +256,139 @@
{
final int SIZE = 15;
- for ( int ii = 0; ii < SIZE; ii++ )
+ for ( int i = 0; i < SIZE; i++ )
{
- table.put( ii, ii );
+ String istr = Integer.toString( i );
+ table.put( istr, istr );
}
+
assertEquals( SIZE, table.count() );
- table.put( 0, 0 );
- assertTrue( table.has( 0, 0 ) );
+ table.put( "0", "0" );
+ assertTrue( table.has( "0", "0" ) );
// add some duplicates
- for ( int ii = 0; ii < SIZE*2; ii++ )
+ for ( int i = 0; i < SIZE*2; i++ )
{
- table.put( SIZE*2, ii );
+ String istr = Integer.toString( i );
+ table.put( SIZE2_STR, istr );
}
+
assertEquals( SIZE*3, table.count() );
- table.put( 0, 0 );
- assertTrue( table.has( 0, 0 ) );
+ table.put( "0", "0" );
+ assertTrue( table.has( "0", "0" ) );
- table.put( SIZE*2, 0 );
- assertTrue( table.has( SIZE*2, 0 ) );
+ table.put( SIZE2_STR, "0" );
+ assertTrue( table.has( SIZE2_STR, "0" ) );
}
@Test
public void testHas() throws Exception
{
- assertFalse( table.has( 1 ) );
+ assertFalse( table.has( "1" ) );
- for ( int ii = 0; ii < SIZE*2; ii++ )
+ for ( int i = 0; i < SIZE*2; i++ )
{
- table.put( 1, ii );
+ String istr = Integer.toString( i );
+ table.put( "1", istr );
}
- assertEquals( SIZE*2, table.count() );
+
+ assertEquals( SIZE2, table.count() );
+
+ assertTrue( table.has( "1" ) );
+ assertTrue( table.has( "1", "0" ) );
+ assertFalse( table.has( "1", SIZE2_STR ) );
- assertTrue( table.has( 1 ) );
- assertTrue( table.has( 1, 0 ) );
- assertFalse( table.has( 1, SIZE*2 ) );
-
- assertTrue( table.hasGreaterOrEqual( 1, 0 ) );
- assertTrue( table.hasLessOrEqual( 1, 0 ) );
- assertFalse( table.hasLessOrEqual( 1, -1 ) );
-
- assertTrue( table.hasGreaterOrEqual( 1, SIZE*2 - 1 ) );
- assertTrue( table.hasLessOrEqual( 1, SIZE*2 - 1 ) );
- assertTrue( table.hasGreaterOrEqual( 1, SIZE*2 - 1 ) );
- assertTrue( table.hasLessOrEqual( 1, SIZE*2 ) );
- assertFalse( table.hasGreaterOrEqual( 1, SIZE*2 ) );
- assertFalse( table.has( 1, SIZE*2 ) );
+ assertTrue( table.hasGreaterOrEqual( "1", "0" ) );
+ assertTrue( table.hasLessOrEqual( "1", "0" ) );
+ assertFalse( table.hasLessOrEqual( "1", "-1" ) );
+
+ assertTrue( table.hasGreaterOrEqual( "1", SIZE2_MINUS_ONE_STR ) );
+ assertTrue( table.hasLessOrEqual( "1", SIZE2_MINUS_ONE_STR ) );
+ assertTrue( table.hasGreaterOrEqual( "1", SIZE2_MINUS_ONE_STR ) );
+ assertTrue( table.hasLessOrEqual( "1", SIZE2_STR ) );
+ assertFalse( table.hasGreaterOrEqual( "1", SIZE2_STR ) );
+ assertFalse( table.has( "1", SIZE2_STR ) );
// let's go over the this limit now and ask the same questions
- table.put( 1, SIZE*2 );
+ table.put( "1", SIZE2_STR );
- assertTrue( table.has( 1 ) );
- assertTrue( table.has( 1, 0 ) );
- assertTrue( table.has( 1, SIZE*2 ) );
+ assertTrue( table.has( "1" ) );
+ assertTrue( table.has( "1", "0" ) );
+ assertTrue( table.has( "1", SIZE2_STR ) );
assertFalse( table.has( null, null ) );
- assertTrue( table.hasGreaterOrEqual( 1, 0 ) );
- assertTrue( table.hasLessOrEqual( 1, 0 ) );
- assertFalse( table.hasLessOrEqual( 1, -1 ) );
+ assertTrue( table.hasGreaterOrEqual( "1", "0" ) );
+ assertTrue( table.hasLessOrEqual( "1", "0" ) );
+ assertFalse( table.hasLessOrEqual( "1", "-1" ) );
assertFalse( table.hasGreaterOrEqual( null, null ) );
assertFalse( table.hasLessOrEqual( null, null ) );
- assertTrue( table.hasGreaterOrEqual( 1, SIZE*2 ) );
- assertTrue( table.hasLessOrEqual( 1, SIZE*2 ) );
- assertTrue( table.hasGreaterOrEqual( 1, SIZE*2 ) );
- assertTrue( table.hasLessOrEqual( 1, SIZE*2 + 1 ) );
- assertFalse( table.hasGreaterOrEqual( 1, SIZE*2 + 1 ) );
- assertFalse( table.has( 1, SIZE*2 + 1 ) );
+ assertTrue( table.hasGreaterOrEqual( "1", SIZE2_STR ) );
+ assertTrue( table.hasLessOrEqual( "1", SIZE2_STR ) );
+ assertTrue( table.hasGreaterOrEqual( "1", SIZE2_STR ) );
+ assertTrue( table.hasLessOrEqual( "1", SIZE2_STR ) );
+ assertFalse( table.hasGreaterOrEqual( "1", SIZE2_PLUS_ONE_STR ) );
+ assertFalse( table.has( "1", SIZE2_PLUS_ONE_STR ) );
// now do not add duplicates and check has( key, boolean )
- for ( int ii = 0; ii < SIZE; ii++ )
+ for ( int i = 0; i < SIZE; i++ )
{
- // note we are not adding duplicates not put( 1, ii )
- table.put( ii, ii );
+ // note we are not adding duplicates not put( 1, i )
+ String istr = Integer.toString( i );
+ table.put( istr, istr );
}
- assertFalse( table.has( -1 ) );
- assertTrue( table.hasGreaterOrEqual( -1 ) );
- assertFalse( table.hasLessOrEqual( -1 ) );
+ assertFalse( table.has( "-1" ) );
+ assertTrue( table.hasGreaterOrEqual( "-1" ) );
+ assertFalse( table.hasLessOrEqual( "-1" ) );
- assertTrue( table.has( 0 ) );
- assertTrue( table.hasGreaterOrEqual( 0 ) );
- assertTrue( table.hasLessOrEqual( 0 ) );
+ assertTrue( table.has( "0" ) );
+ assertTrue( table.hasGreaterOrEqual( "0" ) );
+ assertTrue( table.hasLessOrEqual( "0" ) );
- assertTrue( table.has( SIZE - 1 ) );
- assertTrue( table.hasGreaterOrEqual( SIZE - 1 ) );
- assertTrue( table.hasLessOrEqual( SIZE - 1 ) );
+ assertTrue( table.has( SIZE_MINUS_ONE_STR ) );
+ assertTrue( table.hasGreaterOrEqual( SIZE_MINUS_ONE_STR ) );
+ assertTrue( table.hasLessOrEqual( SIZE_MINUS_ONE_STR ) );
- assertFalse( table.has( SIZE ) );
- assertFalse( table.hasGreaterOrEqual( SIZE ) );
- assertTrue( table.hasLessOrEqual( SIZE ) );
+ assertFalse( table.has( SIZE_STR ) );
+ assertFalse( table.hasGreaterOrEqual( SIZE_STR ) );
+ assertTrue( table.hasLessOrEqual( SIZE_STR ) );
- for ( int ii = 0; ii < SIZE; ii++ )
+ for ( int i = 0; i < SIZE; i++ )
{
- if ( ii == 1 ) // don't delete the node which had multiple values
+ if ( i == 1 ) // don't delete the node which had multiple values
{
continue;
}
- table.remove( ii, ii );
+
+ String istr = Integer.toString( i );
+ table.remove( istr, istr );
}
// delete all values of the duplicate key one by one
- for ( int ii = 0; ii < SIZE * 2 + 1; ii++ )
+ for ( int i = 0; i < SIZE * 2 + 1; i++ )
{
- table.remove( 1, ii );
+ String istr = Integer.toString( i );
+ table.remove( "1", istr );
}
- Cursor<Tuple<Integer, Integer>> cursor = table.cursor();
+ Cursor<Tuple<String, String>> cursor = table.cursor();
//System.out.println( "remaining ..." );
cursor.beforeFirst();
+
while ( cursor.next() )
{
//System.out.println( cursor.get() );
}
- assertFalse( table.hasLessOrEqual( 1 ) );
- assertFalse( table.hasLessOrEqual( 1, 10 ) );
- assertFalse( table.hasGreaterOrEqual( 1 ) );
- assertFalse( table.hasGreaterOrEqual( 1, 0 ) );
+ assertFalse( table.hasLessOrEqual( "1" ) );
+ assertFalse( table.hasLessOrEqual( "1", "10" ) );
+ assertFalse( table.hasGreaterOrEqual( "1" ) );
+ assertFalse( table.hasGreaterOrEqual( "1", "0" ) );
- table.put( 1, 0 );
+ table.put( "1", "0" );
}
@@ -337,35 +398,36 @@
{
assertEquals( 0, table.count() );
- table.put( 1, 1 );
- table.put( 1, 2 );
+ table.put( "1", "1" );
+ table.put( "1", "2" );
assertEquals( 2, table.count() );
- table.remove( 1 );
- assertFalse( table.has( 1 ) );
+ table.remove( "1" );
+ assertFalse( table.has( "1" ) );
assertEquals( 0, table.count() );
- table.put( 10, 10 );
+ table.put( "10", "10" );
assertEquals( 1, table.count() );
- table.remove( 10, 11 );
- assertFalse( table.has( 10, 11 ) );
+ table.remove( "10", "11" );
+ assertFalse( table.has( "10", "11" ) );
assertEquals( 1, table.count() );
- table.remove( 10, 10 );
- assertFalse( table.has( 10, 10 ) );
+ table.remove( "10", "10" );
+ assertFalse( table.has( "10", "10" ) );
assertEquals( 0, table.count() );
// add duplicates
- for ( int ii = 0; ii < SIZE*2; ii++ )
+ for ( int i = 0; i < SIZE*2; i++ )
{
- table.put( 0, ii );
+ String istr = Integer.toString( i );
+ table.put( "0", istr );
}
assertEquals( SIZE*2, table.count() );
- table.remove( 0, 100 );
- assertFalse( table.has( 0, 100 ) );
+ table.remove( "0", "100" );
+ assertFalse( table.has( "0", "100" ) );
assertEquals( SIZE*2, table.count() );
- table.remove( 0 );
- assertNull( table.get( 0 ) );
+ table.remove( "0" );
+ assertNull( table.get( "0" ) );
}
@@ -373,13 +435,14 @@
public void testLoadData() throws Exception
{
// add some data to it
- for ( int ii = 0; ii < SIZE; ii++ )
+ for ( int i = 0; i < SIZE; i++ )
{
- table.put( ii, ii );
+ String istr = Integer.toString( i );
+ table.put( istr, istr );
}
assertEquals( 15, table.count() );
- assertEquals( 1, table.count( 0 ) );
+ assertEquals( 1, table.count( "0" ) );
/*
* If counts are exact then we can test for exact values. Again this
@@ -389,13 +452,13 @@
if ( table.isCountExact() )
{
- assertEquals( 5, table.lessThanCount( 5 ) );
- assertEquals( 9, table.greaterThanCount( 5 ) );
+ assertEquals( 5, table.lessThanCount( "5" ) );
+ assertEquals( 9, table.greaterThanCount( "5" ) );
}
else
{
- assertEquals( SIZE, table.lessThanCount( 5 ) );
- assertEquals( SIZE, table.greaterThanCount( 5 ) );
+ assertEquals( SIZE, table.lessThanCount( "5" ) );
+ assertEquals( SIZE, table.greaterThanCount( "5" ) );
}
}
@@ -403,50 +466,55 @@
@Test
public void testDuplicateLimit() throws Exception
{
- for ( int ii = 0; ii < SIZE; ii++ )
+ for ( int i = 0; i < SIZE; i++ )
{
- table.put( 1, ii );
+ String istr = Integer.toString( i );
+ table.put( "1", istr );
}
assertEquals( SIZE, table.count() );
- assertEquals( SIZE, table.count( 1 ) );
+ assertEquals( SIZE, table.count( "1" ) );
// this switches to B+Trees from AvlTree
- table.put( 1, SIZE );
+ table.put( "1", SIZE_STR );
assertEquals( SIZE + 1, table.count() );
- assertEquals( SIZE + 1, table.count( 1 ) );
+ assertEquals( SIZE + 1, table.count( "1" ) );
// go one more over still a B+Tree
- table.put( 1, SIZE + 1 );
+ table.put( "1", SIZE_PLUS_ONE_STR );
assertEquals( SIZE + 2, table.count() );
- assertEquals( SIZE + 2, table.count( 1 ) );
- assertEquals( 0, ( int ) table.get( 1 ) );
+ assertEquals( SIZE + 2, table.count( "1" ) );
+ assertEquals( "0", table.get( "1" ) );
// now start removing and see what happens
- table.remove( 1, SIZE + 1 );
- assertFalse( table.has( 1, SIZE + 1 ) );
- assertTrue( table.has( 1, SIZE ) );
+ table.remove( "1", SIZE_PLUS_ONE_STR );
+ assertFalse( table.has( "1", SIZE_PLUS_ONE_STR ) );
+ assertTrue( table.has( "1", SIZE_STR ) );
assertEquals( SIZE + 1, table.count() );
- assertEquals( SIZE + 1, table.count( 1 ) );
+ assertEquals( SIZE + 1, table.count( "1" ) );
// this switches to AvlTree from B+Trees
- table.remove( 1, SIZE );
- assertFalse( table.has( 1, SIZE ) );
+ table.remove( "1", SIZE_STR );
+ assertFalse( table.has( "1", SIZE_STR ) );
assertEquals( SIZE, table.count() );
- assertEquals( SIZE, table.count( 1 ) );
- assertTrue( 0 == table.get( 1 ) );
+ assertEquals( SIZE, table.count( "1" ) );
+ assertEquals( "0", table.get( "1" ) );
- for ( int ii = SIZE - 1; ii >= 0; ii-- )
+ for ( int i = SIZE - 1; i >= 0; i-- )
{
- table.remove( 1, ii );
+ String istr = Integer.toString( i );
+ table.remove( "1", istr );
}
+
assertEquals( 0, table.count() );
- for ( int ii = 0; ii < SIZE - 1; ii++ )
+ for ( int i = 0; i < SIZE - 1; i++ )
{
- table.put( 1, ii );
+ String istr = Integer.toString( i );
+ table.put( "1", istr );
}
+
assertEquals( SIZE - 1, table.count() );
- table.remove( 1 );
+ table.remove( "1" );
assertEquals( 0, table.count() );
}
@@ -463,7 +531,7 @@
try
{
- table.put( 1, null );
+ table.put( "1", null );
fail( "should never get here due to IllegalArgumentException" );
}
catch( IllegalArgumentException e )
@@ -473,7 +541,7 @@
try
{
- table.put( null, 1 );
+ table.put( null, "1" );
fail( "should never get here due to IllegalArgumentException" );
}
catch( IllegalArgumentException e )
@@ -482,21 +550,21 @@
}
assertEquals( 0, table.count() );
- assertEquals( null, table.get( 1 ) );
+ assertEquals( null, table.get( "1" ) );
// Let's add the key with two valid values and remove all values
- table.remove( 1 );
- table.put( 1, 1 );
- table.put( 1, 2 );
- assertEquals( 2, table.count( 1 ) );
- table.remove( 1, 1 );
- assertEquals( 1, table.count( 1 ) );
- assertTrue( 2 == table.get( 1 ) );
-
- table.remove( 1, 2 );
- assertNull( table.get( 1 ) );
- assertEquals( 0, table.count( 1 ) );
- assertFalse( table.has( 1 ) );
+ table.remove( "1" );
+ table.put( "1", "1" );
+ table.put( "1", "2" );
+ assertEquals( 2, table.count( "1" ) );
+ table.remove( "1", "1" );
+ assertEquals( 1, table.count( "1" ) );
+ assertEquals( "2", table.get( "1" ) );
+
+ table.remove( "1", "2" );
+ assertNull( table.get( "1" ) );
+ assertEquals( 0, table.count( "1" ) );
+ assertFalse( table.has( "1" ) );
}
@@ -507,17 +575,21 @@
( ( JdbmTable ) table ).close();
// test value btree creation without serializer
- table = new JdbmTable<Integer,Integer>( "test", SIZE, recman,
- new SerializableComparator<Integer>( "" ),
- new SerializableComparator<Integer>( "" ),
- new IntegerSerializer(), null );
+ SerializableComparator<String> comparator = new SerializableComparator<String>( SchemaConstants.INTEGER_ORDERING_MATCH_MR_OID );
+ comparator.setSchemaManager( schemaManager );
+
+ table = new JdbmTable<String,String>( schemaManager, "test", SIZE, recman,
+ comparator, comparator, new DefaultSerializer(), null );
assertNull( ( ( JdbmTable ) table ).getValueSerializer() );
- for ( int ii = 0; ii < SIZE + 1; ii++ )
+
+ for ( int i = 0; i < SIZE + 1; i++ )
{
- table.put( 0, ii );
+ String istr = Integer.toString( i );
+ table.put( "0", istr );
}
- table.remove( 0 );
- assertFalse( table.has( 0 ) );
+
+ table.remove( "0" );
+ assertFalse( table.has( "0" ) );
}
@@ -532,7 +604,7 @@
try
{
- table.put( 1, null );
+ table.put( "1", null );
fail( "should never get here due to IllegalArgumentException" );
}
catch( IllegalArgumentException e )
@@ -542,7 +614,7 @@
try
{
- table.put( null, 2 );
+ table.put( null, "2" );
fail( "should never get here due to IllegalArgumentException" );
}
catch( IllegalArgumentException e )
@@ -551,81 +623,20 @@
}
assertEquals( 0, table.count() );
- assertEquals( null, table.get( 1 ) );
+ assertEquals( null, table.get( "1" ) );
// Let's add the key with two valid values and remove all values
- table.remove( 1 );
- table.put( 1, 1 );
- table.put( 1, 2 );
- assertEquals( 2, table.count( 1 ) );
- table.remove( 1, 1 );
- assertEquals( 1, table.count( 1 ) );
- assertTrue( 2 == table.get( 1 ) );
-
- table.remove( 1, 2 );
- assertNull( table.get( 1 ) );
- assertEquals( 0, table.count( 1 ) );
- assertFalse( table.has( 1 ) );
- }
-
-
- private class MockComparatorRegistry implements ComparatorRegistry
- {
- private Comparator<Integer> comparator = new Comparator<Integer>()
- {
- public int compare( Integer i1, Integer i2 )
- {
- return i1.compareTo( i2 );
- }
- };
-
- public String getSchemaName( String oid ) throws NamingException
- {
- return null;
- }
-
-
- public void register( ComparatorDescription description, Comparator comparator ) throws NamingException
- {
- }
-
-
- public Comparator lookup( String oid ) throws NamingException
- {
- return comparator;
- }
-
-
- public boolean hasComparator( String oid )
- {
- return true;
- }
-
-
- public Iterator<String> iterator()
- {
- return null;
- }
-
-
- public Iterator<ComparatorDescription> comparatorDescriptionIterator()
- {
- return null;
- }
-
-
- public void unregister( String oid ) throws NamingException
- {
- }
-
-
- public void unregisterSchemaElements( String schemaName )
- {
- }
-
-
- public void renameSchema( String originalSchemaName, String newSchemaName )
- {
- }
+ table.remove( "1" );
+ table.put( "1", "1" );
+ table.put( "1", "2" );
+ assertEquals( 2, table.count( "1" ) );
+ table.remove( "1", "1" );
+ assertEquals( 1, table.count( "1" ) );
+ assertEquals( "2", table.get( "1" ) );
+
+ table.remove( "1", "2" );
+ assertNull( table.get( "1" ) );
+ assertEquals( 0, table.count( "1" ) );
+ assertFalse( table.has( "1" ) );
}
}
Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursorTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursorTest.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursorTest.java Wed Jan 6 18:26:43 2010
@@ -19,7 +19,6 @@
package org.apache.directory.server.core.partition.impl.btree.jdbm;
-import org.junit.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
@@ -27,6 +26,9 @@
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNull;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -67,6 +69,7 @@
public void createCursor() throws Exception
{
File tmpDir = null;
+
if ( System.getProperty( TEST_OUTPUT_PATH, null ) != null )
{
tmpDir = new File( System.getProperty( TEST_OUTPUT_PATH ) );
Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java Wed Jan 6 18:26:43 2010
@@ -19,7 +19,6 @@
package org.apache.directory.server.core.partition.impl.btree.jdbm;
-import org.junit.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
@@ -27,6 +26,9 @@
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNull;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -67,6 +69,7 @@
public void createCursor() throws Exception
{
File tmpDir = null;
+
if ( System.getProperty( TEST_OUTPUT_PATH, null ) != null )
{
tmpDir = new File( System.getProperty( TEST_OUTPUT_PATH ) );
Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursorTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursorTest.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursorTest.java Wed Jan 6 18:26:43 2010
@@ -22,25 +22,29 @@
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import java.util.Comparator;
-import java.util.Iterator;
-
-import javax.naming.NamingException;
import jdbm.RecordManager;
import jdbm.btree.BTree;
-import jdbm.helper.IntegerSerializer;
+import jdbm.helper.DefaultSerializer;
import jdbm.recman.BaseRecordManager;
-import org.apache.directory.server.schema.SerializableComparator;
-import org.apache.directory.server.schema.registries.ComparatorRegistry;
import org.apache.directory.server.xdbm.Tuple;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.cursor.InvalidCursorPositionException;
-import org.apache.directory.shared.ldap.schema.parsers.ComparatorDescription;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.comparators.SerializableComparator;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
import org.junit.After;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
@@ -52,23 +56,50 @@
*/
public class KeyTupleBTreeCursorTest
{
-
- JdbmTable<Integer,Integer> table;
- Comparator<Integer> comparator;
- KeyTupleBTreeCursor<Integer, Integer> cursor;
+ JdbmTable<String,String> table;
+ Comparator<String> comparator;
+ KeyTupleBTreeCursor<String, String> cursor;
File dbFile;
RecordManager recman;
- private static final Integer KEY = 1;
+ private static final String KEY = "1";
private static final String TEST_OUTPUT_PATH = "test.output.path";
+ private static SchemaManager schemaManager;
+
+
+ @BeforeClass
+ public static void init() throws Exception
+ {
+ String workingDirectory = System.getProperty( "workingDirectory" );
+
+ if ( workingDirectory == null )
+ {
+ String path = DupsContainerCursorTest.class.getResource( "" ).getPath();
+ int targetPos = path.indexOf( "target" );
+ workingDirectory = path.substring( 0, targetPos + 6 );
+ }
+
+ File schemaRepository = new File( workingDirectory, "schema" );
+ SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
+ extractor.extractOrCopy( true );
+ LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+ schemaManager = new DefaultSchemaManager( loader );
+
+ boolean loaded = schemaManager.loadAllEnabled();
+
+ if ( !loaded )
+ {
+ fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+ }
+ }
@Before
public void createTree() throws Exception
{
- comparator = new Comparator<Integer>()
+ comparator = new Comparator<String>()
{
- public int compare( Integer i1, Integer i2 )
+ public int compare( String i1, String i2 )
{
return i1.compareTo( i2 );
}
@@ -84,14 +115,13 @@
dbFile = File.createTempFile( getClass().getSimpleName(), "db", tmpDir );
recman = new BaseRecordManager( dbFile.getAbsolutePath() );
- SerializableComparator.setRegistry( new MockComparatorRegistry() );
-
- table = new JdbmTable<Integer,Integer>( "test", 6, recman,
- new SerializableComparator<Integer>( "" ),
- new SerializableComparator<Integer>( "" ),
- new IntegerSerializer(), new IntegerSerializer() );
+ SerializableComparator<String> comparator = new SerializableComparator<String>( SchemaConstants.INTEGER_ORDERING_MATCH_MR_OID );
+ comparator.setSchemaManager( schemaManager );
+
+ table = new JdbmTable<String,String>( schemaManager, "test", 6, recman,
+ comparator, comparator, new DefaultSerializer(), new DefaultSerializer() );
- cursor = new KeyTupleBTreeCursor<Integer, Integer>( table.getBTree(), KEY, comparator );
+ cursor = new KeyTupleBTreeCursor<String, String>( table.getBTree(), KEY, comparator );
}
@@ -129,49 +159,49 @@
@Test
public void testNonEmptyCursor() throws Exception
{
- table.put( KEY, 3 );
- table.put( KEY, 5 );
- table.put( KEY, 7 );
- table.put( KEY, 12 );
- table.put( KEY, 0 );
- table.put( KEY, 30 );
- table.put( KEY, 25 );
+ table.put( KEY, "3" );
+ table.put( KEY, "5" );
+ table.put( KEY, "7" );
+ table.put( KEY, "12" );
+ table.put( KEY, "0" );
+ table.put( KEY, "30" );
+ table.put( KEY, "25" );
- cursor = new KeyTupleBTreeCursor<Integer, Integer>( getDupsContainer(), KEY, comparator );
+ cursor = new KeyTupleBTreeCursor<String, String>( getDupsContainer(), KEY, comparator );
- cursor.before( new Tuple<Integer, Integer>( KEY, 3) );
+ cursor.before( new Tuple<String, String>( KEY, "3" ) );
assertTrue( cursor.next() );
- assertEquals( 3, ( int ) cursor.get().getValue() );
+ assertEquals( "3", cursor.get().getValue() );
- cursor.after( new Tuple<Integer, Integer>( KEY, 100 ) );
+ cursor.after( new Tuple<String, String>( KEY, "100" ) );
assertFalse( cursor.next() );
cursor.beforeFirst();
- cursor.after( new Tuple<Integer, Integer>( KEY, 13 ) );
+ cursor.after( new Tuple<String, String>( KEY, "13" ) );
assertTrue( cursor.next() );
- assertEquals( 25, ( int ) cursor.get().getValue() );
+ assertEquals( "25", cursor.get().getValue() );
cursor.beforeFirst();
assertFalse( cursor.previous() );
assertTrue( cursor.next() );
- assertEquals( 0, ( int ) cursor.get().getValue() );
+ assertEquals( "0", cursor.get().getValue() );
cursor.afterLast();
assertFalse( cursor.next() );
assertTrue( cursor.first() );
assertTrue( cursor.available() );
- assertEquals( 0, ( int ) cursor.get().getValue() );
+ assertEquals( "0", cursor.get().getValue() );
assertTrue( cursor.last() );
assertTrue( cursor.available() );
- assertEquals( 30, ( int ) cursor.get().getValue() );
+ assertEquals( "30", cursor.get().getValue() );
assertTrue( cursor.previous() );
- assertEquals( 25, ( int ) cursor.get().getValue() );
+ assertEquals( "25", cursor.get().getValue() );
assertTrue( cursor.next() );
- assertEquals( 30, ( int ) cursor.get().getValue() );
+ assertEquals( "30", cursor.get().getValue() );
}
@@ -179,68 +209,8 @@
{
BTree tree = table.getBTree();
- DupsContainer<Integer> values = table.getDupsContainer( ( byte[] ) tree.find( KEY ) );
+ DupsContainer<String> values = table.getDupsContainer( ( byte[] ) tree.find( KEY ) );
return table.getBTree( values.getBTreeRedirect() );
}
-
- private class MockComparatorRegistry implements ComparatorRegistry
- {
- private Comparator<Integer> comparator = new Comparator<Integer>()
- {
- public int compare( Integer i1, Integer i2 )
- {
- return i1.compareTo( i2 );
- }
- };
-
- public String getSchemaName( String oid ) throws NamingException
- {
- return null;
- }
-
-
- public void register( ComparatorDescription description, Comparator comparator ) throws NamingException
- {
- }
-
-
- public Comparator lookup( String oid ) throws NamingException
- {
- return comparator;
- }
-
-
- public boolean hasComparator( String oid )
- {
- return true;
- }
-
-
- public Iterator<String> iterator()
- {
- return null;
- }
-
-
- public Iterator<ComparatorDescription> comparatorDescriptionIterator()
- {
- return null;
- }
-
-
- public void unregister( String oid ) throws NamingException
- {
- }
-
-
- public void unregisterSchemaElements( String schemaName )
- {
- }
-
-
- public void renameSchema( String originalSchemaName, String newSchemaName )
- {
- }
- }
}
Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MockComparatorRegistry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MockComparatorRegistry.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MockComparatorRegistry.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MockComparatorRegistry.java Wed Jan 6 18:26:43 2010
@@ -20,12 +20,13 @@
package org.apache.directory.server.core.partition.impl.btree.jdbm;
-import org.apache.directory.server.schema.registries.ComparatorRegistry;
-import org.apache.directory.shared.ldap.schema.parsers.ComparatorDescription;
+import java.util.Iterator;
import javax.naming.NamingException;
-import java.util.Comparator;
-import java.util.Iterator;
+
+import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.apache.directory.shared.ldap.schema.parsers.LdapComparatorDescription;
+import org.apache.directory.shared.ldap.schema.registries.DefaultComparatorRegistry;
/**
@@ -34,53 +35,74 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $$Rev$$
*/
-class MockComparatorRegistry implements ComparatorRegistry
+class MockComparatorRegistry extends DefaultComparatorRegistry
{
- private Comparator<Integer> comparator = new Comparator<Integer>()
+ public MockComparatorRegistry()
+ {
+ super();
+ }
+
+
+ private LdapComparator<Integer> comparator = new LdapComparator<Integer>( "1.1.1" )
{
- public int compare( Integer i1, Integer i2 )
+ private static final long serialVersionUID = -4049615866911565018L;
+
+ public int compare( Integer i1, Integer i2 )
{
return i1.compareTo( i2 );
}
};
+
public String getSchemaName( String oid ) throws NamingException
{
return null;
}
- public void register( ComparatorDescription description, Comparator comparator ) throws NamingException
+ public void register( LdapComparatorDescription description, LdapComparator<?> comparator ) throws NamingException
{
}
- public Comparator lookup( String oid ) throws NamingException
+ public LdapComparator<?> lookup( String oid ) throws NamingException
{
return comparator;
}
- public boolean hasComparator( String oid )
+ public void register(LdapComparator<?> comparator ) throws NamingException
+ {
+ }
+
+
+ public boolean contains( String oid )
{
return true;
}
- public Iterator<String> iterator()
+ public Iterator<LdapComparator<?>> iterator()
{
return null;
}
+
+ public Iterator<String> oidsIterator()
+ {
+ return null;
+ }
- public Iterator<ComparatorDescription> comparatorDescriptionIterator()
+
+ public Iterator<LdapComparatorDescription> ldapComparatorDescriptionIterator()
{
return null;
}
- public void unregister( String oid ) throws NamingException
+ public LdapComparator<Integer> unregister( String oid ) throws NamingException
{
+ return this.comparator;
}