kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 988a52e52aeede2d436c632d6f7eba381fabc100aa35aead491580fe5de14078 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-01-30 12:55 -06:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-02-13 07:23 -06:00 |
| Parents | 895c38bf77aa |
2 files changed
modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +5 −2
| @@ -75,9 +75,12 @@ | ||
| 75 | 75 | long initTimeMs = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS); |
| 76 | 76 | logger.info("Cluster and session initialized in {} ms", initTimeMs); |
| 77 | 77 | |
| 78 | - // We have one live host so 3 successful connections (1 control connection and 2 core connections in the pool). | |
| 78 | + // We have one live host so we expect 1 control connection + core connection count successful connections. | |
| 79 | 79 | // The other 5 hosts are unreachable, we should attempt to connect to each of them only once. |
| 80 | - verify(socketOptions, times(3 + 5)).getKeepAlive(); | |
| 80 | + int coreConnections = cluster.getConfiguration() | |
| 81 | + .getPoolingOptions() | |
| 82 | + .getCoreConnectionsPerHost(HostDistance.LOCAL); | |
| 83 | + verify(socketOptions, times(1 + coreConnections + 5)).getKeepAlive(); | |
| 81 | 84 | } finally { |
| 82 | 85 | if (cluster != null) |
| 83 | 86 | cluster.close(); |
modified driver-core/src/test/java/com/datastax/driver/core/SessionTest.java +21 −8
| @@ -149,13 +149,20 @@ | ||
| 149 | 149 | Thread.sleep(10); |
| 150 | 150 | |
| 151 | 151 | // create a new cluster object and ensure 0 sessions and connections |
| 152 | - Cluster cluster = Cluster.builder().addContactPoints(CCMBridge.IP_PREFIX + '1').build(); | |
| 152 | + int corePoolSize = 2; | |
| 153 | + PoolingOptions poolingOptions = new PoolingOptions() | |
| 154 | + .setCoreConnectionsPerHost(HostDistance.LOCAL, corePoolSize); | |
| 155 | + Cluster cluster = Cluster.builder() | |
| 156 | + .addContactPoints(CCMBridge.IP_PREFIX + '1') | |
| 157 | + .withPoolingOptions(poolingOptions) | |
| 158 | + .build(); | |
| 159 | + | |
| 153 | 160 | assertEquals(cluster.manager.sessions.size(), 0); |
| 154 | 161 | assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 0); |
| 155 | 162 | |
| 156 | 163 | Session session = cluster.connect(); |
| 157 | 164 | assertEquals(cluster.manager.sessions.size(), 1); |
| 158 | - assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 3); | |
| 165 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + corePoolSize); | |
| 159 | 166 | |
| 160 | 167 | // ensure sessions.size() returns to 0 with only 1 active connection |
| 161 | 168 | session.close(); |
| @@ -174,7 +181,7 @@ | ||
| 174 | 181 | // ensure a new session gets registered and control connections are established |
| 175 | 182 | session = cluster.connect(); |
| 176 | 183 | assertEquals(cluster.manager.sessions.size(), 1); |
| 177 | - assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 3); | |
| 184 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + corePoolSize); | |
| 178 | 185 | session.close(); |
| 179 | 186 | |
| 180 | 187 | // give the driver time to close sessions |
| @@ -198,14 +205,20 @@ | ||
| 198 | 205 | |
| 199 | 206 | // create a new cluster object and ensure 0 sessions and connections |
| 200 | 207 | Cluster cluster = Cluster.builder().addContactPoints(CCMBridge.IP_PREFIX + '1').build(); |
| 208 | + | |
| 209 | + int corePoolSize = cluster.getConfiguration() | |
| 210 | + .getPoolingOptions() | |
| 211 | + .getCoreConnectionsPerHost(HostDistance.LOCAL); | |
| 212 | + | |
| 201 | 213 | assertEquals(cluster.manager.sessions.size(), 0); |
| 202 | 214 | assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 0); |
| 203 | 215 | |
| 216 | + // ensure sessions.size() returns with 1 control connection + core pool size. | |
| 204 | 217 | Session session = cluster.connect(); |
| 205 | 218 | assertEquals(cluster.manager.sessions.size(), 1); |
| 206 | - assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 3); | |
| 219 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + corePoolSize); | |
| 207 | 220 | |
| 208 | - // ensure sessions.size() returns to 0 with only 1 active connection | |
| 221 | + // ensure sessions.size() returns to 0 with only 1 active connection (the control connection) | |
| 209 | 222 | session.close(); |
| 210 | 223 | assertEquals(cluster.manager.sessions.size(), 0); |
| 211 | 224 | assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); |
| @@ -218,11 +231,11 @@ | ||
| 218 | 231 | assertEquals(cluster.manager.sessions.size(), 0); |
| 219 | 232 | assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); |
| 220 | 233 | |
| 221 | - // ensure a new session gets registered and control connections are established | |
| 222 | - // an additional 2 control connections should be seen for node2 | |
| 234 | + // ensure a new session gets registered and core connections are established | |
| 235 | + // there should be corePoolSize more connections to accommodate for the new host. | |
| 223 | 236 | thisSession = cluster.connect(); |
| 224 | 237 | assertEquals(cluster.manager.sessions.size(), 1); |
| 225 | - assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 5); | |
| 238 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + (corePoolSize * 2)); | |
| 226 | 239 | |
| 227 | 240 | // ensure bootstrapping a node does not create additional connections that won't get cleaned up |
| 228 | 241 | thisSession.close(); |