Search in sources :

Example 1 with IllegalStateRuntimeException

use of javax.jms.IllegalStateRuntimeException in project activemq-artemis by apache.

the class JmsContextTest method testContextStopAndCloseFromMessageListeners.

@Test
public void testContextStopAndCloseFromMessageListeners() throws Exception {
    final JMSContext context1 = context.createContext(Session.AUTO_ACKNOWLEDGE);
    JMSConsumer consumer1 = context1.createConsumer(queue1);
    final CountDownLatch latch1 = new CountDownLatch(1);
    InvalidMessageListener listener1 = new InvalidMessageListener(context1, latch1, 1);
    consumer1.setMessageListener(listener1);
    JMSProducer producer = context1.createProducer();
    Message msg = context1.createTextMessage("first message");
    producer.send(queue1, msg);
    latch1.await();
    Throwable error1 = listener1.getError();
    assertNotNull(error1);
    assertTrue(error1 instanceof IllegalStateRuntimeException);
    context1.close();
    final JMSContext context2 = context.createContext(Session.AUTO_ACKNOWLEDGE);
    JMSConsumer consumer2 = context2.createConsumer(queue1);
    final CountDownLatch latch2 = new CountDownLatch(1);
    InvalidMessageListener listener2 = new InvalidMessageListener(context2, latch2, 2);
    consumer2.setMessageListener(listener2);
    JMSProducer producer2 = context2.createProducer();
    Message msg2 = context2.createTextMessage("second message");
    producer2.send(queue1, msg2);
    latch2.await();
    Throwable error2 = listener2.getError();
    assertNotNull(error2);
    assertTrue(error2 instanceof IllegalStateRuntimeException);
    context2.close();
}
Also used : JMSConsumer(javax.jms.JMSConsumer) IllegalStateRuntimeException(javax.jms.IllegalStateRuntimeException) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) StreamMessage(javax.jms.StreamMessage) BytesMessage(javax.jms.BytesMessage) JMSProducer(javax.jms.JMSProducer) CountDownLatch(java.util.concurrent.CountDownLatch) JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Example 2 with IllegalStateRuntimeException

use of javax.jms.IllegalStateRuntimeException in project activemq-artemis by apache.

the class JmsContextTest method testSetClientIdLate.

@Test
public void testSetClientIdLate() {
    JMSProducer producer = context.createProducer();
    Message msg = context.createMessage();
    producer.send(queue1, msg);
    try {
        context.setClientID("id");
        Assert.fail("expected exception");
    } catch (IllegalStateRuntimeException e) {
    // no op
    }
}
Also used : IllegalStateRuntimeException(javax.jms.IllegalStateRuntimeException) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) StreamMessage(javax.jms.StreamMessage) BytesMessage(javax.jms.BytesMessage) JMSProducer(javax.jms.JMSProducer) Test(org.junit.Test)

Example 3 with IllegalStateRuntimeException

use of javax.jms.IllegalStateRuntimeException in project activemq-artemis by apache.

the class JmsProducerCompletionListenerTest method testInvalidCallFromListener.

@Test
public void testInvalidCallFromListener() throws InterruptedException {
    JMSConsumer consumer = context.createConsumer(queue);
    List<InvalidCompletionListener> listeners = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        InvalidCompletionListener cl = new InvalidCompletionListener(context, i);
        listeners.add(cl);
        producer.setAsync(cl);
        sendMessages(context, producer, queue, 1);
    }
    receiveMessages(consumer, 0, 1, true);
    context.close();
    for (InvalidCompletionListener cl : listeners) {
        Assert.assertTrue(cl.latch.await(1, TimeUnit.SECONDS));
        Assert.assertNotNull(cl.error);
        Assert.assertTrue(cl.error instanceof IllegalStateRuntimeException);
    }
}
Also used : JMSConsumer(javax.jms.JMSConsumer) IllegalStateRuntimeException(javax.jms.IllegalStateRuntimeException) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

IllegalStateRuntimeException (javax.jms.IllegalStateRuntimeException)3 Test (org.junit.Test)3 BytesMessage (javax.jms.BytesMessage)2 JMSConsumer (javax.jms.JMSConsumer)2 JMSProducer (javax.jms.JMSProducer)2 Message (javax.jms.Message)2 StreamMessage (javax.jms.StreamMessage)2 TextMessage (javax.jms.TextMessage)2 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 JMSContext (javax.jms.JMSContext)1