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();
}
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
}
}
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);
}
}
Aggregations