Search in sources :

Example 46 with ActiveMQActivationSpec

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

the class ActiveMQMessageHandlerTest method testBadDestinationType.

@Test
public void testBadDestinationType() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("badDestinationType");
    spec.setDestination("mdbTopic");
    spec.setSetupAttempts(1);
    spec.setShareSubscriptions(true);
    spec.setMaxSession(1);
    CountDownLatch latch = new CountDownLatch(5);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    try {
        qResourceAdapter.endpointActivation(endpointFactory, spec);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof InvalidPropertyException);
        assertEquals("destinationType", ((InvalidPropertyException) e).getInvalidPropertyDescriptors()[0].getName());
    }
}
Also used : InvalidPropertyException(javax.resource.spi.InvalidPropertyException) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ResourceException(javax.resource.ResourceException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) JMSException(javax.jms.JMSException) InvalidPropertyException(javax.resource.spi.InvalidPropertyException) Test(org.junit.Test)

Example 47 with ActiveMQActivationSpec

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

the class ActiveMQMessageHandlerTest method testSimpleMessageReceivedOnQueueManyMessagesAndInterruptTimeout.

@Test
public void testSimpleMessageReceivedOnQueueManyMessagesAndInterruptTimeout() throws Exception {
    final int SIZE = 14;
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setCallTimeout(500L);
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(SIZE);
    CountDownLatch latchDone = new CountDownLatch(SIZE);
    MultipleEndpoints endpoint = new MultipleEndpoints(latch, latchDone, true);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    for (int i = 0; i < SIZE; i++) {
        ClientMessage message = session.createMessage(true);
        message.getBodyBuffer().writeString("teststring" + i);
        clientProducer.send(message);
    }
    session.close();
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    latchDone.await(5, TimeUnit.SECONDS);
    assertEquals(SIZE, endpoint.messages.intValue());
    // half onmessage interrupted
    assertEquals(SIZE / 2, endpoint.interrupted.intValue());
    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 48 with ActiveMQActivationSpec

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

the class ActiveMQMessageHandlerTest method testSimpleMessageReceivedOnQueue.

@Test
public void testSimpleMessageReceivedOnQueue() 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.Queue");
    spec.setDestination(MDBQUEUE);
    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(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();
}
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 49 with ActiveMQActivationSpec

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

the class ActiveMQMessageHandlerTest method testNonDurableSubscriptionDeleteAfterCrash.

// https://issues.jboss.org/browse/JBPAPP-8017
@Test
public void testNonDurableSubscriptionDeleteAfterCrash() 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");
    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");
    ActiveMQActivation activation = lookupActivation(qResourceAdapter);
    SimpleString tempQueueName = activation.getTopicTemporaryQueue();
    QueueQuery query = session.queueQuery(tempQueueName);
    assertTrue(query.isExists());
    // this should be enough to simulate the crash
    qResourceAdapter.getDefaultActiveMQConnectionFactory().close();
    qResourceAdapter.stop();
    query = session.queueQuery(tempQueueName);
    assertFalse(query.isExists());
}
Also used : ActiveMQActivation(org.apache.activemq.artemis.ra.inflow.ActiveMQActivation) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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) QueueQuery(org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery) Test(org.junit.Test)

Example 50 with ActiveMQActivationSpec

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

the class ActiveMQMessageHandlerTest method testNullSubscriptionName.

@Test
public void testNullSubscriptionName() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestination("mdbTopic");
    spec.setSubscriptionDurability("Durable");
    spec.setClientID("id-1");
    spec.setSetupAttempts(1);
    spec.setShareSubscriptions(true);
    spec.setMaxSession(1);
    CountDownLatch latch = new CountDownLatch(5);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    try {
        qResourceAdapter.endpointActivation(endpointFactory, spec);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof InvalidPropertyException);
        assertEquals("subscriptionName", ((InvalidPropertyException) e).getInvalidPropertyDescriptors()[0].getName());
    }
}
Also used : InvalidPropertyException(javax.resource.spi.InvalidPropertyException) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ResourceException(javax.resource.ResourceException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) JMSException(javax.jms.JMSException) InvalidPropertyException(javax.resource.spi.InvalidPropertyException) Test(org.junit.Test)

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