Fixed RejectedExecutionException in the OIO-OIO SSL echo test

This commit is contained in:
Trustin Lee 2008-11-06 16:21:35 +00:00
parent 7db3eacbb4
commit 79fe2324c9

View File

@ -71,6 +71,7 @@ public abstract class AbstractSocketSslEchoTest {
static final byte[] data = new byte[1048576]; static final byte[] data = new byte[1048576];
private static ExecutorService executor; private static ExecutorService executor;
private static ExecutorService eventExecutor;
static { static {
random.nextBytes(data); random.nextBytes(data);
@ -79,6 +80,7 @@ public abstract class AbstractSocketSslEchoTest {
@BeforeClass @BeforeClass
public static void init() { public static void init() {
executor = Executors.newCachedThreadPool(); executor = Executors.newCachedThreadPool();
eventExecutor = new OrderedMemoryAwareThreadPoolExecutor(16, 0, 0);
} }
@AfterClass @AfterClass
@ -93,10 +95,18 @@ public abstract class AbstractSocketSslEchoTest {
// Ignore. // Ignore.
} }
} }
eventExecutor.shutdownNow();
for (;;) {
try {
if (eventExecutor.awaitTermination(1, TimeUnit.MILLISECONDS)) {
break;
}
} catch (InterruptedException e) {
// Ignore.
}
}
} }
private ExecutorService extraExecutor = null;
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);
protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor);
@ -104,15 +114,6 @@ public abstract class AbstractSocketSslEchoTest {
return false; return false;
} }
@After
public void shutdownExtraExecutor() {
if (extraExecutor != null) {
extraExecutor.shutdownNow();
extraExecutor = null;
}
}
@Test @Test
public void testSslEcho() throws Throwable { public void testSslEcho() throws Throwable {
ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor));
@ -136,9 +137,8 @@ public abstract class AbstractSocketSslEchoTest {
cb.getPipeline().addLast("handler", ch); cb.getPipeline().addLast("handler", ch);
if (isExecutorRequired()) { if (isExecutorRequired()) {
extraExecutor = new OrderedMemoryAwareThreadPoolExecutor(16, 0, 0); sb.getPipeline().addFirst("executor",new ExecutionHandler(eventExecutor));
sb.getPipeline().addFirst("executor",new ExecutionHandler(extraExecutor)); cb.getPipeline().addFirst("executor",new ExecutionHandler(eventExecutor));
cb.getPipeline().addFirst("executor",new ExecutionHandler(extraExecutor));
} }
Channel sc = sb.bind(new InetSocketAddress(0)); Channel sc = sb.bind(new InetSocketAddress(0));