Search in sources :

Example 1 with HornetQQueue

use of org.hornetq.jms.client.HornetQQueue in project eap-additional-testsuite by jboss-set.

the class HornetQServerManagementTestCase method testCloseConsumerConnectionsForAddress.

@Test
public void testCloseConsumerConnectionsForAddress() throws Exception {
    JMSOperations adminSupport = JMSOperationsProvider.getInstance(managementClient);
    adminSupport.createJmsQueue(getQueueName(), getQueueJndiName());
    Connection connection = connectionFactory.createConnection("guest", "guest");
    HornetQQueue queue = HornetQDestination.createQueue(getQueueName());
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(queue);
    connection.start();
    final CountDownLatch connectionClosed = new CountDownLatch(1);
    connection.setExceptionListener(new ExceptionListener() {

        @Override
        public void onException(JMSException e) {
            System.out.println("HornetQServerManagementTestCase.onException");
            connectionClosed.countDown();
        }
    });
    ModelNode operation = getHornetQServerOperation("close-consumer-connections-for-address");
    operation.get("address-match").set("jms.#");
    System.out.println("operation = " + operation);
    ModelNode result = execute(operation, true);
    System.out.println("result = " + result);
    assertTrue(result.isDefined());
    assertEquals(true, result.asBoolean());
    assertTrue(connectionClosed.await(500, MILLISECONDS));
    // consumer is no longer valid
    try {
        consumer.receiveNoWait();
        connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Assert.fail("consumer can no longer be used after it has been closed");
    } catch (JMSException e) {
    }
    // connection is no longer valid
    try {
        connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Assert.fail("connection can no longer be used after it has been closed");
    } catch (JMSException e) {
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) HornetQQueue(org.hornetq.jms.client.HornetQQueue) JMSOperations(org.jboss.as.test.integration.common.jms.JMSOperations) ExceptionListener(javax.jms.ExceptionListener) JMSException(javax.jms.JMSException) CountDownLatch(java.util.concurrent.CountDownLatch) ModelNode(org.jboss.dmr.ModelNode) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 Connection (javax.jms.Connection)1 ExceptionListener (javax.jms.ExceptionListener)1 JMSException (javax.jms.JMSException)1 MessageConsumer (javax.jms.MessageConsumer)1 Session (javax.jms.Session)1 HornetQQueue (org.hornetq.jms.client.HornetQQueue)1 JMSOperations (org.jboss.as.test.integration.common.jms.JMSOperations)1 ModelNode (org.jboss.dmr.ModelNode)1 Test (org.junit.Test)1