Add test to verify that its possible to add another ChannelInitializer in the initChannel(...) method.
Motivation: I received a report the its not possible to add another ChannelInitialiter in the initChannel(...) method, so we should add a test case for it. Modifications: Added testcase. Result: Validate that all works as expected.
This commit is contained in:
parent
4638df2062
commit
b97a36a10f
@ -17,6 +17,7 @@ package io.netty.channel;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import io.netty.channel.local.LocalAddress;
|
||||
import io.netty.channel.local.LocalChannel;
|
||||
import io.netty.channel.local.LocalServerChannel;
|
||||
@ -25,9 +26,11 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ChannelInitializerTest {
|
||||
private static final int TIMEOUT_MILLIS = 1000;
|
||||
@ -76,6 +79,38 @@ public class ChannelInitializerTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddFirstChannelInitializer() {
|
||||
testAddChannelInitializer(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddLastChannelInitializer() {
|
||||
testAddChannelInitializer(false);
|
||||
}
|
||||
|
||||
private static void testAddChannelInitializer(final boolean first) {
|
||||
final AtomicBoolean called = new AtomicBoolean();
|
||||
EmbeddedChannel channel = new EmbeddedChannel(new ChannelInitializer<Channel>() {
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception {
|
||||
ChannelHandler handler = new ChannelInitializer<Channel>() {
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception {
|
||||
called.set(true);
|
||||
}
|
||||
};
|
||||
if (first) {
|
||||
ch.pipeline().addFirst(handler);
|
||||
} else {
|
||||
ch.pipeline().addLast(handler);
|
||||
}
|
||||
}
|
||||
});
|
||||
channel.finish();
|
||||
assertTrue(called.get());
|
||||
}
|
||||
|
||||
private void testChannelRegisteredEventPropagation(ChannelInitializer<LocalChannel> init) {
|
||||
Channel clientChannel = null, serverChannel = null;
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user