use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class BindingsClusterTest method crash.
private void crash() throws Exception {
/*
* Rather than just calling stop() on the server here we want to simulate an actual node crash or bridge failure
* so the bridge's failure listener needs to get something other than a DISCONNECTED message. In this case we
* simulate a NOT_CONNECTED exception.
*/
final CountDownLatch latch = new CountDownLatch(1);
ClusterConnectionImpl next = (ClusterConnectionImpl) server1.getClusterManager().getClusterConnections().iterator().next();
BridgeImpl bridge = (BridgeImpl) next.getRecords().values().iterator().next().getBridge();
RemotingConnection forwardingConnection = getForwardingConnection(bridge);
forwardingConnection.addFailureListener(new FailureListener() {
@Override
public void connectionFailed(ActiveMQException exception, boolean failedOver) {
latch.countDown();
}
@Override
public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) {
connectionFailed(me, failedOver);
}
});
forwardingConnection.fail(new ActiveMQNotConnectedException());
assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
if (crash) {
jmsServer2.stop();
}
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class JMSFailoverTest method testSendReceiveLargeMessages.
@Test
public void testSendReceiveLargeMessages() throws Exception {
SimpleString QUEUE = new SimpleString("somequeue");
ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc, backuptc);
jbcf.setReconnectAttempts(-1);
jbcf.setBlockOnDurableSend(true);
jbcf.setBlockOnNonDurableSend(true);
jbcf.setMinLargeMessageSize(1024);
// jbcf.setConsumerWindowSize(0);
// jbcf.setMinLargeMessageSize(1024);
final CountDownLatch flagAlign = new CountDownLatch(1);
final CountDownLatch waitToKill = new CountDownLatch(1);
final AtomicBoolean killed = new AtomicBoolean(false);
jbcf.getServerLocator().addIncomingInterceptor(new Interceptor() {
int count = 0;
@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
if (packet instanceof SessionReceiveContinuationMessage) {
if (count++ == 300 && !killed.get()) {
System.out.println("sending countDown on latch waitToKill");
killed.set(true);
waitToKill.countDown();
}
}
return true;
}
});
Connection conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5);
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
final ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession();
// The thread that will fail the server
Thread spoilerThread = new Thread() {
@Override
public void run() {
flagAlign.countDown();
// a large timeout just to help in case of debugging
try {
waitToKill.await(120, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
try {
System.out.println("Killing server...");
JMSUtil.crash(liveServer, coreSession);
} catch (Exception e) {
e.printStackTrace();
}
}
};
coreSession.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, true);
Queue queue = sess.createQueue("somequeue");
MessageProducer producer = sess.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
for (int i = 0; i < 100; i++) {
TextMessage message = sess.createTextMessage(new String(new byte[10 * 1024]));
producer.send(message);
if (i % 10 == 0) {
sess.commit();
}
}
sess.commit();
conn.start();
spoilerThread.start();
assertTrue(flagAlign.await(10, TimeUnit.SECONDS));
MessageConsumer consumer = sess.createConsumer(queue);
// this test is not meant to validate transactionality during Failover as that would require XA and recovery
for (int i = 0; i < 90; i++) {
TextMessage message = null;
int retryNrs = 0;
do {
retryNrs++;
try {
message = (TextMessage) consumer.receive(5000);
assertNotNull(message);
break;
} catch (JMSException e) {
new Exception("Exception on receive message", e).printStackTrace();
}
} while (retryNrs < 10);
assertNotNull(message);
try {
sess.commit();
} catch (Exception e) {
new Exception("Exception during commit", e);
sess.rollback();
}
}
conn.close();
spoilerThread.join();
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class CloseConnectionOnGCTest method testCloseSeveralConnectionsWithSessionsOnGC.
@Test
public void testCloseSeveralConnectionsWithSessionsOnGC() throws Exception {
Connection conn1 = cf.createConnection();
Connection conn2 = cf.createConnection();
Connection conn3 = cf.createConnection();
WeakReference<Connection> wr1 = new WeakReference<>(conn1);
WeakReference<Connection> wr2 = new WeakReference<>(conn2);
WeakReference<Connection> wr3 = new WeakReference<>(conn3);
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session sess2 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session sess3 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session sess4 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session sess5 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session sess6 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session sess7 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
final CountDownLatch latch = new CountDownLatch(3);
Iterator<RemotingConnection> connectionIterator = server.getRemotingService().getConnections().iterator();
while (connectionIterator.hasNext()) {
RemotingConnection remotingConnection = connectionIterator.next();
remotingConnection.addCloseListener(new CloseListener() {
@Override
public void connectionClosed() {
latch.countDown();
}
});
}
sess1 = sess2 = sess3 = sess4 = sess5 = sess6 = sess7 = null;
conn1 = null;
conn2 = null;
conn3 = null;
ActiveMQTestBase.checkWeakReferences(wr1, wr2, wr3);
latch.await(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(0, server.getRemotingService().getConnections().size());
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class CloseConnectionOnGCTest method testCloseSeveralConnectionOnGC.
@Test
public void testCloseSeveralConnectionOnGC() throws Exception {
Connection conn1 = cf.createConnection();
Connection conn2 = cf.createConnection();
Connection conn3 = cf.createConnection();
WeakReference<Connection> wr1 = new WeakReference<>(conn1);
WeakReference<Connection> wr2 = new WeakReference<>(conn2);
WeakReference<Connection> wr3 = new WeakReference<>(conn3);
Assert.assertEquals(3, server.getRemotingService().getConnections().size());
final CountDownLatch latch = new CountDownLatch(3);
Iterator<RemotingConnection> connectionIterator = server.getRemotingService().getConnections().iterator();
while (connectionIterator.hasNext()) {
RemotingConnection remotingConnection = connectionIterator.next();
remotingConnection.addCloseListener(new CloseListener() {
@Override
public void connectionClosed() {
latch.countDown();
}
});
}
conn1 = null;
conn2 = null;
conn3 = null;
ActiveMQTestBase.checkWeakReferences(wr1, wr2, wr3);
latch.await(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(0, server.getRemotingService().getConnections().size());
}
Aggregations