Search in sources :

Example 41 with ActiveMQResourceAdapter

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

the class ResourceAdapterTest method testValidateProperties.

@Test
public void testValidateProperties() throws Exception {
    validateGettersAndSetters(new ActiveMQResourceAdapter(), "backupTransportConfiguration", "connectionParameters", "jndiParams");
    validateGettersAndSetters(new ActiveMQRAManagedConnectionFactory(), "connectionParameters", "sessionDefaultType", "backupConnectionParameters", "jndiParams");
    validateGettersAndSetters(new ActiveMQActivationSpec(), "connectionParameters", "acknowledgeMode", "subscriptionDurability", "jndiParams");
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setAcknowledgeMode("DUPS_OK_ACKNOWLEDGE");
    Assert.assertEquals("Dups-ok-acknowledge", spec.getAcknowledgeMode());
    spec.setSubscriptionDurability("Durable");
    Assert.assertEquals("Durable", spec.getSubscriptionDurability());
    spec.setSubscriptionDurability("NonDurable");
    Assert.assertEquals("NonDurable", spec.getSubscriptionDurability());
    spec = new ActiveMQActivationSpec();
    ActiveMQResourceAdapter adapter = new ActiveMQResourceAdapter();
    adapter.setUserName("us1");
    adapter.setPassword("ps1");
    adapter.setClientID("cl1");
    spec.setResourceAdapter(adapter);
    Assert.assertEquals("us1", spec.getUser());
    Assert.assertEquals("ps1", spec.getPassword());
    spec.setUser("us2");
    spec.setPassword("ps2");
    spec.setClientID("cl2");
    Assert.assertEquals("us2", spec.getUser());
    Assert.assertEquals("ps2", spec.getPassword());
    Assert.assertEquals("cl2", spec.getClientID());
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) Test(org.junit.Test)

Example 42 with ActiveMQResourceAdapter

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

the class ResourceAdapterTest method testCreateConnectionFactoryMultipleConnectorsOverride.

@Test
public void testCreateConnectionFactoryMultipleConnectorsOverride() {
    ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
    ra.setConnectorClassName(NETTY_CONNECTOR_FACTORY + "," + INVM_CONNECTOR_FACTORY + "," + NETTY_CONNECTOR_FACTORY);
    ConnectionFactoryProperties overrideProperties = new ConnectionFactoryProperties();
    ArrayList<String> value = new ArrayList<>();
    value.add(INVM_CONNECTOR_FACTORY);
    value.add(NETTY_CONNECTOR_FACTORY);
    value.add(INVM_CONNECTOR_FACTORY);
    overrideProperties.setParsedConnectorClassNames(value);
    ActiveMQConnectionFactory factory = ra.getConnectionFactory(overrideProperties);
    TransportConfiguration[] configurations = factory.getServerLocator().getStaticTransportConfigurations();
    assertNotNull(configurations);
    assertEquals(3, configurations.length);
    assertEquals(INVM_CONNECTOR_FACTORY, configurations[0].getFactoryClassName());
    assertEquals(1, configurations[0].getParams().size());
    assertEquals(NETTY_CONNECTOR_FACTORY, configurations[1].getFactoryClassName());
    assertEquals(2, configurations[1].getParams().size());
    assertEquals(INVM_CONNECTOR_FACTORY, configurations[2].getFactoryClassName());
    assertEquals(1, configurations[2].getParams().size());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ConnectionFactoryProperties(org.apache.activemq.artemis.ra.ConnectionFactoryProperties) ArrayList(java.util.ArrayList) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Test(org.junit.Test)

Example 43 with ActiveMQResourceAdapter

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

the class OutgoingConnectionTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("testuser", "testpassword");
    securityManager.getConfiguration().addUser("guest", "guest");
    securityManager.getConfiguration().setDefaultUser("guest");
    securityManager.getConfiguration().addRole("testuser", "arole");
    securityManager.getConfiguration().addRole("guest", "arole");
    Role role = new Role("arole", true, true, true, true, true, true, true, true, true, true);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles);
    resourceAdapter = new ActiveMQResourceAdapter();
    resourceAdapter.setEntries("[\"java://jmsXA\"]");
    resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName());
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) InVMConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory) HashSet(java.util.HashSet) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Before(org.junit.Before)

Example 44 with ActiveMQResourceAdapter

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

the class OutgoingConnectionTest method testSharedActiveMQConnectionFactoryWithClose.

@Test
public void testSharedActiveMQConnectionFactoryWithClose() throws Exception {
    Session s = null;
    Session s2 = null;
    ActiveMQRAManagedConnection mc = null;
    ActiveMQRAManagedConnection mc2 = null;
    try {
        server.getConfiguration().setSecurityEnabled(false);
        resourceAdapter = new ActiveMQResourceAdapter();
        resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName());
        MyBootstrapContext ctx = new MyBootstrapContext();
        resourceAdapter.start(ctx);
        ActiveMQRAConnectionManager qraConnectionManager = new ActiveMQRAConnectionManager();
        ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
        mcf.setResourceAdapter(resourceAdapter);
        ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
        QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
        s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        mc = (ActiveMQRAManagedConnection) ((ActiveMQRASession) s).getManagedConnection();
        QueueConnection queueConnection2 = qraConnectionFactory.createQueueConnection();
        s2 = queueConnection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
        mc2 = (ActiveMQRAManagedConnection) ((ActiveMQRASession) s2).getManagedConnection();
        mc.destroy();
        MessageProducer producer = s2.createProducer(ActiveMQJMSClient.createQueue(MDBQUEUE));
        producer.send(s2.createTextMessage("x"));
    } finally {
        if (s != null) {
            s.close();
        }
        if (mc != null) {
            mc.destroy();
        }
        if (s2 != null) {
            s2.close();
        }
        if (mc2 != null) {
            mc2.destroy();
        }
    }
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) ActiveMQRAConnectionManager(org.apache.activemq.artemis.ra.ActiveMQRAConnectionManager) XAQueueConnection(javax.jms.XAQueueConnection) QueueConnection(javax.jms.QueueConnection) ActiveMQRAManagedConnection(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) InVMConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) MessageProducer(javax.jms.MessageProducer) ActiveMQRASession(org.apache.activemq.artemis.ra.ActiveMQRASession) XASession(javax.jms.XASession) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession) ActiveMQRASession(org.apache.activemq.artemis.ra.ActiveMQRASession) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Test(org.junit.Test)

Example 45 with ActiveMQResourceAdapter

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

the class ResourceAdapterTest method testResourceAdapterSetupOverrideNoCFParams.

@Test
public void testResourceAdapterSetupOverrideNoCFParams() 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);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    qResourceAdapter.stop();
    assertFalse(spec.isHasBeenUpdated());
    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)

Aggregations

ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)81 Test (org.junit.Test)72 ActiveMQActivationSpec (org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec)54 CountDownLatch (java.util.concurrent.CountDownLatch)39 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)28 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)24 InVMConnectorFactory (org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory)14 ConnectionFactoryProperties (org.apache.activemq.artemis.ra.ConnectionFactoryProperties)10 ActiveMQRAManagedConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory)9 ActiveMQRAConnectionFactoryImpl (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl)8 Binding (org.apache.activemq.artemis.core.postoffice.Binding)7 HashSet (java.util.HashSet)5 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 Role (org.apache.activemq.artemis.core.security.Role)5 ActiveMQActivation (org.apache.activemq.artemis.ra.inflow.ActiveMQActivation)5 Before (org.junit.Before)5 ArrayList (java.util.ArrayList)4 Session (javax.jms.Session)4