use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class ReattachTest method testReattachAttemptsSucceedsInReconnecting.
@Test
public void testReattachAttemptsSucceedsInReconnecting() throws Exception {
final long retryInterval = 50;
final double retryMultiplier = 1d;
final int reconnectAttempts = 10;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true);
session.createQueue(ReattachTest.ADDRESS, ReattachTest.ADDRESS, null, false);
ClientProducer producer = session.createProducer(ReattachTest.ADDRESS);
final int numMessages = 1000;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
message.putIntProperty(new SimpleString("count"), i);
message.getBodyBuffer().writeString("aardvarks");
producer.send(message);
}
ClientConsumer consumer = session.createConsumer(ReattachTest.ADDRESS);
InVMConnector.failOnCreateConnection = true;
InVMConnector.numberOfFailures = reconnectAttempts - 1;
RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
conn.fail(new ActiveMQNotConnectedException());
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer.receive(500);
Assert.assertNotNull(message);
Assert.assertEquals("aardvarks", message.getBodyBuffer().readString());
Assert.assertEquals(i, message.getIntProperty("count").intValue());
message.acknowledge();
}
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull(message);
session.close();
sf.close();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class ReattachTest method testRetryInterval.
@Test
public void testRetryInterval() throws Exception {
final long retryInterval = 500;
final double retryMultiplier = 1d;
final int reconnectAttempts = 60;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true);
session.createQueue(ReattachTest.ADDRESS, ReattachTest.ADDRESS, null, false);
ClientProducer producer = session.createProducer(ReattachTest.ADDRESS);
final int numMessages = 1000;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
message.putIntProperty(new SimpleString("count"), i);
message.getBodyBuffer().writeString("aardvarks");
producer.send(message);
}
ClientConsumer consumer = session.createConsumer(ReattachTest.ADDRESS);
InVMConnector.failOnCreateConnection = true;
RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
long start = System.currentTimeMillis();
Thread t = new Thread() {
@Override
public void run() {
try {
Thread.sleep(retryInterval / 2);
} catch (InterruptedException ignore) {
}
InVMConnector.failOnCreateConnection = false;
}
};
t.start();
conn.fail(new ActiveMQNotConnectedException());
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer.receive(500);
Assert.assertNotNull(message);
Assert.assertEquals("aardvarks", message.getBodyBuffer().readString());
Assert.assertEquals(i, message.getIntProperty("count").intValue());
message.acknowledge();
}
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull(message);
long end = System.currentTimeMillis();
Assert.assertTrue(end - start >= retryInterval);
session.close();
sf.close();
t.join();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class ReattachTest method testDelayedReattach.
/*
* Test failure on connection, simulate failure to create connection for a while, then
* allow connection to be recreated
*/
@Test
public void testDelayedReattach() throws Exception {
final long retryInterval = 50;
final double retryMultiplier = 1d;
final int reconnectAttempts = 60;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true);
session.createQueue(ReattachTest.ADDRESS, ReattachTest.ADDRESS, null, false);
ClientProducer producer = session.createProducer(ReattachTest.ADDRESS);
final int numMessages = 1000;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
message.putIntProperty(new SimpleString("count"), i);
message.getBodyBuffer().writeString("aardvarks");
producer.send(message);
}
ClientConsumer consumer = session.createConsumer(ReattachTest.ADDRESS);
InVMConnector.failOnCreateConnection = true;
RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
Thread t = new Thread() {
@Override
public void run() {
try {
Thread.sleep(retryInterval * 3);
} catch (InterruptedException ignore) {
}
InVMConnector.failOnCreateConnection = false;
}
};
t.start();
conn.fail(new ActiveMQNotConnectedException());
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer.receive(500);
Assert.assertNotNull(message);
Assert.assertEquals("aardvarks", message.getBodyBuffer().readString());
Assert.assertEquals(i, message.getIntProperty("count").intValue());
message.acknowledge();
}
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull(message);
session.close();
sf.close();
t.join();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class SingleLiveMultipleBackupsFailoverTest method testMultipleFailovers.
@Test
public void testMultipleFailovers() throws Exception {
nodeManager = new InVMNodeManager(!sharedStore);
createLiveConfig(0);
createBackupConfig(0, 1, 0, 2, 3, 4, 5);
createBackupConfig(0, 2, 0, 1, 3, 4, 5);
createBackupConfig(0, 3, 0, 1, 2, 4, 5);
createBackupConfig(0, 4, 0, 1, 2, 3, 5);
createBackupConfig(0, 5, 0, 1, 2, 3, 4);
servers.get(0).start();
waitForServerToStart(servers.get(0).getServer());
servers.get(1).start();
waitForServerToStart(servers.get(1).getServer());
servers.get(2).start();
servers.get(3).start();
servers.get(4).start();
servers.get(5).start();
locator = (ServerLocatorImpl) getServerLocator(0);
Topology topology = locator.getTopology();
// for logging and debugging
topology.setOwner("testMultipleFailovers");
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setReconnectAttempts(15);
ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator, 2);
int backupNode;
ClientSession session = sendAndConsume(sf, true);
log.info("failing node 0");
servers.get(0).crash(session);
session.close();
backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
session = sendAndConsume(sf, false);
log.info("failing node " + backupNode);
servers.get(backupNode).crash(session);
session.close();
backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
session = sendAndConsume(sf, false);
log.info("failing node " + backupNode);
servers.get(backupNode).crash(session);
session.close();
backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
session = sendAndConsume(sf, false);
log.info("failing node " + backupNode);
servers.get(backupNode).crash(session);
session.close();
backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
session = sendAndConsume(sf, false);
log.info("failing node " + backupNode);
servers.get(backupNode).crash(session);
session.close();
backupNode = waitForNewLive(5, false, servers, 1, 2, 3, 4, 5);
session = sendAndConsume(sf, false);
session.close();
servers.get(backupNode).stop();
locator.close();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class ClusterConnectionBridge method createSessionFactory.
@Override
protected ClientSessionFactoryInternal createSessionFactory() throws Exception {
serverLocator.setProtocolManagerFactory(ActiveMQServerSideProtocolManagerFactory.getInstance(serverLocator));
ClientSessionFactoryInternal factory = (ClientSessionFactoryInternal) serverLocator.createSessionFactory(targetNodeID);
// if it is null then its possible the broker was removed after a disconnect so lets try the original connectors
if (factory == null) {
factory = reconnectOnOriginalNode();
if (factory == null) {
return null;
}
}
setSessionFactory(factory);
if (factory == null) {
return null;
}
factory.setReconnectAttempts(0);
factory.getConnection().addFailureListener(this);
return factory;
}
Aggregations