Search in sources :

Example 1 with ActiveMQRAConnectionFactory

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

the class ActiveMQClusteredTest method testOutboundLoadBalancing.

@Test
public void testOutboundLoadBalancing() throws Exception {
    final int CONNECTION_COUNT = 100;
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    List<Session> sessions = new ArrayList<>();
    List<ActiveMQRAManagedConnection> managedConnections = new ArrayList<>();
    try {
        MyBootstrapContext ctx = new MyBootstrapContext();
        qResourceAdapter.start(ctx);
        ActiveMQRAConnectionManager qraConnectionManager = new ActiveMQRAConnectionManager();
        ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
        mcf.setResourceAdapter(qResourceAdapter);
        ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
        QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
        Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        sessions.add(s);
        ActiveMQRAManagedConnection mc = (ActiveMQRAManagedConnection) ((ActiveMQRASession) s).getManagedConnection();
        managedConnections.add(mc);
        ActiveMQConnectionFactory cf1 = mc.getConnectionFactory();
        while (!((ServerLocatorImpl) cf1.getServerLocator()).isReceivedTopology()) {
            Thread.sleep(50);
        }
        for (int i = 0; i < CONNECTION_COUNT; i++) {
            queueConnection = qraConnectionFactory.createQueueConnection();
            s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            sessions.add(s);
            mc = (ActiveMQRAManagedConnection) ((ActiveMQRASession) s).getManagedConnection();
            managedConnections.add(mc);
        }
        assertTrue(server.getConnectionCount() >= (CONNECTION_COUNT / 2));
        assertTrue(secondaryServer.getConnectionCount() >= (CONNECTION_COUNT / 2));
    } finally {
        for (Session s : sessions) {
            s.close();
        }
        for (ActiveMQRAManagedConnection mc : managedConnections) {
            mc.destroy();
        }
    }
}
Also used : ActiveMQRAConnectionManager(org.apache.activemq.artemis.ra.ActiveMQRAConnectionManager) ActiveMQRAManagedConnection(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection) ArrayList(java.util.ArrayList) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) ActiveMQRASession(org.apache.activemq.artemis.ra.ActiveMQRASession) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) QueueConnection(javax.jms.QueueConnection) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Session(javax.jms.Session) ActiveMQRASession(org.apache.activemq.artemis.ra.ActiveMQRASession) Test(org.junit.Test)

Example 2 with ActiveMQRAConnectionFactory

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

the class OutgoingConnectionTest method testConnectionCredentialsOKRecovery.

@Test
public void testConnectionCredentialsOKRecovery() throws Exception {
    resourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
    QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
    QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(mcf.getResourceRecovery());
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) XAQueueConnection(javax.jms.XAQueueConnection) QueueConnection(javax.jms.QueueConnection) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) QueueSession(javax.jms.QueueSession) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Test(org.junit.Test)

Example 3 with ActiveMQRAConnectionFactory

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

the class OutgoingConnectionTest method testConnectionCredentialsFail.

@Test
public void testConnectionCredentialsFail() throws Exception {
    resourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
    QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
    QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    ManagedConnection mc = ((ActiveMQRASession) session).getManagedConnection();
    queueConnection.close();
    mc.destroy();
    try {
        queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testwrongpassword");
        queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE).close();
        fail("should throw esxception");
    } catch (JMSException e) {
    // pass
    }
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) XAQueueConnection(javax.jms.XAQueueConnection) QueueConnection(javax.jms.QueueConnection) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) ManagedConnection(javax.resource.spi.ManagedConnection) ActiveMQRAManagedConnection(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection) JMSException(javax.jms.JMSException) ActiveMQRASession(org.apache.activemq.artemis.ra.ActiveMQRASession) QueueSession(javax.jms.QueueSession) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Test(org.junit.Test)

Example 4 with ActiveMQRAConnectionFactory

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

the class OutgoingConnectionTest method testSharedActiveMQConnectionFactory.

@Test
public void testSharedActiveMQConnectionFactory() throws Exception {
    Session s = null;
    Session s2 = null;
    ActiveMQRAManagedConnection mc = null;
    ActiveMQRAManagedConnection mc2 = null;
    try {
        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();
        ActiveMQConnectionFactory cf1 = mc.getConnectionFactory();
        QueueConnection queueConnection2 = qraConnectionFactory.createQueueConnection();
        s2 = queueConnection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
        mc2 = (ActiveMQRAManagedConnection) ((ActiveMQRASession) s2).getManagedConnection();
        ActiveMQConnectionFactory cf2 = mc2.getConnectionFactory();
        // we're not testing equality so don't use equals(); we're testing if they are actually the *same* object
        assertTrue(cf1 == cf2);
    } 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) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) 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) 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 5 with ActiveMQRAConnectionFactory

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

the class OutgoingConnectionTest method testConnectionCredentials.

@Test
public void testConnectionCredentials() throws Exception {
    resourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
    QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
    QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testpassword");
    session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) XAQueueConnection(javax.jms.XAQueueConnection) QueueConnection(javax.jms.QueueConnection) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) QueueSession(javax.jms.QueueSession) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Test(org.junit.Test)

Aggregations

ActiveMQRAConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory)17 ActiveMQRAConnectionFactoryImpl (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl)15 ActiveMQRAManagedConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory)15 QueueConnection (javax.jms.QueueConnection)14 Test (org.junit.Test)14 Session (javax.jms.Session)9 XAQueueConnection (javax.jms.XAQueueConnection)8 Queue (javax.jms.Queue)7 MessageProducer (javax.jms.MessageProducer)6 QueueSession (javax.jms.QueueSession)6 JMSException (javax.jms.JMSException)5 Message (javax.jms.Message)5 MessageConsumer (javax.jms.MessageConsumer)5 TextMessage (javax.jms.TextMessage)5 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)5 ActiveMQRAManagedConnection (org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection)5 ActiveMQRASession (org.apache.activemq.artemis.ra.ActiveMQRASession)5 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)4 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)4 XASession (javax.jms.XASession)3