You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by sa...@apache.org on 2011/11/09 18:07:56 UTC
svn commit: r1199865 - in
/directory/apacheds/branches/apacheds-txns/server-integ/src/test/java/org/apache/directory:
IndexTest.java server/operations/search/PagedSearchIT.java
Author: saya
Date: Wed Nov 9 17:07:55 2011
New Revision: 1199865
URL: http://svn.apache.org/viewvc?rev=1199865&view=rev
Log:
Fixed some tests. Tests should not assume index order is equal to entry insert order as UUID is generated randomly.
Modified:
directory/apacheds/branches/apacheds-txns/server-integ/src/test/java/org/apache/directory/IndexTest.java
directory/apacheds/branches/apacheds-txns/server-integ/src/test/java/org/apache/directory/server/operations/search/PagedSearchIT.java
Modified: directory/apacheds/branches/apacheds-txns/server-integ/src/test/java/org/apache/directory/IndexTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/server-integ/src/test/java/org/apache/directory/IndexTest.java?rev=1199865&r1=1199864&r2=1199865&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/server-integ/src/test/java/org/apache/directory/IndexTest.java (original)
+++ directory/apacheds/branches/apacheds-txns/server-integ/src/test/java/org/apache/directory/IndexTest.java Wed Nov 9 17:07:55 2011
@@ -25,10 +25,12 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.io.File;
+import java.util.UUID;
import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
import org.apache.directory.server.core.api.partition.index.Index;
import org.apache.directory.server.core.api.partition.index.IndexCursor;
+import org.apache.directory.server.xdbm.StoreUtils;
import org.apache.directory.server.xdbm.impl.avl.AvlIndex;
import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
import org.apache.directory.shared.ldap.model.entry.Entry;
@@ -51,8 +53,8 @@ public class IndexTest
private static File dbFileDir;
private static SchemaManager schemaManager;
- private JdbmIndex<String, Entry> jdbmIndex;
- private AvlIndex<String, Entry> avlIndex;
+ private JdbmIndex<String> jdbmIndex;
+ private AvlIndex<String> avlIndex;
@BeforeClass
@@ -93,11 +95,11 @@ public class IndexTest
AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OU_AT );
- jdbmIndex = new JdbmIndex<String, Entry>();
+ jdbmIndex = new JdbmIndex<String>();
jdbmIndex.setWkDirPath( dbFileDir.toURI() );
jdbmIndex.init( schemaManager, attributeType );
- avlIndex = new AvlIndex<String, Entry>();
+ avlIndex = new AvlIndex<String>();
avlIndex.init( schemaManager, attributeType );
}
@@ -113,38 +115,48 @@ public class IndexTest
doTest( jdbmIndex );
}
- private void doTest(Index<String, Entry, Long> idx) throws Exception
+ private void doTest(Index<String> idx) throws Exception
{
String alphabet = "abcdefghijklmnopqrstuvwxyz";
- for ( long i = 0L; i < 26L; i++ )
+ for ( int i = 0; i < 26; i++ )
{
- String val = alphabet.substring( (int)i, (int)(i+1) );
- idx.add( val, i + 1 );
+ String val = alphabet.substring( i, (i+1) );
+ idx.add( val, StoreUtils.getUUIDString( i + 1 ) );
}
assertEquals( 26, idx.count() );
- IndexCursor<String, Entry, Long> cursor1 = idx.forwardCursor();
+ IndexCursor<String> cursor1 = idx.forwardCursor();
cursor1.beforeFirst();
- assertHasNext(cursor1, 1L);
- assertHasNext(cursor1, 2L);
+ assertHasNext( cursor1, StoreUtils.getUUIDString( 1 ) );
+ assertHasNext( cursor1, StoreUtils.getUUIDString( 2 ) );
- idx.drop( "c", 3L );
+ idx.drop( "c", StoreUtils.getUUIDString( 3 ) );
- for ( long i = 4L; i < 27L; i++ )
+ int id;
+ if ( idx instanceof JdbmIndex )
{
- assertHasNext(cursor1, i);
+ id = 3;
+ }
+ else
+ {
+ id = 4;
+ }
+
+ for ( ; id < 27; id++ )
+ {
+ assertHasNext( cursor1, StoreUtils.getUUIDString( id ) );
}
assertFalse(cursor1.next());
}
- private void assertHasNext( IndexCursor<String, Entry, Long> cursor1, long expectedId ) throws Exception
+ private void assertHasNext( IndexCursor<String> cursor1, UUID expectedId ) throws Exception
{
- assertTrue(cursor1.next());
+ assertTrue( cursor1.next() );
//System.out.println(cursor1.get());
- assertEquals(expectedId, cursor1.get().getId().longValue());
+ assertEquals( expectedId, cursor1.get().getId() );
}
}
Modified: directory/apacheds/branches/apacheds-txns/server-integ/src/test/java/org/apache/directory/server/operations/search/PagedSearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/server-integ/src/test/java/org/apache/directory/server/operations/search/PagedSearchIT.java?rev=1199865&r1=1199864&r2=1199865&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/server-integ/src/test/java/org/apache/directory/server/operations/search/PagedSearchIT.java (original)
+++ directory/apacheds/branches/apacheds-txns/server-integ/src/test/java/org/apache/directory/server/operations/search/PagedSearchIT.java Wed Nov 9 17:07:55 2011
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertTru
import java.util.ArrayList;
import java.util.List;
+import java.util.TreeSet;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
@@ -239,15 +240,27 @@ public class PagedSearchIT extends Abstr
/**
* Check that we got the correct result set
*/
- private void checkResults( List<SearchResult> results, int expectedSize ) throws NamingException
+ private void checkResults( List<SearchResult> results, int expectedSize, boolean hitSizeLimitException ) throws NamingException
{
+ TreeSet<String> cnSet = new TreeSet<String>();
assertEquals( expectedSize, results.size() );
- // check that we have correctly read all the entries
+ if ( hitSizeLimitException )
+ {
+ return;
+ }
+
for ( int i = 0; i < expectedSize; i++ )
{
+
SearchResult entry = results.get( i );
- assertEquals( "user" + i, entry.getAttributes().get( "cn" ).get() );
+ cnSet.add( (String) ( entry.getAttributes().get( "cn" ).get() ) );
+ }
+
+ // check that we have correctly read all the entries
+ for ( int i = 0; i < expectedSize; i++ )
+ {
+ assertTrue( cnSet.contains( "user" + i ) );
}
}
@@ -316,7 +329,7 @@ public class PagedSearchIT extends Abstr
assertEquals( expectedException, hasSizeLimitException );
assertEquals( expectedLoop, loop );
- checkResults( results, expectedNbEntries );
+ checkResults( results, expectedNbEntries, hasSizeLimitException );
// And close the connection
closeConnection( ctx );
@@ -1125,6 +1138,6 @@ public class PagedSearchIT extends Abstr
}
assertEquals( 4, loop );
- checkResults( results, 10 );
+ checkResults( results, 10, false );
}
}
\ No newline at end of file