use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection in project activemq-artemis by apache.
the class CertificateUtil method getPeerPrincipalFromConnection.
public static Principal getPeerPrincipalFromConnection(RemotingConnection remotingConnection) {
Principal result = null;
if (remotingConnection != null) {
Connection transportConnection = remotingConnection.getTransportConnection();
if (transportConnection instanceof NettyConnection) {
NettyConnection nettyConnection = (NettyConnection) transportConnection;
ChannelHandler channelHandler = nettyConnection.getChannel().pipeline().get("ssl");
if (channelHandler != null && channelHandler instanceof SslHandler) {
SslHandler sslHandler = (SslHandler) channelHandler;
try {
result = sslHandler.engine().getSession().getPeerPrincipal();
} catch (SSLPeerUnverifiedException ignored) {
}
}
}
}
return result;
}
use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection 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();
}
}
use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection in project activemq-artemis by apache.
the class NettyConnectionTest method testCreateBuffer.
@Test
public void testCreateBuffer() throws Exception {
EmbeddedChannel channel = createChannel();
NettyConnection conn = new NettyConnection(emptyMap, channel, new MyListener(), false, false);
final int size = 1234;
ActiveMQBuffer buff = conn.createTransportBuffer(size);
// Netty buffer does lazy initialization.
buff.writeByte((byte) 0x00);
Assert.assertEquals(size, buff.capacity());
}
use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection in project activemq-artemis by apache.
the class NettyConnectionTest method testGetID.
@Test
public void testGetID() throws Exception {
Channel channel = createChannel();
NettyConnection conn = new NettyConnection(emptyMap, channel, new MyListener(), false, false);
Assert.assertEquals(channel.id(), conn.getID());
}
use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection in project activemq-artemis by apache.
the class NettyConnectionTest method throwsExceptionOnBlockUntilWritableIfClosed.
@Test(expected = IllegalStateException.class)
public void throwsExceptionOnBlockUntilWritableIfClosed() {
EmbeddedChannel channel = createChannel();
NettyConnection conn = new NettyConnection(emptyMap, channel, new MyListener(), false, false);
conn.close();
// to make sure the channel is closed it needs to run the pending tasks
channel.runPendingTasks();
conn.blockUntilWritable(0, 0, TimeUnit.NANOSECONDS);
}
Aggregations