use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ReattachTest method testCreateQueue.
@Test
public void testCreateQueue() throws Exception {
final long retryInterval = 100;
final double retryMultiplier = 1d;
final int reconnectAttempts = 300;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true);
// Sleep 3 times retryInterval, so it should at least have 3 retries
RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
InVMConnector.failOnCreateConnection = false;
conn.fail(new ActiveMQNotConnectedException());
Thread t = new Thread() {
@Override
public void run() {
try {
Thread.sleep(retryInterval * 3);
} catch (InterruptedException ignore) {
}
InVMConnector.failOnCreateConnection = false;
}
};
t.start();
for (int i = 0; i < 10; i++) {
session.createQueue("address", RoutingType.ANYCAST, "queue" + i);
}
//
// InVMConnector.failOnCreateConnection = true;
//
// //Should throw exception since didn't reconnect
//
// try
// {
// session.start();
//
// fail("Should throw exception");
// }
// catch (ActiveMQException e)
// {
// assertEquals(ActiveMQException.OBJECT_CLOSED, e.getCode());
// }
session.close();
sf.close();
t.join();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal 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.ClientSessionInternal 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.ClientSessionInternal 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.ClientSessionInternal in project activemq-artemis by apache.
the class JMSFailoverTest method testManualFailover.
@Test
public void testManualFailover() throws Exception {
ActiveMQConnectionFactory jbcfLive = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
jbcfLive.setBlockOnNonDurableSend(true);
jbcfLive.setBlockOnDurableSend(true);
ActiveMQConnectionFactory jbcfBackup = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, backupParams));
jbcfBackup.setBlockOnNonDurableSend(true);
jbcfBackup.setBlockOnDurableSend(true);
jbcfBackup.setInitialConnectAttempts(-1);
jbcfBackup.setReconnectAttempts(-1);
Connection connLive = jbcfLive.createConnection();
MyExceptionListener listener = new MyExceptionListener();
connLive.setExceptionListener(listener);
Session sessLive = connLive.createSession(false, Session.AUTO_ACKNOWLEDGE);
ClientSession coreSessionLive = ((ActiveMQSession) sessLive).getCoreSession();
RemotingConnection coreConnLive = ((ClientSessionInternal) coreSessionLive).getConnection();
SimpleString jmsQueueName = new SimpleString("myqueue");
coreSessionLive.createQueue(jmsQueueName, RoutingType.ANYCAST, jmsQueueName, null, true);
Queue queue = sessLive.createQueue("myqueue");
final int numMessages = 1000;
MessageProducer producerLive = sessLive.createProducer(queue);
for (int i = 0; i < numMessages; i++) {
TextMessage tm = sessLive.createTextMessage("message" + i);
producerLive.send(tm);
}
// Note we block on P send to make sure all messages get to server before failover
JMSUtil.crash(liveServer, coreSessionLive);
connLive.close();
// Now recreate on backup
Connection connBackup = jbcfBackup.createConnection();
Session sessBackup = connBackup.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumerBackup = sessBackup.createConsumer(queue);
connBackup.start();
for (int i = 0; i < numMessages; i++) {
TextMessage tm = (TextMessage) consumerBackup.receive(1000);
Assert.assertNotNull(tm);
Assert.assertEquals("message" + i, tm.getText());
}
TextMessage tm = (TextMessage) consumerBackup.receiveNoWait();
Assert.assertNull(tm);
connBackup.close();
}
Aggregations