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 2014/11/08 11:37:36 UTC
svn commit: r1637538 - in
/directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl:
AndCursorTest.java OrCursorTest.java
Author: elecharny
Date: Sat Nov 8 10:37:36 2014
New Revision: 1637538
URL: http://svn.apache.org/r1637538
Log:
Improved the tests to make them independent of the Java version in use, and to reflect what they were testing before : checking that all the elements we fetch from a cursor are present, in both direction.
Modified:
directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java
Modified: directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java?rev=1637538&r1=1637537&r2=1637538&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java Sat Nov 8 10:37:36 2014
@@ -187,17 +187,23 @@ public class AndCursorTest extends Abstr
assertTrue( cursor.next() );
assertTrue( cursor.available() );
Entry entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ String uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( expectedUuid.contains( uuid ) );
+ expectedUuid.remove( uuid );
assertTrue( cursor.next() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( expectedUuid.contains( uuid ) );
+ expectedUuid.remove( uuid );
assertTrue( cursor.next() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( expectedUuid.contains( uuid ) );
+ expectedUuid.remove( uuid );
assertFalse( cursor.next() );
assertFalse( cursor.available() );
@@ -217,6 +223,8 @@ public class AndCursorTest extends Abstr
expectedUuid.add( Strings.getUUID( 6 ) );
expectedUuid.add( Strings.getUUID( 8 ) );
+ Set<String> foundUuid = new HashSet<String>();
+
Cursor<Entry> cursor = buildCursor( exprNode );
cursor.beforeFirst();
@@ -224,19 +232,28 @@ public class AndCursorTest extends Abstr
assertTrue( cursor.next() );
assertTrue( cursor.available() );
Entry entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ String uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
cursor.first();
assertTrue( cursor.next() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
assertTrue( cursor.next() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
assertFalse( cursor.next() );
assertFalse( cursor.available() );
@@ -246,19 +263,25 @@ public class AndCursorTest extends Abstr
assertTrue( cursor.previous() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
cursor.last();
assertTrue( cursor.previous() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
assertTrue( cursor.previous() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
assertFalse( cursor.previous() );
assertFalse( cursor.available() );
Modified: directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java?rev=1637538&r1=1637537&r2=1637538&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java Sat Nov 8 10:37:36 2014
@@ -20,7 +20,6 @@
package org.apache.directory.server.xdbm.search.impl;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -193,6 +192,8 @@ public class OrCursorTest extends Abstra
expectedUuid.add( Strings.getUUID( 10 ) );
expectedUuid.add( Strings.getUUID( 11 ) );
+ Set<String> foundUuid = new HashSet<String>();
+
Cursor<Entry> cursor = buildCursor( exprNode );
cursor.afterLast();
@@ -200,31 +201,50 @@ public class OrCursorTest extends Abstra
assertTrue( cursor.previous() );
assertTrue( cursor.available() );
Entry entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ String uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
assertTrue( cursor.previous() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
assertTrue( cursor.previous() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
assertTrue( cursor.previous() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
assertTrue( cursor.previous() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
assertTrue( cursor.previous() );
assertTrue( cursor.available() );
entry = cursor.get();
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
assertFalse( cursor.previous() );
assertFalse( cursor.available() );
@@ -234,32 +254,44 @@ public class OrCursorTest extends Abstra
assertTrue( cursor.next() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
assertTrue( cursor.next() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
assertTrue( cursor.next() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
assertTrue( cursor.next() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
assertTrue( cursor.next() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
assertTrue( cursor.next() );
assertTrue( cursor.available() );
entry = cursor.get();
- assertTrue( expectedUuid.contains( entry.get( "entryUUID" ).getString() ) );
+ uuid = entry.get( "entryUUID" ).getString();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
assertFalse( cursor.next() );
assertFalse( cursor.available() );
@@ -276,7 +308,7 @@ public class OrCursorTest extends Abstra
List<Evaluator<? extends ExprNode>> evaluators = new ArrayList<Evaluator<? extends ExprNode>>();
List<Cursor<IndexEntry<?, String>>> cursors = new ArrayList<Cursor<IndexEntry<?, String>>>();
Evaluator<? extends ExprNode> eval;
- Cursor<IndexEntry<?, Long>> cursor;
+ Cursor<IndexEntry<?, String>> cursor;
OrNode orNode = new OrNode();
@@ -302,6 +334,16 @@ public class OrCursorTest extends Abstra
orNode.addNode( exprNode );
+ Set<String> expectedUuid = new HashSet<String>();
+ expectedUuid.add( Strings.getUUID( 5 ) );
+ expectedUuid.add( Strings.getUUID( 6 ) );
+ expectedUuid.add( Strings.getUUID( 8 ) );
+ expectedUuid.add( Strings.getUUID( 9 ) );
+ expectedUuid.add( Strings.getUUID( 10 ) );
+ expectedUuid.add( Strings.getUUID( 11 ) );
+
+ Set<String> foundUuid = new HashSet<String>();
+
cursor = new OrCursor( cursors, evaluators );
cursor.beforeFirst();
@@ -310,33 +352,45 @@ public class OrCursorTest extends Abstra
// from first
assertTrue( cursor.first() );
assertTrue( cursor.available() );
- assertEquals( Strings.getUUID( 8 ), cursor.get().getId() );
- assertEquals( "jack daniels", cursor.get().getKey() );
+ String uuid = cursor.get().getId();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
assertTrue( cursor.next() );
assertTrue( cursor.available() );
- assertEquals( Strings.getUUID( 6 ), cursor.get().getId() );
- assertEquals( "jim bean", cursor.get().getKey() );
+ uuid = cursor.get().getId();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
assertTrue( cursor.next() );
assertTrue( cursor.available() );
- assertEquals( Strings.getUUID( 9 ), cursor.get().getId() );
- assertEquals( "jim bean", cursor.get().getKey() );
+ uuid = cursor.get().getId();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
assertTrue( cursor.next() );
assertTrue( cursor.available() );
- assertEquals( Strings.getUUID( 10 ), cursor.get().getId() );
- assertEquals( "jim bean", cursor.get().getKey() );
+ uuid = cursor.get().getId();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
assertTrue( cursor.next() );
assertTrue( cursor.available() );
- assertEquals( Strings.getUUID( 5 ), cursor.get().getId() );
- assertEquals( "walker", cursor.get().getKey() );
+ uuid = cursor.get().getId();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
assertTrue( cursor.next() );
assertTrue( cursor.available() );
- assertEquals( Strings.getUUID( 11 ), cursor.get().getId() );
- assertEquals( "johnny walker", cursor.get().getKey() );
+ uuid = cursor.get().getId();
+ assertTrue( expectedUuid.contains( uuid ) );
+ foundUuid.add( uuid );
+ expectedUuid.remove( uuid );
assertFalse( cursor.next() );
assertFalse( cursor.available() );
@@ -347,40 +401,46 @@ public class OrCursorTest extends Abstra
assertTrue( cursor.last() );
assertTrue( cursor.available() );
- assertEquals( Strings.getUUID( 11 ), cursor.get().getId() );
- assertEquals( "johnny walker", cursor.get().getKey() );
+ uuid = cursor.get().getId();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
assertTrue( cursor.previous() );
assertTrue( cursor.available() );
- assertEquals( Strings.getUUID( 5 ), cursor.get().getId() );
- assertEquals( "walker", cursor.get().getKey() );
+ uuid = cursor.get().getId();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
assertTrue( cursor.previous() );
assertTrue( cursor.available() );
- assertEquals( Strings.getUUID( 10 ), cursor.get().getId() );
- assertEquals( "jim bean", cursor.get().getKey() );
+ uuid = cursor.get().getId();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
assertTrue( cursor.previous() );
assertTrue( cursor.available() );
- assertEquals( Strings.getUUID( 9 ), cursor.get().getId() );
- assertEquals( "jim bean", cursor.get().getKey() );
+ uuid = cursor.get().getId();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
assertTrue( cursor.previous() );
assertTrue( cursor.available() );
- assertEquals( Strings.getUUID( 6 ), cursor.get().getId() );
- assertEquals( "jim bean", cursor.get().getKey() );
+ uuid = cursor.get().getId();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
assertTrue( cursor.previous() );
assertTrue( cursor.available() );
- assertEquals( Strings.getUUID( 8 ), cursor.get().getId() );
- assertEquals( "jack daniels", cursor.get().getKey() );
+ uuid = cursor.get().getId();
+ assertTrue( foundUuid.contains( uuid ) );
+ foundUuid.remove( uuid );
assertFalse( cursor.previous() );
assertFalse( cursor.available() );
try
{
- cursor.after( new IndexEntry<String, Long>() );
+ cursor.after( new IndexEntry<String, String>() );
fail( "should fail with UnsupportedOperationException " );
}
catch ( UnsupportedOperationException uoe )
@@ -389,7 +449,7 @@ public class OrCursorTest extends Abstra
try
{
- cursor.before( new IndexEntry<String, Long>() );
+ cursor.before( new IndexEntry<String, String>() );
fail( "should fail with UnsupportedOperationException " );
}
catch ( UnsupportedOperationException uoe )