kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 12df520b331ade4fd9d54eefdbdf59b161d11574ff9d5983f450a824b359d100 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2016-12-06 20:21 -06:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2016-12-14 17:44 -06:00 |
| Parents | ded53c12ab71 |
2 files changed
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +39 −6
| @@ -34,8 +34,7 @@ | ||
| 34 | 34 | import java.util.regex.Matcher; |
| 35 | 35 | import java.util.regex.Pattern; |
| 36 | 36 | |
| 37 | -import static com.datastax.driver.core.TestUtils.executeNoFail; | |
| 38 | -import static com.datastax.driver.core.TestUtils.findAvailablePort; | |
| 37 | +import static com.datastax.driver.core.TestUtils.*; | |
| 39 | 38 | |
| 40 | 39 | public class CCMBridge implements CCMAccess { |
| 41 | 40 | |
| @@ -236,7 +235,9 @@ | ||
| 236 | 235 | |
| 237 | 236 | private boolean closed = false; |
| 238 | 237 | |
| 239 | - private CCMBridge(String clusterName, boolean isDSE, VersionNumber version, int storagePort, int thriftPort, int binaryPort, String jvmArgs) { | |
| 238 | + private final int[] nodes; | |
| 239 | + | |
| 240 | + private CCMBridge(String clusterName, boolean isDSE, VersionNumber version, int storagePort, int thriftPort, int binaryPort, String jvmArgs, int[] nodes) { | |
| 240 | 241 | this.clusterName = clusterName; |
| 241 | 242 | this.version = version; |
| 242 | 243 | this.storagePort = storagePort; |
| @@ -244,6 +245,7 @@ | ||
| 244 | 245 | this.binaryPort = binaryPort; |
| 245 | 246 | this.isDSE = isDSE; |
| 246 | 247 | this.jvmArgs = jvmArgs; |
| 248 | + this.nodes = nodes; | |
| 247 | 249 | this.ccmDir = Files.createTempDir(); |
| 248 | 250 | } |
| 249 | 251 | |
| @@ -394,6 +396,21 @@ | ||
| 394 | 396 | logger.debug("Closed: {}", this); |
| 395 | 397 | } |
| 396 | 398 | |
| 399 | + /** | |
| 400 | + * Based on C* version, return the wait arguments. | |
| 401 | + * | |
| 402 | + * @return For C* 1.x, --wait-other-notice otherwise --no-wait | |
| 403 | + */ | |
| 404 | + private String getStartWaitArguments() { | |
| 405 | + // make a small exception for C* 1.2 as it has a bug where it starts listening on the binary | |
| 406 | + // interface slightly before it joins the cluster. | |
| 407 | + if (getCassandraVersion().startsWith("1.")) { | |
| 408 | + return " --wait-other-notice"; | |
| 409 | + } else { | |
| 410 | + return " --no-wait"; | |
| 411 | + } | |
| 412 | + } | |
| 413 | + | |
| 397 | 414 | @Override |
| 398 | 415 | public synchronized void start() { |
| 399 | 416 | if (started) |
| @@ -401,11 +418,23 @@ | ||
| 401 | 418 | if (logger.isDebugEnabled()) |
| 402 | 419 | logger.debug("Starting: {} - free memory: {} MB", this, TestUtils.getFreeMemoryMB()); |
| 403 | 420 | try { |
| 404 | - String cmd = CCM_COMMAND + " start --wait-other-notice --wait-for-binary-proto" + jvmArgs; | |
| 421 | + String cmd = CCM_COMMAND + " start " + jvmArgs + getStartWaitArguments(); | |
| 405 | 422 | if (isWindows() && this.version.compareTo(VersionNumber.parse("2.2.4")) >= 0) { |
| 406 | 423 | cmd += " --quiet-windows"; |
| 407 | 424 | } |
| 408 | 425 | execute(cmd); |
| 426 | + | |
| 427 | + // Wait for binary interface on each node. | |
| 428 | + int n = 1; | |
| 429 | + for (int dc = 1; dc <= nodes.length; dc++) { | |
| 430 | + int nodesInDc = nodes[dc - 1]; | |
| 431 | + for (int i = 0; i < nodesInDc; i++) { | |
| 432 | + InetSocketAddress addr = new InetSocketAddress(ipOfNode(n), binaryPort); | |
| 433 | + logger.debug("Waiting for binary protocol to show up for {}", addr); | |
| 434 | + TestUtils.waitUntilPortIsUp(addr); | |
| 435 | + n++; | |
| 436 | + } | |
| 437 | + } | |
| 409 | 438 | } catch (CCMException e) { |
| 410 | 439 | logger.error("Could not start " + this, e); |
| 411 | 440 | logger.error("CCM output:\n{}", e.getOut()); |
| @@ -463,11 +492,15 @@ | ||
| 463 | 492 | public void start(int n) { |
| 464 | 493 | logger.debug(String.format("Starting: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 465 | 494 | try { |
| 466 | - String cmd = CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto" + jvmArgs; | |
| 495 | + String cmd = CCM_COMMAND + " node%d start " + jvmArgs + getStartWaitArguments(); | |
| 467 | 496 | if (isWindows() && this.version.compareTo(VersionNumber.parse("2.2.4")) >= 0) { |
| 468 | 497 | cmd += " --quiet-windows"; |
| 469 | 498 | } |
| 470 | 499 | execute(cmd, n); |
| 500 | + // Wait for binary interface | |
| 501 | + InetSocketAddress addr = new InetSocketAddress(ipOfNode(n), binaryPort); | |
| 502 | + logger.debug("Waiting for binary protocol to show up for {}", addr); | |
| 503 | + TestUtils.waitUntilPortIsUp(addr); | |
| 471 | 504 | } catch (CCMException e) { |
| 472 | 505 | logger.error(String.format("Could not start node %s in %s", n, this), e); |
| 473 | 506 | logger.error("CCM output:\n{}", e.getOut()); |
| @@ -875,7 +908,7 @@ | ||
| 875 | 908 | int storagePort = Integer.parseInt(cassandraConfiguration.get("storage_port").toString()); |
| 876 | 909 | int thriftPort = Integer.parseInt(cassandraConfiguration.get("rpc_port").toString()); |
| 877 | 910 | int binaryPort = Integer.parseInt(cassandraConfiguration.get("native_transport_port").toString()); |
| 878 | - final CCMBridge ccm = new CCMBridge(clusterName, dse, version, storagePort, thriftPort, binaryPort, joinJvmArgs()); | |
| 911 | + final CCMBridge ccm = new CCMBridge(clusterName, dse, version, storagePort, thriftPort, binaryPort, joinJvmArgs(), nodes); | |
| 879 | 912 | |
| 880 | 913 | Runtime.getRuntime().addShutdownHook(new Thread() { |
| 881 | 914 | @Override |
modified driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java +0 −6
| @@ -919,12 +919,6 @@ | ||
| 919 | 919 | } |
| 920 | 920 | LOGGER.debug("Using {}", ccm); |
| 921 | 921 | } |
| 922 | - | |
| 923 | - // Check to ensure binary protocol is listening before proceeding. | |
| 924 | - for (InetSocketAddress node : getContactPointsWithPorts()) { | |
| 925 | - LOGGER.debug("Waiting for binary protocol to show up for {}", node); | |
| 926 | - TestUtils.waitUntilPortIsUp(node); | |
| 927 | - } | |
| 928 | 922 | } |
| 929 | 923 | |
| 930 | 924 | protected void initTestCluster(Object testInstance) throws Exception { |