use of javax.jms.ExceptionListener in project qpid-broker-j by apache.
the class ExceptionListenerTest method testExceptionListenerStopsConnection_ThrowsIllegalStateException.
@Test
public void testExceptionListenerStopsConnection_ThrowsIllegalStateException() throws Exception {
assumeThat(getBrokerAdmin().supportsRestart(), is(equalTo(true)));
final Connection connection = getConnection();
try {
final CountDownLatch exceptionReceivedLatch = new CountDownLatch(1);
final AtomicReference<JMSException> exceptionHolder = new AtomicReference<>();
final AtomicReference<Throwable> unexpectedExceptionHolder = new AtomicReference<>();
final ExceptionListener listener = exception -> {
exceptionHolder.set(exception);
try {
connection.stop();
fail("Exception not thrown");
} catch (IllegalStateException ise) {
// PASS
} catch (Throwable t) {
unexpectedExceptionHolder.set(t);
} finally {
exceptionReceivedLatch.countDown();
}
};
connection.setExceptionListener(listener);
getBrokerAdmin().restart();
assertTrue("Exception was not propagated into exception listener in timely manner", exceptionReceivedLatch.await(getReceiveTimeout(), TimeUnit.MILLISECONDS));
assertNotNull("Unexpected exception", exceptionHolder.get());
assertNull("Connection#stop() should not have thrown exception", unexpectedExceptionHolder.get());
} finally {
connection.close();
}
}
use of javax.jms.ExceptionListener 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) {
}
}
use of javax.jms.ExceptionListener in project scout.rt by eclipse.
the class JmsMomImplementor method postCreateConnection.
protected void postCreateConnection(Connection connection) throws JMSException {
connection.setClientID(m_clientId);
connection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(final JMSException exception) {
BEANS.get(MomExceptionHandler.class).handle(exception);
}
});
// we directly start the shared connection
connection.start();
}
Aggregations