|
21 | 21 | import io.netty.channel.Channel; |
22 | 22 | import io.netty.channel.ChannelHandlerContext; |
23 | 23 | import io.netty.channel.ChannelInboundHandlerAdapter; |
24 | | -import io.netty.channel.ChannelInitializer; |
25 | 24 | import io.netty.channel.ChannelOption; |
26 | 25 | import io.netty.channel.SimpleChannelInboundHandler; |
27 | | -import io.netty.util.concurrent.DefaultEventExecutorGroup; |
28 | | -import io.netty.util.concurrent.EventExecutorGroup; |
29 | 26 | import java.util.concurrent.TimeUnit; |
30 | 27 |
|
31 | | -import org.junit.jupiter.api.AfterAll; |
32 | | -import org.junit.jupiter.api.BeforeAll; |
33 | 28 | import org.junit.jupiter.api.Test; |
34 | 29 |
|
35 | 30 | import java.io.IOException; |
@@ -47,22 +42,10 @@ public class SocketEchoTest extends AbstractSocketTest { |
47 | 42 | private static final Random random = new Random(); |
48 | 43 | static final byte[] data = new byte[1048576]; |
49 | 44 |
|
50 | | - private static EventExecutorGroup group; |
51 | | - |
52 | 45 | static { |
53 | 46 | random.nextBytes(data); |
54 | 47 | } |
55 | 48 |
|
56 | | - @BeforeAll |
57 | | - public static void createGroup() { |
58 | | - group = new DefaultEventExecutorGroup(2); |
59 | | - } |
60 | | - |
61 | | - @AfterAll |
62 | | - public static void destroyGroup() throws Exception { |
63 | | - group.shutdownGracefully().sync(); |
64 | | - } |
65 | | - |
66 | 49 | @Test |
67 | 50 | @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS) |
68 | 51 | public void testSimpleEcho(TestInfo testInfo) throws Throwable { |
@@ -75,7 +58,7 @@ public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Thr |
75 | 58 | } |
76 | 59 |
|
77 | 60 | public void testSimpleEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { |
78 | | - testSimpleEcho0(sb, cb, false, false, true); |
| 61 | + testSimpleEcho0(sb, cb, false, true); |
79 | 62 | } |
80 | 63 |
|
81 | 64 | @Test |
@@ -90,35 +73,7 @@ public void run(ServerBootstrap sb1, Bootstrap cb1) throws Throwable { |
90 | 73 | } |
91 | 74 |
|
92 | 75 | public void testSimpleEchoNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { |
93 | | - testSimpleEcho0(sb, cb, false, false, false); |
94 | | - } |
95 | | - |
96 | | - @Test |
97 | | - public void testSimpleEchoWithAdditionalExecutor(TestInfo testInfo) throws Throwable { |
98 | | - run(testInfo, new Runner<ServerBootstrap, Bootstrap>() { |
99 | | - @Override |
100 | | - public void run(ServerBootstrap sb1, Bootstrap cb1) throws Throwable { |
101 | | - testSimpleEchoWithAdditionalExecutor(sb1, cb1); |
102 | | - } |
103 | | - }); |
104 | | - } |
105 | | - |
106 | | - public void testSimpleEchoWithAdditionalExecutor(ServerBootstrap sb, Bootstrap cb) throws Throwable { |
107 | | - testSimpleEcho0(sb, cb, true, false, true); |
108 | | - } |
109 | | - |
110 | | - @Test |
111 | | - public void testSimpleEchoWithAdditionalExecutorNotAutoRead(TestInfo testInfo) throws Throwable { |
112 | | - run(testInfo, new Runner<ServerBootstrap, Bootstrap>() { |
113 | | - @Override |
114 | | - public void run(ServerBootstrap sb1, Bootstrap cb1) throws Throwable { |
115 | | - testSimpleEchoWithAdditionalExecutorNotAutoRead(sb1, cb1); |
116 | | - } |
117 | | - }); |
118 | | - } |
119 | | - |
120 | | - public void testSimpleEchoWithAdditionalExecutorNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { |
121 | | - testSimpleEcho0(sb, cb, true, false, false); |
| 76 | + testSimpleEcho0(sb, cb, false, false); |
122 | 77 | } |
123 | 78 |
|
124 | 79 | @Test |
@@ -132,7 +87,7 @@ public void run(ServerBootstrap sb1, Bootstrap cb1) throws Throwable { |
132 | 87 | } |
133 | 88 |
|
134 | 89 | public void testSimpleEchoWithVoidPromise(ServerBootstrap sb, Bootstrap cb) throws Throwable { |
135 | | - testSimpleEcho0(sb, cb, false, true, true); |
| 90 | + testSimpleEcho0(sb, cb, true, true); |
136 | 91 | } |
137 | 92 |
|
138 | 93 | @Test |
@@ -146,54 +101,24 @@ public void run(ServerBootstrap sb1, Bootstrap cb1) throws Throwable { |
146 | 101 | } |
147 | 102 |
|
148 | 103 | public void testSimpleEchoWithVoidPromiseNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { |
149 | | - testSimpleEcho0(sb, cb, false, true, false); |
150 | | - } |
151 | | - |
152 | | - @Test |
153 | | - @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS) |
154 | | - public void testSimpleEchoWithAdditionalExecutorAndVoidPromise(TestInfo testInfo) throws Throwable { |
155 | | - run(testInfo, new Runner<ServerBootstrap, Bootstrap>() { |
156 | | - @Override |
157 | | - public void run(ServerBootstrap sb1, Bootstrap cb1) throws Throwable { |
158 | | - testSimpleEchoWithAdditionalExecutorAndVoidPromise(sb1, cb1); |
159 | | - } |
160 | | - }); |
161 | | - } |
162 | | - |
163 | | - public void testSimpleEchoWithAdditionalExecutorAndVoidPromise(ServerBootstrap sb, Bootstrap cb) throws Throwable { |
164 | | - testSimpleEcho0(sb, cb, true, true, true); |
| 104 | + testSimpleEcho0(sb, cb, true, false); |
165 | 105 | } |
166 | 106 |
|
167 | 107 | private static void testSimpleEcho0( |
168 | | - ServerBootstrap sb, Bootstrap cb, boolean additionalExecutor, boolean voidPromise, boolean autoRead) |
| 108 | + ServerBootstrap sb, Bootstrap cb, boolean voidPromise, boolean autoRead) |
169 | 109 | throws Throwable { |
170 | 110 |
|
171 | 111 | final EchoHandler sh = new EchoHandler(autoRead); |
172 | 112 | final EchoHandler ch = new EchoHandler(autoRead); |
173 | 113 |
|
174 | | - if (additionalExecutor) { |
175 | | - sb.childHandler(new ChannelInitializer<Channel>() { |
176 | | - @Override |
177 | | - protected void initChannel(Channel c) throws Exception { |
178 | | - c.pipeline().addLast(group, sh); |
179 | | - } |
180 | | - }); |
181 | | - cb.handler(new ChannelInitializer<Channel>() { |
182 | | - @Override |
183 | | - protected void initChannel(Channel c) throws Exception { |
184 | | - c.pipeline().addLast(group, ch); |
185 | | - } |
186 | | - }); |
187 | | - } else { |
188 | | - sb.childHandler(sh); |
189 | | - sb.handler(new ChannelInboundHandlerAdapter() { |
190 | | - @Override |
191 | | - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { |
192 | | - cause.printStackTrace(); |
193 | | - } |
194 | | - }); |
195 | | - cb.handler(ch); |
196 | | - } |
| 114 | + sb.childHandler(sh); |
| 115 | + sb.handler(new ChannelInboundHandlerAdapter() { |
| 116 | + @Override |
| 117 | + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { |
| 118 | + cause.printStackTrace(); |
| 119 | + } |
| 120 | + }); |
| 121 | + cb.handler(ch); |
197 | 122 | sb.childOption(ChannelOption.AUTO_READ, autoRead); |
198 | 123 | cb.option(ChannelOption.AUTO_READ, autoRead); |
199 | 124 |
|
|