File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
zookeeper-server/src/test/java/org/apache/zookeeper/server Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ public void testMaxZooKeeperClientsWithNettyServerCnxnFactory() throws Exception
6767
6868 private void testMaxZooKeeperClients (String serverCnxnFactory ) throws Exception {
6969 final int clientPorts [] = new int [SERVER_COUNT ];
70- int maxCnxns = 2 ;
70+ final int maxCnxns = 2 ;
7171 StringBuilder sb = new StringBuilder ();
7272 sb .append ("maxCnxns=" + maxCnxns + "\n " );
7373 sb .append ("serverCnxnFactory=" + serverCnxnFactory + "\n " );
@@ -108,9 +108,13 @@ public void process(WatchedEvent event) {
108108 }
109109 }
110110 };
111- for (int i = 0 ; i < maxAllowedConnection ; i ++) {
112- clients [i ] = new ZooKeeper (cxnString , ClientBase .CONNECTION_TIMEOUT , watcher );
113- Thread .sleep (100 );
111+ // There are could be concurrent races to make maxCnxns restriction not accurate.
112+ // So we connect to each server with maxCnxns connections to overcome this.
113+ for (int i = 0 ; i < SERVER_COUNT ; i ++) {
114+ String addr = "127.0.0.1:" + clientPorts [i ];
115+ for (int j = 0 ; j < maxCnxns ; j ++) {
116+ clients [i * maxCnxns + j ] = new ZooKeeper (addr , ClientBase .CONNECTION_TIMEOUT , watcher );
117+ }
114118 }
115119 countDownLatch .await ();
116120 // reaching this point indicates that all maxAllowedConnection connected
You can’t perform that action at this time.
0 commit comments