use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection 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.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class CloseDestroyedConnectionTest method testCloseDestroyedConnection.
/*
* Closing a connection that is destroyed should cleanly close everything without throwing exceptions
*/
@Test
public void testCloseDestroyedConnection() throws Exception {
long connectionTTL = 500;
cf.setClientFailureCheckPeriod(connectionTTL / 2);
// Need to set connection ttl to a low figure so connections get removed quickly on the server
cf.setConnectionTTL(connectionTTL);
conn = cf.createConnection();
Assert.assertEquals(1, server.getRemotingService().getConnections().size());
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Give time for the initial ping to reach the server before we fail (it has connection TTL in it)
Thread.sleep(500);
String queueName = "myqueue";
Queue queue = ActiveMQJMSClient.createQueue(queueName);
super.createQueue(queueName);
sess.createConsumer(queue);
sess.createProducer(queue);
sess.createBrowser(queue);
// Now fail the underlying connection
ClientSessionInternal sessi = (ClientSessionInternal) ((ActiveMQSession) sess).getCoreSession();
RemotingConnection rc = sessi.getConnection();
rc.fail(new ActiveMQInternalErrorException());
// Now close the connection
conn.close();
long start = System.currentTimeMillis();
while (true) {
int cons = server.getRemotingService().getConnections().size();
if (cons == 0) {
break;
}
long now = System.currentTimeMillis();
if (now - start > 10000) {
throw new Exception("Timed out waiting for connections to close");
}
Thread.sleep(50);
}
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class SessionClosedOnRemotingConnectionFailureTest method testSessionClosedOnRemotingConnectionFailure.
@Test
public void testSessionClosedOnRemotingConnectionFailure() throws Exception {
ClientSession session = addClientSession(sf.createSession());
session.createQueue("fooaddress", RoutingType.ANYCAST, "fooqueue");
ClientProducer prod = session.createProducer("fooaddress");
ClientConsumer cons = session.createConsumer("fooqueue");
session.start();
prod.send(session.createMessage(false));
Assert.assertNotNull(cons.receive());
// Now fail the underlying connection
RemotingConnection connection = ((ClientSessionInternal) session).getConnection();
connection.fail(new ActiveMQNotConnectedException());
Assert.assertTrue(session.isClosed());
Assert.assertTrue(prod.isClosed());
Assert.assertTrue(cons.isClosed());
try {
prod.send(session.createMessage(false));
Assert.fail("Should throw exception");
} catch (ActiveMQObjectClosedException oce) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
try {
cons.receive();
Assert.fail("Should throw exception");
} catch (ActiveMQObjectClosedException oce) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
session.close();
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class BridgeReconnectTest method testDeliveringCountOnBridgeConnectionFailure.
@Test
public void testDeliveringCountOnBridgeConnectionFailure() throws Exception {
server0 = createActiveMQServer(0, isNetty(), server0Params);
TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params, "server0tc");
server0.getConfiguration().setConnectorConfigurations(connectors);
BridgeConfiguration bridgeConfiguration = createBridgeConfig();
List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
bridgeConfigs.add(bridgeConfiguration);
server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName);
List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
queueConfigs0.add(queueConfig0);
server0.getConfiguration().setQueueConfigurations(queueConfigs0);
CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName);
List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
queueConfigs1.add(queueConfig1);
server1.getConfiguration().setQueueConfigurations(queueConfigs1);
startServers();
locator = addServerLocator(ActiveMQClient.createServerLocatorWithHA(server0tc, server1tc));
ClientSessionFactory csf0 = locator.createSessionFactory(server0tc);
session0 = csf0.createSession(false, true, true);
ClientSessionFactory csf1 = locator.createSessionFactory(server1tc);
session1 = csf1.createSession(false, true, true);
ClientProducer prod0 = session0.createProducer(testAddress);
session1.start();
Bridge bridge = server0.getClusterManager().getBridges().get(bridgeName);
RemotingConnection forwardingConnection = getForwardingConnection(bridge);
InVMConnector.failOnCreateConnection = true;
InVMConnector.numberOfFailures = reconnectAttempts - 1;
// forwardingConnection.fail(new ActiveMQNotConnectedException());
final int numMessages = NUM_MESSAGES;
SimpleString propKey = new SimpleString("propkey");
final Queue queue = (Queue) server0.getPostOffice().getBinding(new SimpleString(queueName)).getBindable();
System.out.println("DeliveringCount: " + queue.getDeliveringCount());
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session0.createMessage(false);
message.putIntProperty(propKey, i);
prod0.send(message);
if (i == 50) {
forwardingConnection.fail(new ActiveMQException(ActiveMQExceptionType.UNBLOCKED));
}
}
for (int i = 0; i < 100 && queue.getDeliveringCount() != 0; i++) {
Thread.sleep(10);
}
System.out.println("Check.. DeliveringCount: " + queue.getDeliveringCount());
assertEquals("Delivering count of a source queue should be zero on connection failure", 0, queue.getDeliveringCount());
closeServers();
assertNoMoreConnections();
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class BridgeReconnectTest method getForwardingConnection.
private RemotingConnection getForwardingConnection(final Bridge bridge) throws Exception {
long start = System.currentTimeMillis();
do {
RemotingConnection forwardingConnection = ((BridgeImpl) bridge).getForwardingConnection();
if (forwardingConnection != null) {
return forwardingConnection;
}
Thread.sleep(10);
} while (System.currentTimeMillis() - start < 50000);
throw new IllegalStateException("Failed to get forwarding connection");
}
Aggregations