use of javax.jms.ExceptionListener in project rabbitmq-jms-client by rabbitmq.
the class ConnectionCloseIT method testCloseDuringReceiveWithExceptionListener.
@Test
public void testCloseDuringReceiveWithExceptionListener() throws Exception {
ExceptionListener eListener = new ExceptionListener() {
@Override
public void onException(JMSException exception) {
atomBool.set(true);
atomJMSExceptionRef.set(exception);
}
};
topicConn.setExceptionListener(eListener);
topicConn.start();
TopicSession topicSession = topicConn.createTopicSession(true, Session.DUPS_OK_ACKNOWLEDGE);
Topic topicDestination = topicSession.createTopic(TOPIC_NAME);
MessageConsumer messageConsumer = topicSession.createConsumer(topicDestination);
Completion receiveCompletion = new Completion();
Thread receiver = new DelayedReceive(ZERO_SECONDS, messageConsumer, receiveCompletion);
Thread closer = new DelayedClose(ONE_SECOND, topicConn);
receiver.start();
closer.start();
try {
receiveCompletion.waitUntilComplete(FIVE_SECONDS, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
fail("Timeout before receive returns!");
}
if (atomBool.get()) {
fail(String.format("ExceptionListener driven with exception %s", atomJMSExceptionRef.get()));
}
}
use of javax.jms.ExceptionListener in project activemq-artemis by apache.
the class NioQueueSubscriptionTestListener method testLotsOfConcurrentConnections.
@Ignore("See AMQ-4286")
@Test(timeout = 60 * 1000)
public void testLotsOfConcurrentConnections() throws Exception {
ExecutorService executor = Executors.newCachedThreadPool();
final ConnectionFactory factory = createConnectionFactory();
int connectionCount = 400;
final AtomicInteger threadId = new AtomicInteger(0);
for (int i = 0; i < connectionCount; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
final int innerId = threadId.incrementAndGet();
try {
ExceptionListener listener = new NioQueueSubscriptionTestListener(innerId, exceptions, LOG);
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
connection.setExceptionListener(listener);
connection.start();
assertNotNull(connection.getBrokerName());
connections.add(connection);
} catch (Exception e) {
LOG.error(">>>> Exception in run() on thread " + innerId, e);
exceptions.put(Thread.currentThread(), e);
}
}
});
}
executor.shutdown();
executor.awaitTermination(30, TimeUnit.SECONDS);
if (!exceptions.isEmpty()) {
LOG.error(">>>> " + exceptions.size() + " exceptions like", exceptions.values().iterator().next());
fail("unexpected exceptions in worker threads: " + exceptions.values().iterator().next());
}
LOG.info("created " + connectionCount + " connections");
}
use of javax.jms.ExceptionListener in project activemq-artemis by apache.
the class FailureDeadlockTest method testDeadlock.
// https://jira.jboss.org/jira/browse/JBMESSAGING-1702
// Test that two failures concurrently executing and calling the same exception listener
// don't deadlock
@Test
public void testDeadlock() throws Exception {
for (int i = 0; i < 100; i++) {
final Connection conn1 = cf1.createConnection();
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
RemotingConnection rc1 = ((ClientSessionInternal) ((ActiveMQSession) sess1).getCoreSession()).getConnection();
final Connection conn2 = cf2.createConnection();
Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
RemotingConnection rc2 = ((ClientSessionInternal) ((ActiveMQSession) sess2).getCoreSession()).getConnection();
ExceptionListener listener1 = new ExceptionListener() {
@Override
public void onException(final JMSException exception) {
try {
conn2.close();
} catch (Exception e) {
FailureDeadlockTest.log.error("Failed to close connection2", e);
}
}
};
conn1.setExceptionListener(listener1);
conn2.setExceptionListener(listener1);
Failer f1 = new Failer(rc1);
Failer f2 = new Failer(rc2);
f1.start();
f2.start();
f1.join();
f2.join();
conn1.close();
conn2.close();
}
}
use of javax.jms.ExceptionListener in project activemq-artemis by apache.
the class ActiveMQConnectionFactoryTest method testSetExceptionListener.
public void testSetExceptionListener() throws Exception {
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
connection = (ActiveMQConnection) cf.createConnection();
assertNull(connection.getExceptionListener());
ExceptionListener exListener = new ExceptionListener() {
@Override
public void onException(JMSException arg0) {
}
};
cf.setExceptionListener(exListener);
connection.close();
connection = (ActiveMQConnection) cf.createConnection();
assertNotNull(connection.getExceptionListener());
assertEquals(exListener, connection.getExceptionListener());
connection.close();
connection = (ActiveMQConnection) cf.createConnection();
assertEquals(exListener, connection.getExceptionListener());
assertEquals(exListener, cf.getExceptionListener());
connection.close();
}
use of javax.jms.ExceptionListener in project activemq-artemis by apache.
the class DisconnectOnCriticalFailureTest method testClientDisconnectLarge.
@Test(timeout = 60000)
@BMRules(rules = { @BMRule(name = "Corrupt Decoding", targetClass = "org.apache.activemq.artemis.core.protocol.ClientPacketDecoder", targetMethod = "decode(org.apache.activemq.artemis.api.core.ActiveMQBuffer)", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.DisconnectOnCriticalFailureTest.doThrow($1);") })
public void testClientDisconnectLarge() throws Exception {
Queue q1 = createQueue("queue1");
final Connection connection = nettyCf.createConnection();
final CountDownLatch latch = new CountDownLatch(1);
ServerLocator locator = ((ActiveMQConnectionFactory) nettyCf).getServerLocator();
int minSize = locator.getMinLargeMessageSize();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < minSize; i++) {
builder.append("a");
}
try {
connection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(JMSException e) {
latch.countDown();
}
});
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(q1);
TextMessage m = session.createTextMessage(builder.toString());
producer.send(m);
connection.start();
corruptPacket.set(true);
MessageConsumer consumer = session.createConsumer(q1);
Message lm = consumer.receive(2000);
// first receive won't crash because the packet
// is SESS_RECEIVE_LARGE_MSG
assertNotNull(lm);
// second receive will force server to send a
// "forced delivery" message, and will cause
// the exception to be thrown.
lm = consumer.receive(5000);
assertNull(lm);
assertTrue(latch.await(5, TimeUnit.SECONDS));
} finally {
corruptPacket.set(false);
if (connection != null) {
connection.close();
}
}
}
Aggregations