kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 6154c03e10b0abb62058a62d24e1e4c56c9fe15ea7b4a5e03afdfd5bc1514029 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2017-01-10 23:21 -06:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2017-01-11 21:47 -06:00 |
| Parents | acff5551b9b4 |
12 files changed
modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +0 −5
| @@ -26,7 +26,6 @@ | ||
| 26 | 26 | import org.scassandra.http.client.PrimingRequest; |
| 27 | 27 | import org.slf4j.Logger; |
| 28 | 28 | import org.slf4j.LoggerFactory; |
| 29 | -import org.testng.SkipException; | |
| 30 | 29 | import org.testng.annotations.Test; |
| 31 | 30 | |
| 32 | 31 | import java.net.InetAddress; |
| @@ -55,9 +54,6 @@ | ||
| 55 | 54 | */ |
| 56 | 55 | @Test(groups = "short") |
| 57 | 56 | public void should_handle_failing_or_missing_contact_points() throws UnknownHostException { |
| 58 | - if (TestUtils.getDesiredProtocolVersion().compareTo(ProtocolVersion.V2) > 0) | |
| 59 | - throw new SkipException("Scassandra does not yet support protocol >= V3"); | |
| 60 | - | |
| 61 | 57 | Cluster cluster = null; |
| 62 | 58 | Scassandra scassandra = null; |
| 63 | 59 | List<FakeHost> failingHosts = Lists.newArrayList(); |
| @@ -107,7 +103,6 @@ | ||
| 107 | 103 | .withSocketOptions(socketOptions) |
| 108 | 104 | .withReconnectionPolicy(reconnectionPolicy) |
| 109 | 105 | .withPoolingOptions(poolingOptions) |
| 110 | - .withProtocolVersion(TestUtils.getDesiredProtocolVersion()) | |
| 111 | 106 | .build(); |
| 112 | 107 | cluster.connect(); |
| 113 | 108 |
modified driver-core/src/test/java/com/datastax/driver/core/ConnectionReleaseTest.java +0 −1
| @@ -86,7 +86,6 @@ | ||
| 86 | 86 | cluster = Cluster.builder() |
| 87 | 87 | .addContactPoints(hostAddress.getAddress()) |
| 88 | 88 | .withPort(scassandra.getBinaryPort()) |
| 89 | - .withProtocolVersion(ProtocolVersion.V2) | |
| 90 | 89 | .withPoolingOptions(new PoolingOptions() |
| 91 | 90 | .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) |
| 92 | 91 | .setMaxConnectionsPerHost(HostDistance.LOCAL, 1)) |
modified driver-core/src/test/java/com/datastax/driver/core/HeartbeatTest.java +0 −3
| @@ -67,7 +67,6 @@ | ||
| 67 | 67 | Cluster cluster = Cluster.builder() |
| 68 | 68 | .addContactPoints(hostAddress.getAddress()) |
| 69 | 69 | .withPort(scassandra.getBinaryPort()) |
| 70 | - .withProtocolVersion(ProtocolVersion.V2) | |
| 71 | 70 | .withPoolingOptions(new PoolingOptions().setHeartbeatIntervalSeconds(3)) |
| 72 | 71 | .build(); |
| 73 | 72 | |
| @@ -157,7 +156,6 @@ | ||
| 157 | 156 | Cluster cluster = Cluster.builder() |
| 158 | 157 | .addContactPoints(hostAddress.getAddress()) |
| 159 | 158 | .withPort(scassandra.getBinaryPort()) |
| 160 | - .withProtocolVersion(ProtocolVersion.V2) | |
| 161 | 159 | .withPoolingOptions(new PoolingOptions().setHeartbeatIntervalSeconds(3).setConnectionsPerHost(HostDistance.LOCAL, 1, 1)) |
| 162 | 160 | .build(); |
| 163 | 161 | |
| @@ -257,7 +255,6 @@ | ||
| 257 | 255 | .withPort(scassandra.getBinaryPort()) |
| 258 | 256 | .withPoolingOptions(new PoolingOptions() |
| 259 | 257 | .setHeartbeatIntervalSeconds(0)) |
| 260 | - .withProtocolVersion(ProtocolVersion.V2) | |
| 261 | 258 | .build(); |
| 262 | 259 | |
| 263 | 260 | try { |
modified driver-core/src/test/java/com/datastax/driver/core/HostConnectionPoolTest.java +11 −24
| @@ -16,7 +16,10 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import com.codahale.metrics.Gauge; |
| 19 | -import com.datastax.driver.core.exceptions.*; | |
| 19 | +import com.datastax.driver.core.exceptions.BusyConnectionException; | |
| 20 | +import com.datastax.driver.core.exceptions.BusyPoolException; | |
| 21 | +import com.datastax.driver.core.exceptions.ConnectionException; | |
| 22 | +import com.datastax.driver.core.exceptions.DriverException; | |
| 20 | 23 | import com.datastax.driver.core.policies.ConstantReconnectionPolicy; |
| 21 | 24 | import com.datastax.driver.core.utils.MoreFutures; |
| 22 | 25 | import com.google.common.base.Predicate; |
| @@ -201,32 +204,14 @@ | ||
| 201 | 204 | // be called when connection is released by previous requests completing, and that one set |
| 202 | 205 | // keyspace attempt should be tried. |
| 203 | 206 | |
| 204 | - // Because Scassandra currently returns a 'ROWS' response for set keyspace, the attempt | |
| 205 | - // will fail, and thus the enqueued connection futures will fail in the following ways: | |
| 206 | - // 1. DriverInternalError for set keyspace returning 'ROWS' response | |
| 207 | - // 2. TransportException for connection being closed, when this happens we stop checking these futures. | |
| 208 | - // 3. Never completing because no connections are available. | |
| 209 | - boolean timeoutAcceptable = false; | |
| 207 | + int count = 0; | |
| 210 | 208 | for (MockRequest queuedRequest : queuedRequests) { |
| 211 | 209 | try { |
| 212 | 210 | Uninterruptibles.getUninterruptibly(queuedRequest.connectionFuture, 5, TimeUnit.SECONDS); |
| 213 | - fail("Expected an exception (because Scassandra doesn't support 'USE keyspace'"); | |
| 214 | - } catch (ExecutionException e) { | |
| 215 | - try { | |
| 216 | - throw e.getCause(); | |
| 217 | - } catch (DriverInternalError die) { | |
| 218 | - assertThat(die.getMessage()).contains("Unexpected response while setting keyspace"); | |
| 219 | - // Subsequent futures may timeout because the connection is closed. | |
| 220 | - timeoutAcceptable = true; | |
| 221 | - } catch (TransportException ce) { | |
| 222 | - /* expected, Scassandra returning a ROWS response for 'USE keyspace' should defunct and close the connection */ | |
| 223 | - // all remaining futures will timeout since there are no remaining connections. | |
| 224 | - break; | |
| 225 | - } catch (Throwable t) { | |
| 226 | - fail("Unexpected cause of future failing", t); | |
| 227 | - } | |
| 211 | + count++; | |
| 228 | 212 | } catch (TimeoutException te) { |
| 229 | - assertThat(timeoutAcceptable).isTrue(); | |
| 213 | + // 128th request should timeout since all in flight requests are used. | |
| 214 | + assertThat(count).isEqualTo(128); | |
| 230 | 215 | break; |
| 231 | 216 | } |
| 232 | 217 | } |
| @@ -291,9 +276,9 @@ | ||
| 291 | 276 | Cluster cluster = createClusterBuilder().build(); |
| 292 | 277 | List<MockRequest> requests = newArrayList(); |
| 293 | 278 | try { |
| 279 | + HostConnectionPool pool = createPool(cluster, 1, 1); | |
| 294 | 280 | // Limit requests per connection to 100 so we don't exhaust stream ids. |
| 295 | 281 | cluster.getConfiguration().getPoolingOptions().setMaxRequestsPerConnection(HostDistance.LOCAL, 100); |
| 296 | - HostConnectionPool pool = createPool(cluster, 1, 1); | |
| 297 | 282 | int maxQueueSize = 256; |
| 298 | 283 | |
| 299 | 284 | assertThat(pool.connections.size()).isEqualTo(1); |
| @@ -1181,6 +1166,8 @@ | ||
| 1181 | 1166 | |
| 1182 | 1167 | private HostConnectionPool createPool(Cluster cluster, int coreConnections, int maxConnections) { |
| 1183 | 1168 | cluster.getConfiguration().getPoolingOptions() |
| 1169 | + .setNewConnectionThreshold(HostDistance.LOCAL, 100) | |
| 1170 | + .setMaxRequestsPerConnection(HostDistance.LOCAL, 128) | |
| 1184 | 1171 | .setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnections) |
| 1185 | 1172 | .setCoreConnectionsPerHost(HostDistance.LOCAL, coreConnections); |
| 1186 | 1173 | Session session = cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/RequestHandlerTest.java +0 −2
| @@ -46,8 +46,6 @@ | ||
| 46 | 46 | cluster = Cluster.builder() |
| 47 | 47 | .addContactPoint(TestUtils.ipOfNode(1)) |
| 48 | 48 | .withPort(scassandra.getBinaryPort()) |
| 49 | - // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash | |
| 50 | - .withProtocolVersion(ProtocolVersion.V2) | |
| 51 | 49 | .withPoolingOptions(new PoolingOptions() |
| 52 | 50 | .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) |
| 53 | 51 | .setMaxConnectionsPerHost(HostDistance.LOCAL, 1) |
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraCluster.java +73 −23
| @@ -19,6 +19,7 @@ | ||
| 19 | 19 | import com.google.common.collect.*; |
| 20 | 20 | import org.scassandra.Scassandra; |
| 21 | 21 | import org.scassandra.ScassandraFactory; |
| 22 | +import org.scassandra.cql.MapType; | |
| 22 | 23 | import org.scassandra.http.client.PrimingClient; |
| 23 | 24 | import org.scassandra.http.client.PrimingRequest; |
| 24 | 25 | import org.slf4j.Logger; |
| @@ -52,16 +53,26 @@ | ||
| 52 | 53 | |
| 53 | 54 | private final List<Map<String, ?>> keyspaceRows; |
| 54 | 55 | |
| 55 | - private static final java.util.UUID schemaVersion = UUIDs.random(); | |
| 56 | + private final String cassandraVersion; | |
| 56 | 57 | |
| 58 | + private static final java.util.UUID schemaVersion = UUIDs.random(); | |
| 57 | 59 | |
| 58 | 60 | private final Map<Integer, Map<Integer, Map<String, Object>>> forcedPeerInfos; |
| 59 | 61 | |
| 62 | + private final String keyspaceQuery; | |
| 63 | + | |
| 64 | + private final org.scassandra.http.client.types.ColumnMetadata[] keyspaceColumnTypes; | |
| 65 | + | |
| 60 | 66 | ScassandraCluster(Integer[] nodes, String ipPrefix, int binaryPort, int adminPort, |
| 61 | - List<Map<String, ?>> keyspaceRows, | |
| 67 | + List<Map<String, ?>> keyspaceRows, String cassandraVersion, | |
| 62 | 68 | Map<Integer, Map<Integer, Map<String, Object>>> forcedPeerInfos) { |
| 63 | 69 | this.ipPrefix = ipPrefix; |
| 64 | 70 | this.binaryPort = binaryPort; |
| 71 | + // If cassandraVersion is not explicitly provided, use 3.0.10 as current version of SCassandra that | |
| 72 | + // supports up to protocol version 4. Without specifying a newer version, could cause the driver | |
| 73 | + // to think the node doesn't support a protocol version that it indeed does. | |
| 74 | + this.cassandraVersion = cassandraVersion != null ? | |
| 75 | + cassandraVersion : "3.0.10"; | |
| 65 | 76 | this.forcedPeerInfos = forcedPeerInfos; |
| 66 | 77 | |
| 67 | 78 | int node = 1; |
| @@ -79,7 +90,30 @@ | ||
| 79 | 90 | } |
| 80 | 91 | instances = instanceListBuilder.build(); |
| 81 | 92 | dcNodeMap = dcNodeMapBuilder.build(); |
| 82 | - this.keyspaceRows = keyspaceRows; | |
| 93 | + | |
| 94 | + // Prime correct keyspace table based on C* version. | |
| 95 | + String[] versionArray = this.cassandraVersion.split("\\.|-"); | |
| 96 | + double major = Double.parseDouble(versionArray[0] + "." + versionArray[1]); | |
| 97 | + | |
| 98 | + if (major < 3.0) { | |
| 99 | + this.keyspaceQuery = "SELECT * FROM system.schema_keyspaces"; | |
| 100 | + this.keyspaceColumnTypes = SELECT_SCHEMA_KEYSPACES; | |
| 101 | + this.keyspaceRows = Lists.newArrayList(keyspaceRows); | |
| 102 | + // remove replication map as it is not part of the < 3.0 schema. | |
| 103 | + for (Map<String, ?> keyspaceRow : this.keyspaceRows) { | |
| 104 | + keyspaceRow.remove("replication"); | |
| 105 | + } | |
| 106 | + } else { | |
| 107 | + this.keyspaceQuery = "SELECT * FROM system_schema.keyspaces"; | |
| 108 | + this.keyspaceColumnTypes = SELECT_SCHEMA_KEYSPACES_V3; | |
| 109 | + this.keyspaceRows = Lists.newArrayList(keyspaceRows); | |
| 110 | + // remove strategy options and strategy class as these are not part of the 3.0+ schema. | |
| 111 | + for (Map<String, ?> keyspaceRow : this.keyspaceRows) { | |
| 112 | + keyspaceRow.remove("strategy_class"); | |
| 113 | + keyspaceRow.remove("strategy_options"); | |
| 114 | + } | |
| 115 | + } | |
| 116 | + | |
| 83 | 117 | } |
| 84 | 118 | |
| 85 | 119 | public Scassandra node(int node) { |
| @@ -297,7 +331,7 @@ | ||
| 297 | 331 | addPeerInfo(row, dc, n + 1, "listen_address", getPeerInfo(dc, n + 1, "listen_address", address)); |
| 298 | 332 | addPeerInfo(row, dc, n + 1, "partitioner", "org.apache.cassandra.dht.Murmur3Partitioner"); |
| 299 | 333 | addPeerInfo(row, dc, n + 1, "rack", getPeerInfo(dc, n + 1, "rack", "rack1")); |
| 300 | - addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", "2.1.8")); | |
| 334 | + addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", cassandraVersion)); | |
| 301 | 335 | addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(tokens.get(n))); |
| 302 | 336 | addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion); |
| 303 | 337 | addPeerInfo(row, dc, n + 1, "graph", false); |
| @@ -314,7 +348,7 @@ | ||
| 314 | 348 | addPeerInfo(row, dc, n + 1, "rpc_address", address); |
| 315 | 349 | addPeerInfo(row, dc, n + 1, "data_center", datacenter(dc)); |
| 316 | 350 | addPeerInfo(row, dc, n + 1, "rack", getPeerInfo(dc, n + 1, "rack", "rack1")); |
| 317 | - addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", "2.1.8")); | |
| 351 | + addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", cassandraVersion)); | |
| 318 | 352 | addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(Long.toString(tokens.get(n)))); |
| 319 | 353 | addPeerInfo(row, dc, n + 1, "host_id", UUIDs.random()); |
| 320 | 354 | addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion); |
| @@ -356,11 +390,11 @@ | ||
| 356 | 390 | .build()) |
| 357 | 391 | .build()); |
| 358 | 392 | |
| 359 | - // Prime keyspaces | |
| 393 | + | |
| 360 | 394 | client.prime(PrimingRequest.queryBuilder() |
| 361 | - .withQuery("SELECT * FROM system.schema_keyspaces") | |
| 395 | + .withQuery(keyspaceQuery) | |
| 362 | 396 | .withThen(then() |
| 363 | - .withColumnTypes(SELECT_SCHEMA_KEYSPACES) | |
| 397 | + .withColumnTypes(keyspaceColumnTypes) | |
| 364 | 398 | .withRows(keyspaceRows) |
| 365 | 399 | .build()) |
| 366 | 400 | .build()); |
| @@ -440,6 +474,12 @@ | ||
| 440 | 474 | column("strategy_options", TEXT) |
| 441 | 475 | }; |
| 442 | 476 | |
| 477 | + static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_SCHEMA_KEYSPACES_V3 = { | |
| 478 | + column("durable_writes", BOOLEAN), | |
| 479 | + column("keyspace_name", TEXT), | |
| 480 | + column("replication", MapType.map(TEXT, TEXT)) | |
| 481 | + }; | |
| 482 | + | |
| 443 | 483 | static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_SCHEMA_COLUMN_FAMILIES = { |
| 444 | 484 | column("bloom_filter_fp_chance", DOUBLE), |
| 445 | 485 | column("caching", TEXT), |
| @@ -495,6 +535,7 @@ | ||
| 495 | 535 | private String ipPrefix = TestUtils.IP_PREFIX; |
| 496 | 536 | private final List<Map<String, ?>> keyspaceRows = Lists.newArrayList(); |
| 497 | 537 | private final Map<Integer, Map<Integer, Map<String, Object>>> forcedPeerInfos = Maps.newHashMap(); |
| 538 | + private String cassandraVersion = null; | |
| 498 | 539 | |
| 499 | 540 | public ScassandraClusterBuilder withNodes(Integer... nodes) { |
| 500 | 541 | this.nodes = nodes; |
| @@ -507,36 +548,40 @@ | ||
| 507 | 548 | } |
| 508 | 549 | |
| 509 | 550 | public ScassandraClusterBuilder withSimpleKeyspace(String name, int replicationFactor) { |
| 510 | - Map<String, Object> simpleKeyspaceRow = ImmutableMap.<String, Object>builder() | |
| 511 | - .put("durable_writes", false) | |
| 512 | - .put("keyspace_name", name) | |
| 513 | - .put("strategy_class", "SimpleStrategy") | |
| 514 | - .put("strategy_options", "{\"replication_factor\":\"" + replicationFactor + "\"}") | |
| 515 | - .build(); | |
| 516 | - | |
| 551 | + Map<String, Object> simpleKeyspaceRow = Maps.newHashMap(); | |
| 552 | + simpleKeyspaceRow.put("durable_writes", false); | |
| 553 | + simpleKeyspaceRow.put("keyspace_name", name); | |
| 554 | + simpleKeyspaceRow.put("replication", ImmutableMap.<String, String>builder() | |
| 555 | + .put("class", "org.apache.cassandra.locator.SimpleStrategy") | |
| 556 | + .put("replication_factor", "" + replicationFactor).build()); | |
| 557 | + simpleKeyspaceRow.put("strategy_class", "SimpleStrategy"); | |
| 558 | + simpleKeyspaceRow.put("strategy_options", "{\"replication_factor\":\"" + replicationFactor + "\"}"); | |
| 517 | 559 | keyspaceRows.add(simpleKeyspaceRow); |
| 518 | 560 | return this; |
| 519 | 561 | } |
| 520 | 562 | |
| 521 | 563 | public ScassandraClusterBuilder withNetworkTopologyKeyspace(String name, Map<Integer, Integer> replicationFactors) { |
| 522 | 564 | StringBuilder strategyOptionsBuilder = new StringBuilder("{"); |
| 565 | + ImmutableMap.Builder<String, String> replicationBuilder = ImmutableMap.builder(); | |
| 566 | + replicationBuilder.put("class", "org.apache.cassandra.locator.NetworkTopologyStrategy"); | |
| 567 | + | |
| 523 | 568 | for (Map.Entry<Integer, Integer> dc : replicationFactors.entrySet()) { |
| 524 | 569 | strategyOptionsBuilder.append("\""); |
| 525 | 570 | strategyOptionsBuilder.append(datacenter(dc.getKey())); |
| 526 | 571 | strategyOptionsBuilder.append("\":\""); |
| 527 | 572 | strategyOptionsBuilder.append(dc.getValue()); |
| 528 | 573 | strategyOptionsBuilder.append("\","); |
| 574 | + replicationBuilder.put(datacenter(dc.getKey()), "" + dc.getValue()); | |
| 529 | 575 | } |
| 530 | 576 | |
| 531 | 577 | String strategyOptions = strategyOptionsBuilder.substring(0, strategyOptionsBuilder.length() - 1) + "}"; |
| 532 | 578 | |
| 533 | - Map<String, Object> ntsKeyspaceRow = ImmutableMap.<String, Object>builder() | |
| 534 | - .put("durable_writes", false) | |
| 535 | - .put("keyspace_name", name) | |
| 536 | - .put("strategy_class", "NetworkTopologyStrategy") | |
| 537 | - .put("strategy_options", strategyOptions) | |
| 538 | - .build(); | |
| 539 | - | |
| 579 | + Map<String, Object> ntsKeyspaceRow = Maps.newHashMap(); | |
| 580 | + ntsKeyspaceRow.put("durable_writes", false); | |
| 581 | + ntsKeyspaceRow.put("keyspace_name", name); | |
| 582 | + ntsKeyspaceRow.put("strategy_class", "NetworkTopologyStrategy"); | |
| 583 | + ntsKeyspaceRow.put("strategy_options", strategyOptions); | |
| 584 | + ntsKeyspaceRow.put("replication", replicationBuilder.build()); | |
| 540 | 585 | keyspaceRows.add(ntsKeyspaceRow); |
| 541 | 586 | return this; |
| 542 | 587 | } |
| @@ -556,8 +601,13 @@ | ||
| 556 | 601 | return this; |
| 557 | 602 | } |
| 558 | 603 | |
| 604 | + public ScassandraClusterBuilder withCassandraVersion(String version) { | |
| 605 | + this.cassandraVersion = version; | |
| 606 | + return this; | |
| 607 | + } | |
| 608 | + | |
| 559 | 609 | public ScassandraCluster build() { |
| 560 | - return new ScassandraCluster(nodes, ipPrefix, TestUtils.findAvailablePort(), TestUtils.findAvailablePort(), keyspaceRows, forcedPeerInfos); | |
| 610 | + return new ScassandraCluster(nodes, ipPrefix, TestUtils.findAvailablePort(), TestUtils.findAvailablePort(), keyspaceRows, cassandraVersion, forcedPeerInfos); | |
| 561 | 611 | } |
| 562 | 612 | } |
| 563 | 613 | } |
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraTestBase.java +0 −2
| @@ -79,8 +79,6 @@ | ||
| 79 | 79 | .withPort(scassandra.getBinaryPort()) |
| 80 | 80 | .addContactPoints(hostAddress.getAddress()) |
| 81 | 81 | .withPort(scassandra.getBinaryPort()) |
| 82 | - // Scassandra does not support V3 yet, and V4 may cause the server to crash | |
| 83 | - .withProtocolVersion(TestUtils.getDesiredProtocolVersion(ProtocolVersion.V2)) | |
| 84 | 82 | .withPoolingOptions(new PoolingOptions() |
| 85 | 83 | .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) |
| 86 | 84 | .setMaxConnectionsPerHost(HostDistance.LOCAL, 1) |
deleted driver-core/src/test/java/com/datastax/driver/core/SpeculativeExecutionIntegrationTest.java +0 −86
| @@ -1,86 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | - * | |
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | - * you may not use this file except in compliance with the License. | |
| 6 | - * You may obtain a copy of the License at | |
| 7 | - * | |
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | - * | |
| 10 | - * Unless required by applicable law or agreed to in writing, software | |
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | - * See the License for the specific language governing permissions and | |
| 14 | - * limitations under the License. | |
| 15 | - */ | |
| 16 | -package com.datastax.driver.core; | |
| 17 | - | |
| 18 | -import com.datastax.driver.core.policies.ConstantSpeculativeExecutionPolicy; | |
| 19 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 20 | -import org.mockito.Mockito; | |
| 21 | -import org.testng.annotations.Test; | |
| 22 | - | |
| 23 | -import static org.assertj.core.api.Assertions.fail; | |
| 24 | -import static org.mockito.Mockito.times; | |
| 25 | - | |
| 26 | -/** | |
| 27 | - * Test that needs a real CCM cluster (as opposed to SCassandra for other specex tests), because | |
| 28 | - * it uses a protocol v3 feature. | |
| 29 | - */ | |
| 30 | -public class SpeculativeExecutionIntegrationTest extends CCMTestsSupport { | |
| 31 | - | |
| 32 | - TimestampGenerator timestampGenerator; | |
| 33 | - | |
| 34 | - @Override | |
| 35 | - public void onTestContextInitialized() { | |
| 36 | - execute("create table foo(k int primary key, v int)"); | |
| 37 | - } | |
| 38 | - | |
| 39 | - @Override | |
| 40 | - public Cluster.Builder createClusterBuilder() { | |
| 41 | - timestampGenerator = Mockito.spy(ServerSideTimestampGenerator.INSTANCE); | |
| 42 | - return Cluster.builder() | |
| 43 | - .withTimestampGenerator(timestampGenerator) | |
| 44 | - // Set an artificially low timeout to force speculative execution | |
| 45 | - .withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(1, 2)); | |
| 46 | - } | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * Validates that if a query gets speculatively re-executed, the second execution uses the same default timestamp. | |
| 50 | - * | |
| 51 | - * @test_category tracing | |
| 52 | - * @jira_ticket JAVA-724 | |
| 53 | - * @expected_result timestamp generator invoked only once for a query that caused two executions. | |
| 54 | - */ | |
| 55 | - @Test(groups = "short") | |
| 56 | - @CassandraVersion(major = 2.1) | |
| 57 | - public void should_use_same_default_timestamp_for_all_executions() { | |
| 58 | - Metrics.Errors errors = cluster().getMetrics().getErrorMetrics(); | |
| 59 | - | |
| 60 | - // The check is attempted up to 10 times to account for the small possibility that a | |
| 61 | - // scheduled execution is not needed/exercised. Even though the policy is set up | |
| 62 | - // to schedule an execution after 1ms, the timeout might not fire before the response is received. | |
| 63 | - int tryCount = 0; | |
| 64 | - int maxTries = 10; | |
| 65 | - while (tryCount++ < maxTries) { | |
| 66 | - Mockito.reset(timestampGenerator); | |
| 67 | - long execStartCount = errors.getSpeculativeExecutions().getCount(); | |
| 68 | - | |
| 69 | - BatchStatement batch = new BatchStatement(); | |
| 70 | - for (int k = 0; k < 1000; k++) { | |
| 71 | - batch.add(new SimpleStatement("insert into foo(k,v) values (?,1)", k).setIdempotent(true)); | |
| 72 | - } | |
| 73 | - batch.setIdempotent(true); | |
| 74 | - session().execute(batch); | |
| 75 | - | |
| 76 | - if (errors.getSpeculativeExecutions().getCount() == execStartCount + 1) { | |
| 77 | - Mockito.verify(timestampGenerator, times(1)).next(); | |
| 78 | - break; | |
| 79 | - } | |
| 80 | - } | |
| 81 | - | |
| 82 | - if (tryCount == maxTries) { | |
| 83 | - fail("Observed no speculative executions in 10 attempts"); | |
| 84 | - } | |
| 85 | - } | |
| 86 | -} |
modified driver-core/src/test/java/com/datastax/driver/core/SpeculativeExecutionTest.java +47 −3
| @@ -21,6 +21,7 @@ | ||
| 21 | 21 | import com.datastax.driver.core.policies.SpeculativeExecutionPolicy; |
| 22 | 22 | import com.google.common.collect.ImmutableList; |
| 23 | 23 | import com.google.common.collect.ImmutableMap; |
| 24 | +import org.mockito.Mockito; | |
| 24 | 25 | import org.scassandra.http.client.Consistency; |
| 25 | 26 | import org.scassandra.http.client.PrimingRequest; |
| 26 | 27 | import org.scassandra.http.client.Result; |
| @@ -55,7 +56,6 @@ | ||
| 55 | 56 | cluster = Cluster.builder() |
| 56 | 57 | .addContactPoints(scassandras.address(2).getAddress()) |
| 57 | 58 | .withPort(scassandras.getBinaryPort()) |
| 58 | - .withProtocolVersion(ProtocolVersion.V2) // Scassandra does not support V3 nor V4 yet | |
| 59 | 59 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 60 | 60 | .withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(speculativeExecutionDelay, 1)) |
| 61 | 61 | .withQueryOptions(new QueryOptions().setDefaultIdempotence(true)) |
| @@ -208,8 +208,6 @@ | ||
| 208 | 208 | Cluster cluster = Cluster.builder() |
| 209 | 209 | .addContactPoints(scassandras.address(2).getAddress()) |
| 210 | 210 | .withPort(scassandras.getBinaryPort()) |
| 211 | - // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash | |
| 212 | - .withProtocolVersion(ProtocolVersion.V2) | |
| 213 | 211 | .withSpeculativeExecutionPolicy(mockPolicy) |
| 214 | 212 | .build(); |
| 215 | 213 | |
| @@ -225,6 +223,52 @@ | ||
| 225 | 223 | } |
| 226 | 224 | } |
| 227 | 225 | |
| 226 | + /** | |
| 227 | + * Validates that if a query gets speculatively re-executed, the second execution uses the same default timestamp. | |
| 228 | + * | |
| 229 | + * @test_category tracing | |
| 230 | + * @jira_ticket JAVA-724 | |
| 231 | + * @expected_result timestamp generator invoked only once for a query that caused two executions. | |
| 232 | + */ | |
| 233 | + @Test(groups = "short") | |
| 234 | + public void should_use_same_default_timestamp_for_all_executions() { | |
| 235 | + TimestampGenerator timestampGenerator = Mockito.spy(ServerSideTimestampGenerator.INSTANCE); | |
| 236 | + Cluster cluster = Cluster.builder() | |
| 237 | + .addContactPoints(scassandras.address(2).getAddress()) | |
| 238 | + .withPort(scassandras.getBinaryPort()) | |
| 239 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 240 | + .withTimestampGenerator(timestampGenerator) | |
| 241 | + .withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(1, 2)) | |
| 242 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 243 | + .build(); | |
| 244 | + | |
| 245 | + try { | |
| 246 | + scassandras.node(1).primingClient() | |
| 247 | + // execution1 starts with host1, which will time out at t=1000 | |
| 248 | + .prime(PrimingRequest.queryBuilder() | |
| 249 | + .withQuery("mock query") | |
| 250 | + .withFixedDelay(2000) | |
| 251 | + .withRows(row("result", "result1")) | |
| 252 | + .build()); | |
| 253 | + | |
| 254 | + Session session = cluster.connect(); | |
| 255 | + Metrics.Errors errors = cluster.getMetrics().getErrorMetrics(); | |
| 256 | + | |
| 257 | + long execStartCount = errors.getSpeculativeExecutions().getCount(); | |
| 258 | + | |
| 259 | + SimpleStatement statement = new SimpleStatement("mock query"); | |
| 260 | + statement.setIdempotent(true); | |
| 261 | + session.execute(statement); | |
| 262 | + | |
| 263 | + // Should have only requested one timestamp. | |
| 264 | + if (errors.getSpeculativeExecutions().getCount() == execStartCount + 1) { | |
| 265 | + Mockito.verify(timestampGenerator, times(1)).next(); | |
| 266 | + } | |
| 267 | + } finally { | |
| 268 | + cluster.close(); | |
| 269 | + } | |
| 270 | + } | |
| 271 | + | |
| 228 | 272 | /** |
| 229 | 273 | * Custom retry policy that retries at ONE on read timeout. |
| 230 | 274 | * This deals with the fact that Scassandra only allows read timeouts with 0 replicas. |
modified driver-core/src/test/java/com/datastax/driver/core/policies/AbstractRetryPolicyIntegrationTest.java +0 −2
| @@ -82,8 +82,6 @@ | ||
| 82 | 82 | .withPort(scassandras.getBinaryPort()) |
| 83 | 83 | .withRetryPolicy(retryPolicy) |
| 84 | 84 | .withLoadBalancingPolicy(new SortingLoadBalancingPolicy()) |
| 85 | - // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash | |
| 86 | - .withProtocolVersion(ProtocolVersion.V2) | |
| 87 | 85 | .withPoolingOptions(new PoolingOptions() |
| 88 | 86 | .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) |
| 89 | 87 | .setMaxConnectionsPerHost(HostDistance.LOCAL, 1) |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DefaultRetryPolicyIntegrationTest.java +0 −2
| @@ -119,8 +119,6 @@ | ||
| 119 | 119 | Cluster whiteListedCluster = Cluster.builder() |
| 120 | 120 | .addContactPoints(scassandras.address(1).getAddress()) |
| 121 | 121 | .withPort(scassandras.getBinaryPort()) |
| 122 | - // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash | |
| 123 | - .withProtocolVersion(ProtocolVersion.V2) | |
| 124 | 122 | .withRetryPolicy(retryPolicy) |
| 125 | 123 | .withLoadBalancingPolicy(firstHostOnlyPolicy) |
| 126 | 124 | .build(); |
modified pom.xml +1 −1
| @@ -66,7 +66,7 @@ | ||
| 66 | 66 | <assertj.version>1.7.0</assertj.version> |
| 67 | 67 | <mockito.version>1.10.8</mockito.version> |
| 68 | 68 | <commons-exec.version>1.3</commons-exec.version> |
| 69 | - <scassandra.version>1.0.9</scassandra.version> | |
| 69 | + <scassandra.version>1.1.1</scassandra.version> | |
| 70 | 70 | <main.basedir>${project.basedir}</main.basedir> |
| 71 | 71 | <ipprefix>127.0.1.</ipprefix> |
| 72 | 72 | <test.groups>unit</test.groups> |