use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.
the class ReattachTest method testExponentialBackoff.
@Test
public void testExponentialBackoff() throws Exception {
final long retryInterval = 50;
final double retryMultiplier = 2d;
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;
InVMConnector.numberOfFailures = 3;
RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
long start = System.currentTimeMillis();
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.getObjectProperty(new SimpleString("count")));
message.acknowledge();
}
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull(message);
long end = System.currentTimeMillis();
double wait = retryInterval + retryMultiplier * retryInterval + retryMultiplier * retryMultiplier * retryInterval;
Assert.assertTrue(end - start >= wait);
session.close();
sf.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.
the class ReattachTest method testImmediateReattach.
/*
* Test failure on connection, but server is still up so should immediately reconnect
*/
@Test
public void testImmediateReattach() 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);
final int numIterations = 10;
for (int j = 0; j < numIterations; j++) {
ClientProducer producer = session.createProducer(ReattachTest.ADDRESS);
final int numMessages = 100;
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);
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.getObjectProperty(new SimpleString("count")));
message.acknowledge();
}
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull(message);
producer.close();
consumer.close();
}
session.close();
sf.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.
the class NettyAsynchronousReattachTest method crash.
@Override
protected void crash(final ClientSession... sessions) throws Exception {
for (ClientSession session : sessions) {
log.debug("Crashing session " + session);
ClientSessionInternal internalSession = (ClientSessionInternal) session;
internalSession.getConnection().fail(new ActiveMQNotConnectedException("oops"));
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.
the class FailoverWithSharedStoreTest method testNoConnection.
@Test
public void testNoConnection() throws Exception {
ServerLocator locator = ActiveMQClient.createServerLocatorWithHA(new TransportConfiguration(NettyConnectorFactory.class.getName()));
try {
createSessionFactory(locator);
fail();
} catch (ActiveMQNotConnectedException nce) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.
the class ConnectionLimitTest method testInVMConnectionLimit.
@Test
public void testInVMConnectionLimit() throws Exception {
ServerLocator locator = addServerLocator(createNonHALocator(false));
ClientSessionFactory clientSessionFactory = locator.createSessionFactory();
try {
ClientSessionFactory extraClientSessionFactory = locator.createSessionFactory();
fail("creating a session factory here should fail");
} catch (Exception e) {
assertTrue(e instanceof ActiveMQNotConnectedException);
}
}
Aggregations