use of org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl 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();
}
}
}
use of org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl 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());
}
use of org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl 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
}
}
use of org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl 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();
}
}
}
use of org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl 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);
}
Aggregations