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 2009/11/07 08:57:42 UTC
svn commit: r833647 [12/17] - in /directory:
apacheds/branches/apacheds-schema/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/
apacheds/branches/apacheds-schema/avl-partition/src/test/java/org/apache/directory/server/core/pa...
Modified: directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java (original)
+++ directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java Sat Nov 7 07:57:34 2009
@@ -19,27 +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.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import org.apache.directory.server.xdbm.Table;
-import org.apache.directory.shared.ldap.schema.registries.OidRegistry;
-import org.apache.directory.shared.ldap.schema.comparators.SerializableComparator;
-
import java.io.File;
import jdbm.RecordManager;
import jdbm.recman.BaseRecordManager;
+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.util.ExceptionUtils;
+import org.apache.directory.shared.schema.DefaultSchemaManager;
+import org.apache.directory.shared.schema.loader.ldif.LdifSchemaLoader;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Document me!
@@ -52,11 +58,39 @@
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 SchemaLdifExtractor( new File( workingDirectory ) );
+ extractor.extractOrCopy();
+ 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
{
@@ -71,9 +105,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( new OidRegistry() ) );
- 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" );
}
@@ -111,10 +145,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" ) );
}
@@ -132,24 +168,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 )
@@ -158,7 +194,7 @@
try
{
- assertFalse( table.hasLessOrEqual( 1, 0 ) );
+ assertFalse( table.hasLessOrEqual( "1", "0" ) );
fail( "Should never get here." );
}
catch ( UnsupportedOperationException e )
@@ -171,13 +207,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
@@ -187,13 +224,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" ) );
}
}
@@ -209,7 +246,7 @@
try
{
- table.put( 1, null );
+ table.put( "1", null );
fail( "should never get here due to IllegalArgumentException" );
}
catch( IllegalArgumentException e )
@@ -219,7 +256,7 @@
try
{
- table.put( null, 2 );
+ table.put( null, "2" );
fail( "should never get here due to IllegalArgumentException" );
}
catch( IllegalArgumentException e )
@@ -228,32 +265,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 ) );
@@ -265,50 +302,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 )
@@ -317,7 +357,7 @@
try
{
- assertFalse( table.hasLessOrEqual( 1, 1 ) );
+ assertFalse( table.hasLessOrEqual( "1", "1" ) );
fail( "Should never get here." );
}
catch ( UnsupportedOperationException e )
@@ -326,7 +366,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" );
}
Modified: directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java (original)
+++ directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java Sat Nov 7 07:57:34 2009
@@ -19,30 +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.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import org.apache.directory.server.xdbm.Table;
-import org.apache.directory.server.xdbm.Tuple;
-import org.apache.directory.shared.ldap.cursor.Cursor;
-import org.apache.directory.shared.ldap.schema.registries.OidRegistry;
-import org.apache.directory.shared.ldap.schema.comparators.SerializableComparator;
-
import java.io.File;
import jdbm.RecordManager;
+import jdbm.helper.DefaultSerializer;
import jdbm.helper.IntegerSerializer;
import jdbm.recman.BaseRecordManager;
+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.util.ExceptionUtils;
+import org.apache.directory.shared.schema.DefaultSchemaManager;
+import org.apache.directory.shared.schema.loader.ldif.LdifSchemaLoader;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Tests JdbmTable operations with duplicates. Does not test Cursor capabilities.
@@ -55,10 +62,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 SchemaLdifExtractor( new File( workingDirectory ) );
+ extractor.extractOrCopy();
+ LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+ schemaManager = new DefaultSchemaManager( loader );
+
+ boolean loaded = schemaManager.loadAllEnabled();
+
+ if ( !loaded )
+ {
+ fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+ }
+ }
@Before
@@ -75,15 +120,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(
- new OidRegistry() ) );
-
- table = new JdbmTable<Integer,Integer>( "test", SIZE, 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", SIZE, recman,
+ comparator, comparator, new DefaultSerializer(), new DefaultSerializer() );
LOG.debug( "Created new table and populated it with data" );
}
@@ -129,7 +170,7 @@
@Test
public void testCountOneArg() throws Exception
{
- assertEquals( 0, table.count( 3 ) );
+ assertEquals( 0, table.count( "3" ) );
assertEquals( 0, table.count( null ) );
}
@@ -138,10 +179,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() );
}
@@ -149,24 +192,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" ) );
}
@@ -184,23 +230,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" ) );
}
@@ -209,128 +255,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.hasGreaterOrEqual( "1", "0" ) );
+ assertTrue( table.hasLessOrEqual( "1", "0" ) );
+ assertFalse( table.hasLessOrEqual( "1", "-1" ) );
- 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", 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" );
}
@@ -340,35 +397,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" ) );
}
@@ -376,13 +434,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
@@ -392,13 +451,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" ) );
}
}
@@ -406,50 +465,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() );
}
@@ -466,7 +530,7 @@
try
{
- table.put( 1, null );
+ table.put( "1", null );
fail( "should never get here due to IllegalArgumentException" );
}
catch( IllegalArgumentException e )
@@ -476,7 +540,7 @@
try
{
- table.put( null, 1 );
+ table.put( null, "1" );
fail( "should never get here due to IllegalArgumentException" );
}
catch( IllegalArgumentException e )
@@ -485,21 +549,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" ) );
}
@@ -510,17 +574,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" ) );
}
@@ -535,7 +603,7 @@
try
{
- table.put( 1, null );
+ table.put( "1", null );
fail( "should never get here due to IllegalArgumentException" );
}
catch( IllegalArgumentException e )
@@ -545,7 +613,7 @@
try
{
- table.put( null, 2 );
+ table.put( null, "2" );
fail( "should never get here due to IllegalArgumentException" );
}
catch( IllegalArgumentException e )
@@ -554,20 +622,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 ) );
+ 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/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursorTest.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursorTest.java (original)
+++ directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursorTest.java Sat Nov 7 07:57:34 2009
@@ -22,21 +22,28 @@
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 jdbm.RecordManager;
import jdbm.btree.BTree;
-import jdbm.helper.IntegerSerializer;
+import jdbm.helper.DefaultSerializer;
import jdbm.recman.BaseRecordManager;
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.registries.OidRegistry;
+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.util.ExceptionUtils;
+import org.apache.directory.shared.schema.DefaultSchemaManager;
+import org.apache.directory.shared.schema.loader.ldif.LdifSchemaLoader;
import org.junit.After;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
@@ -48,23 +55,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 SchemaLdifExtractor( new File( workingDirectory ) );
+ extractor.extractOrCopy();
+ 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 );
}
@@ -80,16 +114,13 @@
dbFile = File.createTempFile( getClass().getSimpleName(), "db", tmpDir );
recman = new BaseRecordManager( dbFile.getAbsolutePath() );
- SerializableComparator.setRegistry(
- new MockComparatorRegistry(
- new OidRegistry() ) );
-
- 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 );
}
@@ -127,49 +158,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() );
}
@@ -177,7 +208,7 @@
{
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() );
}
Modified: directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MockComparatorRegistry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MockComparatorRegistry.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MockComparatorRegistry.java (original)
+++ directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MockComparatorRegistry.java Sat Nov 7 07:57:34 2009
@@ -20,14 +20,15 @@
package org.apache.directory.server.core.partition.impl.btree.jdbm;
+import java.util.Iterator;
+
+import javax.naming.NamingException;
+
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.ComparatorRegistry;
+import org.apache.directory.shared.ldap.schema.registries.DefaultComparatorRegistry;
import org.apache.directory.shared.ldap.schema.registries.OidRegistry;
-import javax.naming.NamingException;
-import java.util.Iterator;
-
/**
* TODO doc me!
@@ -35,7 +36,7 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $$Rev$$
*/
-class MockComparatorRegistry extends ComparatorRegistry
+class MockComparatorRegistry extends DefaultComparatorRegistry
{
public MockComparatorRegistry( OidRegistry oidRegistry )
{
Modified: directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursorTest.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursorTest.java (original)
+++ directory/apacheds/branches/apacheds-schema/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursorTest.java Sat Nov 7 07:57:34 2009
@@ -19,29 +19,35 @@
package org.apache.directory.server.core.partition.impl.btree.jdbm;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.directory.server.xdbm.Table;
-import org.apache.directory.server.xdbm.Tuple;
-import org.apache.directory.shared.ldap.cursor.Cursor;
-import org.apache.directory.shared.ldap.cursor.InvalidCursorPositionException;
-import org.apache.directory.shared.ldap.schema.registries.OidRegistry;
-import org.apache.directory.shared.ldap.schema.comparators.SerializableComparator;
-import org.junit.Before;
-import org.junit.After;
-import org.junit.Test;
-
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertEquals;
-
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import jdbm.RecordManager;
import jdbm.recman.BaseRecordManager;
+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.cursor.InvalidCursorPositionException;
+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.util.ExceptionUtils;
+import org.apache.directory.shared.schema.DefaultSchemaManager;
+import org.apache.directory.shared.schema.loader.ldif.LdifSchemaLoader;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Tests the Cursor functionality of a JdbmTable when duplicate keys are not
@@ -55,9 +61,37 @@
private static final Logger LOG = LoggerFactory.getLogger( NoDupsCursorTest.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 SchemaLdifExtractor( new File( workingDirectory ) );
+ extractor.extractOrCopy();
+ LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+ schemaManager = new DefaultSchemaManager( loader );
+
+ boolean loaded = schemaManager.loadAllEnabled();
+
+ if ( !loaded )
+ {
+ fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+ }
+ }
@Before
@@ -73,11 +107,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(
- new OidRegistry() ) );
- 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" );
}
@@ -100,7 +134,7 @@
@Test( expected=InvalidCursorPositionException.class )
public void testEmptyTable() throws Exception
{
- Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+ Cursor<Tuple<String,String>> cursor = table.cursor();
assertNotNull( cursor );
assertFalse( cursor.available() );
@@ -113,7 +147,7 @@
cursor = table.cursor();
assertFalse( cursor.next() );
- cursor.after( new Tuple<Integer,Integer>(7,7) );
+ cursor.after( new Tuple<String,String>( "7", "7" ) );
cursor.get();
}
@@ -121,13 +155,13 @@
@Test
public void testOnTableWithSingleEntry() throws Exception
{
- table.put( 1, 1 );
- Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+ table.put( "1", "1" );
+ Cursor<Tuple<String,String>> cursor = table.cursor();
assertTrue( cursor.first() );
- Tuple<Integer,Integer> tuple = cursor.get();
- assertTrue( tuple.getKey().equals( 1 ) );
- assertTrue( tuple.getValue().equals( 1 ) );
+ Tuple<String,String> tuple = cursor.get();
+ assertEquals( "1", tuple.getKey() );
+ assertEquals( "1", tuple.getValue() );
cursor.beforeFirst();
assertFalse( cursor.previous() );
@@ -140,35 +174,36 @@
{
for( int i=1; i < 10; i++ )
{
- table.put( i, i );
+ String istr = Integer.toString( i );
+ table.put( istr, istr );
}
- Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+ Cursor<Tuple<String,String>> cursor = table.cursor();
- cursor.after( new Tuple<Integer,Integer>( 2,2 ) );
+ cursor.after( new Tuple<String,String>( "2", "2" ) );
assertTrue( cursor.next() );
- Tuple<Integer,Integer> tuple = cursor.get();
- assertTrue( tuple.getKey().equals( 3 ) );
- assertTrue( tuple.getValue().equals( 3 ) );
+ Tuple<String,String> tuple = cursor.get();
+ assertEquals( "3", tuple.getKey() );
+ assertEquals( "3", tuple.getValue() );
- cursor.before( new Tuple<Integer,Integer>(7,7) );
+ cursor.before( new Tuple<String,String>( "7", "7" ) );
cursor.next();
tuple = cursor.get();
- assertTrue( tuple.getKey().equals( 7 ) );
- assertTrue( tuple.getValue().equals( 7 ) );
+ assertEquals( "7", tuple.getKey() );
+ assertEquals( "7", tuple.getValue() );
cursor.last();
cursor.next();
tuple = cursor.get();
- assertTrue( tuple.getKey().equals( 9 ) );
- assertTrue( tuple.getValue().equals( 9 ) );
+ assertEquals( "9", tuple.getKey() );
+ assertEquals( "9", tuple.getValue() );
cursor.beforeFirst();
cursor.next();
tuple = cursor.get();
- assertTrue( tuple.getKey().equals( 1 ) );
- assertTrue( tuple.getValue().equals( 1 ) );
+ assertEquals( "1", tuple.getKey() );
+ assertEquals( "1", tuple.getValue() );
cursor.afterLast();
assertFalse( cursor.next() );
@@ -178,13 +213,13 @@
// just to clear the jdbmTuple value so that line 127 inside after(tuple) method
// can be executed as part of the below after(tuple) call
- cursor.before(new Tuple<Integer,Integer>( 1,1 ));
- cursor.after( new Tuple<Integer,Integer>( 0,0 ) );
+ cursor.before(new Tuple<String,String>( "1", "1" ));
+ cursor.after( new Tuple<String,String>( "0", "0" ) );
cursor.next();
tuple = cursor.get();
- assertTrue( tuple.getKey().equals( 1 ) );
- assertTrue( tuple.getValue().equals( 1 ) );
+ assertEquals( "1", tuple.getKey() );
+ assertEquals( "1", tuple.getValue() );
}
@@ -193,59 +228,60 @@
{
for( int i=1; i < 10; i++ )
{
- table.put( i, i );
+ String istr = Integer.toString( i );
+ table.put( istr, istr );
}
- Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+ Cursor<Tuple<String,String>> cursor = table.cursor();
// go to last and call next then previous twice then next
cursor.afterLast();
assertFalse( cursor.next() );
assertTrue( cursor.previous() );
- assertEquals( 9, ( int ) cursor.get().getKey() );
+ assertEquals( "9", cursor.get().getKey() );
assertTrue( cursor.previous() );
- assertEquals( 8, ( int ) cursor.get().getKey() );
+ assertEquals( "8", cursor.get().getKey() );
assertTrue( cursor.next() );
- assertEquals( 9, ( int ) cursor.get().getKey() );
+ assertEquals( "9", cursor.get().getKey() );
// go to last and call previous then next and again previous
cursor.afterLast();
assertTrue( cursor.previous() );
- assertEquals( 9, ( int ) cursor.get().getKey() );
+ assertEquals( "9", cursor.get().getKey() );
assertTrue( cursor.next() );
- assertEquals( 9, ( int ) cursor.get().getKey() );
+ assertEquals( "9", cursor.get().getKey() );
assertTrue( cursor.previous() );
- assertEquals( 8, ( int ) cursor.get().getKey() );
+ assertEquals( "8", cursor.get().getKey() );
// go to first and call previous then next twice and again next
cursor.beforeFirst();
assertFalse( cursor.previous() );
assertTrue( cursor.next() );
- assertEquals( 1, ( int ) cursor.get().getKey() );
+ assertEquals( "1", cursor.get().getKey() );
assertTrue( cursor.next() );
- assertEquals( 2, ( int ) cursor.get().getKey() );
+ assertEquals( "2", cursor.get().getKey() );
assertTrue( cursor.previous() );
- assertEquals( 1, ( int ) cursor.get().getKey() );
+ assertEquals( "1", cursor.get().getKey() );
// go to first and call next twice then previous
cursor.beforeFirst();
assertTrue( cursor.next() );
- assertEquals( 1, ( int ) cursor.get().getKey() );
+ assertEquals( "1", cursor.get().getKey() );
assertTrue( cursor.next() );
- assertEquals( 2, ( int ) cursor.get().getKey() );
+ assertEquals( "2", cursor.get().getKey() );
assertTrue( cursor.previous() );
- assertEquals( 1, ( int ) cursor.get().getKey() );
+ assertEquals( "1", cursor.get().getKey() );
}
Modified: directory/apacheds/branches/apacheds-schema/jdbm/src/main/java/jdbm/btree/BTree.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/jdbm/src/main/java/jdbm/btree/BTree.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/jdbm/src/main/java/jdbm/btree/BTree.java (original)
+++ directory/apacheds/branches/apacheds-schema/jdbm/src/main/java/jdbm/btree/BTree.java Sat Nov 7 07:57:34 2009
@@ -46,20 +46,18 @@
package jdbm.btree;
-import jdbm.RecordManager;
-
-import jdbm.helper.Serializer;
-import jdbm.helper.Tuple;
-import jdbm.helper.TupleBrowser;
-
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
-
import java.util.Comparator;
+import jdbm.RecordManager;
+import jdbm.helper.Serializer;
+import jdbm.helper.Tuple;
+import jdbm.helper.TupleBrowser;
+
/**
* B+Tree persistent indexing data structure. B+Trees are optimized for
* block-based, random I/O storage because they store multiple keys on
@@ -605,5 +603,14 @@
return false;
}
}
+
+
+ /**
+ * @return the _comparator
+ */
+ public Comparator getComparator()
+ {
+ return _comparator;
+ }
}
Modified: directory/apacheds/branches/apacheds-schema/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/store/operations/ChangePassword.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/store/operations/ChangePassword.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/store/operations/ChangePassword.java (original)
+++ directory/apacheds/branches/apacheds-schema/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/store/operations/ChangePassword.java Sat Nov 7 07:57:34 2009
@@ -23,7 +23,6 @@
import java.util.ArrayList;
import java.util.List;
-import javax.naming.directory.DirContext;
import javax.security.auth.kerberos.KerberosPrincipal;
import org.apache.directory.server.core.CoreSession;
@@ -37,7 +36,7 @@
import org.apache.directory.shared.ldap.entry.Modification;
import org.apache.directory.shared.ldap.entry.ModificationOperation;
import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -77,16 +76,16 @@
return null;
}
- AttributeTypeRegistry registry = session.getDirectoryService().getRegistries().getAttributeTypeRegistry();
+ SchemaManager schemaManager = session.getDirectoryService().getSchemaManager();
List<Modification> mods = new ArrayList<Modification>(2);
ServerAttribute newPasswordAttribute = new DefaultServerAttribute(
- registry.lookup( SchemaConstants.USER_PASSWORD_AT ), StringTools.getBytesUtf8( newPassword ) );
+ schemaManager.lookupAttributeTypeRegistry( SchemaConstants.USER_PASSWORD_AT ), StringTools.getBytesUtf8( newPassword ) );
mods.add( new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE, newPasswordAttribute ) );
ServerAttribute principalAttribute = new DefaultServerAttribute(
- registry.lookup( KerberosAttribute.KRB5_PRINCIPAL_NAME_AT ), principal.getName() );
+ schemaManager.lookupAttributeTypeRegistry( KerberosAttribute.KRB5_PRINCIPAL_NAME_AT ), principal.getName() );
mods.add( new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE, principalAttribute ) );
//FIXME check if keyderivation is necessary
Modified: directory/apacheds/branches/apacheds-schema/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/store/operations/StoreUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/store/operations/StoreUtils.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/store/operations/StoreUtils.java (original)
+++ directory/apacheds/branches/apacheds-schema/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/store/operations/StoreUtils.java Sat Nov 7 07:57:34 2009
@@ -36,7 +36,7 @@
import org.apache.directory.shared.ldap.message.AliasDerefMode;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -101,9 +101,9 @@
* @return the filter expression tree
* @throws Exception if there are problems while looking up attributes
*/
- private static ExprNode getFilter( AttributeTypeRegistry registry, String principal ) throws Exception
+ private static ExprNode getFilter( SchemaManager schemaManager, String principal ) throws Exception
{
- AttributeType type = registry.lookup( KerberosAttribute.KRB5_PRINCIPAL_NAME_AT );
+ AttributeType type = schemaManager.lookupAttributeTypeRegistry( KerberosAttribute.KRB5_PRINCIPAL_NAME_AT );
Value<String> value = new ServerStringValue( type, principal );
return new EqualityNode<String>( KerberosAttribute.KRB5_PRINCIPAL_NAME_AT, value );
}
@@ -125,9 +125,9 @@
try
{
- AttributeTypeRegistry registry = session.getDirectoryService().getRegistries().getAttributeTypeRegistry();
+ SchemaManager schemaManager = session.getDirectoryService().getSchemaManager();
cursor = session.search( searchBaseDn, SearchScope.SUBTREE,
- getFilter( registry, principal ), AliasDerefMode.DEREF_ALWAYS, null );
+ getFilter( schemaManager, principal ), AliasDerefMode.DEREF_ALWAYS, null );
cursor.beforeFirst();
if ( cursor.next() )
Modified: directory/apacheds/branches/apacheds-schema/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/unit/AbstractServerTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/unit/AbstractServerTest.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/unit/AbstractServerTest.java (original)
+++ directory/apacheds/branches/apacheds-schema/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/unit/AbstractServerTest.java Sat Nov 7 07:57:34 2009
@@ -144,7 +144,7 @@
for ( LdifEntry entry:ldifReader )
{
rootDSE.add(
- new DefaultServerEntry( directoryService.getRegistries(), entry.getEntry() ) );
+ new DefaultServerEntry( directoryService.getSchemaManager(), entry.getEntry() ) );
if ( verifyEntries )
{
@@ -406,7 +406,7 @@
{
rootDSE.add(
new DefaultServerEntry(
- rootDSE.getDirectoryService().getRegistries(), ldifEntry.getEntry() ) );
+ rootDSE.getDirectoryService().getSchemaManager(), ldifEntry.getEntry() ) );
}
}
catch ( Exception e )
@@ -434,7 +434,7 @@
{
rootDSE.add(
new DefaultServerEntry(
- rootDSE.getDirectoryService().getRegistries(), entry.getEntry() ) );
+ rootDSE.getDirectoryService().getSchemaManager(), entry.getEntry() ) );
}
}
}
Modified: directory/apacheds/branches/apacheds-schema/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java (original)
+++ directory/apacheds/branches/apacheds-schema/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java Sat Nov 7 07:57:34 2009
@@ -55,8 +55,8 @@
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.name.Rdn;
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.registries.Registries;
import org.apache.directory.shared.ldap.util.StringTools;
import org.apache.directory.shared.ldap.util.SystemUtils;
import org.slf4j.Logger;
@@ -163,7 +163,7 @@
// Initialize the AvlPartition
wrappedPartition.setId( id );
wrappedPartition.setSuffix( suffix.getUpName() );
- wrappedPartition.setRegistries( registries );
+ wrappedPartition.setSchemaManager( schemaManager );
wrappedPartition.initialize();
// Create the CsnFactory with a invalid ReplicaId
@@ -185,7 +185,7 @@
if ( !suffix.isNormalized() )
{
- suffix.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ suffix.normalize( schemaManager.getNormalizerMapping() );
}
String suffixDirName = getFileName( suffix );
@@ -221,7 +221,7 @@
if ( contextEntryFile.exists() )
{
LdifReader reader = new LdifReader( contextEntryFile );
- contextEntry = new DefaultServerEntry( registries, reader.next().getEntry() );
+ contextEntry = new DefaultServerEntry( schemaManager, reader.next().getEntry() );
}
else
{
@@ -475,7 +475,7 @@
LdifEntry ldifEntry = ldifEntries.get( 0 );
LOG.debug( "Adding entry {}", ldifEntry );
- ServerEntry serverEntry = new DefaultServerEntry( registries, ldifEntry.getEntry() );
+ ServerEntry serverEntry = new DefaultServerEntry( schemaManager, ldifEntry.getEntry() );
if ( !serverEntry.containsAttribute( SchemaConstants.ENTRY_CSN_AT ) )
{
@@ -561,7 +561,7 @@
{
// First, get the AT name, or OID
String normAT = rdn.getAtav().getNormType();
- AttributeType at = registries.getAttributeTypeRegistry().lookup( normAT );
+ AttributeType at = schemaManager.lookupAttributeTypeRegistry( normAT );
String atName = at.getName();
@@ -589,7 +589,7 @@
{
// First, get the AT name, or OID
String normAT = rdn.getAtav().getNormType();
- AttributeType at = registries.getAttributeTypeRegistry().lookup( normAT );
+ AttributeType at = schemaManager.lookupAttributeTypeRegistry( normAT );
String atName = at.getName();
@@ -969,9 +969,9 @@
@Override
- public void setRegistries( Registries registries )
+ public void setSchemaManager( SchemaManager schemaManager )
{
- super.setRegistries( registries );
+ super.setSchemaManager( schemaManager );
}
@@ -1085,7 +1085,7 @@
{
List<LdifEntry> entries = ldifParser.parseLdif( contextEntry );
- this.contextEntry = new DefaultServerEntry( registries, entries.get( 0 ).getEntry() );
+ this.contextEntry = new DefaultServerEntry( schemaManager, entries.get( 0 ).getEntry() );
}
Modified: directory/apacheds/branches/apacheds-schema/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifStore.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifStore.java (original)
+++ directory/apacheds/branches/apacheds-schema/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifStore.java Sat Nov 7 07:57:34 2009
@@ -42,7 +42,7 @@
import org.apache.directory.shared.ldap.ldif.LdifUtils;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.name.Rdn;
-import org.apache.directory.shared.ldap.schema.registries.Registries;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -65,7 +65,7 @@
/** in memory store used for serving the config data present in LDIF files */
private AvlStore<E> wrappedStore = new AvlStore<E>();
- private Registries registries;
+ private SchemaManager schemaManager;
private LdifReader ldifParser = new LdifReader();
@@ -81,10 +81,10 @@
private static Logger LOG = LoggerFactory.getLogger( LdifStore.class );
- public void init( Registries registries ) throws Exception
+ public void init( SchemaManager schemaManager ) throws Exception
{
- this.registries = registries;
- wrappedStore.init( registries );
+ this.schemaManager = schemaManager;
+ wrappedStore.init( schemaManager );
// load the config
loadConfig();
@@ -128,7 +128,7 @@
LdifEntry ldifEntry = entries.get( 0 );
LOG.debug( "adding entry {}", ldifEntry );
- ServerEntry serverEntry = new DefaultServerEntry( registries, ldifEntry.getEntry() );
+ ServerEntry serverEntry = new DefaultServerEntry( schemaManager, ldifEntry.getEntry() );
// call add on the wrapped store not on the self
wrappedStore.add( serverEntry );
@@ -424,9 +424,9 @@
}
- public void initRegistries( Registries registries )
+ public void initSchemaManager( SchemaManager schemaManager )
{
- wrappedStore.initRegistries( registries );
+ wrappedStore.initSchemaManager( schemaManager );
}
Modified: directory/apacheds/branches/apacheds-schema/ldif-partition/src/test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/ldif-partition/src/test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java?rev=833647&r1=833646&r2=833647&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/ldif-partition/src/test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java (original)
+++ directory/apacheds/branches/apacheds-schema/ldif-partition/src/test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java Sat Nov 7 07:57:34 2009
@@ -61,7 +61,6 @@
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.registries.Registries;
import org.apache.directory.shared.ldap.util.ExceptionUtils;
import org.apache.directory.shared.schema.DefaultSchemaManager;
import org.apache.directory.shared.schema.loader.ldif.LdifSchemaLoader;
@@ -85,7 +84,7 @@
private static File wkdir;
private static LdifPartition partition;
- private static Registries registries = null;
+ private static SchemaManager schemaManager = null;
private static CsnFactory defaultCSNFactory;
@@ -105,16 +104,15 @@
SchemaLdifExtractor extractor = new SchemaLdifExtractor( new File( workingDirectory ) );
extractor.extractOrCopy();
LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
- SchemaManager sm = new DefaultSchemaManager( loader );
+ schemaManager = new DefaultSchemaManager( loader );
- boolean loaded = sm.loadAllEnabled();
+ boolean loaded = schemaManager.loadAllEnabled();
if ( !loaded )
{
- fail( "Schema load failed : " + ExceptionUtils.printErrors( sm.getErrors() ) );
+ fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
}
- registries = sm.getRegistries();
defaultCSNFactory = new CsnFactory( 0 );
wkdir = File.createTempFile( LdifPartitionTest.class.getSimpleName(), "db" );
@@ -144,7 +142,7 @@
partition = new LdifPartition();
partition.setId( "test-ldif" );
partition.setSuffix( "ou=test,ou=system" );
- partition.setRegistries( registries );
+ partition.setSchemaManager( schemaManager );
partition.setWorkingDirectory( wkdir.getAbsolutePath() );
partition.setContextEntry( contextEntry );
@@ -164,8 +162,8 @@
private ClonedServerEntry createEntry( String dn ) throws Exception
{
- ServerEntry entry = new DefaultServerEntry( registries );
- entry.setDn( new LdapDN( dn ).normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() ) );
+ ServerEntry entry = new DefaultServerEntry( schemaManager );
+ entry.setDn( new LdapDN( dn ).normalize( schemaManager.getNormalizerMapping() ) );
entry.put( SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString() );
entry.add( SchemaConstants.ENTRY_UUID_AT, SchemaUtils.uuidToBytes( UUID.randomUUID() ) );
@@ -186,7 +184,7 @@
@Test
public void testLdifAddEntries() throws Exception
{
- LdapDN adminDn = new LdapDN( "uid=admin,ou=system" ).normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ LdapDN adminDn = new LdapDN( "uid=admin,ou=system" ).normalize( schemaManager.getNormalizerMapping() );
CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG ), new MockDirectoryService( 1 ) );
AddOperationContext addCtx = new AddOperationContext( session );
@@ -221,7 +219,7 @@
@Test
public void testLdifAddExistingEntry() throws Exception
{
- LdapDN adminDn = new LdapDN( "uid=admin,ou=system" ).normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ LdapDN adminDn = new LdapDN( "uid=admin,ou=system" ).normalize( schemaManager.getNormalizerMapping() );
CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG ), new MockDirectoryService( 1 ) );
AddOperationContext addCtx = new AddOperationContext( session );
@@ -274,7 +272,7 @@
@Test
public void testLdifDeleteExistingEntry() throws Exception
{
- LdapDN adminDn = new LdapDN( "uid=admin,ou=system" ).normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ LdapDN adminDn = new LdapDN( "uid=admin,ou=system" ).normalize( schemaManager.getNormalizerMapping() );
CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG ), new MockDirectoryService( 1 ) );
AddOperationContext addCtx = new AddOperationContext( session );
@@ -302,7 +300,7 @@
DeleteOperationContext delCtx = new DeleteOperationContext( session );
LdapDN dn = new LdapDN( "dc=test1,dc=test,ou=test,ou=system" );
- dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
delCtx.setDn( dn );
@@ -318,7 +316,7 @@
assertTrue( new File( wkdir, "ou=test,ou=system/dc=test/dc=test2.ldif" ).exists() );
dn = new LdapDN( "dc=test2,dc=test,ou=test,ou=system" );
- dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
delCtx.setDn( dn );
@@ -342,7 +340,7 @@
@Test
public void testLdifSearchExistingEntry() throws Exception
{
- LdapDN adminDn = new LdapDN( "uid=admin,ou=system" ).normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ LdapDN adminDn = new LdapDN( "uid=admin,ou=system" ).normalize( schemaManager.getNormalizerMapping() );
CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG ), new MockDirectoryService( 1 ) );
AddOperationContext addCtx = new AddOperationContext( session );
@@ -370,7 +368,7 @@
SearchOperationContext searchCtx = new SearchOperationContext( session );
LdapDN dn = new LdapDN( "dc=test,ou=test,ou=system" );
- dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ dn.normalize( schemaManager.getNormalizerMapping() );
searchCtx.setDn( dn );
ExprNode filter = FilterParser.parse( "(ObjectClass=domain)" );
searchCtx.setFilter( filter );
@@ -407,8 +405,8 @@
{
CoreSession session = injectEntries();
- ClonedServerEntry childEntry1 = partition.lookup( partition.getEntryId( new LdapDN( "dc=child1,ou=test,ou=system" ).normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() ).getNormName() ) );
- ClonedServerEntry childEntry2 = partition.lookup( partition.getEntryId( new LdapDN( "dc=child2,ou=test,ou=system" ).normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() ).getNormName() ) );
+ ClonedServerEntry childEntry1 = partition.lookup( partition.getEntryId( new LdapDN( "dc=child1,ou=test,ou=system" ).normalize( schemaManager.getNormalizerMapping() ).getNormName() ) );
+ ClonedServerEntry childEntry2 = partition.lookup( partition.getEntryId( new LdapDN( "dc=child2,ou=test,ou=system" ).normalize( schemaManager.getNormalizerMapping() ).getNormName() ) );
MoveOperationContext moveOpCtx = new MoveOperationContext( session, childEntry1.getDn(), childEntry2.getDn() );
partition.move( moveOpCtx );
@@ -434,7 +432,7 @@
CoreSession session = injectEntries();
LdapDN childDn1 = new LdapDN( "dc=child1,ou=test,ou=system" );
- childDn1.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ childDn1.normalize( schemaManager.getNormalizerMapping() );
Rdn newRdn = new Rdn( SchemaConstants.DC_AT + "=" + "renamedChild1" );
RenameOperationContext renameOpCtx = new RenameOperationContext( session, childDn1, newRdn, true );
@@ -460,7 +458,7 @@
CoreSession session = injectEntries();
LdapDN childDn1 = new LdapDN( "dc=child1,ou=test,ou=system" );
- childDn1.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ childDn1.normalize( schemaManager.getNormalizerMapping() );
Rdn newRdn = new Rdn( SchemaConstants.DC_AT + "=" + "renamedChild1" );
RenameOperationContext renameOpCtx = new RenameOperationContext( session, childDn1, newRdn, false );
@@ -486,10 +484,10 @@
CoreSession session = injectEntries();
LdapDN childDn1 = new LdapDN( "dc=child1,ou=test,ou=system" );
- childDn1.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ childDn1.normalize( schemaManager.getNormalizerMapping() );
LdapDN childDn2 = new LdapDN( "dc=child2,ou=test,ou=system" );
- childDn2.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ childDn2.normalize( schemaManager.getNormalizerMapping() );
Rdn newRdn = new Rdn( SchemaConstants.DC_AT + "=" + "movedChild1" );
MoveAndRenameOperationContext moveAndRenameOpCtx = new MoveAndRenameOperationContext( session, childDn1, childDn2, newRdn, true );
@@ -515,10 +513,10 @@
CoreSession session = injectEntries();
LdapDN childDn1 = new LdapDN( "dc=child1,ou=test,ou=system" );
- childDn1.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ childDn1.normalize( schemaManager.getNormalizerMapping() );
LdapDN childDn2 = new LdapDN( "dc=child2,ou=test,ou=system" );
- childDn2.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ childDn2.normalize( schemaManager.getNormalizerMapping() );
Rdn newRdn = new Rdn( SchemaConstants.DC_AT + "=" + "movedChild1" );
MoveAndRenameOperationContext moveAndRenameOpCtx = new MoveAndRenameOperationContext( session, childDn1, childDn2, newRdn, false );
@@ -540,7 +538,7 @@
private CoreSession injectEntries() throws Exception
{
- LdapDN adminDn = new LdapDN( "uid=admin,ou=system" ).normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+ LdapDN adminDn = new LdapDN( "uid=admin,ou=system" ).normalize( schemaManager.getNormalizerMapping() );
CoreSession session = new MockCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG ), new MockDirectoryService( 1 ) );
AddOperationContext addCtx = new AddOperationContext( session );