use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class SessionTest method testFailureListenerRemoved.
@Test
public void testFailureListenerRemoved() throws Exception {
cf = createSessionFactory(locator);
try {
ClientSession clientSession = cf.createSession(false, true, true);
class MyFailureListener implements SessionFailureListener {
boolean called = false;
@Override
public void connectionFailed(final ActiveMQException me, boolean failedOver) {
called = true;
}
@Override
public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) {
connectionFailed(me, failedOver);
}
@Override
public void beforeReconnect(final ActiveMQException me) {
}
}
MyFailureListener listener = new MyFailureListener();
clientSession.addFailureListener(listener);
Assert.assertTrue(clientSession.removeFailureListener(listener));
clientSession.close();
server.stop();
Assert.assertFalse(listener.called);
} finally {
((ClientSessionFactoryInternal) cf).causeExit();
cf.close();
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class ServerLocatorConnectTest method testMultipleConnectorSingleServerConnect.
@Test
public void testMultipleConnectorSingleServerConnect() throws Exception {
ServerLocatorInternal locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false, generateParams(0, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(1, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(2, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(3, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(4, isNetty())));
ClientSessionFactoryInternal csf = locator.connect();
assertNotNull(csf);
assertEquals(csf.numConnections(), 1);
locator.close();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class ServerLocatorConnectTest method testSingleConnectorSingleServerConnect.
@Test
public void testSingleConnectorSingleServerConnect() throws Exception {
ServerLocatorInternal locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false, generateParams(0, isNetty())));
ClientSessionFactoryInternal csf = locator.connect();
assertNotNull(csf);
assertEquals(csf.numConnections(), 1);
locator.close();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class ServerLocatorConnectTest method testMultipleConnectorSingleServerConnectReconnect.
@Test
public void testMultipleConnectorSingleServerConnectReconnect() throws Exception {
ServerLocatorInternal locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false, generateParams(0, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(1, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(2, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(3, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(4, isNetty())));
locator.setReconnectAttempts(15);
ClientSessionFactoryInternal csf = locator.connect();
assertNotNull(csf);
assertEquals(csf.numConnections(), 1);
locator.close();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class FailoverTest method testTimeoutOnFailoverTransactionCommitTimeoutCommunication.
/**
* This test would fail one in three or five times,
* where the commit would leave the session dirty after a timeout.
*/
@Test(timeout = 120000)
public void testTimeoutOnFailoverTransactionCommitTimeoutCommunication() throws Exception {
locator.setCallTimeout(1000).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setAckBatchSize(0).setReconnectAttempts(300).setRetryInterval(500);
if (nodeManager instanceof InVMNodeManager) {
((InVMNodeManager) nodeManager).failoverPause = 6000L;
}
ClientSessionFactoryInternal sf1 = (ClientSessionFactoryInternal) createSessionFactory(locator);
final ClientSession session = createSession(sf1, false, false, false);
session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
final CountDownLatch connectionFailed = new CountDownLatch(1);
session.addFailureListener(new SessionFailureListener() {
@Override
public void beforeReconnect(ActiveMQException exception) {
}
@Override
public void connectionFailed(ActiveMQException exception, boolean failedOver) {
}
@Override
public void connectionFailed(ActiveMQException exception, boolean failedOver, String scaleDownTargetNodeID) {
connectionFailed.countDown();
}
});
final ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
for (int i = 0; i < 500; i++) {
ClientMessage message = session.createMessage(true);
message.putIntProperty("counter", i);
producer.send(message);
}
session.commit();
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
ClientMessage m = null;
for (int i = 0; i < 500; i++) {
m = consumer.receive(1000);
Assert.assertNotNull(m);
Assert.assertEquals(i, m.getIntProperty("counter").intValue());
}
m.acknowledge();
crash(false, session);
try {
session.commit();
fail("Exception expected");
} catch (Exception expected) {
expected.printStackTrace();
}
Thread.sleep(2000);
m = null;
for (int i = 0; i < 500; i++) {
m = consumer.receive(1000);
Assert.assertNotNull(m);
Assert.assertEquals(i, m.getIntProperty("counter").intValue());
}
m.acknowledge();
session.commit();
}
Aggregations