kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | cd9155c21b837fef395fe78663f373c245126f1910c7c90a7a575610f8d842bc |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-03-10 17:53 -05:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-03-10 18:10 -05:00 |
| Parents | 4c091160f4a0 |
3 files changed
modified driver-core/src/test/java/com/datastax/driver/core/ClusterStressTest.java +7 −2
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | import java.util.List; |
| 6 | 6 | import java.util.concurrent.*; |
| 7 | 7 | |
| 8 | +import com.google.common.util.concurrent.Uninterruptibles; | |
| 8 | 9 | import org.slf4j.Logger; |
| 9 | 10 | import org.slf4j.LoggerFactory; |
| 10 | 11 | import org.testng.annotations.Test; |
| @@ -29,7 +30,10 @@ | ||
| 29 | 30 | @Test(groups = "long") |
| 30 | 31 | public void clusters_should_not_leak_connections() { |
| 31 | 32 | 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); | |
| 33 | 37 | List<Cluster> clusters = waitForCreates(createClustersConcurrently(numberOfClusters)); |
| 34 | 38 | waitForCloses(closeClustersConcurrently(clusters)); |
| 35 | 39 | logger.debug("# {} threads currently running", Thread.getAllStackTraces().keySet().size()); |
| @@ -131,7 +135,8 @@ | ||
| 131 | 135 | public Cluster call() throws Exception { |
| 132 | 136 | startSignal.await(); |
| 133 | 137 | |
| 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(); | |
| 135 | 140 | |
| 136 | 141 | try { |
| 137 | 142 | // 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 @@ | ||
| 27 | 27 | |
| 28 | 28 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| 29 | 29 | import com.datastax.driver.core.exceptions.UnsupportedFeatureException; |
| 30 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 30 | 31 | |
| 31 | 32 | import static com.datastax.driver.core.TestUtils.*; |
| 32 | 33 | |
| @@ -423,6 +424,7 @@ | ||
| 423 | 424 | } |
| 424 | 425 | |
| 425 | 426 | @Test(groups = "short", expectedExceptions = { IllegalStateException.class }) |
| 427 | + @CassandraVersion(major=2.0) | |
| 426 | 428 | public void unboundVariableInBatchStatementTest() { |
| 427 | 429 | PreparedStatement ps = session.prepare("INSERT INTO " + SIMPLE_TABLE + " (k, i) VALUES (?, ?)"); |
| 428 | 430 | BatchStatement batch = new BatchStatement(); |
modified driver-core/src/test/java/com/datastax/driver/core/SessionStressTest.java +15 −10
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | package com.datastax.driver.core; |
| 2 | 2 | |
| 3 | +import com.google.common.util.concurrent.Uninterruptibles; | |
| 3 | 4 | import org.slf4j.Logger; |
| 4 | 5 | import org.slf4j.LoggerFactory; |
| 5 | 6 | import org.testng.annotations.Test; |
| @@ -53,7 +54,8 @@ | ||
| 53 | 54 | @Test(groups = "long") |
| 54 | 55 | public void sessions_should_not_leak_connections() { |
| 55 | 56 | // 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(); | |
| 57 | 59 | |
| 58 | 60 | // The cluster has not been initialized yet, therefore the control connection is not opened |
| 59 | 61 | assertEquals(cluster.manager.sessions.size(), 0); |
| @@ -74,8 +76,12 @@ | ||
| 74 | 76 | try { |
| 75 | 77 | int nbOfSessions = 2000; |
| 76 | 78 | 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); | |
| 79 | 85 | waitFor(openSessionsConcurrently(nbOfSessions)); |
| 80 | 86 | |
| 81 | 87 | // We should see the exact number of opened sessions |
| @@ -85,6 +91,7 @@ | ||
| 85 | 91 | coreConnections * nbOfSessions + 1); |
| 86 | 92 | |
| 87 | 93 | // Close half of the sessions asynchronously |
| 94 | + logger.info("Closing {}/{} sessions.", halfOfTheSessions, nbOfSessions); | |
| 88 | 95 | waitFor(closeSessionsConcurrently(halfOfTheSessions)); |
| 89 | 96 | |
| 90 | 97 | // Check that we have the right number of sessions and connections |
| @@ -93,6 +100,7 @@ | ||
| 93 | 100 | coreConnections * (nbOfSessions / 2) + 1); |
| 94 | 101 | |
| 95 | 102 | // Close and open the same number of sessions concurrently |
| 103 | + logger.info("Closing and Opening {} sessions concurrently.", halfOfTheSessions); | |
| 96 | 104 | CountDownLatch startSignal = new CountDownLatch(1); |
| 97 | 105 | List<Future<Session>> openSessionFutures = openSessionsConcurrently(halfOfTheSessions, startSignal); |
| 98 | 106 | List<Future<CloseFuture>> closeSessionsFutures = closeSessionsConcurrently(halfOfTheSessions, |
| @@ -107,19 +115,16 @@ | ||
| 107 | 115 | coreConnections * (nbOfSessions / 2) + 1); |
| 108 | 116 | |
| 109 | 117 | // Close the remaining sessions |
| 118 | + logger.info("Closing remaining {} sessions.", halfOfTheSessions); | |
| 110 | 119 | waitFor(closeSessionsConcurrently(halfOfTheSessions)); |
| 111 | 120 | |
| 112 | 121 | // Check that we have a clean state |
| 113 | 122 | assertEquals(cluster.manager.sessions.size(), 0); |
| 114 | 123 | assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); |
| 115 | 124 | |
| 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); | |
| 123 | 128 | } |
| 124 | 129 | } finally { |
| 125 | 130 | cluster.close(); |