Search in sources :

Example 1 with JMSRuntimeException

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;
}
Also used : JMSConsumer(javax.jms.JMSConsumer) JMSRuntimeException(javax.jms.JMSRuntimeException) JMSRuntimeException(javax.jms.JMSRuntimeException)

Example 2 with JMSRuntimeException

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"));
        }
    }
}
Also used : Destination(javax.jms.Destination) JMSProducer(javax.jms.JMSProducer) JMSContext(javax.jms.JMSContext) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test)

Example 3 with JMSRuntimeException

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"));
        }
    }
}
Also used : Destination(javax.jms.Destination) JMSConsumer(javax.jms.JMSConsumer) Message(javax.jms.Message) JMSProducer(javax.jms.JMSProducer) JMSContext(javax.jms.JMSContext) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test)

Example 4 with JMSRuntimeException

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);
    }
}
Also used : JMSException(javax.jms.JMSException) JMSRuntimeException(javax.jms.JMSRuntimeException) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test)

Example 5 with 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);
}
Also used : ContextsService(org.apache.webbeans.spi.ContextsService) AtomicReference(java.util.concurrent.atomic.AtomicReference) RequestScoped(javax.enterprise.context.RequestScoped) CountDownLatch(java.util.concurrent.CountDownLatch) JMSContext(javax.jms.JMSContext) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test)

Aggregations

JMSRuntimeException (javax.jms.JMSRuntimeException)24 Test (org.junit.Test)13 JMSContext (javax.jms.JMSContext)12 Message (javax.jms.Message)8 JMSException (javax.jms.JMSException)7 JMSConsumer (javax.jms.JMSConsumer)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 JMSProducer (javax.jms.JMSProducer)4 TextMessage (javax.jms.TextMessage)4 Destination (javax.jms.Destination)3 MessageFormatRuntimeException (javax.jms.MessageFormatRuntimeException)3 RequestScoped (javax.enterprise.context.RequestScoped)2 JMSSecurityException (javax.jms.JMSSecurityException)2 JMSSecurityRuntimeException (javax.jms.JMSSecurityRuntimeException)2 ActiveMQPropertyConversionException (org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ContextsService (org.apache.webbeans.spi.ContextsService)2 HashSet (java.util.HashSet)1 BytesMessage (javax.jms.BytesMessage)1