Search in sources :

Example 1 with ActiveMQRAManagedConnection

use of org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection 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 ActiveMQRAManagedConnection

use of org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection 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 3 with ActiveMQRAManagedConnection

use of org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection 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)

Aggregations

QueueConnection (javax.jms.QueueConnection)3 Session (javax.jms.Session)3 ActiveMQRAConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory)3 ActiveMQRAConnectionFactoryImpl (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl)3 ActiveMQRAConnectionManager (org.apache.activemq.artemis.ra.ActiveMQRAConnectionManager)3 ActiveMQRAManagedConnection (org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection)3 ActiveMQRAManagedConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory)3 ActiveMQRASession (org.apache.activemq.artemis.ra.ActiveMQRASession)3 ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)3 Test (org.junit.Test)3 QueueSession (javax.jms.QueueSession)2 XAQueueConnection (javax.jms.XAQueueConnection)2 XASession (javax.jms.XASession)2 InVMConnectorFactory (org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory)2 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)2 ArrayList (java.util.ArrayList)1 MessageProducer (javax.jms.MessageProducer)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1