use of org.apache.activemq.artemis.api.core.ActiveMQException 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.api.core.ActiveMQException in project activemq-artemis by apache.
the class FailoverTest method testForceBlockingReturn.
@Test(timeout = 120000)
public void testForceBlockingReturn() throws Exception {
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setReconnectAttempts(300).setRetryInterval(100);
createClientSessionFactory();
// Add an interceptor to delay the send method so we can get time to cause failover before it returns
liveServer.getServer().getRemotingService().addIncomingInterceptor(new DelayInterceptor());
final ClientSession session = createSession(sf, true, true, 0);
session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
final ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
class Sender extends Thread {
@Override
public void run() {
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeString("message");
try {
producer.send(message);
} catch (ActiveMQException e1) {
this.e = e1;
}
}
volatile ActiveMQException e;
}
Sender sender = new Sender();
sender.start();
crash(session);
sender.join();
Assert.assertNotNull(sender.e);
Assert.assertNotNull(sender.e.getCause());
Assert.assertEquals(sender.e.getType(), ActiveMQExceptionType.UNBLOCKED);
Assert.assertEquals(((ActiveMQException) sender.e.getCause()).getType(), ActiveMQExceptionType.DISCONNECTED);
session.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class FailoverTest method testTransactedMessagesSentSoRollback.
@Test(timeout = 120000)
public void testTransactedMessagesSentSoRollback() throws Exception {
createSessionFactory();
ClientSession session = createSessionAndQueue();
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
sendMessagesSomeDurable(session, producer);
crash(session);
Assert.assertTrue(session.isRollbackOnly());
try {
session.commit();
Assert.fail("Should throw exception");
} catch (ActiveMQTransactionRolledBackException trbe) {
// ok
} catch (ActiveMQException e) {
Assert.fail("Invalid Exception type:" + e.getType());
}
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull("message should be null! Was: " + message, message);
session.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQException 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.api.core.ActiveMQException in project activemq-artemis by apache.
the class FailoverOnFlowControlTest method testOverflowSend.
@Test
public void testOverflowSend() throws Exception {
ServerLocator locator = getServerLocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setReconnectAttempts(300).setProducerWindowSize(1000).setRetryInterval(100);
final ArrayList<ClientSession> sessionList = new ArrayList<>();
Interceptor interceptorClient = new Interceptor() {
AtomicInteger count = new AtomicInteger(0);
@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
log.debug("Intercept..." + packet.getClass().getName());
if (packet instanceof SessionProducerCreditsMessage) {
SessionProducerCreditsMessage credit = (SessionProducerCreditsMessage) packet;
log.debug("Credits: " + credit.getCredits());
if (count.incrementAndGet() == 2) {
log.debug("### crashing server");
try {
InVMConnection.setFlushEnabled(false);
crash(false, sessionList.get(0));
} catch (Exception e) {
e.printStackTrace();
} finally {
InVMConnection.setFlushEnabled(true);
}
return false;
}
}
return true;
}
};
locator.addIncomingInterceptor(interceptorClient);
ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator, 2);
ClientSession session = sf.createSession(true, true);
sessionList.add(session);
session.createQueue(ADDRESS, ADDRESS, null, true);
ClientProducer producer = session.createProducer(ADDRESS);
final int numMessages = 10;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeBytes(new byte[5000]);
message.putIntProperty("counter", i);
producer.send(message);
}
session.close();
}
Aggregations