use of org.junit.jupiter.api.Timeout in project netty by netty.
the class ParameterizedSslHandlerTest method reentryOnHandshakeCompleteNioChannel.
@ParameterizedTest(name = PARAMETERIZED_NAME)
@MethodSource("data")
@Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
public void reentryOnHandshakeCompleteNioChannel(SslProvider clientProvider, SslProvider serverProvider) throws Exception {
EventLoopGroup group = new NioEventLoopGroup();
try {
Class<? extends ServerChannel> serverClass = NioServerSocketChannel.class;
Class<? extends Channel> clientClass = NioSocketChannel.class;
SocketAddress bindAddress = new InetSocketAddress(0);
reentryOnHandshakeComplete(clientProvider, serverProvider, group, bindAddress, serverClass, clientClass, false, false);
reentryOnHandshakeComplete(clientProvider, serverProvider, group, bindAddress, serverClass, clientClass, false, true);
reentryOnHandshakeComplete(clientProvider, serverProvider, group, bindAddress, serverClass, clientClass, true, false);
reentryOnHandshakeComplete(clientProvider, serverProvider, group, bindAddress, serverClass, clientClass, true, true);
} finally {
group.shutdownGracefully();
}
}
use of org.junit.jupiter.api.Timeout in project netty by netty.
the class ParameterizedSslHandlerTest method reentryOnHandshakeCompleteLocalChannel.
@ParameterizedTest(name = PARAMETERIZED_NAME)
@MethodSource("data")
@Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
public void reentryOnHandshakeCompleteLocalChannel(SslProvider clientProvider, SslProvider serverProvider) throws Exception {
EventLoopGroup group = new DefaultEventLoopGroup();
try {
Class<? extends ServerChannel> serverClass = LocalServerChannel.class;
Class<? extends Channel> clientClass = LocalChannel.class;
SocketAddress bindAddress = new LocalAddress(String.valueOf(current().nextLong()));
reentryOnHandshakeComplete(clientProvider, serverProvider, group, bindAddress, serverClass, clientClass, false, false);
reentryOnHandshakeComplete(clientProvider, serverProvider, group, bindAddress, serverClass, clientClass, false, true);
reentryOnHandshakeComplete(clientProvider, serverProvider, group, bindAddress, serverClass, clientClass, true, false);
reentryOnHandshakeComplete(clientProvider, serverProvider, group, bindAddress, serverClass, clientClass, true, true);
} finally {
group.shutdownGracefully();
}
}
use of org.junit.jupiter.api.Timeout in project netty by netty.
the class LocalTransportThreadModelTest method testStagedExecution.
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testStagedExecution() throws Throwable {
EventLoopGroup l = new DefaultEventLoopGroup(4, new DefaultThreadFactory("l"));
EventExecutorGroup e1 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e1"));
EventExecutorGroup e2 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e2"));
ThreadNameAuditor h1 = new ThreadNameAuditor();
ThreadNameAuditor h2 = new ThreadNameAuditor();
ThreadNameAuditor h3 = new ThreadNameAuditor(true);
Channel ch = new LocalChannel();
// With no EventExecutor specified, h1 will be always invoked by EventLoop 'l'.
ch.pipeline().addLast(h1);
// h2 will be always invoked by EventExecutor 'e1'.
ch.pipeline().addLast(e1, h2);
// h3 will be always invoked by EventExecutor 'e2'.
ch.pipeline().addLast(e2, h3);
l.register(ch).sync().channel().connect(localAddr).sync();
// Fire inbound events from all possible starting points.
ch.pipeline().fireChannelRead("1");
ch.pipeline().context(h1).fireChannelRead("2");
ch.pipeline().context(h2).fireChannelRead("3");
ch.pipeline().context(h3).fireChannelRead("4");
// Fire outbound events from all possible starting points.
ch.pipeline().write("5");
ch.pipeline().context(h3).write("6");
ch.pipeline().context(h2).write("7");
ch.pipeline().context(h1).writeAndFlush("8").sync();
ch.close().sync();
// Wait until all events are handled completely.
while (h1.outboundThreadNames.size() < 3 || h3.inboundThreadNames.size() < 3 || h1.removalThreadNames.size() < 1) {
if (h1.exception.get() != null) {
throw h1.exception.get();
}
if (h2.exception.get() != null) {
throw h2.exception.get();
}
if (h3.exception.get() != null) {
throw h3.exception.get();
}
Thread.sleep(10);
}
String currentName = Thread.currentThread().getName();
try {
// Events should never be handled from the current thread.
assertFalse(h1.inboundThreadNames.contains(currentName));
assertFalse(h2.inboundThreadNames.contains(currentName));
assertFalse(h3.inboundThreadNames.contains(currentName));
assertFalse(h1.outboundThreadNames.contains(currentName));
assertFalse(h2.outboundThreadNames.contains(currentName));
assertFalse(h3.outboundThreadNames.contains(currentName));
assertFalse(h1.removalThreadNames.contains(currentName));
assertFalse(h2.removalThreadNames.contains(currentName));
assertFalse(h3.removalThreadNames.contains(currentName));
// Assert that events were handled by the correct executor.
for (String name : h1.inboundThreadNames) {
assertTrue(name.startsWith("l-"));
}
for (String name : h2.inboundThreadNames) {
assertTrue(name.startsWith("e1-"));
}
for (String name : h3.inboundThreadNames) {
assertTrue(name.startsWith("e2-"));
}
for (String name : h1.outboundThreadNames) {
assertTrue(name.startsWith("l-"));
}
for (String name : h2.outboundThreadNames) {
assertTrue(name.startsWith("e1-"));
}
for (String name : h3.outboundThreadNames) {
assertTrue(name.startsWith("e2-"));
}
for (String name : h1.removalThreadNames) {
assertTrue(name.startsWith("l-"));
}
for (String name : h2.removalThreadNames) {
assertTrue(name.startsWith("e1-"));
}
for (String name : h3.removalThreadNames) {
assertTrue(name.startsWith("e2-"));
}
// Assert that the events for the same handler were handled by the same thread.
Set<String> names = new HashSet<String>();
names.addAll(h1.inboundThreadNames);
names.addAll(h1.outboundThreadNames);
names.addAll(h1.removalThreadNames);
assertEquals(1, names.size());
names.clear();
names.addAll(h2.inboundThreadNames);
names.addAll(h2.outboundThreadNames);
names.addAll(h2.removalThreadNames);
assertEquals(1, names.size());
names.clear();
names.addAll(h3.inboundThreadNames);
names.addAll(h3.outboundThreadNames);
names.addAll(h3.removalThreadNames);
assertEquals(1, names.size());
// Count the number of events
assertEquals(1, h1.inboundThreadNames.size());
assertEquals(2, h2.inboundThreadNames.size());
assertEquals(3, h3.inboundThreadNames.size());
assertEquals(3, h1.outboundThreadNames.size());
assertEquals(2, h2.outboundThreadNames.size());
assertEquals(1, h3.outboundThreadNames.size());
assertEquals(1, h1.removalThreadNames.size());
assertEquals(1, h2.removalThreadNames.size());
assertEquals(1, h3.removalThreadNames.size());
} catch (AssertionError e) {
System.out.println("H1I: " + h1.inboundThreadNames);
System.out.println("H2I: " + h2.inboundThreadNames);
System.out.println("H3I: " + h3.inboundThreadNames);
System.out.println("H1O: " + h1.outboundThreadNames);
System.out.println("H2O: " + h2.outboundThreadNames);
System.out.println("H3O: " + h3.outboundThreadNames);
System.out.println("H1R: " + h1.removalThreadNames);
System.out.println("H2R: " + h2.removalThreadNames);
System.out.println("H3R: " + h3.removalThreadNames);
throw e;
} finally {
l.shutdownGracefully();
e1.shutdownGracefully();
e2.shutdownGracefully();
l.terminationFuture().sync();
e1.terminationFuture().sync();
e2.terminationFuture().sync();
}
}
use of org.junit.jupiter.api.Timeout in project netty by netty.
the class DefaultChannelPipelineTest method testAddRemoveHandlerCalledOnceRegistered.
@Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testAddRemoveHandlerCalledOnceRegistered() throws Throwable {
ChannelPipeline pipeline = new LocalChannel().pipeline();
CallbackCheckHandler handler = new CallbackCheckHandler();
pipeline.addFirst(handler);
pipeline.remove(handler);
assertNull(handler.addedHandler.getNow());
assertNull(handler.removedHandler.getNow());
group.register(pipeline.channel()).syncUninterruptibly();
Throwable cause = handler.error.get();
if (cause != null) {
throw cause;
}
assertTrue(handler.addedHandler.get());
assertTrue(handler.removedHandler.get());
}
use of org.junit.jupiter.api.Timeout in project netty by netty.
the class DefaultChannelPipelineTest method testAddHandlerBeforeRegisteredThenReplace.
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testAddHandlerBeforeRegisteredThenReplace() throws Exception {
final EventLoop loop = group.next();
final CountDownLatch latch = new CountDownLatch(1);
CheckEventExecutorHandler handler = new CheckEventExecutorHandler(loop);
ChannelPipeline pipeline = new LocalChannel().pipeline();
pipeline.addFirst(handler);
assertFalse(handler.addedPromise.isDone());
group.register(pipeline.channel());
handler.addedPromise.syncUninterruptibly();
pipeline.replace(handler, null, new ChannelHandlerAdapter() {
@Override
public void handlerAdded(ChannelHandlerContext ctx) {
latch.countDown();
}
});
handler.removedPromise.syncUninterruptibly();
latch.await();
}
Aggregations