Search in sources :

Example 31 with RemotingConnection

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());
}
Also used : CloseListener(org.apache.activemq.artemis.core.remoting.CloseListener) WeakReference(java.lang.ref.WeakReference) Connection(javax.jms.Connection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 32 with RemotingConnection

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);
    }
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) Queue(javax.jms.Queue) JMSException(javax.jms.JMSException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) Test(org.junit.Test)

Example 33 with RemotingConnection

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();
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQObjectClosedException(org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 34 with RemotingConnection

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();
}
Also used : BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) ArrayList(java.util.ArrayList) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) Bridge(org.apache.activemq.artemis.core.server.cluster.Bridge) Test(org.junit.Test)

Example 35 with RemotingConnection

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");
}
Also used : BridgeImpl(org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)

Aggregations

RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)84 Test (org.junit.Test)44 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)36 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)31 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)30 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)22 ClientSessionInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionInternal)21 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)17 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)16 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)16 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)15 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)14 CoreRemotingConnection (org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection)13 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)12 Connection (javax.jms.Connection)11 Interceptor (org.apache.activemq.artemis.api.core.Interceptor)11 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)11 Session (javax.jms.Session)10