Simplified some test code using ChannelFactoryResource.release()

This commit is contained in:
Trustin Lee 2008-11-26 10:22:55 +00:00
parent 5a4e0e4d47
commit 96c98f636a
2 changed files with 9 additions and 54 deletions

View File

@ -28,9 +28,7 @@ import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel; import java.nio.channels.ServerSocketChannel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.jboss.netty.bootstrap.ClientBootstrap; import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ChannelFuture;
@ -60,9 +58,10 @@ public class NioClientSocketShutdownTimeTest {
ServerSocketChannel serverSocket = ServerSocketChannel.open(); ServerSocketChannel serverSocket = ServerSocketChannel.open();
serverSocket.socket().bind(new InetSocketAddress(0)); serverSocket.socket().bind(new InetSocketAddress(0));
ExecutorService e1 = Executors.newCachedThreadPool(); ClientBootstrap b = new ClientBootstrap(
ExecutorService e2 = Executors.newCachedThreadPool(); new NioClientSocketChannelFactory(
ClientBootstrap b = new ClientBootstrap(new NioClientSocketChannelFactory(e1, e2)); Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
b.getPipeline().addLast("handler", new DummyHandler()); b.getPipeline().addLast("handler", new DummyHandler());
long startTime; long startTime;
@ -86,26 +85,7 @@ public class NioClientSocketShutdownTimeTest {
f.getChannel().close().awaitUninterruptibly(); f.getChannel().close().awaitUninterruptibly();
} finally { } finally {
assertEquals(0, e1.shutdownNow().size()); b.getFactory().getExternalResource().release();
assertEquals(0, e2.shutdownNow().size());
for (;;) {
try {
if (e1.awaitTermination(1, TimeUnit.SECONDS)) {
break;
}
} catch (InterruptedException ex) {
// Ignore
}
}
for (;;) {
try {
if (e2.awaitTermination(1, TimeUnit.SECONDS)) {
break;
}
} catch (InterruptedException ex) {
// Ignore
}
}
try { try {
serverSocket.close(); serverSocket.close();

View File

@ -28,9 +28,7 @@ import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.Channel;
@ -60,11 +58,10 @@ public class NioServerSocketShutdownTimeTest {
@Test(timeout = 10000) @Test(timeout = 10000)
public void testSuccessfulBindAttempt() throws Exception { public void testSuccessfulBindAttempt() throws Exception {
ExecutorService e1 = Executors.newCachedThreadPool();
ExecutorService e2 = Executors.newCachedThreadPool();
ServerBootstrap bootstrap = new ServerBootstrap( ServerBootstrap bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(e1, e2)); new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
bootstrap.setOption("localAddress", new InetSocketAddress(0)); bootstrap.setOption("localAddress", new InetSocketAddress(0));
bootstrap.setOption("child.receiveBufferSize", 9753); bootstrap.setOption("child.receiveBufferSize", 9753);
@ -109,29 +106,7 @@ public class NioServerSocketShutdownTimeTest {
} }
} }
channel.close().awaitUninterruptibly(); channel.close().awaitUninterruptibly();
bootstrap.getFactory().getExternalResource().release();
e1.shutdownNow();
e2.shutdownNow();
for (;;) {
try {
if (e1.awaitTermination(1, TimeUnit.MILLISECONDS)) {
break;
}
} catch (InterruptedException e) {
// Ignore.
}
}
for (;;) {
try {
if (e2.awaitTermination(1, TimeUnit.MILLISECONDS)) {
break;
}
} catch (InterruptedException e) {
// Ignore.
}
}
} }
long shutdownTime = System.currentTimeMillis() - startTime; long shutdownTime = System.currentTimeMillis() - startTime;