Elffuss BraidHub

kikocis/java-driver public

< ProtocolVersion.V3 compatibility updates for Integration Tests.

Set Core connection pool size to 1 explicitly in Session and
ClusterStressTest since < V3 protocol version clients create many more
connections causing OS to run out of file descriptors.

Require 2.0+ for unboundVariableInBatchStatementTest since native
protocol batches are not supported until 2.0.
Changesetcd9155c21b837fef395fe78663f373c245126f1910c7c90a7a575610f8d842bc
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-03-10 17:53 -05:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-03-10 18:10 -05:00
Parents4c091160f4a0

Browse the files at this changeset

3 files changed

modified driver-core/src/test/java/com/datastax/driver/core/ClusterStressTest.java +7 −2
@@ -5,6 +5,7 @@
55 import java.util.List;
66 import java.util.concurrent.*;
77
8+import com.google.common.util.concurrent.Uninterruptibles;
89 import org.slf4j.Logger;
910 import org.slf4j.LoggerFactory;
1011 import org.testng.annotations.Test;
@@ -29,7 +30,10 @@
2930 @Test(groups = "long")
3031 public void clusters_should_not_leak_connections() {
3132 int numberOfClusters = 10;
32- for (int i = 0; i < 500; i++) {
33+ int numberOfIterations = 500;
34+ for (int i = 1; i < numberOfIterations; i++) {
35+ logger.info("On iteration {}/{}.", i, numberOfIterations);
36+ logger.info("Creating {} clusters", numberOfClusters);
3337 List<Cluster> clusters = waitForCreates(createClustersConcurrently(numberOfClusters));
3438 waitForCloses(closeClustersConcurrently(clusters));
3539 logger.debug("# {} threads currently running", Thread.getAllStackTraces().keySet().size());
@@ -131,7 +135,8 @@
131135 public Cluster call() throws Exception {
132136 startSignal.await();
133137
134- Cluster cluster = Cluster.builder().addContactPoints(CCMBridge.IP_PREFIX + '1').build();
138+ Cluster cluster = Cluster.builder().addContactPoints(CCMBridge.IP_PREFIX + '1')
139+ .withPoolingOptions(new PoolingOptions().setCoreConnectionsPerHost(HostDistance.LOCAL, 1)).build();
135140
136141 try {
137142 // The cluster has not been initialized yet, therefore the control connection is not opened
modified driver-core/src/test/java/com/datastax/driver/core/PreparedStatementTest.java +2 −0
@@ -27,6 +27,7 @@
2727
2828 import com.datastax.driver.core.exceptions.NoHostAvailableException;
2929 import com.datastax.driver.core.exceptions.UnsupportedFeatureException;
30+import com.datastax.driver.core.utils.CassandraVersion;
3031
3132 import static com.datastax.driver.core.TestUtils.*;
3233
@@ -423,6 +424,7 @@
423424 }
424425
425426 @Test(groups = "short", expectedExceptions = { IllegalStateException.class })
427+ @CassandraVersion(major=2.0)
426428 public void unboundVariableInBatchStatementTest() {
427429 PreparedStatement ps = session.prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)");
428430 BatchStatement batch = new BatchStatement();
modified driver-core/src/test/java/com/datastax/driver/core/SessionStressTest.java +15 −10
@@ -1,5 +1,6 @@
11 package com.datastax.driver.core;
22
3+import com.google.common.util.concurrent.Uninterruptibles;
34 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
56 import org.testng.annotations.Test;
@@ -53,7 +54,8 @@
5354 @Test(groups = "long")
5455 public void sessions_should_not_leak_connections() {
5556 // override inherited field with a new cluster object and ensure 0 sessions and connections
56- cluster = Cluster.builder().addContactPoints(CCMBridge.IP_PREFIX + '1').build();
57+ cluster = Cluster.builder().addContactPoints(CCMBridge.IP_PREFIX + '1')
58+ .withPoolingOptions(new PoolingOptions().setCoreConnectionsPerHost(HostDistance.LOCAL, 1)).build();
5759
5860 // The cluster has not been initialized yet, therefore the control connection is not opened
5961 assertEquals(cluster.manager.sessions.size(), 0);
@@ -74,8 +76,12 @@
7476 try {
7577 int nbOfSessions = 2000;
7678 int halfOfTheSessions = nbOfSessions / 2;
77-
78- for (int iteration = 0; iteration < 5; iteration++) {
79+ int nbOfIterations = 5;
80+ int sleepTime = 20;
81+
82+ for (int iteration = 1; iteration <= nbOfIterations; iteration++) {
83+ logger.info("On iteration {}/{}.", iteration, nbOfIterations);
84+ logger.info("Creating {} sessions.", nbOfSessions);
7985 waitFor(openSessionsConcurrently(nbOfSessions));
8086
8187 // We should see the exact number of opened sessions
@@ -85,6 +91,7 @@
8591 coreConnections * nbOfSessions + 1);
8692
8793 // Close half of the sessions asynchronously
94+ logger.info("Closing {}/{} sessions.", halfOfTheSessions, nbOfSessions);
8895 waitFor(closeSessionsConcurrently(halfOfTheSessions));
8996
9097 // Check that we have the right number of sessions and connections
@@ -93,6 +100,7 @@
93100 coreConnections * (nbOfSessions / 2) + 1);
94101
95102 // Close and open the same number of sessions concurrently
103+ logger.info("Closing and Opening {} sessions concurrently.", halfOfTheSessions);
96104 CountDownLatch startSignal = new CountDownLatch(1);
97105 List<Future<Session>> openSessionFutures = openSessionsConcurrently(halfOfTheSessions, startSignal);
98106 List<Future<CloseFuture>> closeSessionsFutures = closeSessionsConcurrently(halfOfTheSessions,
@@ -107,19 +115,16 @@
107115 coreConnections * (nbOfSessions / 2) + 1);
108116
109117 // Close the remaining sessions
118+ logger.info("Closing remaining {} sessions.", halfOfTheSessions);
110119 waitFor(closeSessionsConcurrently(halfOfTheSessions));
111120
112121 // Check that we have a clean state
113122 assertEquals(cluster.manager.sessions.size(), 0);
114123 assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1);
115124
116- try {
117- // On OSX, the TCP connections are released after 15s by default (sysctl -a net.inet.tcp.msl)
118- logger.debug("Sleeping so that TCP connections are released by the OS");
119- TimeUnit.SECONDS.sleep(20);
120- } catch (InterruptedException e) {
121- throw new RuntimeException("Interrupted during test!", e);
122- }
125+ // On OSX, the TCP connections are released after 15s by default (sysctl -a net.inet.tcp.msl)
126+ logger.info("Sleeping {} seconds so that TCP connections are released by the OS", sleepTime);
127+ Uninterruptibles.sleepUninterruptibly(sleepTime, TimeUnit.SECONDS);
123128 }
124129 } finally {
125130 cluster.close();