@@ -15,43 +15,38 @@ public void connectionLeakTest() throws Exception {
1515 // Checking for JAVA-342
1616 CCMBridge ccmBridge ;
1717 ccmBridge = CCMBridge .create ("test" , 1 );
18+ Cluster cluster = null ;
19+ try {
20+ // create a new cluster object and ensure 0 sessions and connections
21+ cluster = Cluster .builder ().addContactPoints (CCMBridge .IP_PREFIX + '1' ).build ();
22+ cluster .init ();
1823
19- // give the driver time to close other sessions in this class
20- //Thread.sleep(10);
21-
22- // create a new cluster object and ensure 0 sessions and connections
23- Cluster cluster = Cluster .builder ().addContactPoints (CCMBridge .IP_PREFIX + '1' ).build ();
24-
25- int corePoolSize = cluster .getConfiguration ()
26- .getPoolingOptions ()
27- .getCoreConnectionsPerHost (HostDistance .LOCAL );
28-
29- assertEquals (cluster .manager .sessions .size (), 0 );
30- assertEquals ((int ) cluster .getMetrics ().getOpenConnections ().getValue (), 0 );
24+ int corePoolSize = cluster .getConfiguration ()
25+ .getPoolingOptions ()
26+ .getCoreConnectionsPerHost (HostDistance .LOCAL );
3127
32- // ensure sessions.size() returns with 1 control connection + core pool size.
33- Session session = cluster .connect ();
34- assertEquals (cluster .manager .sessions .size (), 1 );
35- assertEquals ((int ) cluster .getMetrics ().getOpenConnections ().getValue (), 1 + corePoolSize );
28+ assertEquals (cluster .manager .sessions .size (), 0 );
29+ // Should be 1 control connection after initialization.
30+ assertEquals ((int ) cluster .getMetrics ().getOpenConnections ().getValue (), 1 );
3631
37- // ensure sessions.size() returns to 0 with only 1 active connection (the control connection)
38- session . close ();
39- assertEquals (cluster .manager .sessions .size (), 0 );
40- assertEquals ((int ) cluster .getMetrics ().getOpenConnections ().getValue (), 1 );
32+ // ensure sessions.size() returns with 1 control connection + core pool size.
33+ Session session = cluster . connect ();
34+ assertEquals (cluster .manager .sessions .size (), 1 );
35+ assertEquals ((int ) cluster .getMetrics ().getOpenConnections ().getValue (), 1 + corePoolSize );
4136
42- try {
43- Session thisSession ;
37+ // ensure sessions.size() returns to 0 with only 1 active connection (the control connection)
38+ session .close ();
39+ assertEquals (cluster .manager .sessions .size (), 0 );
40+ assertEquals ((int ) cluster .getMetrics ().getOpenConnections ().getValue (), 1 );
4441
4542 // ensure bootstrapping a node does not create additional connections
46-
47-
4843 ccmBridge .bootstrapNode (2 );
4944 assertEquals (cluster .manager .sessions .size (), 0 );
5045 assertEquals ((int ) cluster .getMetrics ().getOpenConnections ().getValue (), 1 );
5146
5247 // ensure a new session gets registered and core connections are established
5348 // there should be corePoolSize more connections to accommodate for the new host.
54- thisSession = cluster .connect ();
49+ Session thisSession = cluster .connect ();
5550 assertEquals (cluster .manager .sessions .size (), 1 );
5651
5752 assertEquals ((int ) cluster .getMetrics ().getOpenConnections ().getValue (), 1 + (corePoolSize * 2 ));
@@ -60,26 +55,14 @@ public void connectionLeakTest() throws Exception {
6055 thisSession .close ();
6156
6257 assertEquals (cluster .manager .sessions .size (), 0 );
63-
6458 assertEquals ((int ) cluster .getMetrics ().getOpenConnections ().getValue (), 1 );
65-
66-
6759 } finally {
68- // ensure we decommission node2 for the rest of the tests
69-
70- assertEquals (cluster .manager .sessions .size (), 0 );
71- assertEquals ((int ) cluster .getMetrics ().getOpenConnections ().getValue (), 1 );
72-
7360 if (cluster != null ){
7461 cluster .close ();
75-
7662 }
77-
7863 if (ccmBridge != null ) {
7964 ccmBridge .remove ();
8065 }
81-
82-
8366 }
8467 }
8568}
0 commit comments