use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class AmqpInboundConnectionTest method testCloseIsSentOnConnectionClose.
@Test(timeout = 60000)
public void testCloseIsSentOnConnectionClose() throws Exception {
AmqpClient client = createAmqpClient();
AmqpConnection amqpConnection = client.connect();
try {
for (RemotingConnection connection : server.getRemotingService().getConnections()) {
server.getRemotingService().removeConnection(connection);
connection.disconnect(true);
}
Wait.assertTrue(amqpConnection::isClosed);
assertEquals(AmqpSupport.CONNECTION_FORCED, amqpConnection.getConnection().getRemoteCondition().getCondition());
} finally {
amqpConnection.close();
}
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class XaTimeoutTest method testTimeoutOnXACall.
// HORNETQ-1117 - Test that will timeout on a XA transaction and then will perform another XA operation
@Test
public void testTimeoutOnXACall() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
class SomeInterceptor implements Interceptor {
/* (non-Javadoc)
* @see Interceptor#intercept(org.apache.activemq.artemis.core.protocol.core.Packet, RemotingConnection)
*/
@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
if (packet instanceof SessionXAStartMessage) {
try {
latch.await(1, TimeUnit.MINUTES);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return true;
}
}
server.getRemotingService().addIncomingInterceptor(new SomeInterceptor());
ServerLocator locatorTimeout = createInVMNonHALocator().setCallTimeout(300);
ClientSessionFactory factoryTimeout = locatorTimeout.createSessionFactory();
final ClientSession sessionTimeout = factoryTimeout.createSession(true, false, false);
Xid xid = newXID();
boolean expectedException = false;
try {
sessionTimeout.start(xid, XAResource.TMNOFLAGS);
} catch (Exception e) {
expectedException = true;
e.printStackTrace();
}
assertTrue(expectedException);
// this will release the interceptor and the next response will be out of sync unless we do something about
latch.countDown();
sessionTimeout.setTransactionTimeout(30);
sessionTimeout.close();
factoryTimeout.close();
locatorTimeout.close();
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class StompPluginTest method createServer.
@Override
protected JMSServerManager createServer() throws Exception {
JMSServerManager server = super.createServer();
server.getActiveMQServer().registerBrokerPlugin(verifier);
server.getActiveMQServer().registerBrokerPlugin(new ActiveMQServerPlugin() {
@Override
public void beforeCreateSession(String name, String username, int minLargeMessageSize, RemotingConnection connection, boolean autoCommitSends, boolean autoCommitAcks, boolean preAcknowledge, boolean xa, String defaultAddress, SessionCallback callback, boolean autoCreateQueues, OperationContext context, Map<SimpleString, RoutingType> prefixes) throws ActiveMQException {
if (connection instanceof StompConnection) {
stompBeforeCreateSession.set(true);
}
}
@Override
public void beforeCloseSession(ServerSession session, boolean failed) throws ActiveMQException {
if (session.getRemotingConnection() instanceof StompConnection) {
stompBeforeRemoveSession.set(true);
}
}
});
return server;
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class NetworkAddressTestBase method testConnection.
public void testConnection(final String acceptorHost, final String connectorHost, final boolean mustConnect, final int localPort) throws Exception {
System.out.println("acceptor=" + acceptorHost + ", connector=" + connectorHost + ", mustConnect=" + mustConnect);
Map<String, Object> params = new HashMap<>();
params.put(getHostPropertyKey(), acceptorHost);
TransportConfiguration acceptorConfig = new TransportConfiguration(getAcceptorFactoryClassName(), params);
Set<TransportConfiguration> transportConfigs = new HashSet<>();
transportConfigs.add(acceptorConfig);
Configuration config = createDefaultNettyConfig();
config.setAcceptorConfigurations(transportConfigs);
ActiveMQServer messagingService = createServer(false, config);
try {
messagingService.start();
params = new HashMap<>();
params.put(getHostPropertyKey(), connectorHost);
if (localPort != 0) {
params.put(getLocalPortProperty(), localPort);
}
TransportConfiguration connectorConfig = new TransportConfiguration(getConnectorFactoryClassName(), params);
ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(connectorConfig));
if (mustConnect) {
ClientSessionFactory sf = createSessionFactory(locator);
if (localPort != 0) {
Iterator<RemotingConnection> iterator = messagingService.getRemotingService().getConnections().iterator();
Assert.assertTrue("no connection created", iterator.hasNext());
String address = iterator.next().getTransportConnection().getRemoteAddress();
Assert.assertTrue(address.endsWith(":" + localPort));
}
sf.close();
System.out.println("connection OK");
} else {
try {
locator.createSessionFactory();
Assert.fail("session creation must fail because connector must not be able to connect to the server bound to another network interface");
} catch (Exception e) {
}
}
} finally {
messagingService.stop();
}
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection 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();
}
Aggregations