Fix resource management
This commit is contained in:
parent
c883b61503
commit
debaa6a72a
@ -26,18 +26,15 @@ import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
|||||||
import io.netty.channel.ChannelInboundStreamHandlerAdapter;
|
import io.netty.channel.ChannelInboundStreamHandlerAdapter;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ServerChannelBootstrap;
|
import io.netty.channel.ServerChannelBootstrap;
|
||||||
import io.netty.util.internal.ExecutorUtil;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.After;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public abstract class AbstractSocketSpdyEchoTest {
|
public abstract class AbstractSocketSpdyEchoTest {
|
||||||
@ -46,8 +43,6 @@ public abstract class AbstractSocketSpdyEchoTest {
|
|||||||
static final ChannelBuffer frames = ChannelBuffers.buffer(1160);
|
static final ChannelBuffer frames = ChannelBuffers.buffer(1160);
|
||||||
static final int ignoredBytes = 20;
|
static final int ignoredBytes = 20;
|
||||||
|
|
||||||
private static ExecutorService executor;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// SPDY UNKNOWN Frame
|
// SPDY UNKNOWN Frame
|
||||||
frames.writeByte(0x80);
|
frames.writeByte(0x80);
|
||||||
@ -132,14 +127,19 @@ public abstract class AbstractSocketSpdyEchoTest {
|
|||||||
frames.writeInt(random.nextInt() & 0x7FFFFFFF);
|
frames.writeInt(random.nextInt() & 0x7FFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
private ServerChannelBootstrap sb;
|
||||||
public static void init() {
|
private ChannelBootstrap cb;
|
||||||
executor = Executors.newCachedThreadPool();
|
|
||||||
|
@Before
|
||||||
|
public void initBootstrap() {
|
||||||
|
sb = newServerBootstrap();
|
||||||
|
cb = newClientBootstrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@After
|
||||||
public static void destroy() {
|
public void destroyBootstrap() {
|
||||||
ExecutorUtil.terminate(executor);
|
sb.shutdown();
|
||||||
|
cb.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract ServerChannelBootstrap newServerBootstrap();
|
protected abstract ServerChannelBootstrap newServerBootstrap();
|
||||||
@ -147,9 +147,6 @@ public abstract class AbstractSocketSpdyEchoTest {
|
|||||||
|
|
||||||
@Test(timeout = 10000)
|
@Test(timeout = 10000)
|
||||||
public void testSpdyEcho() throws Throwable {
|
public void testSpdyEcho() throws Throwable {
|
||||||
ServerChannelBootstrap sb = newServerBootstrap();
|
|
||||||
ChannelBootstrap cb = newClientBootstrap();
|
|
||||||
|
|
||||||
final ServerHandler sh = new ServerHandler();
|
final ServerHandler sh = new ServerHandler();
|
||||||
final ClientHandler ch = new ClientHandler();
|
final ClientHandler ch = new ClientHandler();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user