kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 5cd205e3f80217abd21b99e7e40c8ee470bea0e7e968aceef3e386d115b67c8a |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-01-16 14:52 -06:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-01-18 16:29 +01:00 |
| Parents | f6f0073f252c |
7 files changed
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +10 −10
| @@ -30,6 +30,7 @@ | ||
| 30 | 30 | import java.io.*; |
| 31 | 31 | import java.net.InetSocketAddress; |
| 32 | 32 | import java.util.*; |
| 33 | +import java.util.concurrent.TimeUnit; | |
| 33 | 34 | import java.util.concurrent.atomic.AtomicInteger; |
| 34 | 35 | |
| 35 | 36 | import static com.datastax.driver.core.TestUtils.executeNoFail; |
| @@ -378,10 +379,10 @@ | ||
| 378 | 379 | if (started) |
| 379 | 380 | return; |
| 380 | 381 | if (logger.isDebugEnabled()) |
| 381 | - logger.debug("Starting: {} - free memory: {}", this, TestUtils.getFreeMemoryMB()); | |
| 382 | + logger.debug("Starting: {} - free memory: {} MB", this, TestUtils.getFreeMemoryMB()); | |
| 382 | 383 | execute(CCM_COMMAND + " start --wait-other-notice --wait-for-binary-proto" + jvmArgs); |
| 383 | 384 | if (logger.isDebugEnabled()) |
| 384 | - logger.debug("Started: {} - Free memory: {}", this, TestUtils.getFreeMemoryMB()); | |
| 385 | + logger.debug("Started: {} - Free memory: {} MB", this, TestUtils.getFreeMemoryMB()); | |
| 385 | 386 | started = true; |
| 386 | 387 | } |
| 387 | 388 | |
| @@ -390,11 +391,10 @@ | ||
| 390 | 391 | if (closed) |
| 391 | 392 | return; |
| 392 | 393 | if (logger.isDebugEnabled()) |
| 393 | - logger.debug("Stopping: {} - free memory: {}", this, TestUtils.getFreeMemoryMB()); | |
| 394 | + logger.debug("Stopping: {} - free memory: {} MB", this, TestUtils.getFreeMemoryMB()); | |
| 394 | 395 | execute(CCM_COMMAND + " stop"); |
| 395 | - System.gc(); | |
| 396 | 396 | if (logger.isDebugEnabled()) |
| 397 | - logger.debug("Stopped: {} - free memory: {}", this, TestUtils.getFreeMemoryMB()); | |
| 397 | + logger.debug("Stopped: {} - free memory: {} MB", this, TestUtils.getFreeMemoryMB()); | |
| 398 | 398 | closed = true; |
| 399 | 399 | } |
| 400 | 400 | |
| @@ -513,10 +513,10 @@ | ||
| 513 | 513 | |
| 514 | 514 | String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir; |
| 515 | 515 | Closer closer = Closer.create(); |
| 516 | - // 5 minutes timeout | |
| 517 | - ExecuteWatchdog watchDog = new ExecuteWatchdog(5 * 60 * 1000); | |
| 516 | + // 10 minutes timeout | |
| 517 | + ExecuteWatchdog watchDog = new ExecuteWatchdog(TimeUnit.MINUTES.toMillis(10)); | |
| 518 | 518 | try { |
| 519 | - logger.debug("Executing: " + fullCommand); | |
| 519 | + logger.trace("Executing: " + fullCommand); | |
| 520 | 520 | CommandLine cli = CommandLine.parse(fullCommand); |
| 521 | 521 | Executor executor = new DefaultExecutor(); |
| 522 | 522 | |
| @@ -836,7 +836,7 @@ | ||
| 836 | 836 | for (int i = 0; i < nodesInDc; i++) { |
| 837 | 837 | int jmxPort = findAvailablePort(); |
| 838 | 838 | int debugPort = findAvailablePort(); |
| 839 | - logger.debug("Node {} in cluster {} using JMX port {} and debug port {}", n, clusterName, jmxPort, debugPort); | |
| 839 | + logger.trace("Node {} in cluster {} using JMX port {} and debug port {}", n, clusterName, jmxPort, debugPort); | |
| 840 | 840 | File nodeConf = new File(ccm.getNodeDir(n), "node.conf"); |
| 841 | 841 | File nodeConf2 = new File(ccm.getNodeDir(n), "node.conf.tmp"); |
| 842 | 842 | BufferedReader br = closer.register(new BufferedReader(new FileReader(nodeConf))); |
| @@ -910,7 +910,7 @@ | ||
| 910 | 910 | |
| 911 | 911 | @Override |
| 912 | 912 | public String toString() { |
| 913 | - return String.format("%s (weight %s)", clusterName, weight()); | |
| 913 | + return String.format("%s (%s nodes)", clusterName, weight()); | |
| 914 | 914 | } |
| 915 | 915 | } |
| 916 | 916 |
modified driver-core/src/test/java/com/datastax/driver/core/CCMCache.java +1 −1
| @@ -229,7 +229,7 @@ | ||
| 229 | 229 | public void onRemoval(RemovalNotification<CCMBridge.Builder, CachedCCMAccess> notification) { |
| 230 | 230 | CachedCCMAccess cached = notification.getValue(); |
| 231 | 231 | if (cached != null && cached.ccm != null) { |
| 232 | - LOGGER.debug("Evicting: {} because of {}", cached.ccm, notification.getCause()); | |
| 232 | + LOGGER.debug("Evicting: {}, reason: {}", cached.ccm, notification.getCause()); | |
| 233 | 233 | cached.evicted = true; |
| 234 | 234 | cached.maybeClose(); |
| 235 | 235 | } |
modified driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java +6 −1
| @@ -691,7 +691,12 @@ | ||
| 691 | 691 | } else { |
| 692 | 692 | this.ccm = new ReadOnlyCCMBridge(ccm); |
| 693 | 693 | } |
| 694 | - ccm.start(); | |
| 694 | + try { | |
| 695 | + ccm.start(); | |
| 696 | + } catch (RuntimeException e) { | |
| 697 | + LOGGER.error("Could not start " + ccm, e); | |
| 698 | + fail(e.getMessage()); | |
| 699 | + } | |
| 695 | 700 | LOGGER.debug("Using {}", ccm); |
| 696 | 701 | } |
| 697 | 702 | } |
modified driver-core/src/test/java/com/datastax/driver/core/EventDebouncerTest.java +2 −16
| @@ -34,7 +34,7 @@ | ||
| 34 | 34 | import java.util.concurrent.locks.ReentrantLock; |
| 35 | 35 | |
| 36 | 36 | import static java.util.concurrent.TimeUnit.MILLISECONDS; |
| 37 | -import static java.util.concurrent.TimeUnit.SECONDS; | |
| 37 | +import static java.util.concurrent.TimeUnit.MINUTES; | |
| 38 | 38 | import static org.assertj.core.api.Assertions.assertThat; |
| 39 | 39 | |
| 40 | 40 | public class EventDebouncerTest { |
| @@ -190,7 +190,7 @@ | ||
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | void awaitEvents(int expected) throws InterruptedException { |
| 193 | - long nanos = SECONDS.toNanos(60); | |
| 193 | + long nanos = MINUTES.toNanos(5); | |
| 194 | 194 | lock.lock(); |
| 195 | 195 | try { |
| 196 | 196 | while (events.size() < expected) { |
| @@ -203,20 +203,6 @@ | ||
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - void awaitInvocations(int expected) throws InterruptedException { | |
| 207 | - long nanos = SECONDS.toNanos(60); | |
| 208 | - lock.lock(); | |
| 209 | - try { | |
| 210 | - while (invocations.get() < expected) { | |
| 211 | - if (nanos <= 0L) | |
| 212 | - break; // timeout | |
| 213 | - nanos = cond.awaitNanos(nanos); | |
| 214 | - } | |
| 215 | - } finally { | |
| 216 | - lock.unlock(); | |
| 217 | - } | |
| 218 | - } | |
| 219 | - | |
| 220 | 206 | public List<MockEvent> getEvents() { |
| 221 | 207 | return events; |
| 222 | 208 | } |
modified driver-core/src/test/java/com/datastax/driver/core/QueryOptionsTest.java +30 −26
| @@ -22,7 +22,6 @@ | ||
| 22 | 22 | import org.testng.annotations.Test; |
| 23 | 23 | |
| 24 | 24 | import java.util.List; |
| 25 | -import java.util.concurrent.Callable; | |
| 26 | 25 | import java.util.concurrent.TimeUnit; |
| 27 | 26 | |
| 28 | 27 | import static com.datastax.driver.core.Assertions.assertThat; |
| @@ -146,35 +145,40 @@ | ||
| 146 | 145 | |
| 147 | 146 | private void valideReprepareOnUp(boolean expectReprepare) { |
| 148 | 147 | String query = "select sansa_stark from the_known_world"; |
| 149 | - session.prepare(query); | |
| 148 | + int maxTries = 3; | |
| 149 | + for (int i = 1; i <= maxTries; i++) { | |
| 150 | + session.prepare(query); | |
| 150 | 151 | |
| 151 | - List<PreparedStatementPreparation> preparationOne = scassandra.node(1).activityClient().retrievePreparedStatementPreparations(); | |
| 152 | - | |
| 153 | - assertThat(preparationOne).hasSize(1); | |
| 154 | - assertThat(preparationOne.get(0).getPreparedStatementText()).isEqualTo(query); | |
| 152 | + List<PreparedStatementPreparation> preparationOne = scassandra.node(1).activityClient().retrievePreparedStatementPreparations(); | |
| 155 | 153 | |
| 156 | - scassandra.node(1).activityClient().clearAllRecordedActivity(); | |
| 157 | - scassandra.node(1).stop(); | |
| 158 | - assertThat(cluster).host(1).goesDownWithin(10, TimeUnit.SECONDS); | |
| 159 | - | |
| 160 | - scassandra.node(1).start(); | |
| 161 | - assertThat(cluster).host(1).comesUpWithin(60, TimeUnit.SECONDS); | |
| 162 | - | |
| 163 | - preparationOne = scassandra.node(1).activityClient().retrievePreparedStatementPreparations(); | |
| 164 | - if (expectReprepare) { | |
| 165 | - // tests fail randomly at this point, probably due to | |
| 166 | - // https://github.com/scassandra/scassandra-server/issues/116 | |
| 167 | - ConditionChecker.awaitWhile(new Callable<Boolean>() { | |
| 168 | - @Override | |
| 169 | - public Boolean call() { | |
| 170 | - return session.getState().getConnectedHosts().size() < 3 | |
| 171 | - || scassandra.node(1).activityClient().retrievePreparedStatementPreparations().isEmpty(); | |
| 172 | - } | |
| 173 | - }, TimeUnit.MINUTES.toMillis(1)); | |
| 174 | 154 | assertThat(preparationOne).hasSize(1); |
| 175 | 155 | assertThat(preparationOne.get(0).getPreparedStatementText()).isEqualTo(query); |
| 176 | - } else { | |
| 177 | - assertThat(preparationOne).isEmpty(); | |
| 156 | + | |
| 157 | + scassandra.node(1).activityClient().clearAllRecordedActivity(); | |
| 158 | + scassandra.node(1).stop(); | |
| 159 | + assertThat(cluster).host(1).goesDownWithin(10, TimeUnit.SECONDS); | |
| 160 | + | |
| 161 | + scassandra.node(1).start(); | |
| 162 | + assertThat(cluster).host(1).comesUpWithin(60, TimeUnit.SECONDS); | |
| 163 | + | |
| 164 | + preparationOne = scassandra.node(1).activityClient().retrievePreparedStatementPreparations(); | |
| 165 | + if (expectReprepare) { | |
| 166 | + // tests fail randomly at this point, probably due to | |
| 167 | + // https://github.com/scassandra/scassandra-server/issues/116 | |
| 168 | + try { | |
| 169 | + assertThat(preparationOne).hasSize(1); | |
| 170 | + assertThat(preparationOne.get(0).getPreparedStatementText()).isEqualTo(query); | |
| 171 | + break; | |
| 172 | + } catch (AssertionError e) { | |
| 173 | + if (i == maxTries) | |
| 174 | + throw e; | |
| 175 | + // retry | |
| 176 | + scassandra.node(1).activityClient().clearAllRecordedActivity(); | |
| 177 | + } | |
| 178 | + } else { | |
| 179 | + assertThat(preparationOne).isEmpty(); | |
| 180 | + break; | |
| 181 | + } | |
| 178 | 182 | } |
| 179 | 183 | } |
| 180 | 184 |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +23 −0
| @@ -83,6 +83,7 @@ | ||
| 83 | 83 | schemaDisabledCluster.manager.controlConnection = schemaDisabledControlConnection; |
| 84 | 84 | |
| 85 | 85 | session1 = cluster1.connect(); |
| 86 | + cluster2.init(); | |
| 86 | 87 | |
| 87 | 88 | cluster1.register(listener1 = mock(SchemaChangeListener.class)); |
| 88 | 89 | cluster1.register(listener2 = mock(SchemaChangeListener.class)); |
| @@ -146,6 +147,7 @@ | ||
| 146 | 147 | .isInKeyspace(handleId(keyspace)) |
| 147 | 148 | .hasName("table1"); |
| 148 | 149 | } |
| 150 | + refreshSchema(); | |
| 149 | 151 | for (Metadata m : metadatas()) |
| 150 | 152 | assertThat(m.getKeyspace(keyspace).getTable("table1")).isNotNull(); |
| 151 | 153 | } |
| @@ -161,6 +163,7 @@ | ||
| 161 | 163 | .isInKeyspace(handleId(keyspace)) |
| 162 | 164 | .hasName("table1"); |
| 163 | 165 | } |
| 166 | + refreshSchema(); | |
| 164 | 167 | for (Metadata m : metadatas()) |
| 165 | 168 | assertThat(m.getKeyspace(keyspace).getTable("table1")).hasNoColumn("j"); |
| 166 | 169 | assert added != null; |
| @@ -177,6 +180,7 @@ | ||
| 177 | 180 | .hasName("table1") |
| 178 | 181 | .hasColumn("j"); |
| 179 | 182 | } |
| 183 | + refreshSchema(); | |
| 180 | 184 | for (Metadata m : metadatas()) |
| 181 | 185 | assertThat(m.getKeyspace(keyspace).getTable("table1")).hasColumn("j"); |
| 182 | 186 | } |
| @@ -191,12 +195,14 @@ | ||
| 191 | 195 | .hasName("table1") |
| 192 | 196 | .isInKeyspace(handleId(keyspace)); |
| 193 | 197 | } |
| 198 | + refreshSchema(); | |
| 194 | 199 | execute(DROP_TABLE, keyspace); |
| 195 | 200 | for (SchemaChangeListener listener : listeners) { |
| 196 | 201 | ArgumentCaptor<TableMetadata> removed = ArgumentCaptor.forClass(TableMetadata.class); |
| 197 | 202 | verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onTableRemoved(removed.capture()); |
| 198 | 203 | assertThat(removed.getValue()).hasName("table1"); |
| 199 | 204 | } |
| 205 | + refreshSchema(); | |
| 200 | 206 | for (Metadata m : metadatas()) |
| 201 | 207 | assertThat(m.getKeyspace(keyspace).getTable("table1")).isNull(); |
| 202 | 208 | } |
| @@ -212,6 +218,7 @@ | ||
| 212 | 218 | assertThat((DataType) added.getValue()) |
| 213 | 219 | .isUserType(handleId(keyspace), "type1"); |
| 214 | 220 | } |
| 221 | + refreshSchema(); | |
| 215 | 222 | for (Metadata m : metadatas()) |
| 216 | 223 | assertThat((DataType) m.getKeyspace(keyspace).getUserType("type1")).isNotNull(); |
| 217 | 224 | } |
| @@ -228,6 +235,7 @@ | ||
| 228 | 235 | assertThat(previous.getValue().getFieldNames()).doesNotContain("j"); |
| 229 | 236 | assertThat(current.getValue().getFieldNames()).contains("j"); |
| 230 | 237 | } |
| 238 | + refreshSchema(); | |
| 231 | 239 | for (Metadata m : metadatas()) |
| 232 | 240 | assertThat(m.getKeyspace(keyspace).getUserType("type1").getFieldType("j")).isNotNull(); |
| 233 | 241 | } |
| @@ -243,6 +251,7 @@ | ||
| 243 | 251 | verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onUserTypeRemoved(removed.capture()); |
| 244 | 252 | assertThat((DataType) removed.getValue()).isUserType(handleId(keyspace), "type1"); |
| 245 | 253 | } |
| 254 | + refreshSchema(); | |
| 246 | 255 | for (Metadata m : metadatas()) |
| 247 | 256 | assertThat((DataType) m.getKeyspace(keyspace).getUserType("type1")).isNull(); |
| 248 | 257 | } |
| @@ -255,6 +264,7 @@ | ||
| 255 | 264 | verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onKeyspaceAdded(added.capture()); |
| 256 | 265 | assertThat(added.getValue()).hasName(handleId(keyspace)); |
| 257 | 266 | } |
| 267 | + refreshSchema(); | |
| 258 | 268 | for (Metadata m : metadatas()) |
| 259 | 269 | assertThat(m.getKeyspace(keyspace)).isNotNull(); |
| 260 | 270 | } |
| @@ -269,6 +279,7 @@ | ||
| 269 | 279 | assertThat(added.getValue()).hasName(handleId(keyspace)); |
| 270 | 280 | } |
| 271 | 281 | assert added != null; |
| 282 | + refreshSchema(); | |
| 272 | 283 | for (Metadata m : metadatas()) |
| 273 | 284 | assertThat(m.getKeyspace(keyspace).isDurableWrites()).isTrue(); |
| 274 | 285 | execute(ALTER_KEYSPACE, keyspace); |
| @@ -283,6 +294,7 @@ | ||
| 283 | 294 | .hasName(handleId(keyspace)) |
| 284 | 295 | .isNotDurableWrites(); |
| 285 | 296 | } |
| 297 | + refreshSchema(); | |
| 286 | 298 | for (Metadata m : metadatas()) |
| 287 | 299 | assertThat(m.getKeyspace(keyspace)).isNotDurableWrites(); |
| 288 | 300 | } |
| @@ -297,6 +309,7 @@ | ||
| 297 | 309 | assertThat(added.getValue()).hasName(handleId(keyspace)); |
| 298 | 310 | } |
| 299 | 311 | assert added != null; |
| 312 | + refreshSchema(); | |
| 300 | 313 | for (Metadata m : metadatas()) |
| 301 | 314 | assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE"))).isNotEmpty(); |
| 302 | 315 | execute(CREATE_TABLE, keyspace); // to test table drop notifications |
| @@ -312,6 +325,7 @@ | ||
| 312 | 325 | assertThat(ks.getValue()) |
| 313 | 326 | .hasName(handleId(keyspace)); |
| 314 | 327 | } |
| 328 | + refreshSchema(); | |
| 315 | 329 | for (Metadata m : metadatas()) { |
| 316 | 330 | assertThat(m.getKeyspace(keyspace)).isNull(); |
| 317 | 331 | assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE"))).isEmpty(); |
| @@ -445,4 +459,13 @@ | ||
| 445 | 459 | return Lists.newArrayList(cluster1.getMetadata(), cluster2.getMetadata()); |
| 446 | 460 | } |
| 447 | 461 | |
| 462 | + @SuppressWarnings("unchecked") | |
| 463 | + private void refreshSchema() { | |
| 464 | + Futures.getUnchecked( | |
| 465 | + Futures.successfulAsList( | |
| 466 | + cluster1.manager.submitSchemaRefresh(null, null, null), | |
| 467 | + cluster2.manager.submitSchemaRefresh(null, null, null))); | |
| 468 | + } | |
| 469 | + | |
| 470 | + | |
| 448 | 471 | } |
modified driver-core/src/test/java/com/datastax/driver/core/TracingTest.java +6 −1
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy; |
| 19 | 19 | import com.datastax.driver.core.utils.CassandraVersion; |
| 20 | +import com.google.common.util.concurrent.Uninterruptibles; | |
| 20 | 21 | import org.testng.annotations.BeforeClass; |
| 21 | 22 | import org.testng.annotations.Test; |
| 22 | 23 | |
| @@ -24,6 +25,7 @@ | ||
| 24 | 25 | import java.util.Collections; |
| 25 | 26 | import java.util.List; |
| 26 | 27 | import java.util.UUID; |
| 28 | +import java.util.concurrent.TimeUnit; | |
| 27 | 29 | |
| 28 | 30 | import static org.assertj.core.api.Assertions.assertThat; |
| 29 | 31 | |
| @@ -61,7 +63,8 @@ | ||
| 61 | 63 | SimpleStatement st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)); |
| 62 | 64 | ResultSet result = session.execute(st.setFetchSize(40).enableTracing()); |
| 63 | 65 | result.all(); |
| 64 | - | |
| 66 | + // sleep 10 seconds to make sure the trace will be complete | |
| 67 | + Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); | |
| 65 | 68 | List<ExecutionInfo> executions = result.getAllExecutionInfo(); |
| 66 | 69 | |
| 67 | 70 | UUID previousTraceId = null; |
| @@ -91,6 +94,8 @@ | ||
| 91 | 94 | st.setConsistencyLevel(ConsistencyLevel.THREE).enableTracing(); |
| 92 | 95 | |
| 93 | 96 | ResultSet result = session.execute(st); |
| 97 | + // sleep 10 seconds to make sure the trace will be complete | |
| 98 | + Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); | |
| 94 | 99 | |
| 95 | 100 | assertThat(result.getExecutionInfo().getQueryTrace()).isNotNull(); |
| 96 | 101 | } |