Search in sources :

Example 1 with RemotingConnectionImpl

use of org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl in project activemq-artemis by apache.

the class ConsumerStuckTest method testClientStuckTestWithDirectDelivery.

@Test
public void testClientStuckTestWithDirectDelivery() throws Exception {
    ServerLocator locator = createNettyNonHALocator().setConnectionTTL(1000).setClientFailureCheckPeriod(100).setConsumerWindowSize(10 * 1024 * 1024).setCallTimeout(1000);
    ClientSessionFactory sf = locator.createSessionFactory();
    ((ClientSessionFactoryImpl) sf).stopPingingAfterOne();
    RemotingConnectionImpl remotingConnection = (RemotingConnectionImpl) sf.getConnection();
    ClientSession session = sf.createSession(false, true, true, true);
    session.createQueue(QUEUE, QUEUE, null, false);
    final int numMessages = 10000;
    final ClientConsumer consumer = session.createConsumer(QUEUE);
    session.start();
    final NettyConnection nettyConnection = (NettyConnection) remotingConnection.getTransportConnection();
    Thread tReceive = new Thread() {

        @Override
        public void run() {
            boolean first = true;
            try {
                while (!Thread.interrupted()) {
                    ClientMessage received = consumer.receive(500);
                    System.out.println("Received " + received);
                    if (first) {
                        first = false;
                        nettyConnection.getNettyChannel().config().setAutoRead(false);
                    }
                    if (received != null) {
                        received.acknowledge();
                    }
                }
            } catch (Throwable e) {
                Thread.currentThread().interrupt();
                e.printStackTrace();
            }
        }
    };
    tReceive.start();
    Thread sender = new Thread() {

        @Override
        public void run() {
            try (ServerLocator locator = createNettyNonHALocator();
                ClientSessionFactory factory = locator.createSessionFactory();
                ClientSession session = factory.createSession(false, true, true, true);
                ClientProducer producer = session.createProducer(QUEUE)) {
                for (int i = 0; i < numMessages; i++) {
                    ClientMessage message = createTextMessage(session, "m" + i);
                    producer.send(message);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    sender.start();
    try {
        long timeout = System.currentTimeMillis() + 20000;
        while (System.currentTimeMillis() < timeout && server.getSessions().size() != 2) {
            Thread.sleep(10);
        }
        assertEquals(2, server.getSessions().size());
        System.out.println("sessions = " + server.getSessions().size());
        assertEquals(2, server.getConnectionCount());
        timeout = System.currentTimeMillis() + 20000;
        while (System.currentTimeMillis() < timeout && server.getSessions().size() != 1) {
            Thread.sleep(10);
        }
        System.out.println("Size = " + server.getConnectionCount());
        System.out.println("sessions = " + server.getSessions().size());
        if (server.getSessions().size() != 1) {
            System.out.println(threadDump("Thread dump"));
            fail("The cleanup wasn't able to finish cleaning the session. It's probably stuck, look at the thread dump generated by the test for more information");
        }
        sender.join();
        timeout = System.currentTimeMillis() + 20000;
        while (System.currentTimeMillis() < timeout && server.getConnectionCount() != 0) {
            Thread.sleep(10);
        }
        assertEquals(0, server.getConnectionCount());
    } finally {
        nettyConnection.getNettyChannel().config().setAutoRead(true);
        tReceive.interrupt();
        tReceive.join();
    }
}
Also used : NettyConnection(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection) RemotingConnectionImpl(org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientSessionFactoryImpl(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 2 with RemotingConnectionImpl

use of org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl in project activemq-artemis by apache.

the class ConsumerStuckTest method testClientStuckTest.

@Test
public void testClientStuckTest() throws Exception {
    ServerLocator locator = createNettyNonHALocator().setConnectionTTL(1000).setClientFailureCheckPeriod(100).setConsumerWindowSize(10 * 1024 * 1024).setCallTimeout(1000);
    ClientSessionFactory sf = locator.createSessionFactory();
    ((ClientSessionFactoryImpl) sf).stopPingingAfterOne();
    RemotingConnectionImpl remotingConnection = (RemotingConnectionImpl) sf.getConnection();
    ClientSession session = sf.createSession(false, true, true, true);
    session.createQueue(QUEUE, QUEUE, null, false);
    ClientProducer producer = session.createProducer(QUEUE);
    final int numMessages = 10000;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = createTextMessage(session, "m" + i);
        producer.send(message);
    }
    final ClientConsumer consumer = session.createConsumer(QUEUE);
    session.start();
    final NettyConnection nettyConnection = (NettyConnection) remotingConnection.getTransportConnection();
    Thread tReceive = new Thread() {

        @Override
        public void run() {
            boolean first = true;
            try {
                while (!Thread.interrupted()) {
                    ClientMessage received = consumer.receive(500);
                    System.out.println("Received " + received);
                    if (first) {
                        first = false;
                        nettyConnection.getNettyChannel().config().setAutoRead(false);
                    }
                    if (received != null) {
                        received.acknowledge();
                    }
                }
            } catch (Throwable e) {
                Thread.currentThread().interrupt();
                e.printStackTrace();
            }
        }
    };
    tReceive.start();
    try {
        assertEquals(1, server.getSessions().size());
        System.out.println("sessions = " + server.getSessions().size());
        assertEquals(1, server.getConnectionCount());
        long timeout = System.currentTimeMillis() + 20000;
        long timeStart = System.currentTimeMillis();
        while (timeout > System.currentTimeMillis() && (server.getSessions().size() != 0 || server.getConnectionCount() != 0)) {
            Thread.sleep(10);
        }
        System.out.println("Time = " + System.currentTimeMillis() + " time diff = " + (System.currentTimeMillis() - timeStart) + ", connections Size = " + server.getConnectionCount() + " sessions = " + server.getSessions().size());
        if (server.getSessions().size() != 0) {
            System.out.println(threadDump("Thread dump"));
            fail("The cleanup wasn't able to finish cleaning the session. It's probably stuck, look at the thread dump generated by the test for more information");
        }
        System.out.println("Size = " + server.getConnectionCount());
        System.out.println("sessions = " + server.getSessions().size());
        if (server.getSessions().size() != 0) {
            System.out.println(threadDump("Thread dump"));
            fail("The cleanup wasn't able to finish cleaning the session. It's probably stuck, look at the thread dump generated by the test for more information");
        }
        assertEquals(0, server.getConnectionCount());
    } finally {
        nettyConnection.getNettyChannel().config().setAutoRead(true);
        tReceive.interrupt();
        tReceive.join();
    }
}
Also used : NettyConnection(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection) RemotingConnectionImpl(org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientSessionFactoryImpl(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 3 with RemotingConnectionImpl

use of org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl in project activemq-artemis by apache.

the class OrderReattachTest method doTestOrderOnSend.

public void doTestOrderOnSend(final boolean isNetty) throws Throwable {
    server = createServer(false, isNetty);
    server.start();
    ServerLocator locator = createFactory(isNetty).setReconnectAttempts(15).setConfirmationWindowSize(1024 * 1024).setBlockOnNonDurableSend(false).setBlockOnAcknowledge(false);
    ClientSessionFactory sf = createSessionFactory(locator);
    final ClientSession session = sf.createSession(false, true, true);
    final LinkedBlockingDeque<Boolean> failureQueue = new LinkedBlockingDeque<>();
    final CountDownLatch ready = new CountDownLatch(1);
    // this test will use a queue. Whenever the test wants a failure.. it can just send TRUE to failureQueue
    // This Thread will be reading the queue
    Thread failer = new Thread() {

        @Override
        public void run() {
            ready.countDown();
            while (true) {
                try {
                    Boolean poll = false;
                    try {
                        poll = failureQueue.poll(60, TimeUnit.SECONDS);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        break;
                    }
                    Thread.sleep(1);
                    final RemotingConnectionImpl conn = (RemotingConnectionImpl) ((ClientSessionInternal) session).getConnection();
                    // True means... fail session
                    if (poll) {
                        conn.fail(new ActiveMQNotConnectedException("poop"));
                    } else {
                        // false means... finish thread
                        break;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    };
    failer.start();
    ready.await();
    try {
        doSend2(1, sf, failureQueue);
    } finally {
        try {
            session.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            locator.close();
        } catch (Exception e) {
        // 
        }
        try {
            sf.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        failureQueue.put(false);
        failer.join();
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) RemotingConnectionImpl(org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl) CountDownLatch(java.util.concurrent.CountDownLatch) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)

Example 4 with RemotingConnectionImpl

use of org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl in project activemq-artemis by apache.

the class TemporaryQueueTest method testDeleteTemporaryQueueAfterConnectionIsClosed.

@Test
public void testDeleteTemporaryQueueAfterConnectionIsClosed() throws Exception {
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString address = RandomUtil.randomSimpleString();
    session.createTemporaryQueue(address, queue);
    RemotingConnectionImpl conn = (RemotingConnectionImpl) server.getRemotingService().getConnections().iterator().next();
    final CountDownLatch latch = new CountDownLatch(1);
    conn.addCloseListener(new CloseListener() {

        @Override
        public void connectionClosed() {
            latch.countDown();
        }
    });
    session.close();
    sf.close();
    // wait for the closing listeners to be fired
    assertTrue("connection close listeners not fired", latch.await(2 * TemporaryQueueTest.CONNECTION_TTL, TimeUnit.MILLISECONDS));
    sf = addSessionFactory(createSessionFactory(locator));
    session = sf.createSession(false, true, true);
    session.start();
    try {
        session.createConsumer(queue);
        fail("temp queue must not exist after the remoting connection is closed");
    } catch (ActiveMQNonExistentQueueException neqe) {
    // ol
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    session.close();
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) CloseListener(org.apache.activemq.artemis.core.remoting.CloseListener) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) RemotingConnectionImpl(org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) Test(org.junit.Test)

Example 5 with RemotingConnectionImpl

use of org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl in project activemq-artemis by apache.

the class TemporaryQueueTest method testRecreateConsumerOverServerFailure.

@Test
public void testRecreateConsumerOverServerFailure() throws Exception {
    ServerLocator serverWithReattach = createInVMNonHALocator().setReconnectAttempts(30).setRetryInterval(1000).setConfirmationWindowSize(-1).setConnectionTTL(TemporaryQueueTest.CONNECTION_TTL).setClientFailureCheckPeriod(TemporaryQueueTest.CONNECTION_TTL / 3);
    ClientSessionFactory reattachSF = createSessionFactory(serverWithReattach);
    ClientSession session = reattachSF.createSession(false, false);
    session.createTemporaryQueue("tmpAd", "tmpQ");
    ClientConsumer consumer = session.createConsumer("tmpQ");
    ClientProducer prod = session.createProducer("tmpAd");
    session.start();
    RemotingConnectionImpl conn = (RemotingConnectionImpl) ((ClientSessionInternal) session).getConnection();
    conn.fail(new ActiveMQIOErrorException());
    prod.send(session.createMessage(false));
    session.commit();
    assertNotNull(consumer.receive(1000));
    session.close();
    reattachSF.close();
    serverWithReattach.close();
}
Also used : ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) RemotingConnectionImpl(org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Aggregations

RemotingConnectionImpl (org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl)5 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)4 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)4 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)4 Test (org.junit.Test)4 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)3 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 ClientSessionFactoryImpl (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl)2 NettyConnection (org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection)2 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQIOErrorException (org.apache.activemq.artemis.api.core.ActiveMQIOErrorException)1 ActiveMQNonExistentQueueException (org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException)1 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 CloseListener (org.apache.activemq.artemis.core.remoting.CloseListener)1