Search in sources :

Example 1 with Completion

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");
    }
}
Also used : Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Shell(com.rabbitmq.jms.util.Shell) javax.jms(javax.jms) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Completion(com.rabbitmq.jms.client.Completion) Completion(com.rabbitmq.jms.client.Completion) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test)

Example 2 with Completion

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()));
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TopicSession(javax.jms.TopicSession) Completion(com.rabbitmq.jms.client.Completion) ExceptionListener(javax.jms.ExceptionListener) JMSException(javax.jms.JMSException) Topic(javax.jms.Topic) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test)

Example 3 with Completion

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);
}
Also used : Completion(com.rabbitmq.jms.client.Completion)

Example 4 with Completion

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!");
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TopicSession(javax.jms.TopicSession) Completion(com.rabbitmq.jms.client.Completion) Topic(javax.jms.Topic) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test)

Example 5 with Completion

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);
    }
}
Also used : Completion(com.rabbitmq.jms.client.Completion)

Aggregations

Completion (com.rabbitmq.jms.client.Completion)5 TimeoutException (java.util.concurrent.TimeoutException)3 Test (org.junit.jupiter.api.Test)3 MessageConsumer (javax.jms.MessageConsumer)2 Topic (javax.jms.Topic)2 TopicSession (javax.jms.TopicSession)2 Shell (com.rabbitmq.jms.util.Shell)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 javax.jms (javax.jms)1 ExceptionListener (javax.jms.ExceptionListener)1 JMSException (javax.jms.JMSException)1 Assertions.fail (org.junit.jupiter.api.Assertions.fail)1