TestCaseUtils.initializeTestBackend(true);
// Establish a connection to the server and bind as a root user.
Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort());
LDAPReader r = new LDAPReader(s);
LDAPWriter w = new LDAPWriter(s);
s.setSoTimeout(6000);
BindRequestProtocolOp bindRequest =
new BindRequestProtocolOp(ByteString.valueOf("cn=Directory Manager"),
3, ByteString.valueOf("password"));
LDAPMessage message = new LDAPMessage(1, bindRequest);
w.writeMessage(message);
message = r.readMessage();
BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp();
assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS);
long abandonRequests = ldapStatistics.getAbandonRequests();
long abandonsCompleted = ldapStatistics.getOperationsAbandoned();
// Create an add request and send it to the server. Make sure to include
// the delay request control so it won't complete before we can send the
// abandon request.
ArrayList<RawAttribute> attributes = new ArrayList<RawAttribute>();
ArrayList<ByteString> values = new ArrayList<ByteString>(2);
values.add(ByteString.valueOf("top"));
values.add(ByteString.valueOf("organizationalUnit"));
attributes.add(new LDAPAttribute("objectClass", values));
values = new ArrayList<ByteString>(1);
values.add(ByteString.valueOf("People"));
attributes.add(new LDAPAttribute("ou", values));
AddRequestProtocolOp addRequest =
new AddRequestProtocolOp(ByteString.valueOf("ou=People,o=test"),
attributes);
message = new LDAPMessage(2, addRequest,
DelayPreOpPlugin.createDelayControlList(5000));
w.writeMessage(message);
// Send the abandon request to the server.
AbandonRequestProtocolOp abandonRequest = new AbandonRequestProtocolOp(2);
w.writeMessage(new LDAPMessage(3, abandonRequest));
// Normally, abandoned operations don't receive a response. However, the
// testing configuration has been updated to ensure that if an operation
// does get abandoned, the server will return a response for it with a
// result code of "cancelled".
message = r.readMessage();
AddResponseProtocolOp addResponse = message.getAddResponseProtocolOp();
assertEquals(addResponse.getResultCode(), LDAPResultCode.CANCELED);
assertEquals(ldapStatistics.getAbandonRequests(), abandonRequests+1);
waitForAbandon(abandonsCompleted+1);