Simplified some test code using ChannelFactoryResource.release()
This commit is contained in:
parent
5a4e0e4d47
commit
96c98f636a
@ -28,9 +28,7 @@ import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jboss.netty.bootstrap.ClientBootstrap;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
@ -60,9 +58,10 @@ public class NioClientSocketShutdownTimeTest {
|
||||
ServerSocketChannel serverSocket = ServerSocketChannel.open();
|
||||
serverSocket.socket().bind(new InetSocketAddress(0));
|
||||
|
||||
ExecutorService e1 = Executors.newCachedThreadPool();
|
||||
ExecutorService e2 = Executors.newCachedThreadPool();
|
||||
ClientBootstrap b = new ClientBootstrap(new NioClientSocketChannelFactory(e1, e2));
|
||||
ClientBootstrap b = new ClientBootstrap(
|
||||
new NioClientSocketChannelFactory(
|
||||
Executors.newCachedThreadPool(),
|
||||
Executors.newCachedThreadPool()));
|
||||
b.getPipeline().addLast("handler", new DummyHandler());
|
||||
|
||||
long startTime;
|
||||
@ -86,26 +85,7 @@ public class NioClientSocketShutdownTimeTest {
|
||||
|
||||
f.getChannel().close().awaitUninterruptibly();
|
||||
} finally {
|
||||
assertEquals(0, e1.shutdownNow().size());
|
||||
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
|
||||
}
|
||||
}
|
||||
b.getFactory().getExternalResource().release();
|
||||
|
||||
try {
|
||||
serverSocket.close();
|
||||
|
@ -28,9 +28,7 @@ import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jboss.netty.bootstrap.ServerBootstrap;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
@ -60,11 +58,10 @@ public class NioServerSocketShutdownTimeTest {
|
||||
|
||||
@Test(timeout = 10000)
|
||||
public void testSuccessfulBindAttempt() throws Exception {
|
||||
ExecutorService e1 = Executors.newCachedThreadPool();
|
||||
ExecutorService e2 = Executors.newCachedThreadPool();
|
||||
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
new NioServerSocketChannelFactory(e1, e2));
|
||||
new NioServerSocketChannelFactory(
|
||||
Executors.newCachedThreadPool(),
|
||||
Executors.newCachedThreadPool()));
|
||||
|
||||
bootstrap.setOption("localAddress", new InetSocketAddress(0));
|
||||
bootstrap.setOption("child.receiveBufferSize", 9753);
|
||||
@ -109,29 +106,7 @@ public class NioServerSocketShutdownTimeTest {
|
||||
}
|
||||
}
|
||||
channel.close().awaitUninterruptibly();
|
||||
|
||||
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.
|
||||
}
|
||||
}
|
||||
bootstrap.getFactory().getExternalResource().release();
|
||||
}
|
||||
|
||||
long shutdownTime = System.currentTimeMillis() - startTime;
|
||||
|
Loading…
Reference in New Issue
Block a user