|
@@ -18,18 +18,12 @@
|
|
|
|
|
|
package org.apache.zookeeper.server;
|
|
package org.apache.zookeeper.server;
|
|
|
|
|
|
-import java.util.concurrent.CountDownLatch;
|
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
-
|
|
|
|
import junit.framework.Assert;
|
|
import junit.framework.Assert;
|
|
|
|
|
|
import org.apache.zookeeper.CreateMode;
|
|
import org.apache.zookeeper.CreateMode;
|
|
import org.apache.zookeeper.ZooDefs.Ids;
|
|
import org.apache.zookeeper.ZooDefs.Ids;
|
|
import org.apache.zookeeper.ZooKeeper;
|
|
import org.apache.zookeeper.ZooKeeper;
|
|
-import org.apache.zookeeper.server.NettyServerCnxnFactory.CnxnChannelHandler;
|
|
|
|
import org.apache.zookeeper.test.ClientBase;
|
|
import org.apache.zookeeper.test.ClientBase;
|
|
-import org.jboss.netty.channel.ChannelHandlerContext;
|
|
|
|
-import org.jboss.netty.channel.ChannelStateEvent;
|
|
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -63,21 +57,6 @@ public class NettyServerCnxnTest extends ClientBase {
|
|
"Didn't instantiate ServerCnxnFactory with NettyServerCnxnFactory!",
|
|
"Didn't instantiate ServerCnxnFactory with NettyServerCnxnFactory!",
|
|
serverFactory instanceof NettyServerCnxnFactory);
|
|
serverFactory instanceof NettyServerCnxnFactory);
|
|
|
|
|
|
- NettyServerCnxnFactory nettyServerFactory = (NettyServerCnxnFactory) serverFactory;
|
|
|
|
- final CountDownLatch channelLatch = new CountDownLatch(1);
|
|
|
|
- CnxnChannelHandler channelHandler = nettyServerFactory.new CnxnChannelHandler() {
|
|
|
|
- @Override
|
|
|
|
- public void channelDisconnected(ChannelHandlerContext ctx,
|
|
|
|
- ChannelStateEvent e) throws Exception {
|
|
|
|
- LOG.info("Recieves channel disconnected event");
|
|
|
|
- channelLatch.countDown();
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- LOG.info("Adding custom channel handler for simulation");
|
|
|
|
- nettyServerFactory.bootstrap.getPipeline().remove("servercnxnfactory");
|
|
|
|
- nettyServerFactory.bootstrap.getPipeline().addLast("servercnxnfactory",
|
|
|
|
- channelHandler);
|
|
|
|
-
|
|
|
|
final ZooKeeper zk = createClient();
|
|
final ZooKeeper zk = createClient();
|
|
final String path = "/a";
|
|
final String path = "/a";
|
|
try {
|
|
try {
|
|
@@ -93,9 +72,14 @@ public class NettyServerCnxnTest extends ClientBase {
|
|
serverCnxn.sendCloseSession();
|
|
serverCnxn.sendCloseSession();
|
|
}
|
|
}
|
|
LOG.info("Waiting for the channel disconnected event");
|
|
LOG.info("Waiting for the channel disconnected event");
|
|
- channelLatch.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
|
|
|
|
- Assert.assertEquals("Mismatch in number of live connections!", 0,
|
|
|
|
- serverFactory.getNumAliveConnections());
|
|
|
|
|
|
+ int timeout = 0;
|
|
|
|
+ while (serverFactory.getNumAliveConnections() != 0) {
|
|
|
|
+ Thread.sleep(1000);
|
|
|
|
+ timeout += 1000;
|
|
|
|
+ if (timeout > CONNECTION_TIMEOUT) {
|
|
|
|
+ Assert.fail("The number of live connections should be 0");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
} finally {
|
|
} finally {
|
|
zk.close();
|
|
zk.close();
|
|
}
|
|
}
|