Elffuss BraidHub

kikocis/java-driver public

Update to tests to use scassandra 1.1.1

Remove Protocol V2 specific callouts in Scassandra tests.  This is
no longer needed since scassandra supports v3 and v4 now.

Rewrite speculative execution integration test using Scassandra since
it now supports client timestamps.

Allow setting cassandra version in ScassandraCluster.  The
cassandra_version returned in peers table is significant in
determining if the driver should connect to that node depending on its
protocol version.  Defaulting to 3.0.10 is a fair route since Scassandra
supports protocol version 4.

Also prime keyspace metadata based on cassandra version as system schema
tables changed in 3.0.
Changeset6154c03e10b0abb62058a62d24e1e4c56c9fe15ea7b4a5e03afdfd5bc1514029
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2017-01-10 23:21 -06:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2017-01-11 21:47 -06:00
Parentsacff5551b9b4

Browse the files at this changeset

12 files changed

modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +0 −5
@@ -26,7 +26,6 @@
2626 import org.scassandra.http.client.PrimingRequest;
2727 import org.slf4j.Logger;
2828 import org.slf4j.LoggerFactory;
29-import org.testng.SkipException;
3029 import org.testng.annotations.Test;
3130
3231 import java.net.InetAddress;
@@ -55,9 +54,6 @@
5554 */
5655 @Test(groups = "short")
5756 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-
6157 Cluster cluster = null;
6258 Scassandra scassandra = null;
6359 List<FakeHost> failingHosts = Lists.newArrayList();
@@ -107,7 +103,6 @@
107103 .withSocketOptions(socketOptions)
108104 .withReconnectionPolicy(reconnectionPolicy)
109105 .withPoolingOptions(poolingOptions)
110- .withProtocolVersion(TestUtils.getDesiredProtocolVersion())
111106 .build();
112107 cluster.connect();
113108
modified driver-core/src/test/java/com/datastax/driver/core/ConnectionReleaseTest.java +0 −1
@@ -86,7 +86,6 @@
8686 cluster = Cluster.builder()
8787 .addContactPoints(hostAddress.getAddress())
8888 .withPort(scassandra.getBinaryPort())
89- .withProtocolVersion(ProtocolVersion.V2)
9089 .withPoolingOptions(new PoolingOptions()
9190 .setCoreConnectionsPerHost(HostDistance.LOCAL, 1)
9291 .setMaxConnectionsPerHost(HostDistance.LOCAL, 1))
modified driver-core/src/test/java/com/datastax/driver/core/HeartbeatTest.java +0 −3
@@ -67,7 +67,6 @@
6767 Cluster cluster = Cluster.builder()
6868 .addContactPoints(hostAddress.getAddress())
6969 .withPort(scassandra.getBinaryPort())
70- .withProtocolVersion(ProtocolVersion.V2)
7170 .withPoolingOptions(new PoolingOptions().setHeartbeatIntervalSeconds(3))
7271 .build();
7372
@@ -157,7 +156,6 @@
157156 Cluster cluster = Cluster.builder()
158157 .addContactPoints(hostAddress.getAddress())
159158 .withPort(scassandra.getBinaryPort())
160- .withProtocolVersion(ProtocolVersion.V2)
161159 .withPoolingOptions(new PoolingOptions().setHeartbeatIntervalSeconds(3).setConnectionsPerHost(HostDistance.LOCAL, 1, 1))
162160 .build();
163161
@@ -257,7 +255,6 @@
257255 .withPort(scassandra.getBinaryPort())
258256 .withPoolingOptions(new PoolingOptions()
259257 .setHeartbeatIntervalSeconds(0))
260- .withProtocolVersion(ProtocolVersion.V2)
261258 .build();
262259
263260 try {
modified driver-core/src/test/java/com/datastax/driver/core/HostConnectionPoolTest.java +11 −24
@@ -16,7 +16,10 @@
1616 package com.datastax.driver.core;
1717
1818 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;
2023 import com.datastax.driver.core.policies.ConstantReconnectionPolicy;
2124 import com.datastax.driver.core.utils.MoreFutures;
2225 import com.google.common.base.Predicate;
@@ -201,32 +204,14 @@
201204 // be called when connection is released by previous requests completing, and that one set
202205 // keyspace attempt should be tried.
203206
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;
210208 for (MockRequest queuedRequest : queuedRequests) {
211209 try {
212210 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++;
228212 } catch (TimeoutException te) {
229- assertThat(timeoutAcceptable).isTrue();
213+ // 128th request should timeout since all in flight requests are used.
214+ assertThat(count).isEqualTo(128);
230215 break;
231216 }
232217 }
@@ -291,9 +276,9 @@
291276 Cluster cluster = createClusterBuilder().build();
292277 List<MockRequest> requests = newArrayList();
293278 try {
279+ HostConnectionPool pool = createPool(cluster, 1, 1);
294280 // Limit requests per connection to 100 so we don't exhaust stream ids.
295281 cluster.getConfiguration().getPoolingOptions().setMaxRequestsPerConnection(HostDistance.LOCAL, 100);
296- HostConnectionPool pool = createPool(cluster, 1, 1);
297282 int maxQueueSize = 256;
298283
299284 assertThat(pool.connections.size()).isEqualTo(1);
@@ -1181,6 +1166,8 @@
11811166
11821167 private HostConnectionPool createPool(Cluster cluster, int coreConnections, int maxConnections) {
11831168 cluster.getConfiguration().getPoolingOptions()
1169+ .setNewConnectionThreshold(HostDistance.LOCAL, 100)
1170+ .setMaxRequestsPerConnection(HostDistance.LOCAL, 128)
11841171 .setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnections)
11851172 .setCoreConnectionsPerHost(HostDistance.LOCAL, coreConnections);
11861173 Session session = cluster.connect();
modified driver-core/src/test/java/com/datastax/driver/core/RequestHandlerTest.java +0 −2
@@ -46,8 +46,6 @@
4646 cluster = Cluster.builder()
4747 .addContactPoint(TestUtils.ipOfNode(1))
4848 .withPort(scassandra.getBinaryPort())
49- // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash
50- .withProtocolVersion(ProtocolVersion.V2)
5149 .withPoolingOptions(new PoolingOptions()
5250 .setCoreConnectionsPerHost(HostDistance.LOCAL, 1)
5351 .setMaxConnectionsPerHost(HostDistance.LOCAL, 1)
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraCluster.java +73 −23
@@ -19,6 +19,7 @@
1919 import com.google.common.collect.*;
2020 import org.scassandra.Scassandra;
2121 import org.scassandra.ScassandraFactory;
22+import org.scassandra.cql.MapType;
2223 import org.scassandra.http.client.PrimingClient;
2324 import org.scassandra.http.client.PrimingRequest;
2425 import org.slf4j.Logger;
@@ -52,16 +53,26 @@
5253
5354 private final List<Map<String, ?>> keyspaceRows;
5455
55- private static final java.util.UUID schemaVersion = UUIDs.random();
56+ private final String cassandraVersion;
5657
58+ private static final java.util.UUID schemaVersion = UUIDs.random();
5759
5860 private final Map<Integer, Map<Integer, Map<String, Object>>> forcedPeerInfos;
5961
62+ private final String keyspaceQuery;
63+
64+ private final org.scassandra.http.client.types.ColumnMetadata[] keyspaceColumnTypes;
65+
6066 ScassandraCluster(Integer[] nodes, String ipPrefix, int binaryPort, int adminPort,
61- List<Map<String, ?>> keyspaceRows,
67+ List<Map<String, ?>> keyspaceRows, String cassandraVersion,
6268 Map<Integer, Map<Integer, Map<String, Object>>> forcedPeerInfos) {
6369 this.ipPrefix = ipPrefix;
6470 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";
6576 this.forcedPeerInfos = forcedPeerInfos;
6677
6778 int node = 1;
@@ -79,7 +90,30 @@
7990 }
8091 instances = instanceListBuilder.build();
8192 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+
83117 }
84118
85119 public Scassandra node(int node) {
@@ -297,7 +331,7 @@
297331 addPeerInfo(row, dc, n + 1, "listen_address", getPeerInfo(dc, n + 1, "listen_address", address));
298332 addPeerInfo(row, dc, n + 1, "partitioner", "org.apache.cassandra.dht.Murmur3Partitioner");
299333 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));
301335 addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(tokens.get(n)));
302336 addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion);
303337 addPeerInfo(row, dc, n + 1, "graph", false);
@@ -314,7 +348,7 @@
314348 addPeerInfo(row, dc, n + 1, "rpc_address", address);
315349 addPeerInfo(row, dc, n + 1, "data_center", datacenter(dc));
316350 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));
318352 addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(Long.toString(tokens.get(n))));
319353 addPeerInfo(row, dc, n + 1, "host_id", UUIDs.random());
320354 addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion);
@@ -356,11 +390,11 @@
356390 .build())
357391 .build());
358392
359- // Prime keyspaces
393+
360394 client.prime(PrimingRequest.queryBuilder()
361- .withQuery("SELECT * FROM system.schema_keyspaces")
395+ .withQuery(keyspaceQuery)
362396 .withThen(then()
363- .withColumnTypes(SELECT_SCHEMA_KEYSPACES)
397+ .withColumnTypes(keyspaceColumnTypes)
364398 .withRows(keyspaceRows)
365399 .build())
366400 .build());
@@ -440,6 +474,12 @@
440474 column("strategy_options", TEXT)
441475 };
442476
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+
443483 static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_SCHEMA_COLUMN_FAMILIES = {
444484 column("bloom_filter_fp_chance", DOUBLE),
445485 column("caching", TEXT),
@@ -495,6 +535,7 @@
495535 private String ipPrefix = TestUtils.IP_PREFIX;
496536 private final List<Map<String, ?>> keyspaceRows = Lists.newArrayList();
497537 private final Map<Integer, Map<Integer, Map<String, Object>>> forcedPeerInfos = Maps.newHashMap();
538+ private String cassandraVersion = null;
498539
499540 public ScassandraClusterBuilder withNodes(Integer... nodes) {
500541 this.nodes = nodes;
@@ -507,36 +548,40 @@
507548 }
508549
509550 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 + "\"}");
517559 keyspaceRows.add(simpleKeyspaceRow);
518560 return this;
519561 }
520562
521563 public ScassandraClusterBuilder withNetworkTopologyKeyspace(String name, Map<Integer, Integer> replicationFactors) {
522564 StringBuilder strategyOptionsBuilder = new StringBuilder("{");
565+ ImmutableMap.Builder<String, String> replicationBuilder = ImmutableMap.builder();
566+ replicationBuilder.put("class", "org.apache.cassandra.locator.NetworkTopologyStrategy");
567+
523568 for (Map.Entry<Integer, Integer> dc : replicationFactors.entrySet()) {
524569 strategyOptionsBuilder.append("\"");
525570 strategyOptionsBuilder.append(datacenter(dc.getKey()));
526571 strategyOptionsBuilder.append("\":\"");
527572 strategyOptionsBuilder.append(dc.getValue());
528573 strategyOptionsBuilder.append("\",");
574+ replicationBuilder.put(datacenter(dc.getKey()), "" + dc.getValue());
529575 }
530576
531577 String strategyOptions = strategyOptionsBuilder.substring(0, strategyOptionsBuilder.length() - 1) + "}";
532578
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());
540585 keyspaceRows.add(ntsKeyspaceRow);
541586 return this;
542587 }
@@ -556,8 +601,13 @@
556601 return this;
557602 }
558603
604+ public ScassandraClusterBuilder withCassandraVersion(String version) {
605+ this.cassandraVersion = version;
606+ return this;
607+ }
608+
559609 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);
561611 }
562612 }
563613 }
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraTestBase.java +0 −2
@@ -79,8 +79,6 @@
7979 .withPort(scassandra.getBinaryPort())
8080 .addContactPoints(hostAddress.getAddress())
8181 .withPort(scassandra.getBinaryPort())
82- // Scassandra does not support V3 yet, and V4 may cause the server to crash
83- .withProtocolVersion(TestUtils.getDesiredProtocolVersion(ProtocolVersion.V2))
8482 .withPoolingOptions(new PoolingOptions()
8583 .setCoreConnectionsPerHost(HostDistance.LOCAL, 1)
8684 .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 @@
2121 import com.datastax.driver.core.policies.SpeculativeExecutionPolicy;
2222 import com.google.common.collect.ImmutableList;
2323 import com.google.common.collect.ImmutableMap;
24+import org.mockito.Mockito;
2425 import org.scassandra.http.client.Consistency;
2526 import org.scassandra.http.client.PrimingRequest;
2627 import org.scassandra.http.client.Result;
@@ -55,7 +56,6 @@
5556 cluster = Cluster.builder()
5657 .addContactPoints(scassandras.address(2).getAddress())
5758 .withPort(scassandras.getBinaryPort())
58- .withProtocolVersion(ProtocolVersion.V2) // Scassandra does not support V3 nor V4 yet
5959 .withLoadBalancingPolicy(loadBalancingPolicy)
6060 .withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(speculativeExecutionDelay, 1))
6161 .withQueryOptions(new QueryOptions().setDefaultIdempotence(true))
@@ -208,8 +208,6 @@
208208 Cluster cluster = Cluster.builder()
209209 .addContactPoints(scassandras.address(2).getAddress())
210210 .withPort(scassandras.getBinaryPort())
211- // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash
212- .withProtocolVersion(ProtocolVersion.V2)
213211 .withSpeculativeExecutionPolicy(mockPolicy)
214212 .build();
215213
@@ -225,6 +223,52 @@
225223 }
226224 }
227225
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+
228272 /**
229273 * Custom retry policy that retries at ONE on read timeout.
230274 * 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 @@
8282 .withPort(scassandras.getBinaryPort())
8383 .withRetryPolicy(retryPolicy)
8484 .withLoadBalancingPolicy(new SortingLoadBalancingPolicy())
85- // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash
86- .withProtocolVersion(ProtocolVersion.V2)
8785 .withPoolingOptions(new PoolingOptions()
8886 .setCoreConnectionsPerHost(HostDistance.LOCAL, 1)
8987 .setMaxConnectionsPerHost(HostDistance.LOCAL, 1)
modified driver-core/src/test/java/com/datastax/driver/core/policies/DefaultRetryPolicyIntegrationTest.java +0 −2
@@ -119,8 +119,6 @@
119119 Cluster whiteListedCluster = Cluster.builder()
120120 .addContactPoints(scassandras.address(1).getAddress())
121121 .withPort(scassandras.getBinaryPort())
122- // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash
123- .withProtocolVersion(ProtocolVersion.V2)
124122 .withRetryPolicy(retryPolicy)
125123 .withLoadBalancingPolicy(firstHostOnlyPolicy)
126124 .build();
modified pom.xml +1 −1
@@ -66,7 +66,7 @@
6666 <assertj.version>1.7.0</assertj.version>
6767 <mockito.version>1.10.8</mockito.version>
6868 <commons-exec.version>1.3</commons-exec.version>
69- <scassandra.version>1.0.9</scassandra.version>
69+ <scassandra.version>1.1.1</scassandra.version>
7070 <main.basedir>${project.basedir}</main.basedir>
7171 <ipprefix>127.0.1.</ipprefix>
7272 <test.groups>unit</test.groups>