use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException 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.api.core.ActiveMQNotConnectedException 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.api.core.ActiveMQNotConnectedException 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.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.
the class SessionClosedOnRemotingConnectionFailureTest method testSessionClosedOnRemotingConnectionFailure.
@Test
public void testSessionClosedOnRemotingConnectionFailure() throws Exception {
ClientSession session = addClientSession(sf.createSession());
session.createQueue("fooaddress", RoutingType.ANYCAST, "fooqueue");
ClientProducer prod = session.createProducer("fooaddress");
ClientConsumer cons = session.createConsumer("fooqueue");
session.start();
prod.send(session.createMessage(false));
Assert.assertNotNull(cons.receive());
// Now fail the underlying connection
RemotingConnection connection = ((ClientSessionInternal) session).getConnection();
connection.fail(new ActiveMQNotConnectedException());
Assert.assertTrue(session.isClosed());
Assert.assertTrue(prod.isClosed());
Assert.assertTrue(cons.isClosed());
try {
prod.send(session.createMessage(false));
Assert.fail("Should throw exception");
} catch (ActiveMQObjectClosedException oce) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
try {
cons.receive();
Assert.fail("Should throw exception");
} catch (ActiveMQObjectClosedException oce) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
session.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.
the class ReplicatedDistributionTest method fail.
/**
* @param session
* @throws InterruptedException
*/
private void fail(final ClientSession session) throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
session.addFailureListener(new CountDownSessionFailureListener(latch, session));
RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
// Simulate failure on connection
conn.fail(new ActiveMQNotConnectedException());
// Wait to be informed of failure
boolean ok = latch.await(1000, TimeUnit.MILLISECONDS);
Assert.assertTrue(ok);
}
Aggregations