Search in sources :

Example 81 with RemotingConnection

use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.

the class BindingsClusterTest method crash.

private void crash() throws Exception {
    /*
       * Rather than just calling stop() on the server here we want to simulate an actual node crash or bridge failure
       * so the bridge's failure listener needs to get something other than a DISCONNECTED message.  In this case we
       * simulate a NOT_CONNECTED exception.
       */
    final CountDownLatch latch = new CountDownLatch(1);
    ClusterConnectionImpl next = (ClusterConnectionImpl) server1.getClusterManager().getClusterConnections().iterator().next();
    BridgeImpl bridge = (BridgeImpl) next.getRecords().values().iterator().next().getBridge();
    RemotingConnection forwardingConnection = getForwardingConnection(bridge);
    forwardingConnection.addFailureListener(new FailureListener() {

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver) {
            latch.countDown();
        }

        @Override
        public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) {
            connectionFailed(me, failedOver);
        }
    });
    forwardingConnection.fail(new ActiveMQNotConnectedException());
    assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
    if (crash) {
        jmsServer2.stop();
    }
}
Also used : BridgeImpl(org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) FailureListener(org.apache.activemq.artemis.core.remoting.FailureListener) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterConnectionImpl(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)

Example 82 with RemotingConnection

use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.

the class JMSFailoverTest method testSendReceiveLargeMessages.

@Test
public void testSendReceiveLargeMessages() throws Exception {
    SimpleString QUEUE = new SimpleString("somequeue");
    ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc, backuptc);
    jbcf.setReconnectAttempts(-1);
    jbcf.setBlockOnDurableSend(true);
    jbcf.setBlockOnNonDurableSend(true);
    jbcf.setMinLargeMessageSize(1024);
    // jbcf.setConsumerWindowSize(0);
    // jbcf.setMinLargeMessageSize(1024);
    final CountDownLatch flagAlign = new CountDownLatch(1);
    final CountDownLatch waitToKill = new CountDownLatch(1);
    final AtomicBoolean killed = new AtomicBoolean(false);
    jbcf.getServerLocator().addIncomingInterceptor(new Interceptor() {

        int count = 0;

        @Override
        public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
            if (packet instanceof SessionReceiveContinuationMessage) {
                if (count++ == 300 && !killed.get()) {
                    System.out.println("sending countDown on latch waitToKill");
                    killed.set(true);
                    waitToKill.countDown();
                }
            }
            return true;
        }
    });
    Connection conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5);
    Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
    final ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession();
    // The thread that will fail the server
    Thread spoilerThread = new Thread() {

        @Override
        public void run() {
            flagAlign.countDown();
            // a large timeout just to help in case of debugging
            try {
                waitToKill.await(120, TimeUnit.SECONDS);
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                System.out.println("Killing server...");
                JMSUtil.crash(liveServer, coreSession);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    coreSession.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, true);
    Queue queue = sess.createQueue("somequeue");
    MessageProducer producer = sess.createProducer(queue);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
    for (int i = 0; i < 100; i++) {
        TextMessage message = sess.createTextMessage(new String(new byte[10 * 1024]));
        producer.send(message);
        if (i % 10 == 0) {
            sess.commit();
        }
    }
    sess.commit();
    conn.start();
    spoilerThread.start();
    assertTrue(flagAlign.await(10, TimeUnit.SECONDS));
    MessageConsumer consumer = sess.createConsumer(queue);
    // this test is not meant to validate transactionality during Failover as that would require XA and recovery
    for (int i = 0; i < 90; i++) {
        TextMessage message = null;
        int retryNrs = 0;
        do {
            retryNrs++;
            try {
                message = (TextMessage) consumer.receive(5000);
                assertNotNull(message);
                break;
            } catch (JMSException e) {
                new Exception("Exception on receive message", e).printStackTrace();
            }
        } while (retryNrs < 10);
        assertNotNull(message);
        try {
            sess.commit();
        } catch (Exception e) {
            new Exception("Exception during commit", e);
            sess.rollback();
        }
    }
    conn.close();
    spoilerThread.join();
}
Also used : Packet(org.apache.activemq.artemis.core.protocol.core.Packet) SessionReceiveContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionReceiveContinuationMessage) MessageConsumer(javax.jms.MessageConsumer) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JMSException(javax.jms.JMSException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) JMSException(javax.jms.JMSException) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) MessageProducer(javax.jms.MessageProducer) Interceptor(org.apache.activemq.artemis.api.core.Interceptor) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 83 with RemotingConnection

use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.

the class CloseConnectionOnGCTest method testCloseSeveralConnectionsWithSessionsOnGC.

@Test
public void testCloseSeveralConnectionsWithSessionsOnGC() throws Exception {
    Connection conn1 = cf.createConnection();
    Connection conn2 = cf.createConnection();
    Connection conn3 = cf.createConnection();
    WeakReference<Connection> wr1 = new WeakReference<>(conn1);
    WeakReference<Connection> wr2 = new WeakReference<>(conn2);
    WeakReference<Connection> wr3 = new WeakReference<>(conn3);
    Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session sess2 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session sess3 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session sess4 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session sess5 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session sess6 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session sess7 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final CountDownLatch latch = new CountDownLatch(3);
    Iterator<RemotingConnection> connectionIterator = server.getRemotingService().getConnections().iterator();
    while (connectionIterator.hasNext()) {
        RemotingConnection remotingConnection = connectionIterator.next();
        remotingConnection.addCloseListener(new CloseListener() {

            @Override
            public void connectionClosed() {
                latch.countDown();
            }
        });
    }
    sess1 = sess2 = sess3 = sess4 = sess5 = sess6 = sess7 = null;
    conn1 = null;
    conn2 = null;
    conn3 = null;
    ActiveMQTestBase.checkWeakReferences(wr1, wr2, wr3);
    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) Session(javax.jms.Session) Test(org.junit.Test)

Example 84 with RemotingConnection

use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.

the class CloseConnectionOnGCTest method testCloseSeveralConnectionOnGC.

@Test
public void testCloseSeveralConnectionOnGC() throws Exception {
    Connection conn1 = cf.createConnection();
    Connection conn2 = cf.createConnection();
    Connection conn3 = cf.createConnection();
    WeakReference<Connection> wr1 = new WeakReference<>(conn1);
    WeakReference<Connection> wr2 = new WeakReference<>(conn2);
    WeakReference<Connection> wr3 = new WeakReference<>(conn3);
    Assert.assertEquals(3, server.getRemotingService().getConnections().size());
    final CountDownLatch latch = new CountDownLatch(3);
    Iterator<RemotingConnection> connectionIterator = server.getRemotingService().getConnections().iterator();
    while (connectionIterator.hasNext()) {
        RemotingConnection remotingConnection = connectionIterator.next();
        remotingConnection.addCloseListener(new CloseListener() {

            @Override
            public void connectionClosed() {
                latch.countDown();
            }
        });
    }
    conn1 = null;
    conn2 = null;
    conn3 = null;
    ActiveMQTestBase.checkWeakReferences(wr1, wr2, wr3);
    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)

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