Search in sources :

Example 6 with NettyConnection

use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection 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 7 with NettyConnection

use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection in project activemq-artemis by apache.

the class NettyConnectionTest method testWrite.

@Test
public void testWrite() throws Exception {
    ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(ByteBuffer.allocate(128));
    EmbeddedChannel channel = createChannel();
    Assert.assertEquals(0, channel.outboundMessages().size());
    NettyConnection conn = new NettyConnection(emptyMap, channel, new MyListener(), false, false);
    conn.write(buff);
    channel.runPendingTasks();
    Assert.assertEquals(1, channel.outboundMessages().size());
}
Also used : NettyConnection(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

NettyConnection (org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection)7 Test (org.junit.Test)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)2 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)2 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)2 ClientSessionFactoryImpl (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl)2 RemotingConnectionImpl (org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl)2 Channel (io.netty.channel.Channel)1 ChannelHandler (io.netty.channel.ChannelHandler)1 SslHandler (io.netty.handler.ssl.SslHandler)1 Principal (java.security.Principal)1 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)1 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)1 Connection (org.apache.activemq.artemis.spi.core.remoting.Connection)1