Search in sources :

Example 16 with JMSContext

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

the class JMSTestBase method tearDown.

@Override
@After
public void tearDown() throws Exception {
    try {
        for (JMSContext jmsContext : contextSet) {
            jmsContext.close();
        }
    } catch (RuntimeException ignored) {
    // no-op
    } finally {
        contextSet.clear();
    }
    try {
        if (conn != null)
            conn.close();
    } catch (Exception e) {
    // no-op
    }
    namingContext.close();
    jmsServer.stop();
    server = null;
    cf = null;
    jmsServer = null;
    namingContext = null;
    MBeanServerFactory.releaseMBeanServer(mbeanServer);
    mbeanServer = null;
    ServiceUtils.setTransactionManager(null);
    super.tearDown();
}
Also used : JMSRuntimeException(javax.jms.JMSRuntimeException) JMSContext(javax.jms.JMSContext) JMSException(javax.jms.JMSException) JMSRuntimeException(javax.jms.JMSRuntimeException) After(org.junit.After)

Example 17 with JMSContext

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

the class OutgoingConnectionTest method testJMSContext.

@Test
public void testJMSContext() throws Exception {
    resourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
    JMSContext jmsctx = qraConnectionFactory.createContext(JMSContext.DUPS_OK_ACKNOWLEDGE);
    assertEquals(JMSContext.DUPS_OK_ACKNOWLEDGE, jmsctx.getSessionMode());
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) JMSContext(javax.jms.JMSContext) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Test(org.junit.Test)

Example 18 with JMSContext

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

the class JMSContextTest method testCreateXAContextThrowsException.

@Test
public void testCreateXAContextThrowsException() throws Exception {
    JMSContext jmsctx = qraConnectionFactory.createXAContext();
    try {
        jmsctx.createContext(JMSContext.AUTO_ACKNOWLEDGE);
        fail("expected JMSRuntimeException");
    } catch (JMSRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("wrong exception thrown: " + e);
    }
}
Also used : JMSContext(javax.jms.JMSContext) JMSRuntimeException(javax.jms.JMSRuntimeException) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test)

Example 19 with JMSContext

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

the class OutgoingConnectionNoJTATest method testSimpleSendNoXAJMSContext.

@Test
public void testSimpleSendNoXAJMSContext() throws Exception {
    Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
    try (ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession();
        ClientConsumer consVerify = session.createConsumer(MDBQUEUE);
        JMSContext jmsctx = qraConnectionFactory.createContext()) {
        session.start();
        // These next 4 lines could be written in a single line however it makes difficult for debugging
        JMSProducer producer = jmsctx.createProducer();
        producer.setProperty("strvalue", "hello");
        TextMessage msgsend = jmsctx.createTextMessage("hello");
        producer.send(q, msgsend);
        ClientMessage msg = consVerify.receive(1000);
        assertNotNull(msg);
        assertEquals("hello", msg.getStringProperty("strvalue"));
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) JMSProducer(javax.jms.JMSProducer) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Queue(javax.jms.Queue) JMSContext(javax.jms.JMSContext) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 20 with JMSContext

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

the class OutgoingConnectionNoJTATest method sessionNotTransactedTestNoActiveJTATx.

@Test
public void sessionNotTransactedTestNoActiveJTATx() throws Exception {
    JMSContext context = qraConnectionFactory.createContext(JMSContext.AUTO_ACKNOWLEDGE);
    assertEquals(context.getSessionMode(), JMSContext.AUTO_ACKNOWLEDGE);
}
Also used : JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Aggregations

JMSContext (javax.jms.JMSContext)120 Test (org.junit.Test)57 JMSConsumer (javax.jms.JMSConsumer)44 ConnectionFactory (javax.jms.ConnectionFactory)35 Destination (javax.jms.Destination)30 TextMessage (javax.jms.TextMessage)28 JMSProducer (javax.jms.JMSProducer)27 Message (javax.jms.Message)18 JMSRuntimeException (javax.jms.JMSRuntimeException)13 TemporaryQueue (javax.jms.TemporaryQueue)13 InitialContext (javax.naming.InitialContext)12 JMSException (javax.jms.JMSException)10 Queue (javax.jms.Queue)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)7 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 QueueConnectionFactory (javax.jms.QueueConnectionFactory)4 Context (javax.naming.Context)4 NamingException (javax.naming.NamingException)4