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
67
67
68
68
private void testMaxZooKeeperClients (String serverCnxnFactory ) throws Exception {
69
69
final int clientPorts [] = new int [SERVER_COUNT ];
70
- int maxCnxns = 2 ;
70
+ final int maxCnxns = 2 ;
71
71
StringBuilder sb = new StringBuilder ();
72
72
sb .append ("maxCnxns=" + maxCnxns + "\n " );
73
73
sb .append ("serverCnxnFactory=" + serverCnxnFactory + "\n " );
@@ -108,9 +108,13 @@ public void process(WatchedEvent event) {
108
108
}
109
109
}
110
110
};
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
+ }
114
118
}
115
119
countDownLatch .await ();
116
120
// reaching this point indicates that all maxAllowedConnection connected
You can’t perform that action at this time.
0 commit comments