directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r366649 - in /directory/trunk: apacheds-core-unit/src/test/java/org/apache/ldap/server/jndi/ apacheds/src/main/java/org/apache/ldap/server/jndi/ apacheds/src/main/java/org/apache/ldap/server/partition/
Date Sat, 07 Jan 2006 04:28:55 GMT
Author: akarasulu
Date: Fri Jan  6 20:28:48 2006
New Revision: 366649

URL: http://svn.apache.org/viewcvs?rev=366649&view=rev
Log:
completed and passed tests for time and size limit implementation: also fixed bugs in it too

Modified:
    directory/trunk/apacheds-core-unit/src/test/java/org/apache/ldap/server/jndi/SearchContextTest.java
    directory/trunk/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java
    directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DefaultDirectoryPartitionNexus.java
    directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DirectoryPartitionNexusProxy.java

Modified: directory/trunk/apacheds-core-unit/src/test/java/org/apache/ldap/server/jndi/SearchContextTest.java
URL: http://svn.apache.org/viewcvs/directory/trunk/apacheds-core-unit/src/test/java/org/apache/ldap/server/jndi/SearchContextTest.java?rev=366649&r1=366648&r2=366649&view=diff
==============================================================================
--- directory/trunk/apacheds-core-unit/src/test/java/org/apache/ldap/server/jndi/SearchContextTest.java
(original)
+++ directory/trunk/apacheds-core-unit/src/test/java/org/apache/ldap/server/jndi/SearchContextTest.java
Fri Jan  6 20:28:48 2006
@@ -29,7 +29,12 @@
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 
+import org.apache.ldap.common.exception.LdapSizeLimitExceededException;
+import org.apache.ldap.common.exception.LdapTimeLimitExceededException;
 import org.apache.ldap.common.message.DerefAliasesEnum;
+import org.apache.ldap.server.enumeration.SearchResultFilter;
+import org.apache.ldap.server.enumeration.SearchResultFilteringEnumeration;
+import org.apache.ldap.server.invocation.Invocation;
 import org.apache.ldap.server.unit.AbstractAdminTestCase;
 
 
@@ -49,111 +54,70 @@
          * create ou=testing00,ou=system
          */
         Attributes attributes = new BasicAttributes( true );
-
         Attribute attribute = new BasicAttribute( "objectClass" );
-
         attribute.add( "top" );
-
         attribute.add( "organizationalUnit" );
-
         attributes.put( attribute );
-
         attributes.put( "ou", "testing00" );
 
         DirContext ctx = sysRoot.createSubcontext( "ou=testing00", attributes );
-
         assertNotNull( ctx );
-
+        
         ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" );
-
         assertNotNull( ctx );
-
         attributes = ctx.getAttributes( "" );
-
         assertNotNull( attributes );
-
         assertEquals( "testing00", attributes.get( "ou" ).get() );
-
         attribute = attributes.get( "objectClass" );
-
         assertNotNull( attribute );
-
         assertTrue( attribute.contains( "top" ) );
-
         assertTrue( attribute.contains( "organizationalUnit" ) );
 
         /*
          * create ou=testing01,ou=system
          */
         attributes = new BasicAttributes( true );
-
         attribute = new BasicAttribute( "objectClass" );
-
         attribute.add( "top" );
-
         attribute.add( "organizationalUnit" );
-
         attributes.put( attribute );
-
         attributes.put( "ou", "testing01" );
 
         ctx = sysRoot.createSubcontext( "ou=testing01", attributes );
-
         assertNotNull( ctx );
 
         ctx = ( DirContext ) sysRoot.lookup( "ou=testing01" );
-
         assertNotNull( ctx );
-
         attributes = ctx.getAttributes( "" );
-
         assertNotNull( attributes );
-
         assertEquals( "testing01", attributes.get( "ou" ).get() );
-
         attribute = attributes.get( "objectClass" );
-
         assertNotNull( attribute );
-
         assertTrue( attribute.contains( "top" ) );
-
         assertTrue( attribute.contains( "organizationalUnit" ) );
 
         /*
          * create ou=testing02,ou=system
          */
         attributes = new BasicAttributes( true );
-
         attribute = new BasicAttribute( "objectClass" );
-
         attribute.add( "top" );
-
         attribute.add( "organizationalUnit" );
-
         attributes.put( attribute );
-
         attributes.put( "ou", "testing02" );
-
         ctx = sysRoot.createSubcontext( "ou=testing02", attributes );
-
         assertNotNull( ctx );
 
         ctx = ( DirContext ) sysRoot.lookup( "ou=testing02" );
-
         assertNotNull( ctx );
 
         attributes = ctx.getAttributes( "" );
-
         assertNotNull( attributes );
-
         assertEquals( "testing02", attributes.get( "ou" ).get() );
 
         attribute = attributes.get( "objectClass" );
-
         assertNotNull( attribute );
-
         assertTrue( attribute.contains( "top" ) );
-
         assertTrue( attribute.contains( "organizationalUnit" ) );
 
         /*
@@ -162,37 +126,25 @@
         ctx = ( DirContext ) sysRoot.lookup( "ou=testing01" );
 
         attributes = new BasicAttributes( true );
-
         attribute = new BasicAttribute( "objectClass" );
-
         attribute.add( "top" );
-
         attribute.add( "organizationalUnit" );
-
         attributes.put( attribute );
-
         attributes.put( "ou", "subtest" );
 
         ctx = ctx.createSubcontext( "ou=subtest", attributes );
-
         assertNotNull( ctx );
 
         ctx = ( DirContext ) sysRoot.lookup( "ou=subtest,ou=testing01" );
-
         assertNotNull( ctx );
 
         attributes = ctx.getAttributes( "" );
-
         assertNotNull( attributes );
-
         assertEquals( "subtest", attributes.get( "ou" ).get() );
 
         attribute = attributes.get( "objectClass" );
-
         assertNotNull( attribute );
-
         assertTrue( attribute.contains( "top" ) );
-
         assertTrue( attribute.contains( "organizationalUnit" ) );
     }
 
@@ -200,30 +152,21 @@
     public void testSearchOneLevel() throws NamingException
     {
         SearchControls controls = new SearchControls();
-
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-
         controls.setDerefLinkFlag( false );
-
         sysRoot.addToEnvironment( DerefAliasesEnum.JNDI_PROP, DerefAliasesEnum.NEVERDEREFALIASES.getName()
);
-
         HashMap map = new HashMap();
 
         NamingEnumeration list = sysRoot.search( "", "(ou=*)", controls );
-
         while ( list.hasMore() )
         {
             SearchResult result = ( SearchResult ) list.next();
-
             map.put( result.getName(), result.getAttributes() );
         }
 
         assertEquals( "Expected number of results returned was incorrect!", 6, map.size()
);
-
         assertTrue( map.containsKey( "ou=testing00,ou=system" ) );
-
         assertTrue( map.containsKey( "ou=testing01,ou=system" ) );
-
         assertTrue( map.containsKey( "ou=testing02,ou=system" ) );
     }
 
@@ -231,63 +174,109 @@
     public void testSearchSubTreeLevel() throws NamingException
     {
         SearchControls controls = new SearchControls();
-
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-
         controls.setDerefLinkFlag( false );
-
         sysRoot.addToEnvironment( DerefAliasesEnum.JNDI_PROP, DerefAliasesEnum.NEVERDEREFALIASES.getName()
);
 
         HashMap map = new HashMap();
-
         NamingEnumeration list = sysRoot.search( "", "(ou=*)", controls );
-
         while ( list.hasMore() )
         {
             SearchResult result = ( SearchResult ) list.next();
-
             map.put( result.getName(), result.getAttributes() );
         }
 
         assertEquals( "Expected number of results returned was incorrect", 12, map.size()
);
-
         assertTrue( map.containsKey( "ou=system" ) );
-
         assertTrue( map.containsKey( "ou=testing00,ou=system" ) );
-
         assertTrue( map.containsKey( "ou=testing01,ou=system" ) );
-
         assertTrue( map.containsKey( "ou=testing02,ou=system" ) );
-
         assertTrue( map.containsKey( "ou=subtest,ou=testing01,ou=system" ) );
     }
+
     
     public void testSearchFilterArgs() throws NamingException
     {
         SearchControls controls = new SearchControls();
-
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-
         controls.setDerefLinkFlag( false );
-
         sysRoot.addToEnvironment( DerefAliasesEnum.JNDI_PROP, DerefAliasesEnum.NEVERDEREFALIASES.getName()
);
-
         HashMap map = new HashMap();
 
         NamingEnumeration list = sysRoot.search( "", "(| (ou={0}) (ou={1}))", new Object[]
{"testing00", "testing01"}, controls );
-
         while ( list.hasMore() )
         {
             SearchResult result = ( SearchResult ) list.next();
-
             map.put( result.getName(), result.getAttributes() );
         }
 
         assertEquals( "Expected number of results returned was incorrect!", 2, map.size()
);
-
         assertTrue( map.containsKey( "ou=testing00,ou=system" ) );
-
         assertTrue( map.containsKey( "ou=testing01,ou=system" ) );
     }
+    
+    
+    public void testSearchSizeLimit() throws NamingException
+    {
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        controls.setDerefLinkFlag( false );
+        controls.setCountLimit( 7 );
+        sysRoot.addToEnvironment( DerefAliasesEnum.JNDI_PROP, DerefAliasesEnum.NEVERDEREFALIASES.getName()
);
 
+        HashMap map = new HashMap();
+        NamingEnumeration list = sysRoot.search( "", "(ou=*)", controls );
+        
+        try
+        {
+            while ( list.hasMore() )
+            {
+                SearchResult result = ( SearchResult ) list.next();
+                map.put( result.getName(), result.getAttributes() );
+            }
+            fail( "Should not get here due to a SizeLimitExceededException" );
+        }
+        catch( LdapSizeLimitExceededException e ){}
+        assertEquals( "Expected number of results returned was incorrect", 7, map.size()
);
+    }
+
+
+    public void testSearchTimeLimit() throws NamingException
+    {
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        controls.setDerefLinkFlag( false );
+        controls.setTimeLimit( 200 );
+        sysRoot.addToEnvironment( DerefAliasesEnum.JNDI_PROP, DerefAliasesEnum.NEVERDEREFALIASES.getName()
);
+
+        HashMap map = new HashMap();
+        NamingEnumeration list = sysRoot.search( "", "(ou=*)", controls );
+        SearchResultFilteringEnumeration srfe = ( SearchResultFilteringEnumeration ) list;
+        srfe.addResultFilter( new SearchResultFilter() {
+            public boolean accept(Invocation invocation, SearchResult result, SearchControls
controls) throws NamingException
+            {
+                try
+                {
+                    Thread.sleep( 201 );
+                }
+                catch ( InterruptedException e )
+                {
+                    e.printStackTrace();
+                }
+                return true;
+            }
+        });
+        
+        try
+        {
+            while ( list.hasMore() )
+            {
+                SearchResult result = ( SearchResult ) list.next();
+                map.put( result.getName(), result.getAttributes() );
+            }
+            fail( "Should not get here due to a TimeLimitExceededException" );
+        }
+        catch( LdapTimeLimitExceededException e ){}
+        assertEquals( "Expected number of results returned was incorrect", 1, map.size()
);
+    }
 }

Modified: directory/trunk/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java
URL: http://svn.apache.org/viewcvs/directory/trunk/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java?rev=366649&r1=366648&r2=366649&view=diff
==============================================================================
--- directory/trunk/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java
(original)
+++ directory/trunk/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java
Fri Jan  6 20:28:48 2006
@@ -523,7 +523,6 @@
             if ( attr.size() == 0 )
             {
                 filter.addNode( new PresenceNode( attr.getID() ) );
-
                 continue;
             }
             
@@ -539,7 +538,6 @@
                 if ( val instanceof String )
                 {
                     node = new SimpleNode( attr.getID(), ( String ) val, SimpleNode.EQUALITY
);
-
                     filter.addNode( node );
                 }
             }

Modified: directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DefaultDirectoryPartitionNexus.java
URL: http://svn.apache.org/viewcvs/directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DefaultDirectoryPartitionNexus.java?rev=366649&r1=366648&r2=366649&view=diff
==============================================================================
--- directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DefaultDirectoryPartitionNexus.java
(original)
+++ directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DefaultDirectoryPartitionNexus.java
Fri Jan  6 20:28:48 2006
@@ -633,7 +633,6 @@
         if ( base.size() == 0 )
         {
             boolean isObjectScope = searchCtls.getSearchScope() == SearchControls.OBJECT_SCOPE;
-
             boolean isSearchAll = ( ( PresenceNode ) filter ).getAttribute().equalsIgnoreCase(
"objectclass" );
 
             /*
@@ -643,13 +642,11 @@
             if ( filter instanceof PresenceNode && isObjectScope && isSearchAll
)
             {
                 Attributes attrs = ( Attributes ) getRootDSE().clone();
-
                 String[] ids = searchCtls.getReturningAttributes();
 
                 if ( ids != null && ids.length > 0 )
                 {
                     boolean doSwap = true;
-
                     Attributes askedFor = new LockableAttributesImpl();
 
                     for ( int ii = 0; ii < ids.length; ii++ )
@@ -657,7 +654,6 @@
                         if ( ids[ii].trim().equals( "*" ) )
                         {
                             doSwap = false;
-
                             break;
                         }
 
@@ -674,7 +670,6 @@
                 }
 
                 SearchResult result = new SearchResult( "", null, attrs, false );
-
                 return new SingletonEnumeration( result );
             }
 
@@ -682,7 +677,6 @@
         }
 
         DirectoryPartition backend = getBackend( base );
-
         return backend.search( base, env, filter, searchCtls );
     }
 

Modified: directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DirectoryPartitionNexusProxy.java
URL: http://svn.apache.org/viewcvs/directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DirectoryPartitionNexusProxy.java?rev=366649&r1=366648&r2=366649&view=diff
==============================================================================
--- directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DirectoryPartitionNexusProxy.java
(original)
+++ directory/trunk/apacheds/src/main/java/org/apache/ldap/server/partition/DirectoryPartitionNexusProxy.java
Fri Jan  6 20:28:48 2006
@@ -28,14 +28,19 @@
 import javax.naming.directory.ModificationItem;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchResult;
 import javax.naming.event.EventContext;
 import javax.naming.event.NamingListener;
 import javax.naming.ldap.LdapContext;
 
+import org.apache.ldap.common.exception.LdapSizeLimitExceededException;
+import org.apache.ldap.common.exception.LdapTimeLimitExceededException;
 import org.apache.ldap.common.filter.ExprNode;
 import org.apache.ldap.server.DirectoryServiceConfiguration;
 import org.apache.ldap.server.DirectoryService;
 import org.apache.ldap.server.configuration.DirectoryPartitionConfiguration;
+import org.apache.ldap.server.enumeration.SearchResultFilter;
+import org.apache.ldap.server.enumeration.SearchResultFilteringEnumeration;
 import org.apache.ldap.server.event.EventService;
 import org.apache.ldap.server.interceptor.InterceptorChain;
 import org.apache.ldap.server.invocation.Invocation;
@@ -112,37 +117,49 @@
         this.configuration = service.getConfiguration();
     }
     
-    public LdapContext getLdapContext() {
+    
+    public LdapContext getLdapContext() 
+    {
         return this.configuration.getPartitionNexus().getLdapContext();
     }
 
+    
     public void init( DirectoryServiceConfiguration factoryCfg, DirectoryPartitionConfiguration
cfg )
     {
     }
 
+    
     public void destroy()
     {
     }
 
+    
     public DirectoryPartition getSystemPartition()
     {
         return this.configuration.getPartitionNexus().getSystemPartition();
     }
 
+    
     public Name getSuffix( boolean normalized ) throws NamingException
     {
         return this.configuration.getPartitionNexus().getSuffix( normalized );
     }
 
-    public void sync() throws NamingException {
+    
+    public void sync() throws NamingException 
+    {
         this.service.sync();
     }
 
-    public void close() throws NamingException {
+    
+    public void close() throws NamingException 
+    {
         this.service.shutdown();
     }
 
-    public boolean isInitialized() {
+    
+    public boolean isInitialized() 
+    {
         return this.service.isStarted();
     }
 
@@ -368,7 +385,42 @@
     public NamingEnumeration search( Name base, Map env, ExprNode filter, SearchControls
searchCtls )
             throws NamingException
     {
-        return search( base, env, filter, searchCtls, null );
+        SearchResultFilteringEnumeration results = ( SearchResultFilteringEnumeration ) 
+            search( base, env, filter, searchCtls, null );
+        
+        if ( searchCtls.getTimeLimit() + searchCtls.getCountLimit() > 0 )
+        {
+            // this will be he last filter added so other filters before it must 
+            // have passed/approved of the entry to be returned back to the client
+            // so the candidate we have is going to be returned for sure
+            results.addResultFilter( new SearchResultFilter(){
+                final long startTime = System.currentTimeMillis();
+                int count = 1;  // with prefetch we've missed one which is ok since 1 is
the minimum
+                public boolean accept( Invocation invocation, SearchResult result, SearchControls
controls ) throws NamingException
+                {
+                    if ( controls.getTimeLimit() > 0 )
+                    {
+                        long runtime = System.currentTimeMillis() - startTime;
+                        if ( runtime > controls.getTimeLimit() )
+                        {
+                            throw new LdapTimeLimitExceededException();
+                        }
+                    }
+                    
+                    if ( controls.getCountLimit() > 0 )
+                    {
+                       if ( count > controls.getCountLimit() )
+                       {
+                           throw new LdapSizeLimitExceededException();
+                       }
+                    }
+                    
+                    count++;
+                    return true;
+                }
+            });
+        }
+        return results;
     }
 
 



Mime
View raw message