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 2016/03/07 15:21:03 UTC
svn commit: r1733932 - in /directory/apacheds/trunk:
interceptors/operational/src/main/java/org/apache/directory/server/core/operational/
ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/
server-integ/src/test/jav...
Author: elecharny
Date: Mon Mar 7 14:21:03 2016
New Revision: 1733932
URL: http://svn.apache.org/viewvc?rev=1733932&view=rev
Log:
o Added the nbChildren/nbSubordinates attribute to the search operation results.
o Fixed the tests accordingly
Modified:
directory/apacheds/trunk/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java
directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
Modified: directory/apacheds/trunk/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java?rev=1733932&r1=1733931&r2=1733932&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java (original)
+++ directory/apacheds/trunk/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java Mon Mar 7 14:21:03 2016
@@ -22,6 +22,7 @@ package org.apache.directory.server.core
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import java.util.UUID;
import org.apache.directory.api.ldap.model.constants.SchemaConstants;
@@ -82,6 +83,9 @@ public class OperationalAttributeInterce
/** The filter that add the mandatory operational attributes */
private final EntryFilter operationalAttributeSearchFilter = new OperationalAttributeSearchFilter();
+
+ /** The filter that add the subordinates operational attributes */
+ private final EntryFilter subordinatesSearchFilter = new SubordinatesSearchFilter();
/** The subschemasubentry Dn */
private Dn subschemaSubentryDn;
@@ -161,6 +165,33 @@ public class OperationalAttributeInterce
/**
+ * The search result filter to use for the addition of the subordinates attributes, if requested
+ */
+ private class SubordinatesSearchFilter implements EntryFilter
+ {
+ /**
+ * {@inheritDoc}
+ */
+ public boolean accept( SearchOperationContext operation, Entry entry ) throws LdapException
+ {
+ // Add the nbChildren/nbSubordinates attributes if required
+ processSubordinates( operation.getReturningAttributes(), operation.isAllOperationalAttributes(), entry );
+
+ return true;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString( String tabs )
+ {
+ return tabs + "SubordinatesSearchFilter";
+ }
+ }
+
+
+ /**
* Creates the operational attribute management service interceptor.
*/
public OperationalAttributeInterceptor()
@@ -295,52 +326,14 @@ public class OperationalAttributeInterce
return serverEntry;
}
- Entry result = next( lookupContext );
-
- denormalizeEntryOpAttrs( result );
-
- // Bypass the rootDSE : we won't get the nbChildren and nbSubordiantes for this special entry
- if ( Dn.isNullOrEmpty( result.getDn() ) )
- {
- return result;
- }
+ Entry entry = next( lookupContext );
- // Add the Subordinates AttributeType if it's requested
- AttributeType nbChildrenAt = directoryService.getAtProvider().getNbChildren();
- AttributeTypeOptions nbChildrenAto = new AttributeTypeOptions( nbChildrenAt );
- AttributeType nbSubordinatesAt = directoryService.getAtProvider().getNbSubordinates();
- AttributeTypeOptions nbSubordinatesAto = new AttributeTypeOptions( nbSubordinatesAt );
+ denormalizeEntryOpAttrs( entry );
- if ( lookupContext.getReturningAttributes() != null )
- {
- boolean nbChildrenRequested = lookupContext.getReturningAttributes().contains( nbChildrenAto )
- | lookupContext.isAllOperationalAttributes();
- boolean nbSubordinatesRequested = lookupContext.getReturningAttributes().contains( nbSubordinatesAto )
- | lookupContext.isAllOperationalAttributes();
-
- if ( nbChildrenRequested || nbSubordinatesRequested )
- {
- Partition partition = directoryService.getPartitionNexus().getPartition( result.getDn() );
- Subordinates subordinates = partition.getSubordinates( result );
-
- long nbChildren = subordinates.getNbChildren();
- long nbSubordinates = subordinates.getNbSubordinates();
-
- if ( nbChildrenRequested )
- {
- result.add( new DefaultAttribute( nbChildrenAt,
- Long.toString( nbChildren ) ) );
- }
-
- if ( nbSubordinatesRequested )
- {
- result.add( new DefaultAttribute( nbSubordinatesAt,
- Long.toString( nbSubordinates ) ) );
- }
- }
- }
+ // Add the nbChildren/nbSubordinates attributes if required
+ processSubordinates( lookupContext.getReturningAttributes(), lookupContext.isAllOperationalAttributes(), entry );
- return result;
+ return entry;
}
@@ -536,6 +529,7 @@ public class OperationalAttributeInterce
}
cursor.addEntryFilter( operationalAttributeSearchFilter );
+ cursor.addEntryFilter( subordinatesSearchFilter );
return cursor;
}
@@ -644,4 +638,48 @@ public class OperationalAttributeInterce
return newDn;
}
+
+
+ private void processSubordinates( Set<AttributeTypeOptions> returningAttributes, boolean allAttributes, Entry entry )
+ throws LdapException
+ {
+ // Bypass the rootDSE : we won't get the nbChildren and nbSubordiantes for this special entry
+ if ( Dn.isNullOrEmpty( entry.getDn() ) )
+ {
+ return;
+ }
+
+ // Add the Subordinates AttributeType if it's requested
+ AttributeType nbChildrenAt = directoryService.getAtProvider().getNbChildren();
+ AttributeTypeOptions nbChildrenAto = new AttributeTypeOptions( nbChildrenAt );
+ AttributeType nbSubordinatesAt = directoryService.getAtProvider().getNbSubordinates();
+ AttributeTypeOptions nbSubordinatesAto = new AttributeTypeOptions( nbSubordinatesAt );
+
+ if ( returningAttributes != null )
+ {
+ boolean nbChildrenRequested = returningAttributes.contains( nbChildrenAto ) | allAttributes;
+ boolean nbSubordinatesRequested = returningAttributes.contains( nbSubordinatesAto ) | allAttributes;
+
+ if ( nbChildrenRequested || nbSubordinatesRequested )
+ {
+ Partition partition = directoryService.getPartitionNexus().getPartition( entry.getDn() );
+ Subordinates subordinates = partition.getSubordinates( entry );
+
+ long nbChildren = subordinates.getNbChildren();
+ long nbSubordinates = subordinates.getNbSubordinates();
+
+ if ( nbChildrenRequested )
+ {
+ entry.add( new DefaultAttribute( nbChildrenAt,
+ Long.toString( nbChildren ) ) );
+ }
+
+ if ( nbSubordinatesRequested )
+ {
+ entry.add( new DefaultAttribute( nbSubordinatesAt,
+ Long.toString( nbSubordinates ) ) );
+ }
+ }
+ }
+ }
}
\ No newline at end of file
Modified: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java?rev=1733932&r1=1733931&r2=1733932&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java (original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java Mon Mar 7 14:21:03 2016
@@ -110,7 +110,7 @@ public class SearchRequestReturningAttri
assertEquals( 1, count );
assertNotNull( entry );
- assertEquals( 10, entry.size() );
+ assertEquals( 12, entry.size() );
assertTrue( entry.containsAttribute( "objectClass" ) );
assertTrue( entry.containsAttribute( "cn" ) );
assertTrue( entry.containsAttribute( "sn" ) );
@@ -120,6 +120,8 @@ public class SearchRequestReturningAttri
assertTrue( entry.containsAttribute( "entryCSN" ) );
assertTrue( entry.containsAttribute( "entryDN" ) );
assertTrue( entry.containsAttribute( "subschemaSubentry" ) );
+ assertTrue( entry.containsAttribute( "nbChildren" ) );
+ assertTrue( entry.containsAttribute( "nbSubordinates" ) );
}
@@ -178,7 +180,7 @@ public class SearchRequestReturningAttri
assertEquals( 1, count );
assertNotNull( entry );
- assertEquals( 7, entry.size() );
+ assertEquals( 9, entry.size() );
assertTrue( entry.containsAttribute( "creatorsName" ) );
assertTrue( entry.containsAttribute( "createTimestamp" ) );
assertTrue( entry.containsAttribute( "entryUUID" ) );
@@ -186,6 +188,8 @@ public class SearchRequestReturningAttri
assertTrue( entry.containsAttribute( "entryDN" ) );
assertTrue( entry.containsAttribute( "entryParentId" ) );
assertTrue( entry.containsAttribute( "subschemaSubentry" ) );
+ assertTrue( entry.containsAttribute( "nbChildren" ) );
+ assertTrue( entry.containsAttribute( "nbSubordinates" ) );
}
@@ -247,7 +251,7 @@ public class SearchRequestReturningAttri
assertEquals( 1, count );
assertNotNull( entry );
- assertEquals( 9, entry.size() );
+ assertEquals( 11, entry.size() );
assertTrue( entry.containsAttribute( "cn" ) );
assertTrue( entry.containsAttribute( "sn" ) );
assertTrue( entry.containsAttribute( "creatorsName" ) );
@@ -257,6 +261,8 @@ public class SearchRequestReturningAttri
assertTrue( entry.containsAttribute( "entryDN" ) );
assertTrue( entry.containsAttribute( "entryParentId" ) );
assertTrue( entry.containsAttribute( "subschemaSubentry" ) );
+ assertTrue( entry.containsAttribute( "nbChildren" ) );
+ assertTrue( entry.containsAttribute( "nbSubordinates" ) );
}
@@ -468,7 +474,7 @@ public class SearchRequestReturningAttri
assertEquals( 1, count );
assertNotNull( entry );
- assertEquals( 10, entry.size() );
+ assertEquals( 12, entry.size() );
assertTrue( entry.containsAttribute( "objectClass" ) );
assertTrue( entry.containsAttribute( "cn" ) );
assertTrue( entry.containsAttribute( "sn" ) );
@@ -479,6 +485,8 @@ public class SearchRequestReturningAttri
assertTrue( entry.containsAttribute( "entryDN" ) );
assertTrue( entry.containsAttribute( "entryParentId" ) );
assertTrue( entry.containsAttribute( "subschemaSubentry" ) );
+ assertTrue( entry.containsAttribute( "nbChildren" ) );
+ assertTrue( entry.containsAttribute( "nbSubordinates" ) );
}
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=1733932&r1=1733931&r2=1733932&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 Mon Mar 7 14:21:03 2016
@@ -1213,7 +1213,7 @@ public class SearchIT extends AbstractLd
// ensure that all operational attributes are returned
// and no user attributes
- assertEquals( 7, attrs.size() );
+ assertEquals( 9, attrs.size() );
assertNull( attrs.get( "cn" ) );
assertNull( attrs.get( "sn" ) );
assertNull( attrs.get( "objectClass" ) );
@@ -1225,6 +1225,119 @@ public class SearchIT extends AbstractLd
assertNotNull( attrs.get( "entrycsn" ) );
assertNotNull( attrs.get( "entryDn" ) );
assertNotNull( attrs.get( "subschemaSubentry" ) );
+ assertNotNull( attrs.get( "nbChildren" ) );
+ assertNotNull( attrs.get( "nbSubordinates" ) );
+ }
+
+
+ @Test
+ public void testSearchNbChildrenOperationalAttr() throws Exception
+ {
+ LdapContext ctx = ( LdapContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+ controls.setReturningAttributes( new String[]
+ { "nbChildren" } );
+
+ NamingEnumeration<SearchResult> res = ctx.search( "", "(commonName=Tori Amos)", controls );
+
+ assertTrue( res.hasMore() );
+
+ SearchResult result = res.next();
+
+ // ensure that result is not null
+ assertNotNull( result );
+
+ Attributes attrs = result.getAttributes();
+
+ // ensure that all operational attributes are returned
+ // and no user attributes
+ assertEquals( 1, attrs.size() );
+ assertNotNull( attrs.get( "nbChildren" ) );
+ assertNull( attrs.get( "nbSubordinates" ) );
+ }
+
+
+ @Test
+ public void testSearchNbSubordinatesOperationalAttr() throws Exception
+ {
+ LdapContext ctx = ( LdapContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+ controls.setReturningAttributes( new String[]
+ { "nbSubordinates" } );
+
+ NamingEnumeration<SearchResult> res = ctx.search( "", "(commonName=Tori Amos)", controls );
+
+ assertTrue( res.hasMore() );
+
+ SearchResult result = res.next();
+
+ // ensure that result is not null
+ assertNotNull( result );
+
+ Attributes attrs = result.getAttributes();
+
+ // ensure that all operational attributes are returned
+ // and no user attributes
+ assertEquals( 1, attrs.size() );
+ assertNotNull( attrs.get( "nbSubordinates" ) );
+ assertNull( attrs.get( "nbChildren" ) );
+ }
+
+
+ @Test
+ @Ignore
+ public void testSearchSubordinatesPerf() throws Exception
+ {
+ LdapContext ctx = ( LdapContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+ controls.setReturningAttributes( new String[]
+ { "entryUUID" } );
+
+ long t00 = System.currentTimeMillis();
+ for ( int i = 0; i < 10000; i++ )
+ {
+ NamingEnumeration<SearchResult> res = ctx.search( "", "(commonName=Tori Amos)", controls );
+ res.close();
+ }
+ long t01 = System.currentTimeMillis();
+
+ System.out.println( "Delta without children = " + ( t01 - t00 ) );
+
+ controls = new SearchControls();
+ controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+ controls.setReturningAttributes( new String[]
+ { "nbSubordinates" } );
+
+ long t0 = System.currentTimeMillis();
+ for ( int i = 0; i < 100000; i++ )
+ {
+ NamingEnumeration<SearchResult> res = ctx.search( "", "(commonName=Tori Amos)", controls );
+ res.close();
+ }
+ long t1 = System.currentTimeMillis();
+
+ System.out.println( "Delta with children = " + ( t1 - t0 ) );
+
+ controls = new SearchControls();
+ controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+ controls.setReturningAttributes( new String[]
+ { "entryUUID" } );
+
+ long t000 = System.currentTimeMillis();
+ for ( int i = 0; i < 100000; i++ )
+ {
+ NamingEnumeration<SearchResult> res = ctx.search( "", "(commonName=Tori Amos)", controls );
+ res.close();
+ }
+ long t001 = System.currentTimeMillis();
+
+ System.out.println( "Delta without children(2) = " + ( t001 - t000 ) );
}
@@ -1250,7 +1363,7 @@ public class SearchIT extends AbstractLd
Attributes attrs = result.getAttributes();
// ensure that all user attributes are returned
- assertEquals( 13, attrs.size() );
+ assertEquals( 15, attrs.size() );
assertNotNull( attrs.get( "cn" ) );
assertNotNull( attrs.get( "sn" ) );
assertNotNull( attrs.get( "objectClass" ) );
@@ -1263,6 +1376,8 @@ public class SearchIT extends AbstractLd
assertNotNull( attrs.get( "entrycsn" ) );
assertNotNull( attrs.get( "entryDn" ) );
assertNotNull( attrs.get( "subschemaSubentry" ) );
+ assertNotNull( attrs.get( "nbChildren" ) );
+ assertNotNull( attrs.get( "nbSubordinates" ) );
}