DisconnectClientTaskTestCase.java revision 7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * CDDL HEADER START
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * The contents of this file are subject to the terms of the
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * Common Development and Distribution License, Version 1.0 only
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * (the "License"). You may not use this file except in compliance
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * with the License.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * You can obtain a copy of the license at
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * trunk/opends/resource/legal-notices/OpenDS.LICENSE
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * See the License for the specific language governing permissions
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * and limitations under the License.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * When distributing Covered Code, include this CDDL HEADER in each
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * file and include the License file at
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * add the following below this CDDL HEADER, with the fields enclosed
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * by brackets "[]" replaced with your own identifying information:
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * Portions Copyright [yyyy] [name of copyright owner]
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * CDDL HEADER END
05b42f00b813c3dc70cbb80d62089f9cc0f6f549ludovicp * Copyright 2008 Sun Microsystems, Inc.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilsonimport org.opends.server.backends.task.TaskBackend;
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilsonimport org.opends.server.backends.task.TaskState;
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilsonimport org.opends.server.extensions.GetConnectionIDExtendedOperation;
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilsonimport static org.opends.server.util.ServerConstants.*;
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * Tests the disconnect client task.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * Make sure that the Directory Server is running.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * @throws Exception If an unexpected problem occurs.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * Tests the ability of the server to disconnect an arbitrary client
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * connection with a notice of disconnection.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * @throws Exception If an unexpected problem occurs.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson // Establish a connection to the server, bind, and get the connection ID.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort());
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift new BindRequestProtocolOp(ByteString.valueOf("cn=Directory Manager"),
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson LDAPMessage message = new LDAPMessage(1, bindRequest);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp();
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson new ExtendedRequestProtocolOp(OID_GET_CONNECTION_ID_EXTOP);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson message = new LDAPMessage(2, extendedRequest);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson assertEquals(extendedResponse.getResultCode(), LDAPResultCode.SUCCESS);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson assertEquals(extendedResponse.getOID(), OID_GET_CONNECTION_ID_EXTOP);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson long connectionID = GetConnectionIDExtendedOperation.decodeResponseValue(
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson // Invoke the disconnect client task.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson String taskID = "Disconnect Client " + connectionID;
53247d28ba99538f841a13ea2cde01c3faa3ef36kenneth_suter Message disconnectMessage = Message.raw("testDisconnectWithNotification");
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson DN taskDN = DN.decode("ds-task-id=" + taskID +
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson ",cn=Scheduled Tasks,cn=Tasks");
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson "objectClass: top",
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson "objectClass: ds-task",
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson "objectClass: ds-task-disconnect",
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson "ds-task-class-name: org.opends.server.tasks.DisconnectClientTask",
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson "ds-task-disconnect-connection-id: " + connectionID,
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson "ds-task-disconnect-notify-client: true",
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson "ds-task-disconnect-message: " + disconnectMessage);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson assertEquals(task.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson // Make sure that we get a notice of disconnection on the initial
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson // connection.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson extendedResponse = message.getExtendedResponseProtocolOp();
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson assertEquals(extendedResponse.getErrorMessage(), disconnectMessage);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson } catch (Exception e) {}
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * Tests the ability of the server to disconnect an arbitrary client
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * connection without a notice of disconnection.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson * @throws Exception If an unexpected problem occurs.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson public void testDisconnectWithoutNotification()
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson // Establish a connection to the server, bind, and get the connection ID.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort());
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift new BindRequestProtocolOp(ByteString.valueOf("cn=Directory Manager"),
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson LDAPMessage message = new LDAPMessage(1, bindRequest);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp();
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson new ExtendedRequestProtocolOp(OID_GET_CONNECTION_ID_EXTOP);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson message = new LDAPMessage(2, extendedRequest);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson assertEquals(extendedResponse.getResultCode(), LDAPResultCode.SUCCESS);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson assertEquals(extendedResponse.getOID(), OID_GET_CONNECTION_ID_EXTOP);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson long connectionID = GetConnectionIDExtendedOperation.decodeResponseValue(
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson // Invoke the disconnect client task.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson String taskID = "Disconnect Client " + connectionID;
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson DN taskDN = DN.decode("ds-task-id=" + taskID +
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson ",cn=Scheduled Tasks,cn=Tasks");
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson "objectClass: top",
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson "objectClass: ds-task",
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson "objectClass: ds-task-disconnect",
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson "ds-task-class-name: org.opends.server.tasks.DisconnectClientTask",
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson "ds-task-disconnect-connection-id: " + connectionID,
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson "ds-task-disconnect-notify-client: false");
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson assertEquals(task.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY);
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson // Make sure that the client connection has been closed with no notice of
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson // disconnection.
2e3f393aba5a1ea9785f544721879d0a6c8eddcfneil_a_wilson } catch (Exception e) {}