* test a search request perf.
*/
@Test
public void testSearchRequestObjectScopePerf() throws Exception
{
LdapConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
long deltaSearch = 0L;
long deltaGet = 0L;
long deltaClose = 0L;
try
{
// Use the client API as JNDI cannot be used to do a search without
// first binding. (hmmm, even client API won't allow searching without binding)
connection.bind( "uid=admin,ou=system", "secret" );
// Searches for all the entries in ou=system
EntryCursor cursor = connection.search( "uid=admin,ou=system", "(ObjectClass=*)",
SearchScope.OBJECT, "*" );
int i = 0;
while ( cursor.next() )
{
cursor.get();
++i;
}
cursor.close();
assertEquals( 1, i );
for ( int j = 0; j < 10000; j++ )
{
cursor = connection.search( "uid=admin,ou=system", "(ObjectClass=*)", SearchScope.OBJECT, "*" );
while ( cursor.next() )
{
}
cursor.close();
}
Dn dn = new Dn( getService().getSchemaManager(), "uid=admin,ou=system" );
SearchRequest searchRequest = new SearchRequestImpl();
searchRequest.setBase( dn );
searchRequest.setFilter( "(ObjectClass=*)" );
searchRequest.setScope( SearchScope.OBJECT );
searchRequest.addAttributes( "*" );
searchRequest.setDerefAliases( AliasDerefMode.DEREF_ALWAYS );
long t0 = System.currentTimeMillis();
long t00 = 0L;
long tt0 = System.currentTimeMillis();
int nbIterations = 200000;
int count = 0;
for ( int j = 0; j < nbIterations; j++ )
{
if ( j % 10000 == 0 )
{
long tt1 = System.currentTimeMillis();
System.out.println( j + ", " + ( tt1 - tt0 ) );
tt0 = tt1;
}
if ( j == 50000 )
{
t00 = System.currentTimeMillis();
}
long dt0 = System.nanoTime();
cursor = new EntryCursorImpl( connection.search( searchRequest ) );
long dt1 = System.nanoTime();
deltaSearch += Math.abs( dt1 - dt0 );
while ( cursor.next() )
{
long dt2 = System.nanoTime();
cursor.get();
count++;
long dt3 = System.nanoTime();
deltaGet += Math.abs( dt3 - dt2 );
}
long dt4 = System.nanoTime();
cursor.close();
long dt5 = System.nanoTime();
deltaClose += Math.abs( dt5 - dt4 );
}
long t1 = System.currentTimeMillis();
Long deltaWarmed = ( t1 - t00 );
System.out.println( "OBJECT level - Delta : " + deltaWarmed + "( " + ( ( ( nbIterations - 50000 ) * 1000 ) / deltaWarmed )
+ " per s ) /" + ( t1 - t0 ) + ", count : " + count );
System.out.println( "DeltaSearch : " + ( deltaSearch / nbIterations ) );
System.out.println( "DeltaGet : " + ( deltaGet / nbIterations ) );
System.out.println( "DeltaClose : " + ( deltaClose / nbIterations ) );
}
catch ( LdapException e )
{
e.printStackTrace();
fail( "Should not have caught exception." );
}
finally
{
connection.unBind();
connection.close();
}
}