directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1382390 - in /directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl: AbstractCursorTest.java AndCursorTest.java NotCursorTest.java OrCursorTest.java
Date Sun, 09 Sep 2012 02:39:31 GMT
Author: elecharny
Date: Sun Sep  9 02:39:30 2012
New Revision: 1382390

URL: http://svn.apache.org/viewvc?rev=1382390&view=rev
Log:
o Created a class used by cursor tests, containing a common method
o Fixed the NotCursor test

Added:
    directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AbstractCursorTest.java
Modified:
    directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
    directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java
    directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java

Added: directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AbstractCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AbstractCursorTest.java?rev=1382390&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AbstractCursorTest.java
(added)
+++ directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AbstractCursorTest.java
Sun Sep  9 02:39:30 2012
@@ -0,0 +1,108 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.xdbm.search.impl;
+
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.server.core.api.filtering.BaseEntryFilteringCursor;
+import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.SearchingOperationContext;
+import org.apache.directory.server.core.partition.impl.btree.AbstractBTreePartition;
+import org.apache.directory.server.core.partition.impl.btree.EntryCursorAdaptor;
+import org.apache.directory.server.core.partition.impl.btree.IndexCursorAdaptor;
+import org.apache.directory.server.xdbm.ForwardIndexEntry;
+import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.server.xdbm.search.Evaluator;
+import org.apache.directory.server.xdbm.search.PartitionSearchResult;
+import org.apache.directory.shared.ldap.model.cursor.Cursor;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.filter.ExprNode;
+
+
+/**
+ * A class containing common method and fields for Cursor tests.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AbstractCursorTest
+{
+    protected EvaluatorBuilder evaluatorBuilder;
+    protected CursorBuilder cursorBuilder;
+    protected Store store;
+
+
+    /**
+     * Creates a cursor from a filter
+     * 
+     * @param root The filter we are using for the cursor construction
+     * @return The constructed cursor
+     * @throws Exception If anything went wrong
+     */
+    protected Cursor<Entry> buildCursor( ExprNode root ) throws Exception
+    {
+        Evaluator<? extends ExprNode> evaluator = evaluatorBuilder.build( root );
+
+        PartitionSearchResult searchResult = new PartitionSearchResult();
+        Set<IndexEntry<String, String>> resultSet = new HashSet<IndexEntry<String,
String>>();
+
+        Set<String> uuids = new HashSet<String>();
+
+        long candidates = cursorBuilder.build( root, uuids );
+
+        if ( candidates < Long.MAX_VALUE )
+        {
+            for ( String uuid : uuids )
+            {
+                ForwardIndexEntry<String, String> indexEntry = new ForwardIndexEntry<String,
String>();
+                indexEntry.setId( uuid );
+                resultSet.add( indexEntry );
+            }
+        }
+        else
+        {
+            // Full scan : use the MasterTable
+            Cursor<IndexEntry<String, String>> cursor = new IndexCursorAdaptor(
store.getMasterTable().cursor(), true );
+
+            while ( cursor.next() )
+            {
+                IndexEntry<String, String> indexEntry = cursor.get();
+
+                // Here, the indexEntry contains a <UUID, Entry> tuple. Convert it
to <UUID, UUID> 
+                ForwardIndexEntry<String, String> forwardIndexEntry = new ForwardIndexEntry<String,
String>();
+                forwardIndexEntry.setKey( indexEntry.getKey() );
+                forwardIndexEntry.setId( indexEntry.getKey() );
+                forwardIndexEntry.setEntry( ( Entry ) indexEntry.getTuple().getValue() );
+
+                resultSet.add( forwardIndexEntry );
+            }
+        }
+
+        searchResult.setResultSet( resultSet );
+        searchResult.setEvaluator( evaluator );
+
+        SearchingOperationContext operationContext = new SearchOperationContext( null );
+
+        return new BaseEntryFilteringCursor( new EntryCursorAdaptor( ( AbstractBTreePartition
) store, searchResult ),
+            operationContext );
+    }
+}

Modified: directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java?rev=1382390&r1=1382389&r2=1382390&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
(original)
+++ directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
Sun Sep  9 02:39:30 2012
@@ -26,24 +26,12 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 import java.io.File;
-import java.util.HashSet;
-import java.util.Set;
 
 import org.apache.commons.io.FileUtils;
-import org.apache.directory.server.core.api.filtering.BaseEntryFilteringCursor;
-import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
-import org.apache.directory.server.core.api.interceptor.context.SearchingOperationContext;
 import org.apache.directory.server.core.api.partition.Partition;
 import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
-import org.apache.directory.server.core.partition.impl.btree.AbstractBTreePartition;
-import org.apache.directory.server.core.partition.impl.btree.EntryCursorAdaptor;
-import org.apache.directory.server.xdbm.ForwardIndexEntry;
-import org.apache.directory.server.xdbm.IndexEntry;
-import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.server.xdbm.StoreUtils;
 import org.apache.directory.server.xdbm.impl.avl.AvlIndex;
-import org.apache.directory.server.xdbm.search.Evaluator;
-import org.apache.directory.server.xdbm.search.PartitionSearchResult;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.cursor.Cursor;
 import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException;
@@ -72,14 +60,11 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class AndCursorTest
+public class AndCursorTest extends AbstractCursorTest
 {
     private static final Logger LOG = LoggerFactory.getLogger( AndCursorTest.class.getSimpleName()
);
 
     File wkdir;
-    Store store;
-    EvaluatorBuilder evaluatorBuilder;
-    CursorBuilder cursorBuilder;
     private static SchemaManager schemaManager;
 
 
@@ -173,34 +158,6 @@ public class AndCursorTest
     }
 
 
-    private Cursor<Entry> buildCursor( ExprNode root ) throws Exception
-    {
-        Evaluator<? extends ExprNode> evaluator = evaluatorBuilder.build( root );
-
-        PartitionSearchResult searchResult = new PartitionSearchResult();
-        Set<IndexEntry<String, String>> resultSet = new HashSet<IndexEntry<String,
String>>();
-
-        Set<String> uuids = new HashSet<String>();
-
-        long candidates = cursorBuilder.build( root, uuids );
-
-        for ( String uuid : uuids )
-        {
-            ForwardIndexEntry<String, String> indexEntry = new ForwardIndexEntry<String,
String>();
-            indexEntry.setId( uuid );
-            resultSet.add( indexEntry );
-        }
-
-        searchResult.setResultSet( resultSet );
-        searchResult.setEvaluator( evaluator );
-
-        SearchingOperationContext operationContext = new SearchOperationContext( null );
-
-        return new BaseEntryFilteringCursor( new EntryCursorAdaptor( ( AbstractBTreePartition
) store, searchResult ),
-            operationContext );
-    }
-
-
     @Test
     public void testAndCursorWithCursorBuilder() throws Exception
     {

Modified: directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java?rev=1382390&r1=1382389&r2=1382390&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java
(original)
+++ directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java
Sun Sep  9 02:39:30 2012
@@ -33,8 +33,6 @@ import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.core.api.partition.Partition;
 import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
 import org.apache.directory.server.xdbm.ForwardIndexEntry;
-import org.apache.directory.server.xdbm.IndexEntry;
-import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.server.xdbm.StoreUtils;
 import org.apache.directory.server.xdbm.impl.avl.AvlIndex;
 import org.apache.directory.server.xdbm.search.Evaluator;
@@ -43,6 +41,7 @@ import org.apache.directory.server.xdbm.
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.cursor.Cursor;
 import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException;
+import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.filter.ExprNode;
 import org.apache.directory.shared.ldap.model.filter.FilterParser;
 import org.apache.directory.shared.ldap.model.filter.NotNode;
@@ -70,17 +69,14 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class NotCursorTest
+public class NotCursorTest extends AbstractCursorTest
 {
     private static final Logger LOG = LoggerFactory.getLogger( NotCursorTest.class.getSimpleName()
);
 
     UuidSyntaxChecker uuidSynChecker = new UuidSyntaxChecker();
 
     File wkdir;
-    Store store;
     static SchemaManager schemaManager = null;
-    EvaluatorBuilder evaluatorBuilder;
-    CursorBuilder cursorBuilder;
 
 
     @BeforeClass
@@ -176,7 +172,7 @@ public class NotCursorTest
 
         ExprNode exprNode = FilterParser.parse( schemaManager, filter );
 
-        Cursor<IndexEntry<?, String>> cursor = cursorBuilder.build( exprNode
);
+        Cursor<Entry> cursor = buildCursor( exprNode );
 
         assertFalse( cursor.available() );
 
@@ -187,8 +183,10 @@ public class NotCursorTest
         while ( cursor.next() )
         {
             assertTrue( cursor.available() );
-            set.add( cursor.get().getId() );
-            assertTrue( uuidSynChecker.isValidSyntax( cursor.get().getKey() ) );
+            Entry entry = cursor.get();
+            String uuid = entry.get( "entryUUID" ).getString();
+            set.add( uuid );
+            assertTrue( uuidSynChecker.isValidSyntax( uuid ) );
         }
 
         assertEquals( 5, set.size() );

Modified: directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java?rev=1382390&r1=1382389&r2=1382390&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java
(original)
+++ directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java
Sun Sep  9 02:39:30 2012
@@ -27,25 +27,16 @@ import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
 import org.apache.commons.io.FileUtils;
-import org.apache.directory.server.core.api.filtering.BaseEntryFilteringCursor;
-import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
-import org.apache.directory.server.core.api.interceptor.context.SearchingOperationContext;
 import org.apache.directory.server.core.api.partition.Partition;
 import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
-import org.apache.directory.server.core.partition.impl.btree.AbstractBTreePartition;
-import org.apache.directory.server.core.partition.impl.btree.EntryCursorAdaptor;
 import org.apache.directory.server.xdbm.ForwardIndexEntry;
 import org.apache.directory.server.xdbm.IndexEntry;
-import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.server.xdbm.StoreUtils;
 import org.apache.directory.server.xdbm.impl.avl.AvlIndex;
 import org.apache.directory.server.xdbm.search.Evaluator;
-import org.apache.directory.server.xdbm.search.PartitionSearchResult;
 import org.apache.directory.server.xdbm.search.cursor.OrCursor;
 import org.apache.directory.server.xdbm.search.cursor.SubstringCursor;
 import org.apache.directory.server.xdbm.search.evaluator.SubstringEvaluator;
@@ -83,43 +74,12 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class OrCursorTest
+public class OrCursorTest extends AbstractCursorTest
 {
     private static final Logger LOG = LoggerFactory.getLogger( OrCursorTest.class.getSimpleName()
);
 
     File wkdir;
-    Store store;
     static SchemaManager schemaManager = null;
-    EvaluatorBuilder evaluatorBuilder;
-    CursorBuilder cursorBuilder;
-
-
-    private Cursor<Entry> buildCursor( ExprNode root ) throws Exception
-    {
-        Evaluator<? extends ExprNode> evaluator = evaluatorBuilder.build( root );
-
-        PartitionSearchResult searchResult = new PartitionSearchResult();
-        Set<IndexEntry<String, String>> resultSet = new HashSet<IndexEntry<String,
String>>();
-
-        Set<String> uuids = new HashSet<String>();
-
-        long candidates = cursorBuilder.build( root, uuids );
-
-        for ( String uuid : uuids )
-        {
-            ForwardIndexEntry<String, String> indexEntry = new ForwardIndexEntry<String,
String>();
-            indexEntry.setId( uuid );
-            resultSet.add( indexEntry );
-        }
-
-        searchResult.setResultSet( resultSet );
-        searchResult.setEvaluator( evaluator );
-
-        SearchingOperationContext operationContext = new SearchOperationContext( null );
-
-        return new BaseEntryFilteringCursor( new EntryCursorAdaptor( ( AbstractBTreePartition
) store, searchResult ),
-            operationContext );
-    }
 
 
     @BeforeClass



Mime
View raw message