*/
@Test
public void testAbandonnedRequest() throws Exception
{
LdapConnection asyncCnx = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
EntryCursor cursor = null;
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)
asyncCnx.bind( "uid=admin,ou=system", "secret" );
// First, add 1000 entries in the server
for ( int i = 0; i < 1000; i++ )
{
String dn = "cn=user" + i + "," + BASE;
Entry kate = new DefaultEntry( dn );
kate.add( "objectclass", "top", "person" );
kate.add( "sn", "Bush" );
kate.add( "cn", "user" + i );
asyncCnx.add( kate );
}
// Searches for all the entries in ou=system
cursor = asyncCnx.search( "ou=system", "(ObjectClass=*)", SearchScope.SUBTREE, "*" );
// Now loop on all the elements found, and abandon after 10 elements returned
int count = 0;
while ( cursor.next() )
{
count++;
if ( count == 10 )
{
// the message ID = 1 bind op + 1000 add ops + 1 search op
asyncCnx.abandon( 1002 );
}
}
assertEquals( 10, count );
}
catch ( LdapException e )
{
e.printStackTrace();
fail( "Should not have caught exception." );
}
finally
{
asyncCnx.unBind();
asyncCnx.close();
cursor.close();
}
}