use of org.apache.activemq.artemis.core.remoting.CloseListener in project activemq-artemis by apache.
the class JMSTopicConsumerTest method testTemporarySubscriptionDeleted.
@Test(timeout = 60000)
public void testTemporarySubscriptionDeleted() throws Exception {
Connection connection = createConnection();
try {
TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(getTopicName());
TopicSubscriber myNonDurSub = session.createSubscriber(topic);
assertNotNull(myNonDurSub);
Bindings bindingsForAddress = server.getPostOffice().getBindingsForAddress(new SimpleString(getTopicName()));
Assert.assertEquals(2, bindingsForAddress.getBindings().size());
session.close();
final CountDownLatch latch = new CountDownLatch(1);
server.getRemotingService().getConnections().iterator().next().addCloseListener(new CloseListener() {
@Override
public void connectionClosed() {
latch.countDown();
}
});
connection.close();
latch.await(5, TimeUnit.SECONDS);
bindingsForAddress = server.getPostOffice().getBindingsForAddress(new SimpleString(getTopicName()));
Assert.assertEquals(1, bindingsForAddress.getBindings().size());
} finally {
connection.close();
}
}
use of org.apache.activemq.artemis.core.remoting.CloseListener in project activemq-artemis by apache.
the class CloseConnectionOnGCTest method testCloseOneConnectionOnGC.
@Test
public void testCloseOneConnectionOnGC() throws Exception {
// Debug - don't remove this until intermittent failure with this test is fixed
int initialConns = server.getRemotingService().getConnections().size();
Assert.assertEquals(0, initialConns);
Connection conn = cf.createConnection();
WeakReference<Connection> wr = new WeakReference<>(conn);
Assert.assertEquals(1, server.getRemotingService().getConnections().size());
final CountDownLatch latch = new CountDownLatch(1);
Iterator<RemotingConnection> connectionIterator = server.getRemotingService().getConnections().iterator();
connectionIterator.next().addCloseListener(new CloseListener() {
@Override
public void connectionClosed() {
latch.countDown();
}
});
conn = null;
ActiveMQTestBase.checkWeakReferences(wr);
latch.await(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(0, server.getRemotingService().getConnections().size());
}
use of org.apache.activemq.artemis.core.remoting.CloseListener in project activemq-artemis by apache.
the class PingTest method testClientFailureNoServerPing.
/*
* Test the client triggering failure due to no ping from server received in time
*/
@Test
public void testClientFailureNoServerPing() throws Exception {
// server must received at least one ping from the client to pass
// so that the server connection TTL is configured with the client value
final CountDownLatch pingOnServerLatch = new CountDownLatch(2);
server.getRemotingService().addIncomingInterceptor(new Interceptor() {
@Override
public boolean intercept(final Packet packet, final RemotingConnection connection) throws ActiveMQException {
if (packet.getType() == PacketImpl.PING) {
pingOnServerLatch.countDown();
}
return true;
}
});
TransportConfiguration transportConfig = new TransportConfiguration(INVM_CONNECTOR_FACTORY);
ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(transportConfig));
locator.setClientFailureCheckPeriod(PingTest.CLIENT_FAILURE_CHECK_PERIOD);
locator.setConnectionTTL(PingTest.CLIENT_FAILURE_CHECK_PERIOD * 2);
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession session = csf.createSession(false, true, true);
Assert.assertEquals(1, ((ClientSessionFactoryInternal) csf).numConnections());
final CountDownLatch clientLatch = new CountDownLatch(1);
SessionFailureListener clientListener = new SessionFailureListener() {
@Override
public void connectionFailed(final ActiveMQException me, boolean failedOver) {
clientLatch.countDown();
}
@Override
public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) {
connectionFailed(me, failedOver);
}
@Override
public void beforeReconnect(final ActiveMQException exception) {
}
};
final CountDownLatch serverLatch = new CountDownLatch(1);
CloseListener serverListener = new CloseListener() {
@Override
public void connectionClosed() {
serverLatch.countDown();
}
};
session.addFailureListener(clientListener);
CoreRemotingConnection serverConn = null;
while (serverConn == null) {
Set<RemotingConnection> conns = server.getRemotingService().getConnections();
if (!conns.isEmpty()) {
serverConn = (CoreRemotingConnection) server.getRemotingService().getConnections().iterator().next();
} else {
// It's async so need to wait a while
Thread.sleep(10);
}
}
serverConn.addCloseListener(serverListener);
Assert.assertTrue("server has not received any ping from the client", pingOnServerLatch.await(4000, TimeUnit.MILLISECONDS));
// we let the server receives at least 1 ping (so that it uses the client ConnectionTTL value)
// Setting the handler to null will prevent server sending pings back to client
serverConn.getChannel(0, -1).setHandler(null);
Assert.assertTrue(clientLatch.await(8 * PingTest.CLIENT_FAILURE_CHECK_PERIOD, TimeUnit.MILLISECONDS));
// Server connection will be closed too, when client closes client side connection after failure is detected
Assert.assertTrue(serverLatch.await(2 * server.getConfiguration().getConnectionTtlCheckInterval(), TimeUnit.MILLISECONDS));
long start = System.currentTimeMillis();
while (true) {
if (!server.getRemotingService().getConnections().isEmpty() && System.currentTimeMillis() - start < 10000) {
Thread.sleep(500);
} else {
break;
}
}
Assert.assertTrue(server.getRemotingService().getConnections().isEmpty());
session.close();
csf.close();
locator.close();
}
use of org.apache.activemq.artemis.core.remoting.CloseListener in project activemq-artemis by apache.
the class ServerSessionPacketHandler method internaltransferConnection.
private int internaltransferConnection(final CoreRemotingConnection newConnection, final int lastReceivedCommandID) {
// We need to disable delivery on all the consumers while the transfer is occurring- otherwise packets might get
// delivered
// after the channel has transferred but *before* packets have been replayed - this will give the client the wrong
// sequence of packets.
// It is not sufficient to just stop the session, since right after stopping the session, another session start
// might be executed
// before we have transferred the connection, leaving it in a started state
session.setTransferring(true);
List<CloseListener> closeListeners = remotingConnection.removeCloseListeners();
List<FailureListener> failureListeners = remotingConnection.removeFailureListeners();
// Note. We do not destroy the replicating connection here. In the case the live server has really crashed
// then the connection will get cleaned up anyway when the server ping timeout kicks in.
// In the case the live server is really still up, i.e. a split brain situation (or in tests), then closing
// the replicating connection will cause the outstanding responses to be be replayed on the live server,
// if these reach the client who then subsequently fails over, on reconnection to backup, it will have
// received responses that the backup did not know about.
channel.transferConnection(newConnection);
newConnection.syncIDGeneratorSequence(remotingConnection.getIDGeneratorSequence());
Connection oldTransportConnection = remotingConnection.getTransportConnection();
remotingConnection = newConnection;
remotingConnection.setCloseListeners(closeListeners);
remotingConnection.setFailureListeners(failureListeners);
int serverLastReceivedCommandID = channel.getLastConfirmedCommandID();
channel.replayCommands(lastReceivedCommandID);
channel.setTransferring(false);
session.setTransferring(false);
// We do this because the old connection could be out of credits on netty
// this will force anything to resume after the reattach through the ReadyListener callbacks
oldTransportConnection.fireReady(true);
return serverLastReceivedCommandID;
}
use of org.apache.activemq.artemis.core.remoting.CloseListener in project activemq-artemis by apache.
the class TemporaryQueueTest method testDeleteTemporaryQueueAfterConnectionIsClosed.
@Test
public void testDeleteTemporaryQueueAfterConnectionIsClosed() throws Exception {
SimpleString queue = RandomUtil.randomSimpleString();
SimpleString address = RandomUtil.randomSimpleString();
session.createTemporaryQueue(address, queue);
RemotingConnectionImpl conn = (RemotingConnectionImpl) server.getRemotingService().getConnections().iterator().next();
final CountDownLatch latch = new CountDownLatch(1);
conn.addCloseListener(new CloseListener() {
@Override
public void connectionClosed() {
latch.countDown();
}
});
session.close();
sf.close();
// wait for the closing listeners to be fired
assertTrue("connection close listeners not fired", latch.await(2 * TemporaryQueueTest.CONNECTION_TTL, TimeUnit.MILLISECONDS));
sf = addSessionFactory(createSessionFactory(locator));
session = sf.createSession(false, true, true);
session.start();
try {
session.createConsumer(queue);
fail("temp queue must not exist after the remoting connection is closed");
} catch (ActiveMQNonExistentQueueException neqe) {
// ol
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
session.close();
}
Aggregations