use of javax.jms.JMSRuntimeException in project wildfly by wildfly.
the class BeanManagedMessageConsumer method receive.
public boolean receive(Destination destination, String expectedText) throws Exception {
transaction.begin();
JMSConsumer consumer = context.createConsumer(destination);
String text = consumer.receiveBody(String.class, 1000);
assertNotNull(text);
assertEquals(expectedText, text);
transaction.commit();
try {
consumer.receiveBody(String.class, 1000);
Assert.fail("call must fail as the injected JMSContext is closed when the transaction is committed");
} catch (JMSRuntimeException e) {
// exception is expected
} catch (Exception e) {
throw e;
}
return true;
}
use of javax.jms.JMSRuntimeException in project qpid-broker-j by apache.
the class DeliveryDelayTest method testDeliveryDelayNotSupportedByQueue_MessageRejected.
/**
* The target queue, which is addressed directly by the client, does not have
* holdsOnPublish turned on. The Broker must reject the message.
*/
@Test
public void testDeliveryDelayNotSupportedByQueue_MessageRejected() throws Exception {
try (JMSContext context = getConnectionBuilder().buildConnectionFactory().createContext()) {
Destination queue = createQueue(context, BrokerAdmin.TEST_QUEUE_NAME, false);
JMSProducer producer = context.createProducer().setDeliveryDelay(DELIVERY_DELAY);
try {
producer.send(queue, "message");
fail("Exception not thrown");
} catch (JMSRuntimeException e) {
assertTrue("Unexpected exception message: " + e.getMessage(), e.getMessage().contains("amqp:precondition-failed"));
}
}
}
use of javax.jms.JMSRuntimeException in project qpid-broker-j by apache.
the class DeliveryDelayTest method testDeliveryDelayNotSupportedByQueueViaExchange_MessageRejected.
/**
* The client sends a messagge to a fanout exchange instance which is bound to a queue with
* holdsOnPublish turned off. The Broker must reject the message.
*/
@Test
public void testDeliveryDelayNotSupportedByQueueViaExchange_MessageRejected() throws Exception {
try (JMSContext context = getConnectionBuilder().buildConnectionFactory().createContext()) {
String testQueueName = BrokerAdmin.TEST_QUEUE_NAME;
String testExchangeName = "test_exch";
Destination consumeDest = createQueue(context, testQueueName, false);
Destination publishDest = createExchange(context, testExchangeName);
bindQueueToExchange(testExchangeName, testQueueName);
JMSConsumer consumer = context.createConsumer(consumeDest);
JMSProducer producer = context.createProducer();
producer.send(publishDest, "message without delivery delay");
Message message = consumer.receive(getReceiveTimeout());
assertNotNull("Message published without delivery delay not received", message);
producer.setDeliveryDelay(DELIVERY_DELAY);
try {
producer.send(publishDest, "message with delivery delay");
fail("Exception not thrown");
} catch (JMSRuntimeException e) {
assertTrue("Unexpected exception message: " + e.getMessage(), e.getMessage().contains("amqp:precondition-failed"));
}
}
}
use of javax.jms.JMSRuntimeException in project pentaho-kettle by pentaho.
the class JmsStreamSourceTest method handlesJmsRuntimeException.
@Test(timeout = 5000)
public void handlesJmsRuntimeException() {
when(consumer.receive(0)).thenThrow(new JMSRuntimeException("exception"));
source.open();
verify(delegate).getJmsContext(consumerStep);
verify(delegate).getDestination(consumerStep);
try {
source.observable().firstElement().blockingGet(Collections.emptyList());
fail("Expected exception ");
} catch (Exception e) {
assertTrue(e instanceof JMSRuntimeException);
}
}
use of javax.jms.JMSRuntimeException in project tomee by apache.
the class JMS2AMQTest method cdi.
@Test
public void cdi() throws InterruptedException {
final String text = TEXT + "3";
final AtomicReference<Throwable> error = new AtomicReference<>();
final CountDownLatch ready = new CountDownLatch(1);
final CountDownLatch over = new CountDownLatch(1);
new Thread() {
{
setName(JMS2AMQTest.class.getName() + ".cdi#receiver");
}
@Override
public void run() {
final ContextsService contextsService = WebBeansContext.currentInstance().getContextsService();
// spec defines it for request scope an transaction scope
contextsService.startContext(RequestScoped.class, null);
try {
ready.countDown();
assertEquals(text, context.createConsumer(destination3).receiveBody(String.class, TimeUnit.MINUTES.toMillis(1)));
// ensure we dont do a NPE if there is nothing to read
assertNull(context.createConsumer(destination3).receiveBody(String.class, 100));
} catch (final Throwable t) {
error.set(t);
} finally {
contextsService.endContext(RequestScoped.class, null);
over.countDown();
}
}
}.start();
ready.await(1, TimeUnit.MINUTES);
// just to ensure we called receive already
sleep(150);
// now send the message
try (final JMSContext context = cf.createContext()) {
context.createProducer().send(destination3, text);
} catch (final JMSRuntimeException ex) {
fail(ex.getMessage());
}
over.await(1, TimeUnit.MINUTES);
// ensure we got the message and no exception
final Throwable exception = error.get();
if (exception != null) {
exception.printStackTrace();
}
assertNull(exception == null ? "ok" : exception.getMessage(), exception);
}
Aggregations