@Test
public void testSearch100kUsers() throws LdapException, CursorException
{
LdapConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
connection.bind( "uid=admin,ou=system", "secret" );
Entry rootPeople = new DefaultEntry(
"ou=People,dc=example,dc=com",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: People" );
connection.add( rootPeople );
long tadd0 = System.currentTimeMillis();
for ( int i = 0; i < 10000; i++ )
{
Entry user = new DefaultEntry(
"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." );
connection.add( user );
if ( i % 100 == 0 )
{
System.out.println( "Injected " + i );
}
}
long tadd1 = System.currentTimeMillis();
System.out.println( "Time to inject 100k entries : " + ( ( tadd1 - tadd0 ) / 1000 ) + "s" );
// 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 = 200000;
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 == 50000 )
{
t00 = System.currentTimeMillis();
}
searchRequest.setFilter( "(cn=user" + random.nextInt( 10000 ) + ")" );
SearchCursor cursor = connection.search( searchRequest );
while ( cursor.next() )
{
count++;
cursor.getEntry();