@Test
public void testSearchCore100kUsers() throws Exception
{
LdapConnection connection = IntegrationUtils.getAdminConnection( getService() );
connection.bind( "uid=admin,ou=system", "secret" );
Entry rootPeople = new DefaultEntry(
connection.getSchemaManager(),
"ou=People,dc=example,dc=com",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: People" );
connection.add( rootPeople );
int nbUsers = 10000;
System.out.println( "Sleeping..." );
//Thread.sleep( 10000 );
long tadd0 = System.currentTimeMillis();
long tadd = tadd0;
for ( int i = 0; i < nbUsers; i++ )
{
Entry user = new DefaultEntry(
connection.getSchemaManager(),
"uid=user." + i + ",ou=People,dc=example,dc=com",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"givenName: Aaccf",
"sn: Amar",
"cn", "user" + i,
"initials: AA",
"uid", "user." + i,
"mail: user.1@cs.hacettepe.edu.tr",
"userPassword: password",
"telephoneNumber: 314-796-3178",
"homePhone: 514-847-0518",
"pager: 784-600-5445",
"mobile: 801-755-4931",
"street: 00599 First Street",
"l: Augusta",
"st: MN",
"postalCode: 30667",
"postalAddress: Aaccf Amar$00599 First Street$Augusta, MN 30667",
"description: This is the description for Aaccf Amar." );
try
{
connection.add( user );
}
catch ( NullPointerException npe )
{
System.out.println( i );
npe.printStackTrace();
throw npe;
}
if ( i % 1000 == 0 )
{
long tadd1 = System.currentTimeMillis();
System.out.println( "Injected " + i + " in " + ( tadd1 - tadd ) );
tadd = tadd1;
}
}
System.out.println( "Sleeping after add ..." );
//Thread.sleep( 10000 );
long tadd1 = System.currentTimeMillis();
System.out.println( "Time to inject " + nbUsers + " entries : " + ( ( tadd1 - tadd0 ) / 1000 ) + "s" );
//Thread.sleep( 10000 );
// Now do a random search
SearchRequest searchRequest = new SearchRequestImpl();
searchRequest.setBase( new Dn( "dc=example,dc=com" ) );
searchRequest.setScope( SearchScope.SUBTREE );
searchRequest.addAttributes( "*" );
searchRequest.setDerefAliases( AliasDerefMode.DEREF_ALWAYS );
long t0 = System.currentTimeMillis();
long t00 = 0L;
long tt0 = System.currentTimeMillis();
int nbIterations = 400000;
int count = 0;
Random random = new Random();
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 == 100000 )
{
t00 = System.currentTimeMillis();
}
searchRequest.setFilter( "(cn=user" + random.nextInt( nbUsers ) + ")" );
SearchCursor cursor = connection.search( searchRequest );
boolean hasNext = firstNext( cursor );
while ( hasNext )
{