use of com.rabbitmq.jms.client.Completion in project rabbitmq-jms-client by rabbitmq.
the class ConnectionForceCloseOnReceiveIT method testConnectionFailDuringReceiveWithExceptionListener.
@Test
public void testConnectionFailDuringReceiveWithExceptionListener() throws Exception {
ExceptionListener eListener = exception -> {
t("onException called");
atomBool.set(true);
atomJMSExceptionRef.set(exception);
};
topicConn.setExceptionListener(eListener);
topicConn.start();
t("started");
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);
receiver.start();
t("started receiver");
Thread.sleep(ONE_SECOND);
Shell.restartNode();
try {
t("waiting for completion...");
receiveCompletion.waitUntilComplete(TEN_SECONDS, TimeUnit.MILLISECONDS);
t("...complete returned");
} catch (TimeoutException e) {
t("timeout waiting for receive");
fail("Timeout before receive returns!");
}
if (!atomBool.get()) {
t("exception listener was not driven during test");
fail("ExceptionListener was not driven");
}
}
use of com.rabbitmq.jms.client.Completion 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 com.rabbitmq.jms.client.Completion in project rabbitmq-jms-client by rabbitmq.
the class EntryExitManager method registerEntry.
private void registerEntry() {
Completion comp = new Completion();
// thread-local
this.threadCompletion.set(comp);
this.entered.add(comp);
}
use of com.rabbitmq.jms.client.Completion in project rabbitmq-jms-client by rabbitmq.
the class ConnectionCloseIT method testCloseDuringReceive.
@Test
public void testCloseDuringReceive() throws Exception {
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!");
}
}
use of com.rabbitmq.jms.client.Completion in project rabbitmq-jms-client by rabbitmq.
the class EntryExitManager method exit.
/**
* This thread is exiting the region. Must be called eventually by the thread that entered the region.
*/
public void exit() {
// this thread's completion object
Completion comp = this.threadCompletion.get();
if (comp != null) {
comp.setComplete();
this.entered.remove(comp);
}
}
Aggregations