kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 124f3a93f7f65d38179dd04cd32f4c8c3444bd6fbfe08cb0f8d89cf36ada9f80 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-04-02 09:56 -05:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-04-03 12:43 +02:00 |
| Parents | f68609ba757e |
1 file changed
modified driver-core/src/test/java/com/datastax/driver/core/SessionLeakTest.java +20 −37
| @@ -15,43 +15,38 @@ | ||
| 15 | 15 | // Checking for JAVA-342 |
| 16 | 16 | CCMBridge ccmBridge; |
| 17 | 17 | 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(); | |
| 18 | 23 | |
| 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); | |
| 31 | 27 | |
| 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); | |
| 36 | 31 | |
| 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); | |
| 41 | 36 | |
| 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); | |
| 44 | 41 | |
| 45 | 42 | // ensure bootstrapping a node does not create additional connections |
| 46 | - | |
| 47 | - | |
| 48 | 43 | ccmBridge.bootstrapNode(2); |
| 49 | 44 | assertEquals(cluster.manager.sessions.size(), 0); |
| 50 | 45 | assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); |
| 51 | 46 | |
| 52 | 47 | // ensure a new session gets registered and core connections are established |
| 53 | 48 | // there should be corePoolSize more connections to accommodate for the new host. |
| 54 | - thisSession = cluster.connect(); | |
| 49 | + Session thisSession = cluster.connect(); | |
| 55 | 50 | assertEquals(cluster.manager.sessions.size(), 1); |
| 56 | 51 | |
| 57 | 52 | assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + (corePoolSize * 2)); |
| @@ -60,26 +55,14 @@ | ||
| 60 | 55 | thisSession.close(); |
| 61 | 56 | |
| 62 | 57 | assertEquals(cluster.manager.sessions.size(), 0); |
| 63 | - | |
| 64 | 58 | assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); |
| 65 | - | |
| 66 | - | |
| 67 | 59 | } 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 | - | |
| 73 | 60 | if(cluster != null){ |
| 74 | 61 | cluster.close(); |
| 75 | - | |
| 76 | 62 | } |
| 77 | - | |
| 78 | 63 | if (ccmBridge != null) { |
| 79 | 64 | ccmBridge.remove(); |
| 80 | 65 | } |
| 81 | - | |
| 82 | - | |
| 83 | 66 | } |
| 84 | 67 | } |
| 85 | 68 | } |