Fixed incorrect timing test due to slow MD5 algorithm initialization

This commit is contained in:
Trustin Lee 2008-11-16 11:22:40 +00:00
parent b3f39c1bb3
commit c848b8cc58
2 changed files with 18 additions and 4 deletions

View File

@ -36,6 +36,7 @@ import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
import org.jboss.netty.util.DummyHandler;
import org.jboss.netty.util.TimeBasedUuidGenerator;
import org.junit.Test;
@ -48,18 +49,24 @@ import org.junit.Test;
*/
public class NioClientSocketShutdownTimeTest {
static {
// Initialize the MD5 algorithm before testing - it takes too long
// on some JDK.
TimeBasedUuidGenerator.generate();
}
@Test
public void testShutdownTime() throws Throwable {
ServerSocketChannel serverSocket = ServerSocketChannel.open();
serverSocket.socket().bind(new InetSocketAddress(0));
long startTime = System.currentTimeMillis();
ExecutorService e1 = Executors.newCachedThreadPool();
ExecutorService e2 = Executors.newCachedThreadPool();
ClientBootstrap b = new ClientBootstrap(new NioClientSocketChannelFactory(e1, e2));
b.getPipeline().addLast("handler", new DummyHandler());
long startTime = System.currentTimeMillis();
try {
serverSocket.configureBlocking(false);

View File

@ -39,6 +39,7 @@ import org.jboss.netty.channel.ChannelPipelineCoverage;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import org.jboss.netty.util.TimeBasedUuidGenerator;
import org.junit.Test;
@ -51,10 +52,14 @@ import org.junit.Test;
*/
public class NioServerSocketShutdownTimeTest {
static {
// Initialize the MD5 algorithm before testing - it takes too long
// on some JDK.
TimeBasedUuidGenerator.generate();
}
@Test(timeout = 10000)
public void testSuccessfulBindAttempt() throws Exception {
long startTime = System.currentTimeMillis();
ExecutorService e1 = Executors.newCachedThreadPool();
ExecutorService e2 = Executors.newCachedThreadPool();
@ -68,6 +73,8 @@ public class NioServerSocketShutdownTimeTest {
DummyHandler handler = new DummyHandler();
bootstrap.getPipeline().addLast("dummy", handler);
long startTime = System.currentTimeMillis();
Channel channel = bootstrap.bind();
Socket socket = null;