Search in sources :

Example 1 with AmqpConnectionListener

use of org.apache.activemq.transport.amqp.client.AmqpConnectionListener in project activemq-artemis by apache.

the class AmqpBrokerReuqestedHearbeatsTest method testClientWithoutHeartbeatsGetsDropped.

@Test(timeout = 60000)
public void testClientWithoutHeartbeatsGetsDropped() throws Exception {
    final CountDownLatch disconnected = new CountDownLatch(1);
    AmqpClient client = createAmqpClient();
    assertNotNull(client);
    AmqpConnection connection = addConnection(client.createConnection());
    assertNotNull(connection);
    connection.setIdleProcessingDisabled(true);
    connection.setListener(new AmqpConnectionListener() {

        @Override
        public void onException(Throwable ex) {
            disconnected.countDown();
        }
    });
    connection.connect();
    assertEquals(1, server.getConnectionCount());
    assertTrue(disconnected.await(30, TimeUnit.SECONDS));
    connection.close();
    Wait.assertEquals(0, server::getConnectionCount);
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpConnectionListener(org.apache.activemq.transport.amqp.client.AmqpConnectionListener) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with AmqpConnectionListener

use of org.apache.activemq.transport.amqp.client.AmqpConnectionListener in project activemq-artemis by apache.

the class AmqpBrokerReuqestedHearbeatsTest method testClientWithHeartbeatsStaysAlive.

@Test(timeout = 60000)
public void testClientWithHeartbeatsStaysAlive() throws Exception {
    final CountDownLatch disconnected = new CountDownLatch(1);
    AmqpClient client = createAmqpClient();
    assertNotNull(client);
    AmqpConnection connection = addConnection(client.createConnection());
    assertNotNull(connection);
    connection.setListener(new AmqpConnectionListener() {

        @Override
        public void onException(Throwable ex) {
            disconnected.countDown();
        }
    });
    connection.connect();
    assertEquals(1, server.getConnectionCount());
    assertFalse(disconnected.await(5, TimeUnit.SECONDS));
    connection.close();
    Wait.assertEquals(0, server::getConnectionCount);
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpConnectionListener(org.apache.activemq.transport.amqp.client.AmqpConnectionListener) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)2 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)2 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)2 AmqpConnectionListener (org.apache.activemq.transport.amqp.client.AmqpConnectionListener)2 Test (org.junit.Test)2