use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.Ping in project activemq-artemis by apache.
the class PingTest method testNoPingingOnInVMConnection.
/*
* Test that pinging is disabled for in-vm connection when using the default settings
*/
@Test
public void testNoPingingOnInVMConnection() throws Exception {
// server should receive one and only one ping from the client so that
// the server connection TTL is configured with the client value
final CountDownLatch requiredPings = new CountDownLatch(1);
final CountDownLatch unwantedPings = 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) {
Assert.assertEquals(ActiveMQClient.DEFAULT_CONNECTION_TTL_INVM, ((Ping) packet).getConnectionTTL());
unwantedPings.countDown();
requiredPings.countDown();
}
return true;
}
});
TransportConfiguration transportConfig = new TransportConfiguration("org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory");
ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(transportConfig));
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession session = csf.createSession(false, true, true);
Assert.assertEquals(1, ((ClientSessionFactoryInternal) csf).numConnections());
Assert.assertTrue("server didn't received an expected ping from the client", requiredPings.await(5000, TimeUnit.MILLISECONDS));
Assert.assertFalse("server received an unexpected ping from the client", unwantedPings.await(ActiveMQClient.DEFAULT_CONNECTION_TTL * 2, TimeUnit.MILLISECONDS));
session.close();
csf.close();
locator.close();
}
use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.Ping in project activemq-artemis by apache.
the class ActiveMQClientProtocolManager method ping.
@Override
public void ping(long connectionTTL) {
Channel channel = connection.getChannel(ChannelImpl.CHANNEL_ID.PING.id, -1);
Ping ping = new Ping(connectionTTL);
channel.send(ping);
connection.flush();
}
Aggregations