use of org.apache.activemq.artemis.core.server.impl.InVMNodeManager 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();
}
use of org.apache.activemq.artemis.core.server.impl.InVMNodeManager in project activemq-artemis by apache.
the class FailoverTest method testTimeoutOnFailover.
// https://issues.jboss.org/browse/HORNETQ-685
@Test(timeout = 120000)
public void testTimeoutOnFailover() throws Exception {
locator.setCallTimeout(1000).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setAckBatchSize(0).setReconnectAttempts(300).setRetryInterval(100);
if (nodeManager instanceof InVMNodeManager) {
((InVMNodeManager) nodeManager).failoverPause = 500L;
}
ClientSessionFactoryInternal sf1 = (ClientSessionFactoryInternal) createSessionFactory(locator);
final ClientSession session = createSession(sf1, true, true);
session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
final ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
final CountDownLatch latch = new CountDownLatch(10);
final CountDownLatch latchFailed = new CountDownLatch(1);
Runnable r = new Runnable() {
@Override
public void run() {
for (int i = 0; i < 500; i++) {
ClientMessage message = session.createMessage(true);
message.putIntProperty("counter", i);
try {
System.out.println("Sent " + i);
producer.send(message);
if (i < 10) {
latch.countDown();
if (latch.getCount() == 0) {
latchFailed.await(10, TimeUnit.SECONDS);
}
}
} catch (Exception e) {
// this is our retry
try {
if (!producer.isClosed())
producer.send(message);
} catch (ActiveMQException e1) {
e1.printStackTrace();
}
}
}
}
};
Thread t = new Thread(r);
t.start();
Assert.assertTrue("latch released", latch.await(10, TimeUnit.SECONDS));
crash(session);
latchFailed.countDown();
t.join(30000);
if (t.isAlive()) {
t.interrupt();
Assert.fail("Thread still alive");
}
Assert.assertTrue(backupServer.getServer().waitForActivation(5, TimeUnit.SECONDS));
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
for (int i = 0; i < 500; i++) {
ClientMessage m = consumer.receive(1000);
Assert.assertNotNull("message #=" + i, m);
// assertEquals(i, m.getIntProperty("counter").intValue());
}
}
use of org.apache.activemq.artemis.core.server.impl.InVMNodeManager in project activemq-artemis by apache.
the class FailoverTest method testTimeoutOnFailoverTransactionRollback.
// https://issues.jboss.org/browse/HORNETQ-685
@Test(timeout = 120000)
public void testTimeoutOnFailoverTransactionRollback() throws Exception {
locator.setCallTimeout(2000).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setAckBatchSize(0).setReconnectAttempts(300).setRetryInterval(100);
if (nodeManager instanceof InVMNodeManager) {
((InVMNodeManager) nodeManager).failoverPause = 5000L;
}
ClientSessionFactoryInternal sf1 = (ClientSessionFactoryInternal) createSessionFactory(locator);
final ClientSession session = createSession(sf1, true, false, false);
session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
final ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
Xid xid = new XidImpl("uhuhuhu".getBytes(), 126512, "auhsduashd".getBytes());
session.start(xid, XAResource.TMNOFLAGS);
for (int i = 0; i < 500; i++) {
ClientMessage message = session.createMessage(true);
message.putIntProperty("counter", i);
producer.send(message);
}
session.end(xid, XAResource.TMSUCCESS);
session.prepare(xid);
crash(true, session);
try {
session.rollback(xid);
} catch (XAException e) {
try {
// there is still an edge condition that we must deal with
session.rollback(xid);
} catch (Exception ignored) {
log.trace(ignored.getMessage(), ignored);
}
}
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
ClientMessage m = consumer.receive(1000);
Assert.assertNull(m);
}
use of org.apache.activemq.artemis.core.server.impl.InVMNodeManager in project activemq-artemis by apache.
the class FailoverTest method testTimeoutOnFailoverConsumeBlocked.
@Test(timeout = 120000)
public void testTimeoutOnFailoverConsumeBlocked() throws Exception {
locator.setCallTimeout(5000).setBlockOnNonDurableSend(true).setConsumerWindowSize(0).setBlockOnDurableSend(true).setAckBatchSize(0).setBlockOnAcknowledge(true).setReconnectAttempts(-1).setAckBatchSize(0);
if (nodeManager instanceof InVMNodeManager) {
((InVMNodeManager) nodeManager).failoverPause = 5000L;
}
ClientSessionFactoryInternal sf1 = (ClientSessionFactoryInternal) createSessionFactory(locator);
final ClientSession session = createSession(sf1, true, true);
session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
final ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
for (int i = 0; i < 500; i++) {
ClientMessage message = session.createMessage(true);
message.putIntProperty("counter", i);
message.putBooleanProperty("end", i == 499);
producer.send(message);
}
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch endLatch = new CountDownLatch(1);
final ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
final Map<Integer, ClientMessage> received = new HashMap<>();
Thread t = new Thread() {
@Override
public void run() {
ClientMessage message = null;
try {
while ((message = getMessage()) != null) {
Integer counter = message.getIntProperty("counter");
received.put(counter, message);
try {
log.info("acking message = id = " + message.getMessageID() + ", counter = " + message.getIntProperty("counter"));
message.acknowledge();
} catch (ActiveMQException e) {
e.printStackTrace();
continue;
}
log.info("Acked counter = " + counter);
if (counter.equals(10)) {
latch.countDown();
}
if (received.size() == 500) {
endLatch.countDown();
}
if (message.getBooleanProperty("end")) {
break;
}
}
} catch (Exception e) {
Assert.fail("failing due to exception " + e);
}
}
private ClientMessage getMessage() {
while (true) {
try {
ClientMessage msg = consumer.receive(20000);
if (msg == null) {
log.info("Returning null message on consuming");
}
return msg;
} catch (ActiveMQObjectClosedException oce) {
throw new RuntimeException(oce);
} catch (ActiveMQException ignored) {
// retry
ignored.printStackTrace();
}
}
}
};
t.start();
latch.await(10, TimeUnit.SECONDS);
log.info("crashing session");
crash(session);
endLatch.await(60, TimeUnit.SECONDS);
t.join();
Assert.assertTrue("received only " + received.size(), received.size() == 500);
session.close();
}
use of org.apache.activemq.artemis.core.server.impl.InVMNodeManager in project activemq-artemis by apache.
the class FailBackManualTest method createConfigs.
@Override
protected void createConfigs() throws Exception {
nodeManager = new InVMNodeManager(false);
TransportConfiguration liveConnector = getConnectorTransportConfiguration(true);
TransportConfiguration backupConnector = getConnectorTransportConfiguration(false);
backupConfig = super.createDefaultInVMConfig().clearAcceptorConfigurations().addAcceptorConfiguration(getAcceptorTransportConfiguration(false)).setHAPolicyConfiguration(new SharedStoreSlavePolicyConfiguration().setAllowFailBack(false)).addConnectorConfiguration(liveConnector.getName(), liveConnector).addConnectorConfiguration(backupConnector.getName(), backupConnector).addClusterConfiguration(basicClusterConnectionConfig(backupConnector.getName(), liveConnector.getName()));
backupServer = createTestableServer(backupConfig);
liveConfig = super.createDefaultInVMConfig().clearAcceptorConfigurations().addAcceptorConfiguration(getAcceptorTransportConfiguration(true)).setHAPolicyConfiguration(new SharedStoreMasterPolicyConfiguration()).addConnectorConfiguration(liveConnector.getName(), liveConnector).addConnectorConfiguration(backupConnector.getName(), backupConnector).addClusterConfiguration(basicClusterConnectionConfig(liveConnector.getName(), backupConnector.getName()));
liveServer = createTestableServer(liveConfig);
}
Aggregations