Search in sources :

Example 26 with ActiveMQActivationSpec

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

the class ResourceAdapterTest method testResourceAdapterSetupOverrideCFParams.

// https://issues.jboss.org/browse/JBPAPP-5836
@Test
public void testResourceAdapterSetupOverrideCFParams() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    qResourceAdapter.setConnectionParameters("server-id=0");
    ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    // now override the connector class
    spec.setConnectorClassName(NETTY_CONNECTOR_FACTORY);
    spec.setConnectionParameters("port=61616");
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(new CountDownLatch(1));
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    // make sure 2 recovery resources, one is default, one is in activation.
    assertEquals(2, qResourceAdapter.getRecoveryManager().getResources().size());
    qResourceAdapter.stop();
    assertTrue(endpoint.released);
}
Also used : ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 27 with ActiveMQActivationSpec

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

the class ResourceAdapterTest method testResourceAdapterSetupNoHAOverride.

@Test
public void testResourceAdapterSetupNoHAOverride() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    qResourceAdapter.setConnectionParameters("server-id=0");
    qResourceAdapter.setHA(true);
    ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    ActiveMQConnectionFactory fac = qResourceAdapter.getConnectionFactory(spec);
    assertTrue(fac.isHA());
    qResourceAdapter.stop();
    assertFalse(spec.isHasBeenUpdated());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) Test(org.junit.Test)

Example 28 with ActiveMQActivationSpec

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

the class ResourceAdapterTest method testResourceAdapterSetupNoReconnectAttemptsOverride.

@Test
public void testResourceAdapterSetupNoReconnectAttemptsOverride() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    qResourceAdapter.setConnectionParameters("server-id=0");
    qResourceAdapter.setReconnectAttempts(100);
    ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    ActiveMQConnectionFactory fac = qResourceAdapter.getConnectionFactory(spec);
    assertEquals(100, fac.getReconnectAttempts());
    qResourceAdapter.stop();
    assertFalse(spec.isHasBeenUpdated());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) Test(org.junit.Test)

Example 29 with ActiveMQActivationSpec

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

the class ResourceAdapterTest method testRecoveryRegistrationOnFailure.

@Test
public void testRecoveryRegistrationOnFailure() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    qResourceAdapter.setConnectionParameters("server-id=0");
    ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    // now override the connector class
    spec.setConnectorClassName(NETTY_CONNECTOR_FACTORY);
    spec.setSetupAttempts(2);
    // using a wrong port number
    spec.setConnectionParameters("port=6776");
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(new CountDownLatch(1));
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    assertEquals(1, qResourceAdapter.getRecoveryManager().getResources().size());
    qResourceAdapter.stop();
    assertFalse(endpoint.released);
}
Also used : ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 30 with ActiveMQActivationSpec

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

the class ResourceAdapterTest method testStartStopActivationManyTimes.

@Test
public void testStartStopActivationManyTimes() throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, false, false);
    ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue("test");
    session.createQueue(queue.getSimpleAddress(), queue.getSimpleAddress(), true);
    session.close();
    ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
    ra.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    ra.setUserName("userGlobal");
    ra.setPassword("passwordGlobal");
    ra.start(new BootstrapContext());
    Connection conn = ra.getDefaultActiveMQConnectionFactory().createConnection();
    conn.close();
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(ra);
    spec.setUseJNDI(false);
    spec.setUser("user");
    spec.setPassword("password");
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("test");
    spec.setMinSession(1);
    spec.setMaxSession(15);
    ActiveMQActivation activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec);
    ServerLocatorImpl serverLocator = (ServerLocatorImpl) ra.getDefaultActiveMQConnectionFactory().getServerLocator();
    Set<XARecoveryConfig> resources = ra.getRecoveryManager().getResources();
    for (int i = 0; i < 10; i++) {
        System.out.println(i);
        activation.start();
        assertEquals(1, resources.size());
        activation.stop();
    }
    ra.stop();
    assertEquals(0, resources.size());
    locator.close();
}
Also used : MessageEndpointFactory(org.apache.activemq.artemis.tests.unit.ra.MessageEndpointFactory) ActiveMQActivation(org.apache.activemq.artemis.ra.inflow.ActiveMQActivation) Connection(javax.jms.Connection) XARecoveryConfig(org.apache.activemq.artemis.service.extensions.xa.recovery.XARecoveryConfig) BootstrapContext(org.apache.activemq.artemis.tests.unit.ra.BootstrapContext) MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ServerLocatorImpl(org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) 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