Fixed incorrect timing test due to slow MD5 algorithm initialization
This commit is contained in:
parent
b3f39c1bb3
commit
c848b8cc58
@ -36,6 +36,7 @@ import org.jboss.netty.bootstrap.ClientBootstrap;
|
|||||||
import org.jboss.netty.channel.ChannelFuture;
|
import org.jboss.netty.channel.ChannelFuture;
|
||||||
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
||||||
import org.jboss.netty.util.DummyHandler;
|
import org.jboss.netty.util.DummyHandler;
|
||||||
|
import org.jboss.netty.util.TimeBasedUuidGenerator;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
@ -48,18 +49,24 @@ import org.junit.Test;
|
|||||||
*/
|
*/
|
||||||
public class NioClientSocketShutdownTimeTest {
|
public class NioClientSocketShutdownTimeTest {
|
||||||
|
|
||||||
|
static {
|
||||||
|
// Initialize the MD5 algorithm before testing - it takes too long
|
||||||
|
// on some JDK.
|
||||||
|
TimeBasedUuidGenerator.generate();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testShutdownTime() throws Throwable {
|
public void testShutdownTime() throws Throwable {
|
||||||
ServerSocketChannel serverSocket = ServerSocketChannel.open();
|
ServerSocketChannel serverSocket = ServerSocketChannel.open();
|
||||||
serverSocket.socket().bind(new InetSocketAddress(0));
|
serverSocket.socket().bind(new InetSocketAddress(0));
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
ExecutorService e1 = Executors.newCachedThreadPool();
|
ExecutorService e1 = Executors.newCachedThreadPool();
|
||||||
ExecutorService e2 = Executors.newCachedThreadPool();
|
ExecutorService e2 = Executors.newCachedThreadPool();
|
||||||
ClientBootstrap b = new ClientBootstrap(new NioClientSocketChannelFactory(e1, e2));
|
ClientBootstrap b = new ClientBootstrap(new NioClientSocketChannelFactory(e1, e2));
|
||||||
b.getPipeline().addLast("handler", new DummyHandler());
|
b.getPipeline().addLast("handler", new DummyHandler());
|
||||||
|
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
serverSocket.configureBlocking(false);
|
serverSocket.configureBlocking(false);
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ import org.jboss.netty.channel.ChannelPipelineCoverage;
|
|||||||
import org.jboss.netty.channel.ChannelStateEvent;
|
import org.jboss.netty.channel.ChannelStateEvent;
|
||||||
import org.jboss.netty.channel.SimpleChannelHandler;
|
import org.jboss.netty.channel.SimpleChannelHandler;
|
||||||
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||||
|
import org.jboss.netty.util.TimeBasedUuidGenerator;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
@ -51,10 +52,14 @@ import org.junit.Test;
|
|||||||
*/
|
*/
|
||||||
public class NioServerSocketShutdownTimeTest {
|
public class NioServerSocketShutdownTimeTest {
|
||||||
|
|
||||||
|
static {
|
||||||
|
// Initialize the MD5 algorithm before testing - it takes too long
|
||||||
|
// on some JDK.
|
||||||
|
TimeBasedUuidGenerator.generate();
|
||||||
|
}
|
||||||
|
|
||||||
@Test(timeout = 10000)
|
@Test(timeout = 10000)
|
||||||
public void testSuccessfulBindAttempt() throws Exception {
|
public void testSuccessfulBindAttempt() throws Exception {
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
ExecutorService e1 = Executors.newCachedThreadPool();
|
ExecutorService e1 = Executors.newCachedThreadPool();
|
||||||
ExecutorService e2 = Executors.newCachedThreadPool();
|
ExecutorService e2 = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
@ -68,6 +73,8 @@ public class NioServerSocketShutdownTimeTest {
|
|||||||
DummyHandler handler = new DummyHandler();
|
DummyHandler handler = new DummyHandler();
|
||||||
bootstrap.getPipeline().addLast("dummy", handler);
|
bootstrap.getPipeline().addLast("dummy", handler);
|
||||||
|
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
Channel channel = bootstrap.bind();
|
Channel channel = bootstrap.bind();
|
||||||
|
|
||||||
Socket socket = null;
|
Socket socket = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user