Elffuss BraidHub

kikocis/java-driver public

Fix Integration Tests that were assuming 2 default core connections.

In 2.0.9 the default number of core connections increased from 2 to 8 as
a stopgap until JAVA-419 is fixed.  ClusterInitTest and SessionTest have
been updated to use the # of core connections from PoolingOptions to
factor in how many expected connections are attempted or opened.

sessionMemoryLeakTest creates 10,000 sessions and quite a bit of time with
8 connections per session.  Explicitly setting core connections to 2 will
reduce the amount of time and load it takes to run the test.
Changeset988a52e52aeede2d436c632d6f7eba381fabc100aa35aead491580fe5de14078
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-01-30 12:55 -06:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-02-13 07:23 -06:00
Parents895c38bf77aa

Browse the files at this changeset

2 files changed

modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +5 −2
@@ -75,9 +75,12 @@
7575 long initTimeMs = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
7676 logger.info("Cluster and session initialized in {} ms", initTimeMs);
7777
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.
7979 // 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();
8184 } finally {
8285 if (cluster != null)
8386 cluster.close();
modified driver-core/src/test/java/com/datastax/driver/core/SessionTest.java +21 −8
@@ -149,13 +149,20 @@
149149 Thread.sleep(10);
150150
151151 // 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+
153160 assertEquals(cluster.manager.sessions.size(), 0);
154161 assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 0);
155162
156163 Session session = cluster.connect();
157164 assertEquals(cluster.manager.sessions.size(), 1);
158- assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 3);
165+ assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + corePoolSize);
159166
160167 // ensure sessions.size() returns to 0 with only 1 active connection
161168 session.close();
@@ -174,7 +181,7 @@
174181 // ensure a new session gets registered and control connections are established
175182 session = cluster.connect();
176183 assertEquals(cluster.manager.sessions.size(), 1);
177- assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 3);
184+ assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + corePoolSize);
178185 session.close();
179186
180187 // give the driver time to close sessions
@@ -198,14 +205,20 @@
198205
199206 // create a new cluster object and ensure 0 sessions and connections
200207 Cluster cluster = Cluster.builder().addContactPoints(CCMBridge.IP_PREFIX + '1').build();
208+
209+ int corePoolSize = cluster.getConfiguration()
210+ .getPoolingOptions()
211+ .getCoreConnectionsPerHost(HostDistance.LOCAL);
212+
201213 assertEquals(cluster.manager.sessions.size(), 0);
202214 assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 0);
203215
216+ // ensure sessions.size() returns with 1 control connection + core pool size.
204217 Session session = cluster.connect();
205218 assertEquals(cluster.manager.sessions.size(), 1);
206- assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 3);
219+ assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + corePoolSize);
207220
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)
209222 session.close();
210223 assertEquals(cluster.manager.sessions.size(), 0);
211224 assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1);
@@ -218,11 +231,11 @@
218231 assertEquals(cluster.manager.sessions.size(), 0);
219232 assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1);
220233
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.
223236 thisSession = cluster.connect();
224237 assertEquals(cluster.manager.sessions.size(), 1);
225- assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 5);
238+ assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + (corePoolSize * 2));
226239
227240 // ensure bootstrapping a node does not create additional connections that won't get cleaned up
228241 thisSession.close();