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();
}
}
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());
}
Aggregations