use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ProducerCloseTest method testCanNotUseAClosedProducer.
@Test
public void testCanNotUseAClosedProducer() throws Exception {
final ClientProducer producer = session.createProducer(RandomUtil.randomSimpleString());
Assert.assertFalse(producer.isClosed());
producer.close();
Assert.assertTrue(producer.isClosed());
ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {
@Override
public void run() throws ActiveMQException {
producer.send(session.createMessage(false));
}
});
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class BridgeReconnectTest method testDeliveringCountOnBridgeConnectionFailure.
@Test
public void testDeliveringCountOnBridgeConnectionFailure() throws Exception {
server0 = createActiveMQServer(0, isNetty(), server0Params);
TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params, "server0tc");
server0.getConfiguration().setConnectorConfigurations(connectors);
BridgeConfiguration bridgeConfiguration = createBridgeConfig();
List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
bridgeConfigs.add(bridgeConfiguration);
server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName);
List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
queueConfigs0.add(queueConfig0);
server0.getConfiguration().setQueueConfigurations(queueConfigs0);
CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName);
List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
queueConfigs1.add(queueConfig1);
server1.getConfiguration().setQueueConfigurations(queueConfigs1);
startServers();
locator = addServerLocator(ActiveMQClient.createServerLocatorWithHA(server0tc, server1tc));
ClientSessionFactory csf0 = locator.createSessionFactory(server0tc);
session0 = csf0.createSession(false, true, true);
ClientSessionFactory csf1 = locator.createSessionFactory(server1tc);
session1 = csf1.createSession(false, true, true);
ClientProducer prod0 = session0.createProducer(testAddress);
session1.start();
Bridge bridge = server0.getClusterManager().getBridges().get(bridgeName);
RemotingConnection forwardingConnection = getForwardingConnection(bridge);
InVMConnector.failOnCreateConnection = true;
InVMConnector.numberOfFailures = reconnectAttempts - 1;
// forwardingConnection.fail(new ActiveMQNotConnectedException());
final int numMessages = NUM_MESSAGES;
SimpleString propKey = new SimpleString("propkey");
final Queue queue = (Queue) server0.getPostOffice().getBinding(new SimpleString(queueName)).getBindable();
System.out.println("DeliveringCount: " + queue.getDeliveringCount());
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session0.createMessage(false);
message.putIntProperty(propKey, i);
prod0.send(message);
if (i == 50) {
forwardingConnection.fail(new ActiveMQException(ActiveMQExceptionType.UNBLOCKED));
}
}
for (int i = 0; i < 100 && queue.getDeliveringCount() != 0; i++) {
Thread.sleep(10);
}
System.out.println("Check.. DeliveringCount: " + queue.getDeliveringCount());
assertEquals("Delivering count of a source queue should be zero on connection failure", 0, queue.getDeliveringCount());
closeServers();
assertNoMoreConnections();
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class FailoverTest method testCommitDidNotOccurUnblockedAndResend.
@Test(timeout = 120000)
public void testCommitDidNotOccurUnblockedAndResend() throws Exception {
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setReconnectAttempts(300).setRetryInterval(100);
sf = createSessionFactoryAndWaitForTopology(locator, 2);
final ClientSession session = createSession(sf, false, false);
session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
sendMessages(session, producer, NUM_MESSAGES);
class Committer extends Thread {
@Override
public void run() {
Interceptor interceptor = new DelayInterceptor3();
try {
liveServer.addInterceptor(interceptor);
session.commit();
} catch (ActiveMQTransactionRolledBackException trbe) {
// Ok - now we retry the commit after removing the interceptor
liveServer.removeInterceptor(interceptor);
try {
session.commit();
failed = false;
} catch (ActiveMQException e2) {
}
} catch (ActiveMQTransactionOutcomeUnknownException toue) {
// Ok - now we retry the commit after removing the interceptor
liveServer.removeInterceptor(interceptor);
try {
session.commit();
failed = false;
} catch (ActiveMQException e2) {
}
} catch (ActiveMQException e) {
// ignore
}
}
volatile boolean failed = true;
}
Committer committer = new Committer();
committer.start();
crash(session);
committer.join();
Assert.assertFalse("commiter failed should be false", committer.failed);
session.close();
ClientSession session2 = createSession(sf, false, false);
producer = session2.createProducer(FailoverTestBase.ADDRESS);
// We now try and resend the messages since we get a transaction rolled back exception
sendMessages(session2, producer, NUM_MESSAGES);
session2.commit();
ClientConsumer consumer = session2.createConsumer(FailoverTestBase.ADDRESS);
session2.start();
receiveMessages(consumer);
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull("expecting null message", message);
}
use of org.apache.activemq.artemis.api.core.ActiveMQException 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.api.core.ActiveMQException in project activemq-artemis by apache.
the class FailoverTest method testConsumeTransacted.
@Test(timeout = 120000)
public void testConsumeTransacted() throws Exception {
createSessionFactory();
ClientSession session = createSessionAndQueue();
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
final int numMessages = 10;
sendMessages(session, producer, numMessages);
session.commit();
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer.receive(1000);
Assert.assertNotNull("Just crashed? " + (i == 6) + " " + i, message);
message.acknowledge();
if (i == 5) {
crash(session);
}
}
try {
session.commit();
Assert.fail("session must have rolled back on failover");
} catch (ActiveMQTransactionRolledBackException trbe) {
// ok
} catch (ActiveMQException e) {
Assert.fail("Invalid Exception type:" + e.getType());
}
consumer.close();
consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer.receive(1000);
Assert.assertNotNull("Expecting message #" + i, message);
message.acknowledge();
}
session.commit();
session.close();
}
Aggregations