kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 75220a2822819080b38b523ee934af1507b46b15562cf9944829d4cc4343a5b0 |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-01-18 19:04 +01:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-01-18 19:10 +01:00 |
| Parents | 0ff8ef436fa4, 5cd205e3f802 |
8 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; |
| @@ -382,10 +383,10 @@ | ||
| 382 | 383 | if (started) |
| 383 | 384 | return; |
| 384 | 385 | if (logger.isDebugEnabled()) |
| 385 | - logger.debug("Starting: {} - free memory: {}", this, TestUtils.getFreeMemoryMB()); | |
| 386 | + logger.debug("Starting: {} - free memory: {} MB", this, TestUtils.getFreeMemoryMB()); | |
| 386 | 387 | execute(CCM_COMMAND + " start --wait-other-notice --wait-for-binary-proto" + jvmArgs); |
| 387 | 388 | if (logger.isDebugEnabled()) |
| 388 | - logger.debug("Started: {} - Free memory: {}", this, TestUtils.getFreeMemoryMB()); | |
| 389 | + logger.debug("Started: {} - Free memory: {} MB", this, TestUtils.getFreeMemoryMB()); | |
| 389 | 390 | started = true; |
| 390 | 391 | } |
| 391 | 392 | |
| @@ -394,11 +395,10 @@ | ||
| 394 | 395 | if (closed) |
| 395 | 396 | return; |
| 396 | 397 | if (logger.isDebugEnabled()) |
| 397 | - logger.debug("Stopping: {} - free memory: {}", this, TestUtils.getFreeMemoryMB()); | |
| 398 | + logger.debug("Stopping: {} - free memory: {} MB", this, TestUtils.getFreeMemoryMB()); | |
| 398 | 399 | execute(CCM_COMMAND + " stop"); |
| 399 | - System.gc(); | |
| 400 | 400 | if (logger.isDebugEnabled()) |
| 401 | - logger.debug("Stopped: {} - free memory: {}", this, TestUtils.getFreeMemoryMB()); | |
| 401 | + logger.debug("Stopped: {} - free memory: {} MB", this, TestUtils.getFreeMemoryMB()); | |
| 402 | 402 | closed = true; |
| 403 | 403 | } |
| 404 | 404 | |
| @@ -517,10 +517,10 @@ | ||
| 517 | 517 | |
| 518 | 518 | String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir; |
| 519 | 519 | Closer closer = Closer.create(); |
| 520 | - // 5 minutes timeout | |
| 521 | - ExecuteWatchdog watchDog = new ExecuteWatchdog(5 * 60 * 1000); | |
| 520 | + // 10 minutes timeout | |
| 521 | + ExecuteWatchdog watchDog = new ExecuteWatchdog(TimeUnit.MINUTES.toMillis(10)); | |
| 522 | 522 | try { |
| 523 | - logger.debug("Executing: " + fullCommand); | |
| 523 | + logger.trace("Executing: " + fullCommand); | |
| 524 | 524 | CommandLine cli = CommandLine.parse(fullCommand); |
| 525 | 525 | Executor executor = new DefaultExecutor(); |
| 526 | 526 | |
| @@ -840,7 +840,7 @@ | ||
| 840 | 840 | for (int i = 0; i < nodesInDc; i++) { |
| 841 | 841 | int jmxPort = findAvailablePort(); |
| 842 | 842 | int debugPort = findAvailablePort(); |
| 843 | - logger.debug("Node {} in cluster {} using JMX port {} and debug port {}", n, clusterName, jmxPort, debugPort); | |
| 843 | + logger.trace("Node {} in cluster {} using JMX port {} and debug port {}", n, clusterName, jmxPort, debugPort); | |
| 844 | 844 | File nodeConf = new File(ccm.getNodeDir(n), "node.conf"); |
| 845 | 845 | File nodeConf2 = new File(ccm.getNodeDir(n), "node.conf.tmp"); |
| 846 | 846 | BufferedReader br = closer.register(new BufferedReader(new FileReader(nodeConf))); |
| @@ -914,7 +914,7 @@ | ||
| 914 | 914 | |
| 915 | 915 | @Override |
| 916 | 916 | public String toString() { |
| 917 | - return String.format("%s (weight %s)", clusterName, weight()); | |
| 917 | + return String.format("%s (%s nodes)", clusterName, weight()); | |
| 918 | 918 | } |
| 919 | 919 | } |
| 920 | 920 |
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
| @@ -693,7 +693,12 @@ | ||
| 693 | 693 | } else { |
| 694 | 694 | this.ccm = new ReadOnlyCCMBridge(ccm); |
| 695 | 695 | } |
| 696 | - ccm.start(); | |
| 696 | + try { | |
| 697 | + ccm.start(); | |
| 698 | + } catch (RuntimeException e) { | |
| 699 | + LOGGER.error("Could not start " + ccm, e); | |
| 700 | + fail(e.getMessage()); | |
| 701 | + } | |
| 697 | 702 | LOGGER.debug("Using {}", ccm); |
| 698 | 703 | } |
| 699 | 704 | } |
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/PreparedStatementTest.java +12 −2
| @@ -513,6 +513,8 @@ | ||
| 513 | 513 | st3.enableTracing(); |
| 514 | 514 | ResultSet rows = session.execute(st3); |
| 515 | 515 | assertThat(rows.one().getInt("i")).isEqualTo(1234); |
| 516 | + // sleep 10 seconds to make sure the trace will be complete | |
| 517 | + Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); | |
| 516 | 518 | QueryTrace queryTrace = rows.getExecutionInfo().getQueryTrace(); |
| 517 | 519 | assertEventsContain(queryTrace, "0 tombstone"); |
| 518 | 520 | } |
| @@ -542,6 +544,8 @@ | ||
| 542 | 544 | .enableTracing()); |
| 543 | 545 | |
| 544 | 546 | assertThat(rows.one().isNull("i")); |
| 547 | + // sleep 10 seconds to make sure the trace will be complete | |
| 548 | + Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); | |
| 545 | 549 | QueryTrace queryTrace = rows.getExecutionInfo().getQueryTrace(); |
| 546 | 550 | assertEventsContain(queryTrace, "0 tombstone"); |
| 547 | 551 | } |
| @@ -571,6 +575,8 @@ | ||
| 571 | 575 | .enableTracing()); |
| 572 | 576 | |
| 573 | 577 | assertThat(rows.one().isNull("i")); |
| 578 | + // sleep 10 seconds to make sure the trace will be complete | |
| 579 | + Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); | |
| 574 | 580 | QueryTrace queryTrace = rows.getExecutionInfo().getQueryTrace(); |
| 575 | 581 | assertEventsContain(queryTrace, "0 tombstone"); |
| 576 | 582 | } |
| @@ -600,6 +606,8 @@ | ||
| 600 | 606 | st3.enableTracing(); |
| 601 | 607 | ResultSet rows = session.execute(st3); |
| 602 | 608 | assertThat(rows.one().getInt("i")).isEqualTo(1234); |
| 609 | + // sleep 10 seconds to make sure the trace will be complete | |
| 610 | + Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); | |
| 603 | 611 | QueryTrace queryTrace = rows.getExecutionInfo().getQueryTrace(); |
| 604 | 612 | assertEventsContain(queryTrace, "0 tombstone"); |
| 605 | 613 | } |
| @@ -622,8 +630,8 @@ | ||
| 622 | 630 | st2.enableTracing(); |
| 623 | 631 | ResultSet rows = session.execute(st2); |
| 624 | 632 | assertThat(rows.one().isNull(0)).isTrue(); |
| 625 | - // sleep 1 minute to make sure the trace will be complete | |
| 626 | - Uninterruptibles.sleepUninterruptibly(1, TimeUnit.MINUTES); | |
| 633 | + // sleep 10 seconds to make sure the trace will be complete | |
| 634 | + Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); | |
| 627 | 635 | QueryTrace queryTrace = rows.getExecutionInfo().getQueryTrace(); |
| 628 | 636 | assertEventsContain(queryTrace, "1 tombstone"); |
| 629 | 637 | } |
| @@ -647,6 +655,8 @@ | ||
| 647 | 655 | st2.enableTracing(); |
| 648 | 656 | ResultSet rows = session.execute(st2); |
| 649 | 657 | assertThat(rows.one().isNull(0)).isTrue(); |
| 658 | + // sleep 10 seconds to make sure the trace will be complete | |
| 659 | + Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); | |
| 650 | 660 | QueryTrace queryTrace = rows.getExecutionInfo().getQueryTrace(); |
| 651 | 661 | assertEventsContain(queryTrace, "1 tombstone"); |
| 652 | 662 | } |
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 +35 −10
| @@ -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 | } |
| @@ -259,7 +268,7 @@ | ||
| 259 | 268 | .isInKeyspace(handleId(keyspace)) |
| 260 | 269 | .hasSignature("\"ID\"(int)"); |
| 261 | 270 | } |
| 262 | - | |
| 271 | + refreshSchema(); | |
| 263 | 272 | for (Metadata m : metadatas()) |
| 264 | 273 | assertThat(m.getKeyspace(keyspace).getFunction("\"ID\"", DataType.cint())) |
| 265 | 274 | .isNotNull(); |
| @@ -270,6 +279,7 @@ | ||
| 270 | 279 | public void should_notify_of_function_update(String keyspace) { |
| 271 | 280 | session1.execute(String.format("CREATE TYPE IF NOT EXISTS %s.user (\"ID\" int, name text)", keyspace)); |
| 272 | 281 | session1.execute(String.format("CREATE FUNCTION %s.\"ID\"(user user) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return user.getInt(\"ID\");'", keyspace)); |
| 282 | + refreshSchema(); | |
| 273 | 283 | |
| 274 | 284 | for (Metadata m : metadatas()) |
| 275 | 285 | assertThat(m.getKeyspace(keyspace).getFunction("\"ID\"", m.getKeyspace(keyspace).getUserType("user")).getBody()) |
| @@ -285,7 +295,7 @@ | ||
| 285 | 295 | assertThat(previous.getValue()).hasBody("return user.getInt(\"ID\");"); |
| 286 | 296 | assertThat(current.getValue()).hasBody("return 1 + user.getInt(\"ID\");"); |
| 287 | 297 | } |
| 288 | - | |
| 298 | + refreshSchema(); | |
| 289 | 299 | for (Metadata m : metadatas()) |
| 290 | 300 | assertThat(m.getKeyspace(keyspace).getFunction("\"ID\"", m.getKeyspace(keyspace).getUserType("user")).getBody()) |
| 291 | 301 | .isEqualTo("return 1 + user.getInt(\"ID\");"); |
| @@ -305,7 +315,7 @@ | ||
| 305 | 315 | .isInKeyspace(handleId(keyspace)) |
| 306 | 316 | .hasSignature("\"ID\"(user)"); |
| 307 | 317 | } |
| 308 | - | |
| 318 | + refreshSchema(); | |
| 309 | 319 | for (Metadata m : metadatas()) |
| 310 | 320 | assertThat(m.getKeyspace(keyspace).getFunction("\"ID\"", m.getKeyspace(keyspace).getUserType("user"))) |
| 311 | 321 | .isNull(); |
| @@ -325,7 +335,7 @@ | ||
| 325 | 335 | .isInKeyspace(handleId(keyspace)) |
| 326 | 336 | .hasSignature("\"SUM\"(int)"); |
| 327 | 337 | } |
| 328 | - | |
| 338 | + refreshSchema(); | |
| 329 | 339 | for (Metadata m : metadatas()) |
| 330 | 340 | assertThat(m.getKeyspace(keyspace).getAggregate("\"SUM\"", DataType.cint())) |
| 331 | 341 | .isNotNull(); |
| @@ -337,7 +347,7 @@ | ||
| 337 | 347 | session1.execute(String.format("CREATE FUNCTION %s.\"PLUS\"(s int, v int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java" |
| 338 | 348 | + " AS 'return s+v;'", keyspace)); |
| 339 | 349 | session1.execute(String.format("CREATE AGGREGATE %s.\"SUM\"(int) SFUNC \"PLUS\" STYPE int INITCOND 0", keyspace)); |
| 340 | - | |
| 350 | + refreshSchema(); | |
| 341 | 351 | for (Metadata m : metadatas()) |
| 342 | 352 | assertThat(m.getKeyspace(keyspace).getAggregate("\"SUM\"", DataType.cint()).getInitCond()) |
| 343 | 353 | .isEqualTo(0); |
| @@ -351,7 +361,7 @@ | ||
| 351 | 361 | assertThat(previous.getValue()).hasInitCond(0); |
| 352 | 362 | assertThat(current.getValue()).hasInitCond(1); |
| 353 | 363 | } |
| 354 | - | |
| 364 | + refreshSchema(); | |
| 355 | 365 | for (Metadata m : metadatas()) |
| 356 | 366 | assertThat(m.getKeyspace(keyspace).getAggregate("\"SUM\"", DataType.cint()).getInitCond()) |
| 357 | 367 | .isEqualTo(1); |
| @@ -373,6 +383,7 @@ | ||
| 373 | 383 | .hasSignature("\"SUM\"(int)"); |
| 374 | 384 | } |
| 375 | 385 | |
| 386 | + refreshSchema(); | |
| 376 | 387 | for (Metadata m : metadatas()) |
| 377 | 388 | assertThat(m.getKeyspace(keyspace).getAggregate("\"SUM\"", DataType.cint())) |
| 378 | 389 | .isNull(); |
| @@ -383,7 +394,7 @@ | ||
| 383 | 394 | public void should_notify_of_view_creation(String keyspace) { |
| 384 | 395 | session1.execute(String.format("CREATE TABLE %s.table1 (pk int PRIMARY KEY, c int)", keyspace)); |
| 385 | 396 | session1.execute(String.format("CREATE MATERIALIZED VIEW %s.mv1 AS SELECT c FROM %s.table1 WHERE c IS NOT NULL PRIMARY KEY (pk, c)", keyspace, keyspace)); |
| 386 | - | |
| 397 | + refreshSchema(); | |
| 387 | 398 | for (Metadata m : metadatas()) |
| 388 | 399 | assertThat(m.getKeyspace(keyspace).getMaterializedView("mv1")).isNotNull(); |
| 389 | 400 | } |
| @@ -393,12 +404,12 @@ | ||
| 393 | 404 | public void should_notify_of_view_update(String keyspace) { |
| 394 | 405 | session1.execute(String.format("CREATE TABLE %s.table1 (pk int PRIMARY KEY, c int)", keyspace)); |
| 395 | 406 | session1.execute(String.format("CREATE MATERIALIZED VIEW %s.mv1 AS SELECT c FROM %s.table1 WHERE c IS NOT NULL PRIMARY KEY (pk, c) WITH compaction = { 'class' : 'SizeTieredCompactionStrategy' }", keyspace, keyspace)); |
| 396 | - | |
| 407 | + refreshSchema(); | |
| 397 | 408 | for (Metadata m : metadatas()) |
| 398 | 409 | assertThat(m.getKeyspace(keyspace).getMaterializedView("mv1").getOptions().getCompaction().get("class")).contains("SizeTieredCompactionStrategy"); |
| 399 | 410 | |
| 400 | 411 | session1.execute(String.format("ALTER MATERIALIZED VIEW %s.mv1 WITH compaction = { 'class' : 'LeveledCompactionStrategy' }", keyspace)); |
| 401 | - | |
| 412 | + refreshSchema(); | |
| 402 | 413 | for (Metadata m : metadatas()) |
| 403 | 414 | assertThat(m.getKeyspace(keyspace).getMaterializedView("mv1").getOptions().getCompaction().get("class")).contains("LeveledCompactionStrategy"); |
| 404 | 415 | } |
| @@ -409,7 +420,7 @@ | ||
| 409 | 420 | session1.execute(String.format("CREATE TABLE %s.table1 (pk int PRIMARY KEY, c int)", keyspace)); |
| 410 | 421 | session1.execute(String.format("CREATE MATERIALIZED VIEW %s.mv1 AS SELECT c FROM %s.table1 WHERE c IS NOT NULL PRIMARY KEY (pk, c)", keyspace, keyspace)); |
| 411 | 422 | session1.execute(String.format("DROP MATERIALIZED VIEW %s.mv1", keyspace)); |
| 412 | - | |
| 423 | + refreshSchema(); | |
| 413 | 424 | for (Metadata m : metadatas()) |
| 414 | 425 | assertThat(m.getKeyspace(keyspace).getMaterializedView("mv1")).isNull(); |
| 415 | 426 | } |
| @@ -422,6 +433,7 @@ | ||
| 422 | 433 | verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onKeyspaceAdded(added.capture()); |
| 423 | 434 | assertThat(added.getValue()).hasName(handleId(keyspace)); |
| 424 | 435 | } |
| 436 | + refreshSchema(); | |
| 425 | 437 | for (Metadata m : metadatas()) |
| 426 | 438 | assertThat(m.getKeyspace(keyspace)).isNotNull(); |
| 427 | 439 | } |
| @@ -436,6 +448,7 @@ | ||
| 436 | 448 | assertThat(added.getValue()).hasName(handleId(keyspace)); |
| 437 | 449 | } |
| 438 | 450 | assert added != null; |
| 451 | + refreshSchema(); | |
| 439 | 452 | for (Metadata m : metadatas()) |
| 440 | 453 | assertThat(m.getKeyspace(keyspace).isDurableWrites()).isTrue(); |
| 441 | 454 | execute(ALTER_KEYSPACE, keyspace); |
| @@ -450,6 +463,7 @@ | ||
| 450 | 463 | .hasName(handleId(keyspace)) |
| 451 | 464 | .isNotDurableWrites(); |
| 452 | 465 | } |
| 466 | + refreshSchema(); | |
| 453 | 467 | for (Metadata m : metadatas()) |
| 454 | 468 | assertThat(m.getKeyspace(keyspace)).isNotDurableWrites(); |
| 455 | 469 | } |
| @@ -464,6 +478,7 @@ | ||
| 464 | 478 | assertThat(added.getValue()).hasName(handleId(keyspace)); |
| 465 | 479 | } |
| 466 | 480 | assert added != null; |
| 481 | + refreshSchema(); | |
| 467 | 482 | for (Metadata m : metadatas()) |
| 468 | 483 | assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE"))).isNotEmpty(); |
| 469 | 484 | execute(CREATE_TABLE, keyspace); // to test table drop notifications |
| @@ -479,6 +494,7 @@ | ||
| 479 | 494 | assertThat(ks.getValue()) |
| 480 | 495 | .hasName(handleId(keyspace)); |
| 481 | 496 | } |
| 497 | + refreshSchema(); | |
| 482 | 498 | for (Metadata m : metadatas()) { |
| 483 | 499 | assertThat(m.getKeyspace(keyspace)).isNull(); |
| 484 | 500 | assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE"))).isEmpty(); |
| @@ -622,4 +638,13 @@ | ||
| 622 | 638 | return Lists.newArrayList(cluster1.getMetadata(), cluster2.getMetadata()); |
| 623 | 639 | } |
| 624 | 640 | |
| 641 | + @SuppressWarnings("unchecked") | |
| 642 | + private void refreshSchema() { | |
| 643 | + Futures.getUnchecked( | |
| 644 | + Futures.successfulAsList( | |
| 645 | + cluster1.manager.submitSchemaRefresh(null, null, null, null), | |
| 646 | + cluster2.manager.submitSchemaRefresh(null, null, null, null))); | |
| 647 | + } | |
| 648 | + | |
| 649 | + | |
| 625 | 650 | } |
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 | } |