Search in sources :

Example 51 with ActiveMQActivationSpec

use of org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec in project activemq-artemis by apache.

the class ActiveMQMessageHandlerTest method testDurableSubscription.

@Test
public void testDurableSubscription() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("mdbTopic");
    spec.setSubscriptionDurability("Durable");
    spec.setSubscriptionName("durable-mdb");
    spec.setClientID("id-1");
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer("mdbTopic");
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("1");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "1");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    message = session.createMessage(true);
    message.getBodyBuffer().writeString("2");
    clientProducer.send(message);
    latch = new CountDownLatch(1);
    endpoint = new DummyMessageEndpoint(latch);
    endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "2");
    latch = new CountDownLatch(1);
    endpoint.reset(latch);
    message = session.createMessage(true);
    message.getBodyBuffer().writeString("3");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "3");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 52 with ActiveMQActivationSpec

use of org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec in project activemq-artemis by apache.

the class ActiveMQMessageHandlerTest method testServerShutdownAndReconnect.

@Test
public void testServerShutdownAndReconnect() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    qResourceAdapter.setReconnectAttempts(-1);
    qResourceAdapter.setCallTimeout(500L);
    qResourceAdapter.setRetryInterval(500L);
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    // This is just to register a listener
    final CountDownLatch failedLatch = new CountDownLatch(1);
    ClientSessionFactoryInternal factoryListener = (ClientSessionFactoryInternal) qResourceAdapter.getDefaultActiveMQConnectionFactory().getServerLocator().createSessionFactory();
    factoryListener.addFailureListener(new SessionFailureListener() {

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver) {
        }

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver, String scaleDownTargetNodeID) {
            connectionFailed(exception, failedOver);
        }

        @Override
        public void beforeReconnect(ActiveMQException exception) {
            failedLatch.countDown();
        }
    });
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    session.close();
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    server.stop();
    assertTrue(failedLatch.await(5, TimeUnit.SECONDS));
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) CountDownLatch(java.util.concurrent.CountDownLatch) SessionFailureListener(org.apache.activemq.artemis.api.core.client.SessionFailureListener) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 53 with ActiveMQActivationSpec

use of org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec in project activemq-artemis by apache.

the class ActiveMQMessageHandlerTest method testSelectorChangedWithTopic.

@Test
public void testSelectorChangedWithTopic() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("mdbTopic");
    spec.setSubscriptionDurability("Durable");
    spec.setSubscriptionName("durable-mdb");
    spec.setClientID("id-1");
    spec.setMessageSelector("foo='bar'");
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer("mdbTopic");
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("1");
    message.putStringProperty("foo", "bar");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "1");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    message = session.createMessage(true);
    message.getBodyBuffer().writeString("2");
    message.putStringProperty("foo", "bar");
    clientProducer.send(message);
    latch = new CountDownLatch(1);
    endpoint = new DummyMessageEndpoint(latch);
    // change the selector forcing the queue to be recreated
    spec.setMessageSelector("foo='abar'");
    endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    message = session.createMessage(true);
    message.getBodyBuffer().writeString("3");
    message.putStringProperty("foo", "abar");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "3");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 54 with ActiveMQActivationSpec

use of org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec in project activemq-artemis by apache.

the class InterruptedMessageHandlerTest method testSimpleMessageReceivedOnQueueTwoPhaseFailPrepareByConnectionTimout.

@Test
@BMRules(rules = { @BMRule(name = "throw ActiveMQException(CONNETION_TIMEOUT) during rollback", targetClass = "org.apache.activemq.artemis.core.client.impl.ClientSessionImpl", targetMethod = "flushAcks", targetLocation = "AFTER INVOKE flushAcks", action = "org.apache.activemq.artemis.tests.extras.byteman.InterruptedMessageHandlerTest.throwActiveMQQExceptionConnectionTimeout();"), @BMRule(name = "check that outcome of XA transaction is TwoPhaseOutcome.FINISH_ERROR=8", targetClass = "com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord", targetMethod = "topLevelAbort", targetLocation = "AT EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.InterruptedMessageHandlerTest.assertTxOutComeIsOfStatusFinishedError($!);") })
public void testSimpleMessageReceivedOnQueueTwoPhaseFailPrepareByConnectionTimout() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    resourceAdapter = qResourceAdapter;
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.setConnectorClassName(NETTY_CONNECTOR_FACTORY);
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setMaxSession(1);
    spec.setCallTimeout(1000L);
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    CountDownLatch latch = new CountDownLatch(1);
    XADummyEndpointWithDummyXAResourceFailEnd endpoint = new XADummyEndpointWithDummyXAResourceFailEnd(latch, true);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    session.close();
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
    server.stop();
    assertEquals("Two phase outcome must be of TwoPhaseOutcome.FINISH_ERROR.", TwoPhaseOutcome.FINISH_ERROR, txTwoPhaseOutCome.intValue());
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Aggregations

ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)54 ActiveMQActivationSpec (org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec)54 Test (org.junit.Test)52 CountDownLatch (java.util.concurrent.CountDownLatch)39 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)27 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)24 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)24 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)9 Binding (org.apache.activemq.artemis.core.postoffice.Binding)7 ActiveMQActivation (org.apache.activemq.artemis.ra.inflow.ActiveMQActivation)6 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)4 Connection (javax.jms.Connection)3 JMSException (javax.jms.JMSException)3 ResourceException (javax.resource.ResourceException)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)3 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)3 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)3 DefaultSensitiveStringCodec (org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec)3