use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ClusteredBridgeReconnectTest method testReconnectBridge.
@Test
@BMRules(rules = { @BMRule(name = "enter", targetClass = "org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl", targetMethod = "connect", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.ClusteredBridgeReconnectTest.enterConnect();"), @BMRule(name = "exit", targetClass = "org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl", targetMethod = "connect", targetLocation = "EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.ClusteredBridgeReconnectTest.exitConnect();"), @BMRule(name = "send", targetClass = "org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl", targetMethod = "send(org.apache.activemq.artemis.core.protocol.core.Packet)", targetLocation = "EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.ClusteredBridgeReconnectTest.send();") })
public void testReconnectBridge() throws Exception {
setupServer(0, isFileStorage(), isNetty());
setupServer(1, isFileStorage(), isNetty());
setupClusterConnection("cluster0", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 0, 1);
setupClusterConnection("cluster1", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 1, 0);
startServers(0, 1);
setupSessionFactory(0, isNetty());
setupSessionFactory(1, isNetty());
createQueue(0, "queues.testaddress", "queue0", null, true);
createQueue(1, "queues.testaddress", "queue0", null, true);
addConsumer(0, 0, "queue0", null);
addConsumer(1, 1, "queue0", null);
waitForBindings(0, "queues.testaddress", 1, 1, true);
waitForBindings(1, "queues.testaddress", 1, 1, true);
waitForBindings(0, "queues.testaddress", 1, 1, false);
waitForBindings(1, "queues.testaddress", 1, 1, false);
ClientSession session0 = sfs[0].createSession();
ClientSession session1 = sfs[0].createSession();
session0.start();
session1.start();
ClientProducer producer = session0.createProducer("queues.testaddress");
int NUMBER_OF_MESSAGES = 100;
Assert.assertEquals(1, servers[0].getClusterManager().getClusterConnections().size());
ClusterConnectionImpl connection = servers[0].getClusterManager().getClusterConnections().toArray(new ClusterConnectionImpl[0])[0];
Assert.assertEquals(1, connection.getRecords().size());
MessageFlowRecord record = connection.getRecords().values().toArray(new MessageFlowRecord[1])[0];
ClusterConnectionBridge bridge = (ClusterConnectionBridge) record.getBridge();
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
ClientMessage msg = session0.createMessage(true);
producer.send(msg);
session0.commit();
if (i == 17) {
shouldFail = true;
bridge.getSessionFactory().getConnection().fail(new ActiveMQException("failed once!"));
}
}
int cons0Count = 0, cons1Count = 0;
while (true) {
ClientMessage msg = consumers[0].getConsumer().receive(1000);
if (msg == null) {
break;
}
cons0Count++;
msg.acknowledge();
session0.commit();
}
while (true) {
ClientMessage msg = consumers[1].getConsumer().receive(1000);
if (msg == null) {
break;
}
cons1Count++;
msg.acknowledge();
session1.commit();
}
Assert.assertEquals("cons0 = " + cons0Count + ", cons1 = " + cons1Count, NUMBER_OF_MESSAGES, cons0Count + cons1Count);
session0.commit();
session1.commit();
stopServers(0, 1);
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ReattachTest method testReattachAttemptsFailsToReconnect.
@Test
public void testReattachAttemptsFailsToReconnect() throws Exception {
final long retryInterval = 50;
final double retryMultiplier = 1d;
final int reconnectAttempts = 3;
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);
}
session.createConsumer(ReattachTest.ADDRESS);
InVMConnector.failOnCreateConnection = true;
RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
// Sleep for longer than max retries so should fail to reconnect
Thread t = new Thread() {
@Override
public void run() {
try {
Thread.sleep(retryInterval * (reconnectAttempts + 1));
} catch (InterruptedException ignore) {
}
InVMConnector.failOnCreateConnection = false;
}
};
t.start();
conn.fail(new ActiveMQNotConnectedException());
try {
session.start();
Assert.fail("Should throw exception");
} catch (ActiveMQObjectClosedException oce) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
session.close();
sf.close();
t.join();
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ReattachTest method testOverflowCredits.
/*
* Test failure on connection, but server is still up so should immediately reconnect
*/
@Test
public void testOverflowCredits() throws Exception {
final long retryInterval = 500;
final double retryMultiplier = 1d;
final int reconnectAttempts = 1;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024).setProducerWindowSize(1000);
final AtomicInteger count = new AtomicInteger(0);
Interceptor intercept = new Interceptor() {
@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
System.out.println("Intercept..." + packet.getClass().getName());
if (packet instanceof SessionProducerCreditsMessage) {
SessionProducerCreditsMessage credit = (SessionProducerCreditsMessage) packet;
System.out.println("Credits: " + credit.getCredits());
if (count.incrementAndGet() == 2) {
System.out.println("Failing");
connection.fail(new ActiveMQException(ActiveMQExceptionType.UNSUPPORTED_PACKET, "bye"));
return false;
}
}
return true;
}
};
locator.addIncomingInterceptor(intercept);
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 = 10;
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().writeBytes(new byte[5000]);
producer.send(message);
}
session.close();
sf.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class BackupSyncDelay method intercept.
@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
if (packet.getType() == PacketImpl.BACKUP_REGISTRATION) {
try {
SharedNothingBackupActivation activation = (SharedNothingBackupActivation) backup.getActivation();
ReplicationEndpoint repEnd = activation.getReplicationEndpoint();
handler.addSubHandler(repEnd);
Channel repChannel = repEnd.getChannel();
repChannel.setHandler(handler);
handler.setChannel(repChannel);
live.getRemotingService().removeIncomingInterceptor(this);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return true;
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class TopologyClusterTestBase method testStopNodes.
@Test
public void testStopNodes() throws Throwable {
startServers(0, 1, 2, 3, 4);
String[] nodeIDs = getNodeIDs(0, 1, 2, 3, 4);
ServerLocator locator = createHAServerLocator();
waitForClusterConnections(0, 4);
waitForClusterConnections(1, 4);
waitForClusterConnections(2, 4);
waitForClusterConnections(3, 4);
waitForClusterConnections(4, 4);
final List<String> nodes = Collections.synchronizedList(new ArrayList<String>());
final CountDownLatch upLatch = new CountDownLatch(5);
locator.addClusterTopologyListener(new LatchListener(upLatch, nodes, new CountDownLatch(0)));
ClientSessionFactory sf = createSessionFactory(locator);
Assert.assertTrue("Was not notified that all servers are UP", upLatch.await(10, SECONDS));
checkContains(new int[] { 0, 1, 2, 3, 4 }, nodeIDs, nodes);
ClientSession session = sf.createSession();
stopServers(0);
Assert.assertFalse(servers[0].isStarted());
session = checkSessionOrReconnect(session, locator);
checkContains(new int[] { 1, 2, 3, 4 }, nodeIDs, nodes);
stopServers(2);
Assert.assertFalse(servers[2].isStarted());
session = checkSessionOrReconnect(session, locator);
checkContains(new int[] { 1, 3, 4 }, nodeIDs, nodes);
stopServers(4);
Assert.assertFalse(servers[4].isStarted());
session = checkSessionOrReconnect(session, locator);
checkContains(new int[] { 1, 3 }, nodeIDs, nodes);
stopServers(3);
Assert.assertFalse(servers[3].isStarted());
session = checkSessionOrReconnect(session, locator);
checkContains(new int[] { 1 }, nodeIDs, nodes);
stopServers(1);
Assert.assertFalse(servers[1].isStarted());
try {
session = checkSessionOrReconnect(session, locator);
Assert.fail();
} catch (ActiveMQException expected) {
Assert.assertEquals(ActiveMQExceptionType.NOT_CONNECTED, expected.getType());
}
}
Aggregations