kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 9e00c4ef5e03cf6f3cba6e212e1216e6c70fa7a0baf4cd9ba35208da763968a0 |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-03-19 12:16 +01:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-03-19 12:16 +01:00 |
| Parents | a521417641f3, 253ab5bc1334 |
9 files changed
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +133 −72
| @@ -15,31 +15,34 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import com.datastax.driver.core.Cluster.Builder; | |
| 19 | -import com.datastax.driver.core.exceptions.AlreadyExistsException; | |
| 20 | -import com.datastax.driver.core.exceptions.DriverException; | |
| 21 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 22 | - | |
| 23 | -import com.google.common.base.Joiner; | |
| 24 | -import com.google.common.collect.ImmutableMap; | |
| 25 | -import com.google.common.io.*; | |
| 26 | -import org.slf4j.Logger; | |
| 27 | -import org.slf4j.LoggerFactory; | |
| 28 | -import org.testng.annotations.AfterClass; | |
| 29 | -import org.testng.annotations.BeforeClass; | |
| 30 | - | |
| 31 | 18 | import java.io.*; |
| 32 | 19 | import java.net.InetAddress; |
| 33 | 20 | import java.net.InetSocketAddress; |
| 34 | 21 | import java.net.Socket; |
| 35 | 22 | import java.net.UnknownHostException; |
| 36 | 23 | import java.util.Collection; |
| 24 | +import java.util.Collections; | |
| 37 | 25 | import java.util.Map; |
| 38 | 26 | import java.util.concurrent.TimeUnit; |
| 27 | +import java.util.concurrent.atomic.AtomicLong; | |
| 39 | 28 | |
| 40 | -import static org.testng.Assert.fail; | |
| 29 | +import com.google.common.base.Joiner; | |
| 30 | +import com.google.common.collect.ImmutableMap; | |
| 31 | +import com.google.common.io.ByteStreams; | |
| 32 | +import com.google.common.io.Closer; | |
| 33 | +import com.google.common.io.Files; | |
| 34 | +import org.slf4j.Logger; | |
| 35 | +import org.slf4j.LoggerFactory; | |
| 36 | +import org.testng.annotations.AfterClass; | |
| 37 | +import org.testng.annotations.BeforeClass; | |
| 41 | 38 | |
| 42 | 39 | import static com.google.common.base.Preconditions.checkArgument; |
| 40 | +import static org.testng.Assert.fail; | |
| 41 | + | |
| 42 | +import com.datastax.driver.core.Cluster.Builder; | |
| 43 | +import com.datastax.driver.core.exceptions.AlreadyExistsException; | |
| 44 | +import com.datastax.driver.core.exceptions.DriverException; | |
| 45 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 43 | 46 | |
| 44 | 47 | import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT; |
| 45 | 48 | import static com.datastax.driver.core.TestUtils.SIMPLE_KEYSPACE; |
| @@ -70,6 +73,7 @@ | ||
| 70 | 73 | |
| 71 | 74 | static final File CASSANDRA_DIR; |
| 72 | 75 | static final String CASSANDRA_VERSION; |
| 76 | + | |
| 73 | 77 | static { |
| 74 | 78 | String version = System.getProperty("cassandra.version"); |
| 75 | 79 | if (version.matches(CASSANDRA_VERSION_REGEXP)) { |
| @@ -90,8 +94,7 @@ | ||
| 90 | 94 | private final Runtime runtime = Runtime.getRuntime(); |
| 91 | 95 | private final File ccmDir; |
| 92 | 96 | |
| 93 | - private CCMBridge() | |
| 94 | - { | |
| 97 | + private CCMBridge() { | |
| 95 | 98 | this.ccmDir = Files.createTempDir(); |
| 96 | 99 | } |
| 97 | 100 | |
| @@ -118,7 +121,7 @@ | ||
| 118 | 121 | OutputStream trustStoreOs = new FileOutputStream(f); |
| 119 | 122 | closer.register(trustStoreOs); |
| 120 | 123 | ByteStreams.copy(trustStoreIs, trustStoreOs); |
| 121 | - } catch(IOException e) { | |
| 124 | + } catch (IOException e) { | |
| 122 | 125 | logger.warn("Failure to write keystore, SSL-enabled servers may fail to start.", e); |
| 123 | 126 | } finally { |
| 124 | 127 | try { |
| @@ -141,7 +144,7 @@ | ||
| 141 | 144 | |
| 142 | 145 | public static CCMBridge create(String name, int nbNodes, String... options) { |
| 143 | 146 | checkArgument(!"current".equals(name.toLowerCase()), |
| 144 | - "cluster can't be called \"current\""); | |
| 147 | + "cluster can't be called \"current\""); | |
| 145 | 148 | CCMBridge bridge = new CCMBridge(); |
| 146 | 149 | bridge.execute("ccm create %s -n %d -s -i %s -b %s " + Joiner.on(" ").join(options), name, nbNodes, IP_PREFIX, CASSANDRA_VERSION); |
| 147 | 150 | return bridge; |
| @@ -157,7 +160,7 @@ | ||
| 157 | 160 | |
| 158 | 161 | public static CCMBridge create(String name, int nbNodesDC1, int nbNodesDC2) { |
| 159 | 162 | checkArgument(!"current".equals(name.toLowerCase()), |
| 160 | - "cluster can't be called \"current\""); | |
| 163 | + "cluster can't be called \"current\""); | |
| 161 | 164 | CCMBridge bridge = new CCMBridge(); |
| 162 | 165 | bridge.execute("ccm create %s -n %d:%d -s -i %s -b %s", name, nbNodesDC1, nbNodesDC2, IP_PREFIX, CASSANDRA_VERSION); |
| 163 | 166 | return bridge; |
| @@ -198,6 +201,11 @@ | ||
| 198 | 201 | execute("ccm node%d stop", n); |
| 199 | 202 | } |
| 200 | 203 | |
| 204 | + public void stop(String clusterName) { | |
| 205 | + logger.info("Stopping Cluster : "+clusterName); | |
| 206 | + execute("ccm stop "+clusterName); | |
| 207 | + } | |
| 208 | + | |
| 201 | 209 | public void forceStop(int n) { |
| 202 | 210 | logger.info("Force stopping: " + IP_PREFIX + n); |
| 203 | 211 | execute("ccm node%d stop --not-gently", n); |
| @@ -208,6 +216,11 @@ | ||
| 208 | 216 | execute("ccm remove"); |
| 209 | 217 | } |
| 210 | 218 | |
| 219 | + public void remove(String clusterName) { | |
| 220 | + stop(clusterName); | |
| 221 | + execute("ccm remove " + clusterName); | |
| 222 | + } | |
| 223 | + | |
| 211 | 224 | public void remove(int n) { |
| 212 | 225 | logger.info("Removing: " + IP_PREFIX + n); |
| 213 | 226 | execute("ccm node%d remove", n); |
| @@ -227,9 +240,19 @@ | ||
| 227 | 240 | |
| 228 | 241 | public void bootstrapNode(int n, String dc) { |
| 229 | 242 | if (dc == null) |
| 230 | - execute("ccm add node%d -i %s%d -j %d -r %d -b -s", n, IP_PREFIX, n, 7000 + 100*n, 8000 + 100*n); | |
| 243 | + execute("ccm add node%d -i %s%d -j %d -r %d -b -s", n, IP_PREFIX, n, 7000 + 100 * n, 8000 + 100 * n); | |
| 231 | 244 | else |
| 232 | - execute("ccm add node%d -i %s%d -j %d -b -d %s -s", n, IP_PREFIX, n, 7000 + 100*n, dc); | |
| 245 | + execute("ccm add node%d -i %s%d -j %d -b -d %s -s", n, IP_PREFIX, n, 7000 + 100 * n, dc); | |
| 246 | + execute("ccm node%d start --wait-other-notice --wait-for-binary-proto", n); | |
| 247 | + } | |
| 248 | + | |
| 249 | + public void bootstrapNodeWithPorts(int n, int thriftPort, int storagePort, int binaryPort, int jmxPort, int remoteDebugPort) { | |
| 250 | + String thriftItf = IP_PREFIX + n + ":" + thriftPort; | |
| 251 | + String storageItf = IP_PREFIX + n + ":" + storagePort; | |
| 252 | + String binaryItf = IP_PREFIX + n + ":" + binaryPort; | |
| 253 | + String remoteLogItf = IP_PREFIX + n + ":" + remoteDebugPort; | |
| 254 | + execute("ccm add node%d -i %s%d -b -t %s -l %s --binary-itf %s -j %d -r %s -s", | |
| 255 | + n, IP_PREFIX, n, thriftItf, storageItf, binaryItf, jmxPort, remoteLogItf); | |
| 233 | 256 | execute("ccm node%d start --wait-other-notice --wait-for-binary-proto", n); |
| 234 | 257 | } |
| 235 | 258 | |
| @@ -243,7 +266,7 @@ | ||
| 243 | 266 | |
| 244 | 267 | public void updateConfig(Map<String, String> configs) { |
| 245 | 268 | StringBuilder confStr = new StringBuilder(); |
| 246 | - for(Map.Entry<String,String> entry : configs.entrySet()) { | |
| 269 | + for (Map.Entry<String, String> entry : configs.entrySet()) { | |
| 247 | 270 | confStr.append(entry.getKey() + ":" + entry.getValue() + " "); |
| 248 | 271 | } |
| 249 | 272 | execute("ccm updateconf " + confStr); |
| @@ -339,13 +362,13 @@ | ||
| 339 | 362 | * @param requireClientAuth Whether or not to require Clients used authentication. |
| 340 | 363 | */ |
| 341 | 364 | public void enableSSL(boolean requireClientAuth) { |
| 342 | - ImmutableMap.Builder<String,String> configs = ImmutableMap.builder(); | |
| 365 | + ImmutableMap.Builder<String, String> configs = ImmutableMap.builder(); | |
| 343 | 366 | |
| 344 | 367 | configs.put("client_encryption_options.enabled", "true"); |
| 345 | 368 | configs.put("client_encryption_options.keystore", DEFAULT_SERVER_KEYSTORE_FILE.getAbsolutePath()); |
| 346 | 369 | configs.put("client_encryption_options.keystore_password", DEFAULT_SERVER_KEYSTORE_PASSWORD); |
| 347 | 370 | |
| 348 | - if(requireClientAuth) { | |
| 371 | + if (requireClientAuth) { | |
| 349 | 372 | configs.put("client_encryption_options.require_client_auth", "true"); |
| 350 | 373 | configs.put("client_encryption_options.truststore", DEFAULT_SERVER_TRUSTSTORE_FILE.getAbsolutePath()); |
| 351 | 374 | configs.put("client_encryption_options.truststore_password", DEFAULT_SERVER_TRUSTSTORE_PASSWORD); |
| @@ -396,12 +419,37 @@ | ||
| 396 | 419 | return IP_PREFIX + Integer.toString(nodeNumber); |
| 397 | 420 | } |
| 398 | 421 | |
| 422 | + public static class terminationHook extends Thread { | |
| 423 | + public void run() { | |
| 424 | + logger.debug("shut down hook task.."); | |
| 425 | + | |
| 426 | + if (PerClassSingleNodeCluster.cluster != null) { | |
| 427 | + PerClassSingleNodeCluster.cluster.close(); | |
| 428 | + } | |
| 429 | + if (PerClassSingleNodeCluster.ccmBridge == null) { | |
| 430 | + logger.error("No cluster to discard"); | |
| 431 | + } else if (PerClassSingleNodeCluster.erroredOut) { | |
| 432 | + PerClassSingleNodeCluster.ccmBridge.remove("test-class"); | |
| 433 | + logger.info("Error during tests, kept C* logs in " + PerClassSingleNodeCluster.ccmBridge.ccmDir); | |
| 434 | + } else { | |
| 435 | + PerClassSingleNodeCluster.ccmBridge.remove("test-class"); | |
| 436 | + PerClassSingleNodeCluster.ccmBridge.ccmDir.delete(); | |
| 437 | + } | |
| 438 | + | |
| 439 | + } | |
| 440 | + } | |
| 441 | + | |
| 399 | 442 | // One cluster for the whole test class |
| 400 | 443 | public static abstract class PerClassSingleNodeCluster { |
| 401 | 444 | |
| 402 | - protected static CCMBridge cassandraCluster; | |
| 445 | + protected static CCMBridge ccmBridge; | |
| 403 | 446 | private static boolean erroredOut; |
| 404 | - private static boolean schemaCreated; | |
| 447 | + private static boolean clusterInitialized=false; | |
| 448 | + private static AtomicLong ksNumber; | |
| 449 | + protected String keyspace; | |
| 450 | + | |
| 451 | + protected static InetSocketAddress hostAddress; | |
| 452 | + protected static int[] ports; | |
| 405 | 453 | |
| 406 | 454 | protected static Cluster cluster; |
| 407 | 455 | protected static Session session; |
| @@ -417,59 +465,57 @@ | ||
| 417 | 465 | erroredOut = true; |
| 418 | 466 | } |
| 419 | 467 | |
| 420 | - public void createCluster() { | |
| 421 | - erroredOut = false; | |
| 422 | - schemaCreated = false; | |
| 423 | - cassandraCluster = CCMBridge.create("test", 1); | |
| 424 | - try { | |
| 425 | - Builder builder = Cluster.builder(); | |
| 426 | - builder = configure(builder); | |
| 427 | - cluster = builder.addContactPoints(IP_PREFIX + '1').build(); | |
| 428 | - session = cluster.connect(); | |
| 429 | - } catch (NoHostAvailableException e) { | |
| 430 | - erroredOut = true; | |
| 431 | - for (Map.Entry<InetSocketAddress, Throwable> entry : e.getErrors().entrySet()) | |
| 432 | - logger.info("Error connecting to " + entry.getKey() + ": " + entry.getValue()); | |
| 433 | - throw new RuntimeException(e); | |
| 434 | - } | |
| 468 | + @BeforeClass(groups = { "short", "long" }) | |
| 469 | + public void beforeClass() { | |
| 470 | + maybeInitCluster(); | |
| 471 | + initKeyspace(); | |
| 435 | 472 | } |
| 436 | 473 | |
| 437 | - @AfterClass(groups = {"short", "long"}) | |
| 438 | - public static void discardCluster() { | |
| 439 | - if (cluster != null) | |
| 440 | - cluster.close(); | |
| 474 | + @AfterClass(groups = { "short", "long" }) | |
| 475 | + public void afterClass() { | |
| 476 | + clearSimpleKeyspace(); | |
| 477 | + } | |
| 441 | 478 | |
| 442 | - if (cassandraCluster == null) { | |
| 443 | - logger.error("No cluster to discard"); | |
| 444 | - } else if (erroredOut) { | |
| 445 | - cassandraCluster.stop(); | |
| 446 | - logger.info("Error during tests, kept C* logs in " + cassandraCluster.ccmDir); | |
| 447 | - } else { | |
| 448 | - cassandraCluster.remove(); | |
| 449 | - cassandraCluster.ccmDir.delete(); | |
| 479 | + private void maybeInitCluster(){ | |
| 480 | + if (!clusterInitialized){ | |
| 481 | + try { | |
| 482 | + //launch ccm cluster | |
| 483 | + ccmBridge = CCMBridge.create("test-class"); | |
| 484 | + | |
| 485 | + ports = new int[5]; | |
| 486 | + for (int i = 0; i < 5; i++) { | |
| 487 | + ports[i] = TestUtils.findAvailablePort(10000 + i); | |
| 488 | + } | |
| 489 | + | |
| 490 | + ccmBridge.bootstrapNodeWithPorts(1, ports[0], ports[1], ports[2], ports[3], ports[4]); | |
| 491 | + ksNumber = new AtomicLong(0); | |
| 492 | + erroredOut = false; | |
| 493 | + hostAddress = new InetSocketAddress(InetAddress.getByName(IP_PREFIX + 1), ports[2]); | |
| 494 | + | |
| 495 | + Runtime r = Runtime.getRuntime(); | |
| 496 | + r.addShutdownHook(new terminationHook()); | |
| 497 | + clusterInitialized = true; | |
| 498 | + | |
| 499 | + } catch (UnknownHostException e) { | |
| 500 | + throw new RuntimeException(e); | |
| 501 | + } | |
| 450 | 502 | } |
| 451 | - } | |
| 452 | 503 | |
| 453 | - @BeforeClass(groups = {"short", "long"}) | |
| 454 | - public void beforeClass() { | |
| 455 | - createCluster(); | |
| 456 | - maybeCreateSchema(); | |
| 457 | 504 | } |
| 458 | 505 | |
| 459 | - public void maybeCreateSchema() { | |
| 460 | 506 | |
| 507 | + private void initKeyspace() { | |
| 461 | 508 | try { |
| 462 | - if (schemaCreated) | |
| 463 | - return; | |
| 509 | + Builder builder = Cluster.builder(); | |
| 464 | 510 | |
| 465 | - try { | |
| 466 | - session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, SIMPLE_KEYSPACE, 1)); | |
| 467 | - } catch (AlreadyExistsException e) { | |
| 468 | - // It's ok, ignore | |
| 469 | - } | |
| 511 | + builder = configure(builder); | |
| 470 | 512 | |
| 471 | - session.execute("USE " + SIMPLE_KEYSPACE); | |
| 513 | + cluster = builder.addContactPointsWithPorts(Collections.singletonList(hostAddress)).build(); | |
| 514 | + session = cluster.connect(); | |
| 515 | + keyspace = SIMPLE_KEYSPACE + "_" + ksNumber.incrementAndGet(); | |
| 516 | + session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1)); | |
| 472 | 517 | |
| 518 | + session.execute("USE " + keyspace); | |
| 473 | 519 | for (String tableDef : getTableDefinitions()) { |
| 474 | 520 | try { |
| 475 | 521 | session.execute(tableDef); |
| @@ -477,13 +523,26 @@ | ||
| 477 | 523 | // It's ok, ignore |
| 478 | 524 | } |
| 479 | 525 | } |
| 480 | - | |
| 481 | - schemaCreated = true; | |
| 526 | + } catch (AlreadyExistsException e) { | |
| 527 | + // It's ok, ignore (not supposed to go there) | |
| 528 | + } catch (NoHostAvailableException e) { | |
| 529 | + erroredOut = true; | |
| 530 | + for (Map.Entry<InetSocketAddress, Throwable> entry : e.getErrors().entrySet()) | |
| 531 | + logger.info("Error connecting to " + entry.getKey() + ": " + entry.getValue()); | |
| 532 | + throw new RuntimeException(e); | |
| 482 | 533 | } catch (DriverException e) { |
| 483 | 534 | erroredOut = true; |
| 484 | 535 | throw e; |
| 485 | 536 | } |
| 486 | 537 | } |
| 538 | + | |
| 539 | + private void clearSimpleKeyspace() { | |
| 540 | + session.execute("DROP KEYSPACE " + keyspace); | |
| 541 | + if (cluster != null) { | |
| 542 | + cluster.close(); | |
| 543 | + } | |
| 544 | + } | |
| 545 | + | |
| 487 | 546 | } |
| 488 | 547 | |
| 489 | 548 | public static class CCMCluster { |
| @@ -518,10 +577,12 @@ | ||
| 518 | 577 | try { |
| 519 | 578 | String[] contactPoints = new String[totalNodes]; |
| 520 | 579 | for (int i = 0; i < totalNodes; i++) |
| 521 | - contactPoints[i] = IP_PREFIX + (i+1); | |
| 522 | - | |
| 523 | - try { Thread.sleep(1000); } catch (Exception e) {} | |
| 580 | + contactPoints[i] = IP_PREFIX + (i + 1); | |
| 524 | 581 | |
| 582 | + try { | |
| 583 | + Thread.sleep(1000); | |
| 584 | + } catch (Exception e) { | |
| 585 | + } | |
| 525 | 586 | this.cluster = builder.addContactPoints(contactPoints).build(); |
| 526 | 587 | this.session = cluster.connect(); |
| 527 | 588 | } catch (NoHostAvailableException e) { |
modified driver-core/src/test/java/com/datastax/driver/core/PreparedStatementTest.java +5 −4
| @@ -25,6 +25,7 @@ | ||
| 25 | 25 | |
| 26 | 26 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| 27 | 27 | import com.datastax.driver.core.exceptions.UnsupportedFeatureException; |
| 28 | + | |
| 28 | 29 | import static com.datastax.driver.core.TestUtils.*; |
| 29 | 30 | |
| 30 | 31 | /** |
| @@ -301,10 +302,10 @@ | ||
| 301 | 302 | |
| 302 | 303 | assertEquals(session.execute(ps.bind("123")).one().getInt("i"), 17); |
| 303 | 304 | |
| 304 | - cassandraCluster.stop(); | |
| 305 | + ccmBridge.stop(); | |
| 305 | 306 | waitForDown(CCMBridge.IP_PREFIX + '1', cluster); |
| 306 | 307 | |
| 307 | - cassandraCluster.start(); | |
| 308 | + ccmBridge.start(); | |
| 308 | 309 | waitFor(CCMBridge.IP_PREFIX + '1', cluster, 120); |
| 309 | 310 | |
| 310 | 311 | try |
| @@ -413,9 +414,9 @@ | ||
| 413 | 414 | |
| 414 | 415 | @Test(groups="short") |
| 415 | 416 | public void should_set_routing_key_on_case_insensitive_keyspace_and_table() { |
| 416 | - session.execute("CREATE TABLE ks.foo (i int PRIMARY KEY)"); | |
| 417 | + session.execute(String.format("CREATE TABLE %s.foo (i int PRIMARY KEY)",keyspace)); | |
| 417 | 418 | |
| 418 | - PreparedStatement ps = session.prepare("INSERT INTO ks.foo (i) VALUES (?)"); | |
| 419 | + PreparedStatement ps = session.prepare(String.format("INSERT INTO %s.foo (i) VALUES (?)",keyspace)); | |
| 419 | 420 | BoundStatement bs = ps.bind(1); |
| 420 | 421 | assertThat(bs.getRoutingKey()).isNotNull(); |
| 421 | 422 | } |
modified driver-core/src/test/java/com/datastax/driver/core/RecommissionedNodeTest.java +2 −0
| @@ -7,12 +7,14 @@ | ||
| 7 | 7 | import org.testng.annotations.AfterMethod; |
| 8 | 8 | import org.testng.annotations.Test; |
| 9 | 9 | |
| 10 | + | |
| 10 | 11 | import com.datastax.driver.core.utils.CassandraVersion; |
| 11 | 12 | |
| 12 | 13 | import static com.datastax.driver.core.Assertions.*; |
| 13 | 14 | import static com.datastax.driver.core.Host.State.DOWN; |
| 14 | 15 | import static com.datastax.driver.core.Host.State.UP; |
| 15 | 16 | |
| 17 | + | |
| 16 | 18 | /** |
| 17 | 19 | * Due to C* gossip bugs, system.peers may report nodes that are gone from the cluster. |
| 18 | 20 | * |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaTest.java +16 −16
| @@ -33,52 +33,52 @@ | ||
| 33 | 33 | @Override |
| 34 | 34 | protected Collection<String> getTableDefinitions() { |
| 35 | 35 | |
| 36 | - String sparse = "CREATE TABLE ks.sparse (\n" | |
| 36 | + String sparse = String.format("CREATE TABLE %s.sparse (\n" | |
| 37 | 37 | + " k text,\n" |
| 38 | 38 | + " c1 int,\n" |
| 39 | 39 | + " c2 float,\n" |
| 40 | 40 | + " l list<text>,\n" |
| 41 | 41 | + " v int,\n" |
| 42 | 42 | + " PRIMARY KEY (k, c1, c2)\n" |
| 43 | - + ");"; | |
| 43 | + + ");", keyspace); | |
| 44 | 44 | |
| 45 | - String st = "CREATE TABLE ks.static (\n" | |
| 45 | + String st = String.format("CREATE TABLE %s.static (\n" | |
| 46 | 46 | + " k text,\n" |
| 47 | 47 | + " i int,\n" |
| 48 | 48 | + " m map<text, timeuuid>,\n" |
| 49 | 49 | + " v int,\n" |
| 50 | 50 | + " PRIMARY KEY (k)\n" |
| 51 | - + ");"; | |
| 51 | + + ");", keyspace); | |
| 52 | 52 | |
| 53 | - String counters = "CREATE TABLE ks.counters (\n" | |
| 53 | + String counters = String.format("CREATE TABLE %s.counters (\n" | |
| 54 | 54 | + " k text,\n" |
| 55 | 55 | + " c counter,\n" |
| 56 | 56 | + " PRIMARY KEY (k)\n" |
| 57 | - + ");"; | |
| 57 | + + ");", keyspace); | |
| 58 | 58 | |
| 59 | - String compactStatic = "CREATE TABLE ks.compact_static (\n" | |
| 59 | + String compactStatic = String.format("CREATE TABLE %s.compact_static (\n" | |
| 60 | 60 | + " k text,\n" |
| 61 | 61 | + " i int,\n" |
| 62 | 62 | + " t timeuuid,\n" |
| 63 | 63 | + " v int,\n" |
| 64 | 64 | + " PRIMARY KEY (k)\n" |
| 65 | - + ") WITH COMPACT STORAGE;"; | |
| 65 | + + ") WITH COMPACT STORAGE;", keyspace); | |
| 66 | 66 | |
| 67 | - String compactDynamic = "CREATE TABLE ks.compact_dynamic (\n" | |
| 67 | + String compactDynamic = String.format("CREATE TABLE %s.compact_dynamic (\n" | |
| 68 | 68 | + " k text,\n" |
| 69 | 69 | + " c int,\n" |
| 70 | 70 | + " v timeuuid,\n" |
| 71 | 71 | + " PRIMARY KEY (k, c)\n" |
| 72 | - + ") WITH COMPACT STORAGE;"; | |
| 72 | + + ") WITH COMPACT STORAGE;", keyspace); | |
| 73 | 73 | |
| 74 | - String compactComposite = "CREATE TABLE ks.compact_composite (\n" | |
| 74 | + String compactComposite = String.format("CREATE TABLE %s.compact_composite (\n" | |
| 75 | 75 | + " k text,\n" |
| 76 | 76 | + " c1 int,\n" |
| 77 | 77 | + " c2 float,\n" |
| 78 | 78 | + " c3 double,\n" |
| 79 | 79 | + " v timeuuid,\n" |
| 80 | 80 | + " PRIMARY KEY (k, c1, c2, c3)\n" |
| 81 | - + ") WITH COMPACT STORAGE;"; | |
| 81 | + + ") WITH COMPACT STORAGE;", keyspace); | |
| 82 | 82 | |
| 83 | 83 | cql3.put("sparse", sparse); |
| 84 | 84 | cql3.put("static", st); |
| @@ -87,7 +87,7 @@ | ||
| 87 | 87 | compact.put("compact_dynamic", compactDynamic); |
| 88 | 88 | compact.put("compact_composite", compactComposite); |
| 89 | 89 | |
| 90 | - withOptions = "CREATE TABLE ks.with_options (\n" | |
| 90 | + withOptions = String.format("CREATE TABLE %s.with_options (\n" | |
| 91 | 91 | + " k text,\n" |
| 92 | 92 | + " v1 int,\n" |
| 93 | 93 | + " v2 int,\n" |
| @@ -102,7 +102,7 @@ | ||
| 102 | 102 | + " AND caching = 'ALL'\n" |
| 103 | 103 | + " AND comment = 'My awesome table'\n" |
| 104 | 104 | + " AND compaction = { 'class' : 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy', 'sstable_size_in_mb' : 15 }\n" |
| 105 | - + " AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.SnappyCompressor', 'chunk_length_kb' : 128 };"; | |
| 105 | + + " AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.SnappyCompressor', 'chunk_length_kb' : 128 };", keyspace); | |
| 106 | 106 | |
| 107 | 107 | List<String> allDefs = new ArrayList<String>(); |
| 108 | 108 | allDefs.addAll(cql3.values()); |
| @@ -126,7 +126,7 @@ | ||
| 126 | 126 | @Test(groups = "short") |
| 127 | 127 | public void schemaExportTest() { |
| 128 | 128 | |
| 129 | - KeyspaceMetadata metadata = cluster.getMetadata().getKeyspace(TestUtils.SIMPLE_KEYSPACE); | |
| 129 | + KeyspaceMetadata metadata = cluster.getMetadata().getKeyspace(keyspace); | |
| 130 | 130 | |
| 131 | 131 | for (Map.Entry<String, String> tableEntry : cql3.entrySet()) { |
| 132 | 132 | String table = tableEntry.getKey(); |
| @@ -144,7 +144,7 @@ | ||
| 144 | 144 | // Same remark as the preceding test |
| 145 | 145 | @Test(groups = "short") |
| 146 | 146 | public void schemaExportOptionsTest() { |
| 147 | - TableMetadata metadata = cluster.getMetadata().getKeyspace(TestUtils.SIMPLE_KEYSPACE).getTable("with_options"); | |
| 147 | + TableMetadata metadata = cluster.getMetadata().getKeyspace(keyspace).getTable("with_options"); | |
| 148 | 148 | |
| 149 | 149 | String withOpts = withOptions; |
| 150 | 150 | // With C* 2.0 we'll have a few additional options |
added driver-core/src/test/java/com/datastax/driver/core/SessionLeakTest.java +85 −0
| @@ -0,0 +1,85 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +import org.testng.annotations.Test; | |
| 4 | + | |
| 5 | +import java.util.Collections; | |
| 6 | + | |
| 7 | +import static org.testng.Assert.assertEquals; | |
| 8 | + | |
| 9 | + | |
| 10 | +public class SessionLeakTest { | |
| 11 | + | |
| 12 | + | |
| 13 | + @Test(groups = "short") | |
| 14 | + public void connectionLeakTest() throws Exception { | |
| 15 | + // Checking for JAVA-342 | |
| 16 | + CCMBridge ccmBridge; | |
| 17 | + ccmBridge = CCMBridge.create("test", 1); | |
| 18 | + | |
| 19 | + // give the driver time to close other sessions in this class | |
| 20 | + //Thread.sleep(10); | |
| 21 | + | |
| 22 | + // create a new cluster object and ensure 0 sessions and connections | |
| 23 | + Cluster cluster = Cluster.builder().addContactPoints(CCMBridge.IP_PREFIX + '1').build(); | |
| 24 | + | |
| 25 | + int corePoolSize = cluster.getConfiguration() | |
| 26 | + .getPoolingOptions() | |
| 27 | + .getCoreConnectionsPerHost(HostDistance.LOCAL); | |
| 28 | + | |
| 29 | + assertEquals(cluster.manager.sessions.size(), 0); | |
| 30 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 0); | |
| 31 | + | |
| 32 | + // ensure sessions.size() returns with 1 control connection + core pool size. | |
| 33 | + Session session = cluster.connect(); | |
| 34 | + assertEquals(cluster.manager.sessions.size(), 1); | |
| 35 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + corePoolSize); | |
| 36 | + | |
| 37 | + // ensure sessions.size() returns to 0 with only 1 active connection (the control connection) | |
| 38 | + session.close(); | |
| 39 | + assertEquals(cluster.manager.sessions.size(), 0); | |
| 40 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); | |
| 41 | + | |
| 42 | + try { | |
| 43 | + Session thisSession; | |
| 44 | + | |
| 45 | + // ensure bootstrapping a node does not create additional connections | |
| 46 | + | |
| 47 | + | |
| 48 | + ccmBridge.bootstrapNode(2); | |
| 49 | + assertEquals(cluster.manager.sessions.size(), 0); | |
| 50 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); | |
| 51 | + | |
| 52 | + // ensure a new session gets registered and core connections are established | |
| 53 | + // there should be corePoolSize more connections to accommodate for the new host. | |
| 54 | + thisSession = cluster.connect(); | |
| 55 | + assertEquals(cluster.manager.sessions.size(), 1); | |
| 56 | + | |
| 57 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + (corePoolSize * 2)); | |
| 58 | + | |
| 59 | + // ensure bootstrapping a node does not create additional connections that won't get cleaned up | |
| 60 | + thisSession.close(); | |
| 61 | + | |
| 62 | + assertEquals(cluster.manager.sessions.size(), 0); | |
| 63 | + | |
| 64 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); | |
| 65 | + | |
| 66 | + | |
| 67 | + } finally { | |
| 68 | + // ensure we decommission node2 for the rest of the tests | |
| 69 | + | |
| 70 | + assertEquals(cluster.manager.sessions.size(), 0); | |
| 71 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); | |
| 72 | + | |
| 73 | + if(cluster != null){ | |
| 74 | + cluster.close(); | |
| 75 | + | |
| 76 | + } | |
| 77 | + | |
| 78 | + if (ccmBridge != null) { | |
| 79 | + ccmBridge.remove(); | |
| 80 | + } | |
| 81 | + | |
| 82 | + | |
| 83 | + } | |
| 84 | + } | |
| 85 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/SessionTest.java +10 −64
| @@ -15,17 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Arrays; | |
| 19 | -import java.util.Collection; | |
| 20 | -import java.util.List; | |
| 21 | -import java.util.Locale; | |
| 22 | -import java.util.concurrent.*; | |
| 18 | +import java.util.*; | |
| 19 | +import java.util.concurrent.CountDownLatch; | |
| 20 | +import java.util.concurrent.ExecutorService; | |
| 21 | +import java.util.concurrent.Executors; | |
| 22 | +import java.util.concurrent.TimeUnit; | |
| 23 | 23 | |
| 24 | 24 | import org.testng.annotations.Test; |
| 25 | + | |
| 25 | 26 | import static org.testng.Assert.assertEquals; |
| 26 | 27 | import static org.testng.Assert.assertTrue; |
| 27 | 28 | import static org.testng.Assert.fail; |
| 28 | 29 | |
| 30 | + | |
| 31 | + | |
| 29 | 32 | /** |
| 30 | 33 | * Simple test of the Sessions methods against a one node cluster. |
| 31 | 34 | */ |
| @@ -112,7 +115,7 @@ | ||
| 112 | 115 | |
| 113 | 116 | try { |
| 114 | 117 | |
| 115 | - Session compressedSession = cluster.connect(TestUtils.SIMPLE_KEYSPACE); | |
| 118 | + Session compressedSession = cluster.connect(keyspace); | |
| 116 | 119 | |
| 117 | 120 | // Simple calls to all versions of the execute/executeAsync methods |
| 118 | 121 | String key = "execute_compressed_test"; |
| @@ -196,63 +199,6 @@ | ||
| 196 | 199 | } |
| 197 | 200 | } |
| 198 | 201 | |
| 199 | - @Test(groups = "short") | |
| 200 | - public void connectionLeakTest() throws Exception { | |
| 201 | - // Checking for JAVA-342 | |
| 202 | - | |
| 203 | - // give the driver time to close other sessions in this class | |
| 204 | - Thread.sleep(10); | |
| 205 | - | |
| 206 | - // create a new cluster object and ensure 0 sessions and connections | |
| 207 | - Cluster cluster = Cluster.builder().addContactPoints(CCMBridge.IP_PREFIX + '1').build(); | |
| 208 | - | |
| 209 | - int corePoolSize = cluster.getConfiguration() | |
| 210 | - .getPoolingOptions() | |
| 211 | - .getCoreConnectionsPerHost(HostDistance.LOCAL); | |
| 212 | - | |
| 213 | - assertEquals(cluster.manager.sessions.size(), 0); | |
| 214 | - assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 0); | |
| 215 | - | |
| 216 | - // ensure sessions.size() returns with 1 control connection + core pool size. | |
| 217 | - Session session = cluster.connect(); | |
| 218 | - assertEquals(cluster.manager.sessions.size(), 1); | |
| 219 | - assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + corePoolSize); | |
| 220 | - | |
| 221 | - // ensure sessions.size() returns to 0 with only 1 active connection (the control connection) | |
| 222 | - session.close(); | |
| 223 | - assertEquals(cluster.manager.sessions.size(), 0); | |
| 224 | - assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); | |
| 225 | - | |
| 226 | - try { | |
| 227 | - Session thisSession; | |
| 228 | - | |
| 229 | - // ensure bootstrapping a node does not create additional connections | |
| 230 | - cassandraCluster.bootstrapNode(2); | |
| 231 | - assertEquals(cluster.manager.sessions.size(), 0); | |
| 232 | - assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); | |
| 233 | - | |
| 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. | |
| 236 | - thisSession = cluster.connect(); | |
| 237 | - assertEquals(cluster.manager.sessions.size(), 1); | |
| 238 | - assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + (corePoolSize * 2)); | |
| 239 | - | |
| 240 | - // ensure bootstrapping a node does not create additional connections that won't get cleaned up | |
| 241 | - thisSession.close(); | |
| 242 | - assertEquals(cluster.manager.sessions.size(), 0); | |
| 243 | - assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); | |
| 244 | - | |
| 245 | - } finally { | |
| 246 | - // ensure we decommission node2 for the rest of the tests | |
| 247 | - cassandraCluster.decommissionNode(2); | |
| 248 | - | |
| 249 | - assertEquals(cluster.manager.sessions.size(), 0); | |
| 250 | - assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); | |
| 251 | - | |
| 252 | - cluster.close(); | |
| 253 | - } | |
| 254 | - } | |
| 255 | - | |
| 256 | 202 | /** |
| 257 | 203 | * Checks for deadlocks when a session shutdown races with the initialization of the cluster (JAVA-418). |
| 258 | 204 | */ |
| @@ -262,7 +208,7 @@ | ||
| 262 | 208 | |
| 263 | 209 | // Use our own cluster and session (not the ones provided by the parent class) because we want an uninitialized cluster |
| 264 | 210 | // (note the use of newSession below) |
| 265 | - final Cluster cluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "1").build(); | |
| 211 | + final Cluster cluster = Cluster.builder().addContactPointsWithPorts(Collections.singletonList(hostAddress)).build(); | |
| 266 | 212 | final Session session = cluster.newSession(); |
| 267 | 213 | |
| 268 | 214 | // Spawn two threads to simulate the race |
modified driver-core/src/test/java/com/datastax/driver/core/TableMetadataTest.java +1 −1
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | |
| 20 | 20 | @Test(groups = "short") |
| 21 | 21 | public void should_escape_single_quote_table_comment() { |
| 22 | - TableMetadata table = cluster.getMetadata().getKeyspace("ks").getTable("single_quote"); | |
| 22 | + TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("single_quote"); | |
| 23 | 23 | assertThat(table.asCQLQuery()).contains("comment with single quote '' should work"); |
| 24 | 24 | } |
| 25 | 25 | } |
| No newline at the end of the file |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderITest.java +9 −9
| @@ -15,12 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | - | |
| 19 | 18 | import java.util.Arrays; |
| 20 | 19 | import java.util.Collection; |
| 21 | 20 | import java.util.TreeSet; |
| 22 | 21 | |
| 23 | 22 | import org.testng.annotations.Test; |
| 23 | + | |
| 24 | 24 | import static org.testng.Assert.*; |
| 25 | 25 | |
| 26 | 26 | import com.datastax.driver.core.*; |
| @@ -44,10 +44,10 @@ | ||
| 44 | 44 | public void remainingDeleteTests() throws Exception { |
| 45 | 45 | |
| 46 | 46 | Statement query; |
| 47 | - TableMetadata table = cluster.getMetadata().getKeyspace(TestUtils.SIMPLE_KEYSPACE).getTable(TABLE_TEXT); | |
| 47 | + TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable(TABLE_TEXT); | |
| 48 | 48 | assertNotNull(table); |
| 49 | 49 | |
| 50 | - String expected = "DELETE k FROM ks.test_text;"; | |
| 50 | + String expected = String.format("DELETE k FROM %s.test_text;", keyspace); | |
| 51 | 51 | query = delete("k").from(table); |
| 52 | 52 | assertEquals(query.toString(), expected); |
| 53 | 53 | try { |
| @@ -210,25 +210,25 @@ | ||
| 210 | 210 | @Test(groups = "short") |
| 211 | 211 | @CassandraVersion(major=2.0, minor=7, description="DELETE..IF EXISTS only supported in 2.0.7+ (CASSANDRA-5708)") |
| 212 | 212 | public void conditionalDeletesTest() throws Exception { |
| 213 | - session.execute("INSERT INTO ks.test_int (k, a, b) VALUES (1, 1, 1)"); | |
| 213 | + session.execute(String.format("INSERT INTO %s.test_int (k, a, b) VALUES (1, 1, 1)",keyspace)); | |
| 214 | 214 | |
| 215 | 215 | Statement delete; |
| 216 | 216 | Row row; |
| 217 | - delete = delete().from(TestUtils.SIMPLE_KEYSPACE, TABLE_INT).where(eq("k", 2)).ifExists(); | |
| 217 | + delete = delete().from(keyspace, TABLE_INT).where(eq("k", 2)).ifExists(); | |
| 218 | 218 | row = session.execute(delete).one(); |
| 219 | 219 | assertFalse(row.getBool("[applied]")); |
| 220 | 220 | |
| 221 | - delete = delete().from(TestUtils.SIMPLE_KEYSPACE, TABLE_INT).where(eq("k", 1)).ifExists(); | |
| 221 | + delete = delete().from(keyspace, TABLE_INT).where(eq("k", 1)).ifExists(); | |
| 222 | 222 | row = session.execute(delete).one(); |
| 223 | 223 | assertTrue(row.getBool("[applied]")); |
| 224 | 224 | |
| 225 | - session.execute("INSERT INTO ks.test_int (k, a, b) VALUES (1, 1, 1)"); | |
| 225 | + session.execute(String.format("INSERT INTO %s.test_int (k, a, b) VALUES (1, 1, 1)", keyspace)); | |
| 226 | 226 | |
| 227 | - delete = delete().from(TestUtils.SIMPLE_KEYSPACE, TABLE_INT).where(eq("k", 1)).onlyIf(eq("a", 1)).and(eq("b", 2)); | |
| 227 | + delete = delete().from(keyspace, TABLE_INT).where(eq("k", 1)).onlyIf(eq("a", 1)).and(eq("b", 2)); | |
| 228 | 228 | row = session.execute(delete).one(); |
| 229 | 229 | assertFalse(row.getBool("[applied]")); |
| 230 | 230 | |
| 231 | - delete = delete().from(TestUtils.SIMPLE_KEYSPACE, TABLE_INT).where(eq("k", 1)).onlyIf(eq("a", 1)).and(eq("b", 1)); | |
| 231 | + delete = delete().from(keyspace, TABLE_INT).where(eq("k", 1)).onlyIf(eq("a", 1)).and(eq("b", 1)); | |
| 232 | 232 | row = session.execute(delete).one(); |
| 233 | 233 | assertTrue(row.getBool("[applied]")); |
| 234 | 234 | } |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderRoutingKeyTest.java +8 −6
| @@ -20,10 +20,12 @@ | ||
| 20 | 20 | import java.util.Collection; |
| 21 | 21 | |
| 22 | 22 | import org.testng.annotations.Test; |
| 23 | + | |
| 23 | 24 | import static org.testng.Assert.assertEquals; |
| 24 | 25 | import static org.testng.Assert.assertNotNull; |
| 25 | 26 | |
| 26 | 27 | import com.datastax.driver.core.*; |
| 28 | + | |
| 27 | 29 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 28 | 30 | |
| 29 | 31 | public class QueryBuilderRoutingKeyTest extends CCMBridge.PerClassSingleNodeCluster { |
| @@ -41,7 +43,7 @@ | ||
| 41 | 43 | public void textRoutingKeyTest() throws Exception { |
| 42 | 44 | |
| 43 | 45 | Statement query; |
| 44 | - TableMetadata table = cluster.getMetadata().getKeyspace(TestUtils.SIMPLE_KEYSPACE).getTable(TABLE_TEXT); | |
| 46 | + TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable(TABLE_TEXT); | |
| 45 | 47 | assertNotNull(table); |
| 46 | 48 | |
| 47 | 49 | String txt = "If she weighs the same as a duck... she's made of wood."; |
| @@ -61,7 +63,7 @@ | ||
| 61 | 63 | public void intRoutingKeyTest() throws Exception { |
| 62 | 64 | |
| 63 | 65 | Statement query; |
| 64 | - TableMetadata table = cluster.getMetadata().getKeyspace(TestUtils.SIMPLE_KEYSPACE).getTable(TABLE_INT); | |
| 66 | + TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable(TABLE_INT); | |
| 65 | 67 | assertNotNull(table); |
| 66 | 68 | |
| 67 | 69 | query = insertInto(table).values(new String[]{"k", "a", "b"}, new Object[]{42, 1, 2}); |
| @@ -82,7 +84,7 @@ | ||
| 82 | 84 | public void intRoutingBatchKeyTest() throws Exception { |
| 83 | 85 | |
| 84 | 86 | RegularStatement query; |
| 85 | - TableMetadata table = cluster.getMetadata().getKeyspace(TestUtils.SIMPLE_KEYSPACE).getTable(TABLE_INT); | |
| 87 | + TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable(TABLE_INT); | |
| 86 | 88 | assertNotNull(table); |
| 87 | 89 | |
| 88 | 90 | ByteBuffer bb = ByteBuffer.allocate(4); |
| @@ -95,8 +97,8 @@ | ||
| 95 | 97 | query = select().from(table).where(eq("k", 42)); |
| 96 | 98 | |
| 97 | 99 | batch_query = "BEGIN BATCH "; |
| 98 | - batch_query += "INSERT INTO ks.test_int(k,a) VALUES (42,1);"; | |
| 99 | - batch_query += "UPDATE ks.test_int USING TTL 400;"; | |
| 100 | + batch_query += String.format("INSERT INTO %s.test_int(k,a) VALUES (42,1);", keyspace); | |
| 101 | + batch_query += String.format("UPDATE %s.test_int USING TTL 400;", keyspace); | |
| 100 | 102 | batch_query += "APPLY BATCH;"; |
| 101 | 103 | batch = batch() |
| 102 | 104 | .add(insertInto(table).values(new String[]{"k", "a"}, new Object[]{42, 1})) |
| @@ -106,7 +108,7 @@ | ||
| 106 | 108 | // TODO: rs = session.execute(batch); // Not guaranteed to be valid CQL |
| 107 | 109 | |
| 108 | 110 | batch_query = "BEGIN BATCH "; |
| 109 | - batch_query += "SELECT * FROM ks.test_int WHERE k=42;"; | |
| 111 | + batch_query += String.format("SELECT * FROM %s.test_int WHERE k=42;", keyspace); | |
| 110 | 112 | batch_query += "APPLY BATCH;"; |
| 111 | 113 | batch = batch(query); |
| 112 | 114 | assertEquals(batch.getRoutingKey(), bb); |