directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r687556 - in /directory/apacheds/trunk/server-integ/src: main/java/org/apache/directory/server/integ/annotations/ test/java/org/apache/directory/server/operations/search/ test/java/org/apache/directory/server/suites/
Date Thu, 21 Aug 2008 04:39:49 GMT
Author: akarasulu
Date: Wed Aug 20 21:39:48 2008
New Revision: 687556

URL: http://svn.apache.org/viewvc?rev=687556&view=rev
Log:
adding tests for search limits testing, removing empty package and formatting

Added:
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchLimitsIT.java
Removed:
    directory/apacheds/trunk/server-integ/src/main/java/org/apache/directory/server/integ/annotations/
Modified:
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/suites/StockServerISuite.java

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java?rev=687556&r1=687555&r2=687556&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
Wed Aug 20 21:39:48 2008
@@ -931,6 +931,7 @@
         assertFalse( res.hasMore() );
     }
 
+    
     @Test
     public void testSearchAttrCN() throws Exception
     {

Added: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchLimitsIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchLimitsIT.java?rev=687556&view=auto
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchLimitsIT.java
(added)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchLimitsIT.java
Wed Aug 20 21:39:48 2008
@@ -0,0 +1,289 @@
+/*
+ *  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.operations.search;
+
+
+import org.apache.directory.server.core.entry.ClonedServerEntry;
+import org.apache.directory.server.core.filtering.EntryFilter;
+import org.apache.directory.server.core.filtering.EntryFilteringCursor;
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.server.core.interceptor.BaseInterceptor;
+import org.apache.directory.server.core.interceptor.Interceptor;
+import org.apache.directory.server.core.interceptor.NextInterceptor;
+import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.interceptor.context.SearchingOperationContext;
+import org.apache.directory.server.integ.SiRunner;
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
+
+import org.apache.directory.server.ldap.LdapServer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.TimeLimitExceededException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import java.util.HashSet;
+import java.util.Set;
+
+
+/**
+ * A set of tests to make sure the negation operator is working 
+ * properly when included in search filters on indexed attributes.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+@RunWith ( SiRunner.class ) 
+@CleanupLevel ( Level.SUITE )
+@ApplyLdifs( {
+    "dn: ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: organizationalUnit\n" +
+    "ou: actors\n\n" +
+
+    "dn: uid=jblack,ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: person\n" +
+    "objectClass: organizationalPerson\n" +
+    "objectClass: uidObject\n" +
+    "uid: jblack\n" +
+    "ou: comedy\n" +
+    "ou: adventure\n" +
+    "cn: Jack Black\n" +
+    "userPassword: secret\n" +
+    "sn: Black\n\n" +
+
+    "dn: uid=bpitt,ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: person\n" +
+    "objectClass: organizationalPerson\n" +
+    "objectClass: uidObject\n" +
+    "uid: bpitt\n" +
+    "ou: drama\n" +
+    "ou: adventure\n" +
+    "userPassword: secret\n" +
+    "cn: Brad Pitt\n" +
+    "sn: Pitt\n\n" +
+
+    "dn: uid=gcloony,ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: person\n" +
+    "objectClass: organizationalPerson\n" +
+    "objectClass: uidObject\n" +
+    "uid: gcloony\n" +
+    "ou: drama\n" +
+    "userPassword: secret\n" +
+    "cn: Goerge Cloony\n" +
+    "sn: Cloony\n\n" +
+
+    "dn: uid=jnewbie,ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: person\n" +
+    "objectClass: organizationalPerson\n" +
+    "objectClass: uidObject\n" +
+    "uid: jnewbie\n" +
+    "userPassword: secret\n" +
+    "cn: Joe Newbie\n" +
+    "sn: Newbie\n\n" 
+    }
+)
+public class SearchLimitsIT 
+{
+    public static LdapServer ldapServer;
+
+    
+    /**
+     * An {@link Interceptor} that fakes a specified amount of delay to each 
+     * search iteration so we can make sure search time limits are adhered to.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    class DelayInducingInterceptor extends BaseInterceptor
+    {
+        private Long delayMillis;
+
+        
+        public EntryFilteringCursor search( NextInterceptor next, SearchOperationContext
opContext ) throws Exception
+        {
+            EntryFilteringCursor cursor = next.search( opContext );
+            cursor.addEntryFilter( new EntryFilter() {
+                public boolean accept( SearchingOperationContext operation, ClonedServerEntry
result ) throws Exception
+                {
+                    if ( delayMillis != null )
+                    {
+                        Thread.sleep( delayMillis );
+                    }
+
+                    return true;
+                }
+            });
+            return cursor;
+        }
+        
+        
+        public void setDelayMillis( long delayMillis )
+        {
+            if ( delayMillis <= 0 )
+            {
+                this.delayMillis = null;
+            }
+            
+            this.delayMillis = delayMillis;
+        }
+    }
+
+    
+    private int oldMaxTimeLimit;
+    private DelayInducingInterceptor delayInterceptor;
+
+    
+    @Before
+    public void setUp() throws Exception
+    {
+        oldMaxTimeLimit = ldapServer.getMaxTimeLimit();
+        delayInterceptor = new DelayInducingInterceptor();
+        ldapServer.getDirectoryService().getInterceptorChain().addFirst( delayInterceptor
);
+    }
+    
+    
+    @After
+    public void tearDown() throws Exception
+    {
+        ldapServer.setMaxTimeLimit( oldMaxTimeLimit );
+        ldapServer.getDirectoryService().getInterceptorChain().remove( DelayInducingInterceptor.class.getName()
);
+    }
+    
+
+    /**
+     * Sets up the server with unlimited search time limit but constrains time
+     * by request time limit value to cause a time limit exceeded exception on
+     * the client.
+     */
+    @Test ( expected = TimeLimitExceededException.class )
+    public void testRequestConstrainedUnlimitByConfiguration() throws Exception
+    {
+        ldapServer.setMaxTimeLimit( LdapServer.NO_TIME_LIMIT );
+        delayInterceptor.setDelayMillis( 500 );
+        
+        getActorsWithTimeLimit( "(objectClass=*)", 499 );
+    }
+    
+
+    /**
+     * Sets up the server with longer search time limit than the request's 
+     * which constrains time by request time limit value to cause a time limit 
+     * exceeded exception on the client.
+     */
+    @Test ( expected = TimeLimitExceededException.class )
+    public void testRequestConstrainedLessThanConfiguration() throws Exception
+    {
+        ldapServer.setMaxTimeLimit( 10000 ); // this is in seconds
+        delayInterceptor.setDelayMillis( 500 );
+        
+        getActorsWithTimeLimit( "(objectClass=*)", 499 );
+    }
+
+    
+    /**
+     * Sets up the server with shorter search time limit than the request's 
+     * which constrains time by using server max limit value to cause a time 
+     * limit exceeded exception on the client.
+     */
+    @Test ( expected = TimeLimitExceededException.class )
+    public void testRequestConstrainedGreaterThanConfiguration() throws Exception
+    {
+        ldapServer.setMaxTimeLimit( 1 ); // this is in seconds
+        delayInterceptor.setDelayMillis( 1100 );
+        
+        getActorsWithTimeLimit( "(objectClass=*)", 100000 );
+    }
+
+    
+    /**
+     * Sets up the server with limited search time with unlimited request
+     * time limit.  Should work just fine for the administrative user.
+     */
+    @Test 
+    public void testRequestUnlimitedConfigurationLimited() throws Exception
+    {
+        ldapServer.setMaxTimeLimit( 1 ); // this is in seconds
+        delayInterceptor.setDelayMillis( 500 );
+        
+        getActorsWithTimeLimit( "(objectClass=*)", 0 );
+    }
+
+    
+    /**
+     * Sets up the server with limited search time with unlimited request
+     * time limit.  Should not work for non administrative users.
+     */
+    @Test ( expected = TimeLimitExceededException.class ) 
+    public void testNonAdminRequestUnlimitedConfigurationLimited() throws Exception
+    {
+        ldapServer.setMaxTimeLimit( 1 ); // this is in seconds
+        delayInterceptor.setDelayMillis( 500 );
+        
+        getActorsWithTimeLimitNonAdmin( "(objectClass=*)", 0 );
+    }
+
+    
+    Set<String> getActorsWithTimeLimit( String filter, int timeLimitMillis ) throws
Exception
+    {
+        DirContext ctx = getWiredContext( ldapServer );
+        Set<String> results = new HashSet<String>();
+        SearchControls controls = new SearchControls();
+        controls.setTimeLimit( timeLimitMillis );
+        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        
+        NamingEnumeration<SearchResult> namingEnumeration = ctx.search( "ou=actors,ou=system",
filter, controls );
+        while( namingEnumeration.hasMore() )
+        {
+            results.add( namingEnumeration.next().getNameInNamespace() );
+        }
+        
+        return results;
+    }
+
+    
+    Set<String> getActorsWithTimeLimitNonAdmin( String filter, int timeLimitMillis
) throws Exception
+    {
+        DirContext ctx = getWiredContext( ldapServer, "uid=jblack,ou=actors,ou=system", "secret"
);
+        Set<String> results = new HashSet<String>();
+        SearchControls controls = new SearchControls();
+        controls.setTimeLimit( timeLimitMillis );
+        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        
+        NamingEnumeration<SearchResult> namingEnumeration = ctx.search( "ou=actors,ou=system",
filter, controls );
+        while( namingEnumeration.hasMore() )
+        {
+            results.add( namingEnumeration.next().getNameInNamespace() );
+        }
+        
+        return results;
+    }
+}

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/suites/StockServerISuite.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/suites/StockServerISuite.java?rev=687556&r1=687555&r2=687556&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/suites/StockServerISuite.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/suites/StockServerISuite.java
Wed Aug 20 21:39:48 2008
@@ -45,6 +45,7 @@
 import org.apache.directory.server.operations.search.ReferralSearchIT;
 import org.apache.directory.server.operations.search.SchemaSearchIT;
 import org.apache.directory.server.operations.search.SearchIT;
+import org.apache.directory.server.operations.search.SearchLimitsIT;
 import org.apache.directory.server.ssl.StartTlsIT;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
@@ -78,7 +79,8 @@
         ReferralSearchIT.class,
         StartTlsIT.class,
         ModifyDnReferralIT.class,
-        PersistentSearchIT.class
+        PersistentSearchIT.class,
+        SearchLimitsIT.class
         } )
 @CleanupLevel ( Level.SUITE )
 @Mode ( SetupMode.ROLLBACK )



Mime
View raw message