kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | dfb47c04f71cafc661e763a62245e9be159624e1ea20ef9180c6eafead137271 |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2017-03-02 11:12 +01:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2017-03-02 11:12 +01:00 |
| Parents | e89d80dbfee5, 503af700a078 |
26 files changed
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +2 −1
| @@ -1211,6 +1211,7 @@ | ||
| 1211 | 1211 | |
| 1212 | 1212 | ChannelFuture future = channel.close(); |
| 1213 | 1213 | future.addListener(new ChannelFutureListener() { |
| 1214 | + @Override | |
| 1214 | 1215 | public void operationComplete(ChannelFuture future) { |
| 1215 | 1216 | factory.allChannels.remove(channel); |
| 1216 | 1217 | if (future.cause() != null) { |
| @@ -1421,7 +1422,7 @@ | ||
| 1421 | 1422 | pipeline.addLast("ssl", sslOptions.newSSLHandler(channel)); |
| 1422 | 1423 | } |
| 1423 | 1424 | |
| 1424 | - // pipeline.addLast("debug", new LoggingHandler(LogLevel.INFO)); | |
| 1425 | + // pipeline.addLast("debug", new LoggingHandler(LogLevel.INFO)); | |
| 1425 | 1426 | |
| 1426 | 1427 | pipeline.addLast("frameDecoder", new Frame.Decoder()); |
| 1427 | 1428 | pipeline.addLast("frameEncoder", frameEncoder); |
modified driver-core/src/main/java/com/datastax/driver/core/DataType.java +1 −1
| @@ -709,7 +709,7 @@ | ||
| 709 | 709 | * The driver provides a minimal support for such types through |
| 710 | 710 | * instances of this class. |
| 711 | 711 | * <p/> |
| 712 | - * A codec for custom types can be obtained via {@link TypeCodec#custom(CustomType)}. | |
| 712 | + * A codec for custom types can be obtained via {@link TypeCodec#custom(DataType.CustomType)}. | |
| 713 | 713 | */ |
| 714 | 714 | public static class CustomType extends DataType { |
| 715 | 715 |
modified driver-core/src/main/java/com/datastax/driver/core/TypeCodec.java +4 −2
| @@ -90,8 +90,10 @@ | ||
| 90 | 90 | * the wrapper Java class instead, and implement the appropriate interface |
| 91 | 91 | * (e.g. {@link com.datastax.driver.core.TypeCodec.PrimitiveBooleanCodec} for primitive {@code boolean} types; |
| 92 | 92 | * there is one such interface for each Java primitive type).</li> |
| 93 | - * <li>TypeCodec implementations should not consume {@link ByteBuffer} instances by performing read operations | |
| 94 | - * that modify their current position; if necessary, codecs should {@link ByteBuffer#duplicate()} duplicate} them.</li> | |
| 93 | + * <li>When deserializing, TypeCodec implementations should not consume {@link ByteBuffer} instances | |
| 94 | + * by performing relative read operations that modify their current position; | |
| 95 | + * codecs should instead prefer absolute read methods, or, if necessary, they should | |
| 96 | + * {@link ByteBuffer#duplicate() duplicate} their byte buffers prior to reading them.</li> | |
| 95 | 97 | * </ol> |
| 96 | 98 | * |
| 97 | 99 | * @param <T> The codec's Java type |
modified driver-core/src/main/java/com/datastax/driver/core/policies/FallthroughRetryPolicy.java +1 −1
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | /** |
| 25 | 25 | * A retry policy that never retries (nor ignores). |
| 26 | 26 | * <p/> |
| 27 | - * All of the methods of this retry policy unconditionally return {@link RetryDecision#rethrow()}. | |
| 27 | + * All of the methods of this retry policy unconditionally return {@link RetryPolicy.RetryDecision#rethrow()}. | |
| 28 | 28 | * If this policy is used, retry logic will have to be implemented in business code. |
| 29 | 29 | */ |
| 30 | 30 | public class FallthroughRetryPolicy implements RetryPolicy { |
modified driver-core/src/main/java/com/datastax/driver/core/utils/UUIDs.java +1 −0
| @@ -68,6 +68,7 @@ | ||
| 68 | 68 | private UUIDs() { |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | + // http://www.ietf.org/rfc/rfc4122.txt | |
| 71 | 72 | private static final long START_EPOCH = makeEpoch(); |
| 72 | 73 | private static final long CLOCK_SEQ_AND_NODE = makeClockSeqAndNode(); |
| 73 | 74 |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +2 −2
| @@ -44,6 +44,7 @@ | ||
| 44 | 44 | import static com.datastax.driver.core.TestUtils.ipOfNode; |
| 45 | 45 | import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; |
| 46 | 46 | import static org.mockito.Mockito.*; |
| 47 | +import static org.scassandra.http.client.PrimingRequest.then; | |
| 47 | 48 | |
| 48 | 49 | public class ClusterInitTest { |
| 49 | 50 | private static final Logger logger = LoggerFactory.getLogger(ClusterInitTest.class); |
| @@ -278,8 +279,7 @@ | ||
| 278 | 279 | primingClient.prime( |
| 279 | 280 | PrimingRequest.queryBuilder() |
| 280 | 281 | .withQuery("SELECT * FROM system.peers") |
| 281 | - .withColumnTypes(ScassandraCluster.SELECT_PEERS) | |
| 282 | - .withRows(rows) | |
| 282 | + .withThen(then().withRows(rows).withColumnTypes(ScassandraCluster.SELECT_PEERS)) | |
| 283 | 283 | .build()); |
| 284 | 284 | } |
| 285 | 285 | } |
modified driver-core/src/test/java/com/datastax/driver/core/ConnectionReleaseTest.java +5 −4
| @@ -28,6 +28,7 @@ | ||
| 28 | 28 | import java.util.concurrent.TimeoutException; |
| 29 | 29 | |
| 30 | 30 | import static org.assertj.core.api.Assertions.assertThat; |
| 31 | +import static org.scassandra.http.client.PrimingRequest.then; | |
| 31 | 32 | import static org.testng.Assert.fail; |
| 32 | 33 | |
| 33 | 34 | public class ConnectionReleaseTest extends ScassandraTestBase { |
| @@ -66,20 +67,20 @@ | ||
| 66 | 67 | primingClient.prime( |
| 67 | 68 | PrimingRequest.queryBuilder() |
| 68 | 69 | .withQuery("mock query") |
| 69 | - .withRows(ImmutableMap.of("key", 1)) | |
| 70 | - .withFixedDelay(10000) | |
| 70 | + .withThen(then().withRows(ImmutableMap.of("key", 1)) | |
| 71 | + .withFixedDelay(10000L)) | |
| 71 | 72 | .build() |
| 72 | 73 | ); |
| 73 | 74 | primingClient.prime( |
| 74 | 75 | PrimingRequest.queryBuilder() |
| 75 | 76 | .withQuery("select c from test1 where k=1") |
| 76 | - .withRows(ImmutableMap.of("c", "hello")) | |
| 77 | + .withThen(then().withRows(ImmutableMap.of("c", "hello"))) | |
| 77 | 78 | .build() |
| 78 | 79 | ); |
| 79 | 80 | primingClient.prime( |
| 80 | 81 | PrimingRequest.queryBuilder() |
| 81 | 82 | .withQuery("select n from test2 where c='hello'") |
| 82 | - .withRows(ImmutableMap.of("n", "world")) | |
| 83 | + .withThen(then().withRows(ImmutableMap.of("n", "world"))) | |
| 83 | 84 | .build() |
| 84 | 85 | ); |
| 85 | 86 |
modified driver-core/src/test/java/com/datastax/driver/core/ConsistencyTest.java +285 −676
| @@ -15,716 +15,325 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 19 | -import com.datastax.driver.core.exceptions.ReadTimeoutException; | |
| 20 | -import com.datastax.driver.core.exceptions.UnavailableException; | |
| 21 | -import com.datastax.driver.core.exceptions.WriteTimeoutException; | |
| 22 | -import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; | |
| 23 | -import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy; | |
| 24 | -import com.datastax.driver.core.policies.RoundRobinPolicy; | |
| 25 | -import com.datastax.driver.core.policies.TokenAwarePolicy; | |
| 26 | -import com.google.common.util.concurrent.Uninterruptibles; | |
| 18 | +import org.scassandra.Scassandra; | |
| 19 | +import org.scassandra.http.client.BatchExecution; | |
| 20 | +import org.scassandra.http.client.PreparedStatementExecution; | |
| 21 | +import org.scassandra.http.client.Query; | |
| 27 | 22 | import org.slf4j.Logger; |
| 28 | 23 | import org.slf4j.LoggerFactory; |
| 24 | +import org.testng.annotations.AfterClass; | |
| 25 | +import org.testng.annotations.AfterMethod; | |
| 26 | +import org.testng.annotations.BeforeClass; | |
| 29 | 27 | import org.testng.annotations.Test; |
| 30 | 28 | |
| 31 | -import java.util.Arrays; | |
| 32 | -import java.util.EnumSet; | |
| 33 | 29 | import java.util.List; |
| 34 | -import java.util.Set; | |
| 35 | -import java.util.concurrent.TimeUnit; | |
| 36 | - | |
| 37 | -import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD; | |
| 38 | -import static com.datastax.driver.core.TestUtils.IP_PREFIX; | |
| 39 | -import static com.datastax.driver.core.TestUtils.ipOfNode; | |
| 40 | -import static java.util.Collections.emptyList; | |
| 41 | -import static java.util.Collections.singletonList; | |
| 42 | -import static org.testng.Assert.assertTrue; | |
| 43 | -import static org.testng.Assert.fail; | |
| 44 | - | |
| 45 | -@SuppressWarnings("unused") | |
| 46 | -@CreateCCM(PER_METHOD) | |
| 47 | -@CCMConfig( | |
| 48 | - dirtiesContext = true, | |
| 49 | - createKeyspace = false, | |
| 50 | - config = { | |
| 51 | - // tests fail often with write or read timeouts | |
| 52 | - "phi_convict_threshold:5", | |
| 53 | - "read_request_timeout_in_ms:200000", | |
| 54 | - "write_request_timeout_in_ms:200000" | |
| 55 | - } | |
| 56 | -) | |
| 57 | -public class ConsistencyTest extends AbstractPoliciesTest { | |
| 58 | - | |
| 59 | - private static final Logger logger = LoggerFactory.getLogger(ConsistencyTest.class); | |
| 60 | - | |
| 61 | - private Cluster.Builder tokenAwareRoundRobin() { | |
| 62 | - return Cluster.builder() | |
| 63 | - .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000)) | |
| 64 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())); | |
| 65 | - } | |
| 66 | - | |
| 67 | - private Cluster.Builder tokenAwareRoundRobinNoShuffle() { | |
| 68 | - return Cluster.builder() | |
| 69 | - .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000)) | |
| 70 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)); | |
| 71 | - } | |
| 72 | 30 | |
| 73 | - private Cluster.Builder tokenAwareRoundRobinDowngrading() { | |
| 74 | - return Cluster.builder() | |
| 75 | - .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000)) | |
| 76 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) | |
| 77 | - .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 78 | - } | |
| 31 | +import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; | |
| 32 | +import static org.testng.Assert.*; | |
| 79 | 33 | |
| 80 | - private Cluster.Builder tokenAwareRoundRobinNoShuffleDowngrading() { | |
| 81 | - return Cluster.builder() | |
| 82 | - .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000)) | |
| 83 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)) | |
| 84 | - .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 85 | - } | |
| 34 | +public class ConsistencyTest { | |
| 86 | 35 | |
| 87 | - private Cluster.Builder roundRobinDowngrading() { | |
| 88 | - return Cluster.builder() | |
| 89 | - .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000)) | |
| 90 | - .withLoadBalancingPolicy(new RoundRobinPolicy()) | |
| 91 | - .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 92 | - } | |
| 36 | + private static final Logger logger = LoggerFactory.getLogger(ConsistencyTest.class); | |
| 37 | + private ScassandraCluster sCluster; | |
| 93 | 38 | |
| 94 | - private Cluster.Builder tokenAwareDCAwareRoundRobinNoShuffleDowngrading() { | |
| 95 | - return Cluster.builder() | |
| 96 | - .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000)) | |
| 97 | - .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().withLocalDc("dc2").build(), false)) | |
| 98 | - .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 39 | + @BeforeClass(groups = "short") | |
| 40 | + public void setUp() { | |
| 41 | + sCluster = ScassandraCluster.builder().withNodes(1).build(); | |
| 42 | + sCluster.init(); | |
| 99 | 43 | } |
| 100 | 44 | |
| 101 | - @Test(groups = "long") | |
| 102 | - @CCMConfig( | |
| 103 | - numberOfNodes = 3, | |
| 104 | - clusterProvider = "tokenAwareRoundRobin") | |
| 105 | - public void testRFOneTokenAware() throws Throwable { | |
| 106 | - | |
| 107 | - createSchema(1); | |
| 108 | - init(12, ConsistencyLevel.ONE); | |
| 109 | - query(12, ConsistencyLevel.ONE); | |
| 110 | - | |
| 111 | - assertQueried(IP_PREFIX + '1', 0); | |
| 112 | - assertQueried(IP_PREFIX + '2', 12); | |
| 113 | - assertQueried(IP_PREFIX + '3', 0); | |
| 114 | - | |
| 115 | - resetCoordinators(); | |
| 116 | - stopAndWait(2); | |
| 117 | - | |
| 118 | - List<ConsistencyLevel> acceptedList = singletonList(ConsistencyLevel.ANY); | |
| 119 | - | |
| 120 | - List<ConsistencyLevel> failList = Arrays.asList( | |
| 121 | - ConsistencyLevel.ONE, | |
| 122 | - ConsistencyLevel.TWO, | |
| 123 | - ConsistencyLevel.THREE, | |
| 124 | - ConsistencyLevel.QUORUM, | |
| 125 | - ConsistencyLevel.ALL, | |
| 126 | - ConsistencyLevel.LOCAL_QUORUM, | |
| 127 | - ConsistencyLevel.EACH_QUORUM); | |
| 128 | - | |
| 129 | - // Test successful writes | |
| 130 | - for (ConsistencyLevel cl : acceptedList) { | |
| 131 | - try { | |
| 132 | - init(12, cl); | |
| 133 | - } catch (Exception e) { | |
| 134 | - fail(String.format("Test failed at CL.%s with message: %s", cl, e.getMessage())); | |
| 135 | - } | |
| 136 | - } | |
| 137 | - | |
| 138 | - // Test successful reads | |
| 139 | - for (ConsistencyLevel cl : acceptedList) { | |
| 140 | - try { | |
| 141 | - query(12, cl); | |
| 142 | - } catch (InvalidQueryException e) { | |
| 143 | - List<String> acceptableErrorMessages = singletonList( | |
| 144 | - "ANY ConsistencyLevel is only supported for writes"); | |
| 145 | - assertTrue(acceptableErrorMessages.contains(e.getMessage())); | |
| 146 | - } | |
| 147 | - } | |
| 148 | - | |
| 149 | - // Test writes which should fail | |
| 150 | - for (ConsistencyLevel cl : failList) { | |
| 151 | - try { | |
| 152 | - init(12, cl); | |
| 153 | - fail(String.format("Test passed at CL.%s.", cl)); | |
| 154 | - } catch (InvalidQueryException e) { | |
| 155 | - List<String> acceptableErrorMessages = Arrays.asList( | |
| 156 | - "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", | |
| 157 | - "consistency level EACH_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)"); | |
| 158 | - assertTrue(acceptableErrorMessages.contains(e.getMessage()), String.format("Received: %s", e.getMessage())); | |
| 159 | - } catch (UnavailableException e) { | |
| 160 | - // expected to fail when the client has already marked the | |
| 161 | - // node as DOWN | |
| 162 | - } catch (WriteTimeoutException e) { | |
| 163 | - // expected to fail when the client hasn't marked the | |
| 164 | - // node as DOWN yet | |
| 165 | - } | |
| 166 | - } | |
| 167 | - | |
| 168 | - // Test reads which should fail | |
| 169 | - for (ConsistencyLevel cl : failList) { | |
| 170 | - try { | |
| 171 | - query(12, cl); | |
| 172 | - fail(String.format("Test passed at CL.%s.", cl)); | |
| 173 | - } catch (InvalidQueryException e) { | |
| 174 | - List<String> acceptableErrorMessages = Arrays.asList( | |
| 175 | - "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", | |
| 176 | - "EACH_QUORUM ConsistencyLevel is only supported for writes"); | |
| 177 | - assertTrue(acceptableErrorMessages.contains(e.getMessage()), String.format("Received: %s", e.getMessage())); | |
| 178 | - } catch (ReadTimeoutException e) { | |
| 179 | - // expected to fail when the client hasn't marked the | |
| 180 | - // node as DOWN yet | |
| 181 | - } catch (UnavailableException e) { | |
| 182 | - // expected to fail when the client has already marked the | |
| 183 | - // node as DOWN | |
| 184 | - } | |
| 185 | - } | |
| 45 | + @AfterClass(groups = "short") | |
| 46 | + public void tearDownClass() { | |
| 47 | + sCluster.stop(); | |
| 186 | 48 | } |
| 187 | 49 | |
| 188 | - @Test(groups = "long") | |
| 189 | - @CCMConfig(numberOfNodes = 3, | |
| 190 | - clusterProvider = "tokenAwareRoundRobinNoShuffle") | |
| 191 | - public void testRFTwoTokenAware() throws Throwable { | |
| 192 | - createSchema(2); | |
| 193 | - init(12, ConsistencyLevel.TWO); | |
| 194 | - query(12, ConsistencyLevel.TWO); | |
| 195 | - | |
| 196 | - assertQueried(IP_PREFIX + '1', 0); | |
| 197 | - assertQueried(IP_PREFIX + '2', 12); | |
| 198 | - assertQueried(IP_PREFIX + '3', 0); | |
| 199 | - | |
| 200 | - resetCoordinators(); | |
| 201 | - stopAndWait(2); | |
| 202 | - | |
| 203 | - List<ConsistencyLevel> acceptedList = Arrays.asList( | |
| 204 | - ConsistencyLevel.ANY, | |
| 205 | - ConsistencyLevel.ONE | |
| 206 | - ); | |
| 207 | - | |
| 208 | - List<ConsistencyLevel> failList = Arrays.asList( | |
| 209 | - ConsistencyLevel.TWO, | |
| 210 | - ConsistencyLevel.QUORUM, | |
| 211 | - ConsistencyLevel.THREE, | |
| 212 | - ConsistencyLevel.ALL, | |
| 213 | - ConsistencyLevel.LOCAL_QUORUM, | |
| 214 | - ConsistencyLevel.EACH_QUORUM); | |
| 215 | - | |
| 216 | - // Test successful writes | |
| 217 | - for (ConsistencyLevel cl : acceptedList) { | |
| 218 | - try { | |
| 219 | - init(12, cl); | |
| 220 | - } catch (Exception e) { | |
| 221 | - fail(String.format("Test failed at CL.%s with message: %s", cl, e.getMessage())); | |
| 222 | - } | |
| 223 | - } | |
| 224 | - | |
| 225 | - // Test successful reads | |
| 226 | - for (ConsistencyLevel cl : acceptedList) { | |
| 227 | - try { | |
| 228 | - query(12, cl); | |
| 229 | - } catch (InvalidQueryException e) { | |
| 230 | - List<String> acceptableErrorMessages = singletonList( | |
| 231 | - "ANY ConsistencyLevel is only supported for writes"); | |
| 232 | - assertTrue(acceptableErrorMessages.contains(e.getMessage())); | |
| 233 | - } | |
| 234 | - } | |
| 235 | - | |
| 236 | - // Test writes which should fail | |
| 237 | - for (ConsistencyLevel cl : failList) { | |
| 238 | - try { | |
| 239 | - init(12, cl); | |
| 240 | - fail(String.format("Test passed at CL.%s.", cl)); | |
| 241 | - } catch (InvalidQueryException e) { | |
| 242 | - List<String> acceptableErrorMessages = Arrays.asList( | |
| 243 | - "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", | |
| 244 | - "consistency level EACH_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)"); | |
| 245 | - assertTrue(acceptableErrorMessages.contains(e.getMessage()), String.format("Received: %s", e.getMessage())); | |
| 246 | - } catch (UnavailableException e) { | |
| 247 | - // expected to fail when the client has already marked the | |
| 248 | - // node as DOWN | |
| 249 | - } catch (WriteTimeoutException e) { | |
| 250 | - // expected to fail when the client hasn't marked the | |
| 251 | - // node as DOWN yet | |
| 252 | - } | |
| 253 | - } | |
| 254 | - | |
| 255 | - // Test reads which should fail | |
| 256 | - for (ConsistencyLevel cl : failList) { | |
| 257 | - try { | |
| 258 | - query(12, cl); | |
| 259 | - fail(String.format("Test passed at CL.%s.", cl)); | |
| 260 | - } catch (InvalidQueryException e) { | |
| 261 | - List<String> acceptableErrorMessages = Arrays.asList( | |
| 262 | - "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", | |
| 263 | - "EACH_QUORUM ConsistencyLevel is only supported for writes"); | |
| 264 | - assertTrue(acceptableErrorMessages.contains(e.getMessage()), String.format("Received: %s", e.getMessage())); | |
| 265 | - } catch (ReadTimeoutException e) { | |
| 266 | - // expected to fail when the client hasn't marked the | |
| 267 | - // node as DOWN yet | |
| 268 | - } catch (UnavailableException e) { | |
| 269 | - // expected to fail when the client has already marked the | |
| 270 | - // node as DOWN | |
| 271 | - } | |
| 272 | - } | |
| 50 | + @AfterMethod(groups = "short") | |
| 51 | + public void tearDown() { | |
| 52 | + clearActivityLog(); | |
| 273 | 53 | } |
| 274 | 54 | |
| 275 | - @Test(groups = "long") | |
| 276 | - @CCMConfig(numberOfNodes = 3, | |
| 277 | - clusterProvider = "tokenAwareRoundRobinNoShuffle") | |
| 278 | - public void testRFThreeTokenAware() throws Throwable { | |
| 279 | - createSchema(3); | |
| 280 | - init(12, ConsistencyLevel.TWO); | |
| 281 | - query(12, ConsistencyLevel.TWO); | |
| 282 | - | |
| 283 | - assertQueried(IP_PREFIX + '1', 0); | |
| 284 | - assertQueried(IP_PREFIX + '2', 12); | |
| 285 | - assertQueried(IP_PREFIX + '3', 0); | |
| 286 | - | |
| 287 | - resetCoordinators(); | |
| 288 | - stopAndWait(2); | |
| 289 | - | |
| 290 | - Set<ConsistencyLevel> cls = EnumSet.allOf(ConsistencyLevel.class); | |
| 291 | - // Remove serial consistencies as they require conditional read/writes | |
| 292 | - cls.remove(ConsistencyLevel.SERIAL); | |
| 293 | - cls.remove(ConsistencyLevel.LOCAL_SERIAL); | |
| 294 | - | |
| 295 | - List<ConsistencyLevel> acceptedList = Arrays.asList( | |
| 296 | - ConsistencyLevel.ANY, | |
| 297 | - ConsistencyLevel.ONE, | |
| 298 | - ConsistencyLevel.TWO, | |
| 299 | - ConsistencyLevel.QUORUM, | |
| 300 | - ConsistencyLevel.LOCAL_QUORUM, | |
| 301 | - ConsistencyLevel.EACH_QUORUM | |
| 302 | - ); | |
| 303 | - | |
| 304 | - List<ConsistencyLevel> failList = Arrays.asList( | |
| 305 | - ConsistencyLevel.THREE, | |
| 306 | - ConsistencyLevel.ALL | |
| 307 | - ); | |
| 308 | - | |
| 309 | - | |
| 310 | - // Test successful writes | |
| 311 | - for (ConsistencyLevel cl : acceptedList) { | |
| 312 | - try { | |
| 313 | - init(12, cl); | |
| 314 | - } catch (Exception e) { | |
| 315 | - fail(String.format("Test failed at CL.%s with message: %s", cl, e.getMessage())); | |
| 316 | - } | |
| 317 | - } | |
| 318 | - | |
| 319 | - // Test successful reads | |
| 320 | - for (ConsistencyLevel cl : acceptedList) { | |
| 321 | - try { | |
| 322 | - query(12, cl); | |
| 323 | - } catch (InvalidQueryException e) { | |
| 324 | - List<String> acceptableErrorMessages = Arrays.asList( | |
| 325 | - "ANY ConsistencyLevel is only supported for writes", | |
| 326 | - "EACH_QUORUM ConsistencyLevel is only supported for writes" | |
| 327 | - ); | |
| 328 | - assertTrue(acceptableErrorMessages.contains(e.getMessage()), "Got unexpected message " + e.getMessage()); | |
| 329 | - } | |
| 330 | - } | |
| 331 | - | |
| 332 | - // Test writes which should fail | |
| 333 | - for (ConsistencyLevel cl : failList) { | |
| 334 | - try { | |
| 335 | - init(12, cl); | |
| 336 | - fail(String.format("Test passed at CL.%s.", cl)); | |
| 337 | - } catch (UnavailableException e) { | |
| 338 | - // expected to fail when the client has already marked the | |
| 339 | - // node as DOWN | |
| 340 | - } catch (WriteTimeoutException e) { | |
| 341 | - // expected to fail when the client hasn't marked the | |
| 342 | - // node as DOWN yet | |
| 343 | - } | |
| 344 | - } | |
| 345 | - | |
| 346 | - // Test reads which should fail | |
| 347 | - for (ConsistencyLevel cl : failList) { | |
| 348 | - try { | |
| 349 | - query(12, cl); | |
| 350 | - fail(String.format("Test passed at CL.%s.", cl)); | |
| 351 | - } catch (ReadTimeoutException e) { | |
| 352 | - // expected to fail when the client hasn't marked the | |
| 353 | - // node as DOWN yet | |
| 354 | - } catch (UnavailableException e) { | |
| 355 | - // expected to fail when the client has already marked the | |
| 356 | - // node as DOWN | |
| 357 | - } | |
| 55 | + public void clearActivityLog() { | |
| 56 | + for (Scassandra node : sCluster.nodes()) { | |
| 57 | + node.activityClient().clearAllRecordedActivity(); | |
| 358 | 58 | } |
| 359 | 59 | } |
| 360 | 60 | |
| 361 | - | |
| 362 | - @Test(groups = "long") | |
| 363 | - @CCMConfig(numberOfNodes = 3, | |
| 364 | - clusterProvider = "tokenAwareRoundRobinDowngrading") | |
| 365 | - public void testRFOneDowngradingCL() throws Throwable { | |
| 366 | - createSchema(1); | |
| 367 | - init(12, ConsistencyLevel.ONE); | |
| 368 | - query(12, ConsistencyLevel.ONE); | |
| 369 | - | |
| 370 | - assertQueried(IP_PREFIX + '1', 0); | |
| 371 | - assertQueried(IP_PREFIX + '2', 12); | |
| 372 | - assertQueried(IP_PREFIX + '3', 0); | |
| 373 | - | |
| 374 | - resetCoordinators(); | |
| 375 | - stopAndWait(2); | |
| 376 | - | |
| 377 | - List<ConsistencyLevel> acceptedList = singletonList( | |
| 378 | - ConsistencyLevel.ANY | |
| 379 | - ); | |
| 380 | - | |
| 381 | - List<ConsistencyLevel> failList = Arrays.asList( | |
| 382 | - ConsistencyLevel.ONE, | |
| 383 | - ConsistencyLevel.TWO, | |
| 384 | - ConsistencyLevel.THREE, | |
| 385 | - ConsistencyLevel.QUORUM, | |
| 386 | - ConsistencyLevel.ALL, | |
| 387 | - ConsistencyLevel.LOCAL_QUORUM, | |
| 388 | - ConsistencyLevel.EACH_QUORUM); | |
| 389 | - | |
| 390 | - // Test successful writes | |
| 391 | - for (ConsistencyLevel cl : acceptedList) { | |
| 392 | - try { | |
| 393 | - init(12, cl); | |
| 394 | - } catch (Exception e) { | |
| 395 | - fail(String.format("Test failed at CL.%s with message: %s", cl, e.getMessage())); | |
| 396 | - } | |
| 397 | - } | |
| 398 | - | |
| 399 | - // Test successful reads | |
| 400 | - for (ConsistencyLevel cl : acceptedList) { | |
| 401 | - try { | |
| 402 | - query(12, cl); | |
| 403 | - } catch (InvalidQueryException e) { | |
| 404 | - List<String> acceptableErrorMessages = singletonList( | |
| 405 | - "ANY ConsistencyLevel is only supported for writes"); | |
| 406 | - assertTrue(acceptableErrorMessages.contains(e.getMessage())); | |
| 407 | - } | |
| 408 | - } | |
| 409 | - | |
| 410 | - // Test writes which should fail | |
| 411 | - for (ConsistencyLevel cl : failList) { | |
| 412 | - try { | |
| 413 | - init(12, cl); | |
| 414 | - fail(String.format("Test passed at CL.%s.", cl)); | |
| 415 | - } catch (UnavailableException e) { | |
| 416 | - // expected to fail when the client has already marked the | |
| 417 | - // node as DOWN | |
| 418 | - } catch (WriteTimeoutException e) { | |
| 419 | - // expected to fail when the client hasn't marked the | |
| 420 | - // node as DOWN yet | |
| 421 | - } | |
| 422 | - } | |
| 423 | - | |
| 424 | - // Test reads which should fail | |
| 425 | - for (ConsistencyLevel cl : failList) { | |
| 426 | - try { | |
| 427 | - query(12, cl); | |
| 428 | - fail(String.format("Test passed at CL.%s.", cl)); | |
| 429 | - } catch (InvalidQueryException e) { | |
| 430 | - List<String> acceptableErrorMessages = singletonList( | |
| 431 | - "EACH_QUORUM ConsistencyLevel is only supported for writes" | |
| 432 | - ); | |
| 433 | - assertTrue(acceptableErrorMessages.contains(e.getMessage()), "Got unexpected message " + e.getMessage()); | |
| 434 | - } catch (ReadTimeoutException e) { | |
| 435 | - // expected to fail when the client hasn't marked the | |
| 436 | - // node as DOWN yet | |
| 437 | - } catch (UnavailableException e) { | |
| 438 | - // expected to fail when the client has already marked the | |
| 439 | - // node as DOWN | |
| 440 | - } | |
| 441 | - } | |
| 61 | + public Cluster.Builder builder() { | |
| 62 | + //Note: nonQuietClusterCloseOptions is used to speed up tests | |
| 63 | + return Cluster.builder() | |
| 64 | + .addContactPoints(sCluster.address(1).getAddress()) | |
| 65 | + .withPort(sCluster.getBinaryPort()).withNettyOptions(nonQuietClusterCloseOptions); | |
| 442 | 66 | } |
| 443 | 67 | |
| 444 | - @Test(groups = "long") | |
| 445 | - @CCMConfig(numberOfNodes = 3, | |
| 446 | - clusterProvider = "tokenAwareRoundRobinNoShuffleDowngrading") | |
| 447 | - public void testRFTwoDowngradingCL() throws Throwable { | |
| 448 | - createSchema(2); | |
| 449 | - init(12, ConsistencyLevel.TWO); | |
| 450 | - query(12, ConsistencyLevel.TWO); | |
| 451 | - | |
| 452 | - assertQueried(IP_PREFIX + '1', 0); | |
| 453 | - assertQueried(IP_PREFIX + '2', 12); | |
| 454 | - assertQueried(IP_PREFIX + '3', 0); | |
| 455 | - | |
| 456 | - resetCoordinators(); | |
| 457 | - stopAndWait(2); | |
| 458 | - | |
| 459 | - Set<ConsistencyLevel> acceptedList = EnumSet.allOf(ConsistencyLevel.class); | |
| 460 | - // Remove serial consistencies as they require conditional read/writes | |
| 461 | - acceptedList.remove(ConsistencyLevel.SERIAL); | |
| 462 | - acceptedList.remove(ConsistencyLevel.LOCAL_SERIAL); | |
| 463 | - | |
| 464 | - // Test successful writes | |
| 465 | - for (ConsistencyLevel cl : acceptedList) { | |
| 466 | - try { | |
| 467 | - init(12, cl); | |
| 468 | - } catch (Exception e) { | |
| 469 | - fail(String.format("Test failed at CL.%s with message: %s", cl, e.getMessage())); | |
| 470 | - } | |
| 68 | + /** | |
| 69 | + * This method checks the expected/sent serial consistency level against that which is received. | |
| 70 | + * ConsistencyLevel.SERIAL is the default serial consistency level, so even when sent it will return | |
| 71 | + * as null. | |
| 72 | + */ | |
| 73 | + public void checkSerialCLMatch(ConsistencyLevel expected, String received) { | |
| 74 | + if (expected.equals(ConsistencyLevel.SERIAL)) { | |
| 75 | + assertNull(received); | |
| 76 | + } else { | |
| 77 | + assertTrue(received.equals(expected.toString())); | |
| 471 | 78 | } |
| 472 | - | |
| 473 | - // Test successful reads | |
| 474 | - for (ConsistencyLevel cl : acceptedList) { | |
| 475 | - try { | |
| 476 | - query(12, cl); | |
| 477 | - } catch (InvalidQueryException e) { | |
| 478 | - List<String> acceptableErrorMessages = Arrays.asList( | |
| 479 | - "ANY ConsistencyLevel is only supported for writes", | |
| 480 | - "EACH_QUORUM ConsistencyLevel is only supported for writes" | |
| 481 | - ); | |
| 482 | - assertTrue(acceptableErrorMessages.contains(e.getMessage()), "Got unexpected message " + e.getMessage()); | |
| 483 | - } | |
| 484 | - } | |
| 485 | - } | |
| 486 | - | |
| 487 | - @Test(groups = "long") | |
| 488 | - @CCMConfig(numberOfNodes = 3, | |
| 489 | - clusterProvider = "roundRobinDowngrading") | |
| 490 | - public void testRFThreeRoundRobinDowngradingCL() throws Throwable { | |
| 491 | - testRFThreeDowngradingCL(); | |
| 492 | - } | |
| 493 | - | |
| 494 | - @Test(groups = "long") | |
| 495 | - @CCMConfig(numberOfNodes = 3, | |
| 496 | - clusterProvider = "tokenAwareRoundRobinNoShuffleDowngrading") | |
| 497 | - public void testRFThreeTokenAwareDowngradingCL() throws Throwable { | |
| 498 | - testRFThreeDowngradingCL(); | |
| 499 | 79 | } |
| 500 | 80 | |
| 501 | - private void testRFThreeDowngradingCL() throws Throwable { | |
| 502 | - | |
| 503 | - createSchema(3); | |
| 504 | - init(12, ConsistencyLevel.ALL); | |
| 505 | - query(12, ConsistencyLevel.ALL); | |
| 506 | - | |
| 507 | - try { | |
| 508 | - // This test catches TokenAwarePolicy | |
| 509 | - // However, full tests in LoadBalancingPolicyTest.java | |
| 510 | - assertQueried(IP_PREFIX + '1', 0); | |
| 511 | - assertQueried(IP_PREFIX + '2', 12); | |
| 512 | - assertQueried(IP_PREFIX + '3', 0); | |
| 513 | - } catch (AssertionError e) { | |
| 514 | - // This test catches RoundRobinPolicy | |
| 515 | - assertQueried(IP_PREFIX + '1', 4); | |
| 516 | - assertQueried(IP_PREFIX + '2', 4); | |
| 517 | - assertQueried(IP_PREFIX + '3', 4); | |
| 518 | - } | |
| 519 | - | |
| 520 | - resetCoordinators(); | |
| 521 | - stopAndWait(2); | |
| 522 | - | |
| 523 | - Set<ConsistencyLevel> acceptedList = EnumSet.allOf(ConsistencyLevel.class); | |
| 524 | - // Remove serial consistencies as they require conditional read/writes | |
| 525 | - acceptedList.remove(ConsistencyLevel.SERIAL); | |
| 526 | - acceptedList.remove(ConsistencyLevel.LOCAL_SERIAL); | |
| 527 | - | |
| 528 | - // Test successful writes | |
| 529 | - for (ConsistencyLevel cl : acceptedList) { | |
| 530 | - try { | |
| 531 | - init(12, cl); | |
| 532 | - } catch (Exception e) { | |
| 533 | - fail(String.format("Test failed at CL.%s with message: %s", cl, e.getMessage())); | |
| 534 | - } | |
| 81 | + public PreparedStatementExecution executePrepared(Session session, String statement, ConsistencyLevel level, ConsistencyLevel serialLevel) { | |
| 82 | + PreparedStatement ps = session.prepare(statement); | |
| 83 | + BoundStatement bound = ps.bind(); | |
| 84 | + if (level != null) { | |
| 85 | + bound.setConsistencyLevel(level); | |
| 535 | 86 | } |
| 536 | - | |
| 537 | - // Test successful reads | |
| 538 | - for (ConsistencyLevel cl : acceptedList) { | |
| 539 | - try { | |
| 540 | - query(12, cl); | |
| 541 | - } catch (InvalidQueryException e) { | |
| 542 | - List<String> acceptableErrorMessages = Arrays.asList( | |
| 543 | - "ANY ConsistencyLevel is only supported for writes", | |
| 544 | - "EACH_QUORUM ConsistencyLevel is only supported for writes" | |
| 545 | - ); | |
| 546 | - assertTrue(acceptableErrorMessages.contains(e.getMessage()), "Got unexpected message " + e.getMessage()); | |
| 547 | - } | |
| 87 | + if (serialLevel != null) { | |
| 88 | + bound.setSerialConsistencyLevel(serialLevel); | |
| 548 | 89 | } |
| 90 | + session.execute(bound); | |
| 91 | + List<PreparedStatementExecution> pses = sCluster.node(1).activityClient().retrievePreparedStatementExecutions(); | |
| 92 | + PreparedStatementExecution pse = pses.get(0); | |
| 93 | + assertTrue(pse.getPreparedStatementText().equals(statement)); | |
| 94 | + return pse; | |
| 549 | 95 | } |
| 550 | 96 | |
| 551 | - @Test(groups = "long") | |
| 552 | - @CCMConfig( | |
| 553 | - numberOfNodes = {3, 3}, | |
| 554 | - clusterProvider = "tokenAwareRoundRobinNoShuffleDowngrading" | |
| 555 | - ) | |
| 556 | - public void testRFThreeDowngradingCLTwoDCs() throws Throwable { | |
| 557 | - createMultiDCSchema(3, 3); | |
| 558 | - init(12, ConsistencyLevel.TWO); | |
| 559 | - query(12, ConsistencyLevel.TWO); | |
| 560 | - | |
| 561 | - assertQueried(IP_PREFIX + '1', 0); | |
| 562 | - assertQueried(IP_PREFIX + '2', 12); | |
| 563 | - assertQueried(IP_PREFIX + '3', 0); | |
| 564 | - assertQueried(IP_PREFIX + '4', 0); | |
| 565 | - assertQueried(IP_PREFIX + '5', 0); | |
| 566 | - assertQueried(IP_PREFIX + '6', 0); | |
| 567 | - | |
| 568 | - resetCoordinators(); | |
| 569 | - stopAndWait(3); | |
| 570 | - | |
| 571 | - List<ConsistencyLevel> acceptedList = Arrays.asList( | |
| 572 | - ConsistencyLevel.ANY, | |
| 573 | - ConsistencyLevel.ONE, | |
| 574 | - ConsistencyLevel.TWO, | |
| 575 | - ConsistencyLevel.QUORUM, | |
| 576 | - ConsistencyLevel.THREE, | |
| 577 | - ConsistencyLevel.ALL, | |
| 578 | - ConsistencyLevel.LOCAL_QUORUM, | |
| 579 | - ConsistencyLevel.EACH_QUORUM | |
| 580 | - ); | |
| 581 | - | |
| 582 | - List<ConsistencyLevel> failList = emptyList(); | |
| 583 | - | |
| 584 | - // Test successful writes | |
| 585 | - for (ConsistencyLevel cl : acceptedList) { | |
| 586 | - logger.debug("Test successful init(): " + cl); | |
| 587 | - try { | |
| 588 | - init(12, cl); | |
| 589 | - } catch (Exception e) { | |
| 590 | - fail(String.format("Test failed at CL.%s with message: %s", cl, e.getMessage())); | |
| 591 | - } | |
| 592 | - } | |
| 593 | - | |
| 594 | - // Test successful reads | |
| 595 | - for (ConsistencyLevel cl : acceptedList) { | |
| 596 | - logger.debug("Test successful query(): " + cl); | |
| 597 | - try { | |
| 598 | - query(12, cl); | |
| 599 | - } catch (InvalidQueryException e) { | |
| 600 | - List<String> acceptableErrorMessages = Arrays.asList( | |
| 601 | - "EACH_QUORUM ConsistencyLevel is only supported for writes", | |
| 602 | - "ANY ConsistencyLevel is only supported for writes"); | |
| 603 | - assertTrue(acceptableErrorMessages.contains(e.getMessage()), String.format("Received: %s", e.getMessage())); | |
| 604 | - } | |
| 605 | - } | |
| 97 | + public BatchExecution executeBatch(Session session, String statement, ConsistencyLevel level, ConsistencyLevel serialLevel) { | |
| 98 | + BatchStatement batch = new BatchStatement(); | |
| 99 | + batch.add(new SimpleStatement(statement)); | |
| 606 | 100 | |
| 607 | - // Test writes which should fail | |
| 608 | - for (ConsistencyLevel cl : failList) { | |
| 609 | - logger.debug("Test failure init(): " + cl); | |
| 610 | - try { | |
| 611 | - init(12, cl); | |
| 612 | - fail(String.format("Test passed at CL.%s.", cl)); | |
| 613 | - } catch (UnavailableException e) { | |
| 614 | - // expected to fail when the client has already marked the | |
| 615 | - // node as DOWN | |
| 616 | - } catch (WriteTimeoutException e) { | |
| 617 | - // expected to fail when the client hasn't marked the | |
| 618 | - // node as DOWN yet | |
| 619 | - } | |
| 101 | + if (level != null) { | |
| 102 | + batch.setConsistencyLevel(level); | |
| 620 | 103 | } |
| 621 | - | |
| 622 | - // Test reads which should fail | |
| 623 | - for (ConsistencyLevel cl : failList) { | |
| 624 | - logger.debug("Test failure query(): " + cl); | |
| 625 | - try { | |
| 626 | - query(12, cl); | |
| 627 | - fail(String.format("Test passed at CL.%s.", cl)); | |
| 628 | - } catch (ReadTimeoutException e) { | |
| 629 | - // expected to fail when the client hasn't marked the | |
| 630 | - // node as DOWN yet | |
| 631 | - } catch (UnavailableException e) { | |
| 632 | - // expected to fail when the client has already marked the | |
| 633 | - // node as DOWN | |
| 634 | - } | |
| 104 | + if (serialLevel != null) { | |
| 105 | + batch.setSerialConsistencyLevel(serialLevel); | |
| 635 | 106 | } |
| 107 | + session.execute(batch); | |
| 108 | + List<BatchExecution> batches = sCluster.node(1).activityClient().retrieveBatches(); | |
| 109 | + assertEquals(batches.size(), 1); | |
| 110 | + return batches.get(0); | |
| 636 | 111 | } |
| 637 | 112 | |
| 638 | - @Test(groups = "long") | |
| 639 | - @CCMConfig( | |
| 640 | - numberOfNodes = {3, 3}, | |
| 641 | - clusterProvider = "tokenAwareDCAwareRoundRobinNoShuffleDowngrading" | |
| 642 | - ) | |
| 643 | - public void testRFThreeDowngradingCLTwoDCsDCAware() throws Throwable { | |
| 644 | - createMultiDCSchema(3, 3); | |
| 645 | - init(12, ConsistencyLevel.TWO); | |
| 646 | - query(12, ConsistencyLevel.TWO); | |
| 647 | - | |
| 648 | - assertQueried(IP_PREFIX + '1', 0); | |
| 649 | - assertQueried(IP_PREFIX + '2', 0); | |
| 650 | - assertQueried(IP_PREFIX + '3', 0); | |
| 651 | - assertQueried(IP_PREFIX + '4', 0); | |
| 652 | - assertQueried(IP_PREFIX + '5', 12); | |
| 653 | - assertQueried(IP_PREFIX + '6', 0); | |
| 654 | - | |
| 655 | - resetCoordinators(); | |
| 656 | - stopAndWait(2); | |
| 657 | - | |
| 658 | - List<ConsistencyLevel> acceptedList = Arrays.asList( | |
| 659 | - ConsistencyLevel.ANY, | |
| 660 | - ConsistencyLevel.ONE, | |
| 661 | - ConsistencyLevel.TWO, | |
| 662 | - ConsistencyLevel.QUORUM, | |
| 663 | - ConsistencyLevel.THREE, | |
| 664 | - ConsistencyLevel.ALL, | |
| 665 | - ConsistencyLevel.LOCAL_QUORUM, | |
| 666 | - ConsistencyLevel.EACH_QUORUM | |
| 667 | - ); | |
| 668 | - | |
| 669 | - List<ConsistencyLevel> failList = emptyList(); | |
| 670 | - | |
| 671 | - // Test successful writes | |
| 672 | - for (ConsistencyLevel cl : acceptedList) { | |
| 673 | - try { | |
| 674 | - init(12, cl); | |
| 675 | - } catch (Exception e) { | |
| 676 | - fail(String.format("Test failed at CL.%s with message: %s", cl, e.getMessage())); | |
| 677 | - } | |
| 678 | - } | |
| 679 | - | |
| 680 | - // Test successful reads | |
| 681 | - for (ConsistencyLevel cl : acceptedList) { | |
| 682 | - try { | |
| 683 | - query(12, cl); | |
| 684 | - } catch (InvalidQueryException e) { | |
| 685 | - List<String> acceptableErrorMessages = Arrays.asList( | |
| 686 | - "EACH_QUORUM ConsistencyLevel is only supported for writes", | |
| 687 | - "ANY ConsistencyLevel is only supported for writes"); | |
| 688 | - assertTrue(acceptableErrorMessages.contains(e.getMessage()), String.format("Received: %s", e.getMessage())); | |
| 689 | - } | |
| 690 | - } | |
| 691 | - | |
| 692 | - // Test writes which should fail | |
| 693 | - for (ConsistencyLevel cl : failList) { | |
| 694 | - try { | |
| 695 | - init(12, cl); | |
| 696 | - fail(String.format("Test passed at CL.%s.", cl)); | |
| 697 | - } catch (UnavailableException e) { | |
| 698 | - // expected to fail when the client has already marked the | |
| 699 | - // node as DOWN | |
| 700 | - } catch (WriteTimeoutException e) { | |
| 701 | - // expected to fail when the client hasn't marked the | |
| 702 | - // node as DOWN yet | |
| 703 | - } | |
| 113 | + public Query executeSimple(Session session, String statement, ConsistencyLevel level, ConsistencyLevel serialLevel) { | |
| 114 | + SimpleStatement simpleStatement = new SimpleStatement(statement); | |
| 115 | + if (level != null) { | |
| 116 | + simpleStatement.setConsistencyLevel(level); | |
| 704 | 117 | } |
| 118 | + if (serialLevel != null) { | |
| 119 | + simpleStatement.setSerialConsistencyLevel(serialLevel); | |
| 120 | + } | |
| 121 | + session.execute(simpleStatement); | |
| 122 | + //Find the unique query in the activity log. | |
| 123 | + List<Query> queries = sCluster.node(1).activityClient().retrieveQueries(); | |
| 124 | + for (Query query : queries) { | |
| 125 | + if (query.getQuery().equals(statement)) | |
| 126 | + return query; | |
| 127 | + } | |
| 128 | + return null; | |
| 129 | + } | |
| 130 | + | |
| 131 | + /** | |
| 132 | + * When no consistency level is defined the default of LOCAL_ONE should be used. | |
| 133 | + * | |
| 134 | + * @test_category consistency | |
| 135 | + */ | |
| 136 | + @Test(groups = "short") | |
| 137 | + public void should_use_global_default_cl_when_none_specified() throws Throwable { | |
| 138 | + //Build a cluster with no CL level set in the query options. | |
| 139 | + Cluster cluster = builder().build(); | |
| 140 | + try { | |
| 141 | + Session session = cluster.connect(); | |
| 142 | + | |
| 143 | + //Construct unique simple statement query, with no CL defined. | |
| 144 | + //Check to ensure | |
| 145 | + String queryString = "default_cl"; | |
| 146 | + Query clQuery = executeSimple(session, queryString, null, null); | |
| 147 | + assertTrue(clQuery.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString())); | |
| 148 | + | |
| 149 | + //Check prepared statement default CL | |
| 150 | + String prepareString = "prepared_default_cl"; | |
| 151 | + PreparedStatementExecution pse = executePrepared(session, prepareString, null, null); | |
| 152 | + assertTrue(pse.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString())); | |
| 153 | + | |
| 154 | + //Check batch statement default CL | |
| 155 | + String batchStateString = "batch_default_cl"; | |
| 156 | + BatchExecution batch = executeBatch(session, batchStateString, null, null); | |
| 157 | + assertTrue(batch.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString())); | |
| 158 | + } finally { | |
| 159 | + cluster.close(); | |
| 160 | + } | |
| 161 | + } | |
| 162 | + | |
| 163 | + /** | |
| 164 | + * Exhaustively tests all consistency levels when they are set via QueryOptions. | |
| 165 | + * | |
| 166 | + * @test_category consistency | |
| 167 | + */ | |
| 168 | + @Test(groups = "short", dataProvider = "consistencyLevels", dataProviderClass = DataProviders.class) | |
| 169 | + public void should_use_query_option_cl(ConsistencyLevel cl) throws Throwable { | |
| 170 | + //Build a cluster with a CL level set in the query options. | |
| 171 | + Cluster cluster = builder().withQueryOptions(new QueryOptions().setConsistencyLevel(cl)).build(); | |
| 172 | + try { | |
| 173 | + Session session = cluster.connect(); | |
| 174 | + //Construct unique query, with no CL defined. | |
| 175 | + String queryString = "query_cl"; | |
| 176 | + Query clQuery = executeSimple(session, queryString, null, null); | |
| 177 | + assertTrue(clQuery.getConsistency().equals(cl.toString())); | |
| 178 | + | |
| 179 | + //Check prepared statement CL | |
| 180 | + String prepareString = "preapred_query_cl"; | |
| 181 | + PreparedStatementExecution pse = executePrepared(session, prepareString, null, null); | |
| 182 | + assertTrue(pse.getConsistency().equals(cl.toString())); | |
| 183 | + | |
| 184 | + //Check batch statement CL | |
| 185 | + String batchStateString = "batch_query_cl"; | |
| 186 | + BatchExecution batch = executeBatch(session, batchStateString, null, null); | |
| 187 | + assertTrue(batch.getConsistency().equals(cl.toString())); | |
| 188 | + } finally { | |
| 189 | + cluster.close(); | |
| 190 | + } | |
| 191 | + } | |
| 192 | + | |
| 193 | + /** | |
| 194 | + * Exhaustively tests all consistency levels when they are set at the statement level. | |
| 195 | + * | |
| 196 | + * @test_category consistency | |
| 197 | + */ | |
| 198 | + @Test(groups = "short", dataProvider = "consistencyLevels", dataProviderClass = DataProviders.class) | |
| 199 | + public void should_use_statement_cl(ConsistencyLevel cl) throws Throwable { | |
| 200 | + //Build a cluster with no CL set in the query options. | |
| 201 | + //Note: nonQuietClusterCloseOptions is used to speed up tests | |
| 202 | + Cluster cluster = builder().build(); | |
| 203 | + try { | |
| 204 | + Session session = cluster.connect(); | |
| 205 | + //Construct unique query statement with a CL defined. | |
| 206 | + String queryString = "statement_cl"; | |
| 207 | + Query clQuery = executeSimple(session, queryString, cl, null); | |
| 208 | + assertTrue(clQuery.getConsistency().equals(cl.toString())); | |
| 209 | + | |
| 210 | + //Check prepared statement CL | |
| 211 | + String prepareString = "preapred_statement_cl"; | |
| 212 | + PreparedStatementExecution pse = executePrepared(session, prepareString, cl, null); | |
| 213 | + assertTrue(pse.getConsistency().equals(cl.toString())); | |
| 214 | + | |
| 215 | + //Check batch statement CL | |
| 216 | + String batchStateString = "batch_statement_cl"; | |
| 217 | + BatchExecution batch = executeBatch(session, batchStateString, cl, null); | |
| 218 | + assertTrue(batch.getConsistency().equals(cl.toString())); | |
| 219 | + } finally { | |
| 220 | + cluster.close(); | |
| 221 | + } | |
| 222 | + } | |
| 223 | + | |
| 224 | + /** | |
| 225 | + * Tests that order of precedence is followed when defining CLs. | |
| 226 | + * Statement level CL should be honored above QueryOptions. | |
| 227 | + * QueryOptions should be honored above default CL. | |
| 228 | + * | |
| 229 | + * @test_category consistency | |
| 230 | + */ | |
| 231 | + @Test(groups = "short") | |
| 232 | + public void should_use_appropriate_cl_when_multiple_defined() throws Throwable { | |
| 233 | + ConsistencyLevel cl_one = ConsistencyLevel.ONE; | |
| 234 | + //Build a cluster with no CL set in the query options. | |
| 235 | + Cluster cluster = builder().withQueryOptions(new QueryOptions().setConsistencyLevel(cl_one)).build(); | |
| 236 | + try { | |
| 705 | 237 | |
| 706 | - // Test reads which should fail | |
| 707 | - for (ConsistencyLevel cl : failList) { | |
| 708 | - try { | |
| 709 | - query(12, cl); | |
| 710 | - fail(String.format("Test passed at CL.%s.", cl)); | |
| 711 | - } catch (ReadTimeoutException e) { | |
| 712 | - // expected to fail when the client hasn't marked the | |
| 713 | - // node as DOWN yet | |
| 714 | - } catch (UnavailableException e) { | |
| 715 | - // expected to fail when the client has already marked the | |
| 716 | - // node as DOWN | |
| 717 | - } | |
| 238 | + Session session = cluster.connect(); | |
| 239 | + | |
| 240 | + //Check order of precedence for simple statements | |
| 241 | + //Construct unique query statement with no CL defined. | |
| 242 | + String queryString = "opts_cl"; | |
| 243 | + Query clQuery = executeSimple(session, queryString, null, null); | |
| 244 | + assertTrue(clQuery.getConsistency().equals(cl_one.toString())); | |
| 245 | + | |
| 246 | + //Construct unique query statement with a CL defined. | |
| 247 | + ConsistencyLevel cl_all = ConsistencyLevel.ALL; | |
| 248 | + queryString = "stm_cl"; | |
| 249 | + clQuery = executeSimple(session, queryString, cl_all, null); | |
| 250 | + assertTrue(clQuery.getConsistency().equals(cl_all.toString())); | |
| 251 | + | |
| 252 | + //Check order of precedence for prepared statements | |
| 253 | + //Construct unique prepared statement with no CL defined. | |
| 254 | + String prepareString = "prep_opts_cl"; | |
| 255 | + PreparedStatementExecution pse = executePrepared(session, prepareString, null, null); | |
| 256 | + assertTrue(pse.getConsistency().equals(cl_one.toString())); | |
| 257 | + clearActivityLog(); | |
| 258 | + | |
| 259 | + //Construct unique prepared statement with a CL defined. | |
| 260 | + prepareString = "prep_stm_cl"; | |
| 261 | + pse = executePrepared(session, prepareString, cl_all, null); | |
| 262 | + assertTrue(pse.getConsistency().equals(cl_all.toString())); | |
| 263 | + | |
| 264 | + //Check order of precedence for batch statements | |
| 265 | + //Construct unique batch statement with no CL defined. | |
| 266 | + String batchString = "batch_opts_cl"; | |
| 267 | + BatchExecution batch = executeBatch(session, batchString, null, null); | |
| 268 | + assertTrue(batch.getConsistency().equals(cl_one.toString())); | |
| 269 | + clearActivityLog(); | |
| 270 | + | |
| 271 | + //Construct unique prepared statement with a CL defined. | |
| 272 | + batchString = "prep_stm_cl"; | |
| 273 | + batch = executeBatch(session, batchString, cl_all, null); | |
| 274 | + assertTrue(batch.getConsistency().equals(cl_all.toString())); | |
| 275 | + } finally { | |
| 276 | + cluster.close(); | |
| 277 | + } | |
| 278 | + } | |
| 279 | + | |
| 280 | + /** | |
| 281 | + * Exhaustively tests all serial consistency levels when they are set via QueryOptions. | |
| 282 | + * | |
| 283 | + * @test_category consistency | |
| 284 | + */ | |
| 285 | + @Test(groups = "short", dataProvider = "serialConsistencyLevels", dataProviderClass = DataProviders.class) | |
| 286 | + public void should_use_query_option_serial_cl(ConsistencyLevel cl) throws Throwable { | |
| 287 | + //Build a cluster with a CL level set in the query options. | |
| 288 | + Cluster cluster = builder().withQueryOptions(new QueryOptions().setSerialConsistencyLevel(cl)).build(); | |
| 289 | + try { | |
| 290 | + Session session = cluster.connect(); | |
| 291 | + //Construct unique query, with no CL defined. | |
| 292 | + String queryString = "serial_query_cl"; | |
| 293 | + Query clQuery = executeSimple(session, queryString, null, cl); | |
| 294 | + checkSerialCLMatch(cl, clQuery.getSerialConsistency()); | |
| 295 | + | |
| 296 | + //Check prepared statement CL | |
| 297 | + String prepareString = "preapred_statement_serial_cl"; | |
| 298 | + PreparedStatementExecution pse = executePrepared(session, prepareString, null, null); | |
| 299 | + checkSerialCLMatch(cl, pse.getSerialConsistency()); | |
| 300 | + | |
| 301 | + //Check batch statement CL | |
| 302 | + String batchStateString = "batch_statement_serial_cl"; | |
| 303 | + BatchExecution batch = executeBatch(session, batchStateString, null, null); | |
| 304 | + checkSerialCLMatch(cl, batch.getSerialConsistency()); | |
| 305 | + } finally { | |
| 306 | + cluster.close(); | |
| 307 | + } | |
| 308 | + } | |
| 309 | + | |
| 310 | + /** | |
| 311 | + * Exhaustively tests all serial consistency levels when they are set at the statement level. | |
| 312 | + * | |
| 313 | + * @test_category consistency | |
| 314 | + */ | |
| 315 | + @Test(groups = "short", dataProvider = "serialConsistencyLevels", dataProviderClass = DataProviders.class) | |
| 316 | + public void should_use_statement_serial_cl(ConsistencyLevel cl) throws Throwable { | |
| 317 | + //Build a cluster with no CL set in the query options. | |
| 318 | + Cluster cluster = builder().build(); | |
| 319 | + try { | |
| 320 | + Session session = cluster.connect(); | |
| 321 | + //Construct unique query statement with a CL defined. | |
| 322 | + String queryString = "statement_serial_cl"; | |
| 323 | + Query clQuery = executeSimple(session, queryString, null, cl); | |
| 324 | + checkSerialCLMatch(cl, clQuery.getSerialConsistency()); | |
| 325 | + | |
| 326 | + //Check prepared statement CL | |
| 327 | + String prepareString = "preapred_statement_serial_cl"; | |
| 328 | + PreparedStatementExecution pse = executePrepared(session, prepareString, null, cl); | |
| 329 | + checkSerialCLMatch(cl, pse.getSerialConsistency()); | |
| 330 | + | |
| 331 | + //Check batch statement CL | |
| 332 | + String batchStateString = "batch_statement_serial_cl"; | |
| 333 | + BatchExecution batch = executeBatch(session, batchStateString, null, cl); | |
| 334 | + checkSerialCLMatch(cl, batch.getSerialConsistency()); | |
| 335 | + } finally { | |
| 336 | + cluster.close(); | |
| 718 | 337 | } |
| 719 | 338 | } |
| 720 | - | |
| 721 | - private void stopAndWait(int node) { | |
| 722 | - logger.debug("Stopping node " + node); | |
| 723 | - ccm().stop(node); | |
| 724 | - ccm().waitForDown(node);// this uses port ping | |
| 725 | - TestUtils.waitForDown(ipOfNode(node), cluster()); // this uses UP/DOWN events | |
| 726 | - logger.debug("Node " + node + " stopped, sleeping one extra minute to allow nodes to gossip"); | |
| 727 | - Uninterruptibles.sleepUninterruptibly(1, TimeUnit.MINUTES); | |
| 728 | - } | |
| 729 | - | |
| 730 | 339 | } |
modified driver-core/src/test/java/com/datastax/driver/core/HostAssert.java +7 −0
| @@ -123,6 +123,7 @@ | ||
| 123 | 123 | public HostAssert goesDownWithin(long duration, TimeUnit unit) { |
| 124 | 124 | final CountDownLatch downSignal = new CountDownLatch(1); |
| 125 | 125 | StateListener upListener = new StateListenerBase() { |
| 126 | + @Override | |
| 126 | 127 | public void onDown(Host host) { |
| 127 | 128 | downSignal.countDown(); |
| 128 | 129 | } |
| @@ -141,31 +142,37 @@ | ||
| 141 | 142 | return this; |
| 142 | 143 | } |
| 143 | 144 | |
| 145 | + @SuppressWarnings("deprecation") | |
| 144 | 146 | public HostAssert hasWorkload(String workload) { |
| 145 | 147 | assertThat(actual.getDseWorkload()).isNotNull().isEqualTo(workload); |
| 146 | 148 | return this; |
| 147 | 149 | } |
| 148 | 150 | |
| 151 | + @SuppressWarnings("deprecation") | |
| 149 | 152 | public HostAssert hasNoWorkload() { |
| 150 | 153 | assertThat(actual.getDseWorkload()).isNull(); |
| 151 | 154 | return this; |
| 152 | 155 | } |
| 153 | 156 | |
| 157 | + @SuppressWarnings("deprecation") | |
| 154 | 158 | public HostAssert hasDseVersion(VersionNumber versionNumber) { |
| 155 | 159 | assertThat(actual.getDseVersion()).isNotNull().isEqualTo(versionNumber); |
| 156 | 160 | return this; |
| 157 | 161 | } |
| 158 | 162 | |
| 163 | + @SuppressWarnings("deprecation") | |
| 159 | 164 | public HostAssert hasNoDseVersion() { |
| 160 | 165 | assertThat(actual.getDseVersion()).isNull(); |
| 161 | 166 | return this; |
| 162 | 167 | } |
| 163 | 168 | |
| 169 | + @SuppressWarnings("deprecation") | |
| 164 | 170 | public HostAssert hasDseGraph() { |
| 165 | 171 | assertThat(actual.isDseGraphEnabled()).isTrue(); |
| 166 | 172 | return this; |
| 167 | 173 | } |
| 168 | 174 | |
| 175 | + @SuppressWarnings("deprecation") | |
| 169 | 176 | public HostAssert hasNoDseGraph() { |
| 170 | 177 | assertThat(actual.isDseGraphEnabled()).isFalse(); |
| 171 | 178 | return this; |
modified driver-core/src/test/java/com/datastax/driver/core/RequestHandlerTest.java +6 −2
| @@ -20,10 +20,14 @@ | ||
| 20 | 20 | import org.scassandra.http.client.PrimingRequest; |
| 21 | 21 | import org.testng.annotations.Test; |
| 22 | 22 | |
| 23 | +import java.util.Collections; | |
| 24 | +import java.util.List; | |
| 25 | +import java.util.Map; | |
| 23 | 26 | import java.util.concurrent.TimeUnit; |
| 24 | 27 | import java.util.concurrent.TimeoutException; |
| 25 | 28 | |
| 26 | 29 | import static org.assertj.core.api.Assertions.assertThat; |
| 30 | +import static org.scassandra.http.client.PrimingRequest.then; | |
| 27 | 31 | |
| 28 | 32 | public class RequestHandlerTest { |
| 29 | 33 | |
| @@ -35,11 +39,11 @@ | ||
| 35 | 39 | try { |
| 36 | 40 | // Use a mock server that takes a constant time to reply |
| 37 | 41 | scassandra.start(); |
| 42 | + List<Map<String, ?>> rows = Collections.<Map<String, ?>>singletonList(ImmutableMap.of("key", 1)); | |
| 38 | 43 | scassandra.primingClient().prime( |
| 39 | 44 | PrimingRequest.queryBuilder() |
| 40 | 45 | .withQuery("mock query") |
| 41 | - .withRows(ImmutableMap.of("key", 1)) | |
| 42 | - .withFixedDelay(10) | |
| 46 | + .withThen(then().withRows(rows).withFixedDelay(10L)) | |
| 43 | 47 | .build() |
| 44 | 48 | ); |
| 45 | 49 |
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraCluster.java +3 −2
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | |
| 28 | 28 | import java.net.InetAddress; |
| 29 | 29 | import java.net.InetSocketAddress; |
| 30 | +import java.util.Collections; | |
| 30 | 31 | import java.util.List; |
| 31 | 32 | import java.util.Map; |
| 32 | 33 | import java.util.TreeSet; |
| @@ -364,7 +365,7 @@ | ||
| 364 | 365 | .withQuery(query) |
| 365 | 366 | .withThen(then() |
| 366 | 367 | .withColumnTypes(metadata) |
| 367 | - .withRows(row) | |
| 368 | + .withRows(Collections.<Map<String, ?>>singletonList(row)) | |
| 368 | 369 | .build()) |
| 369 | 370 | .build()); |
| 370 | 371 | } |
| @@ -386,7 +387,7 @@ | ||
| 386 | 387 | .withQuery("select cluster_name from system.local") |
| 387 | 388 | .withThen(then() |
| 388 | 389 | .withColumnTypes(SELECT_CLUSTER_NAME) |
| 389 | - .withRows(clusterNameRow) | |
| 390 | + .withRows(Collections.<Map<String, ?>>singletonList(clusterNameRow)) | |
| 390 | 391 | .build()) |
| 391 | 392 | .build()); |
| 392 | 393 |
modified driver-core/src/test/java/com/datastax/driver/core/SpeculativeExecutionTest.java +10 −14
| @@ -35,6 +35,7 @@ | ||
| 35 | 35 | import static com.datastax.driver.core.Assertions.assertThat; |
| 36 | 36 | import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; |
| 37 | 37 | import static org.mockito.Mockito.*; |
| 38 | +import static org.scassandra.http.client.PrimingRequest.then; | |
| 38 | 39 | |
| 39 | 40 | public class SpeculativeExecutionTest { |
| 40 | 41 | ScassandraCluster scassandras; |
| @@ -84,7 +85,7 @@ | ||
| 84 | 85 | public void should_not_start_speculative_execution_if_first_execution_completes_successfully() { |
| 85 | 86 | scassandras.node(1).primingClient().prime(PrimingRequest.queryBuilder() |
| 86 | 87 | .withQuery("mock query") |
| 87 | - .withRows(row("result", "result1")) | |
| 88 | + .withThen(then().withRows(row("result", "result1"))) | |
| 88 | 89 | .build() |
| 89 | 90 | ); |
| 90 | 91 | |
| @@ -104,14 +105,14 @@ | ||
| 104 | 105 | scassandras.node(1).primingClient().prime(PrimingRequest.queryBuilder() |
| 105 | 106 | .withQuery("mock query") |
| 106 | 107 | .withConsistency(Consistency.TWO) |
| 107 | - .withResult(Result.read_request_timeout) | |
| 108 | + .withThen(then().withResult(Result.read_request_timeout)) | |
| 108 | 109 | .build() |
| 109 | 110 | ); |
| 110 | 111 | |
| 111 | 112 | scassandras.node(1).primingClient().prime(PrimingRequest.queryBuilder() |
| 112 | 113 | .withQuery("mock query") |
| 113 | 114 | .withConsistency(Consistency.ONE) |
| 114 | - .withRows(row("result", "result1")) | |
| 115 | + .withThen(then().withRows(row("result", "result1"))) | |
| 115 | 116 | .build() |
| 116 | 117 | ); |
| 117 | 118 | |
| @@ -134,14 +135,13 @@ | ||
| 134 | 135 | public void should_start_speculative_execution_if_first_execution_takes_too_long() { |
| 135 | 136 | scassandras.node(1).primingClient().prime(PrimingRequest.queryBuilder() |
| 136 | 137 | .withQuery("mock query") |
| 137 | - .withFixedDelay(400) | |
| 138 | - .withRows(row("result", "result1")) | |
| 138 | + .withThen(then().withRows(row("result", "result1")).withFixedDelay(400L)) | |
| 139 | 139 | .build() |
| 140 | 140 | ); |
| 141 | 141 | |
| 142 | 142 | scassandras.node(2).primingClient().prime(PrimingRequest.queryBuilder() |
| 143 | 143 | .withQuery("mock query") |
| 144 | - .withRows(row("result", "result2")) | |
| 144 | + .withThen(then().withRows(row("result", "result2"))) | |
| 145 | 145 | .build() |
| 146 | 146 | ); |
| 147 | 147 | long execStartCount = errors.getSpeculativeExecutions().getCount(); |
| @@ -163,15 +163,13 @@ | ||
| 163 | 163 | // execution1 starts with host1, which will time out at t=1000 |
| 164 | 164 | .prime(PrimingRequest.queryBuilder() |
| 165 | 165 | .withQuery("mock query") |
| 166 | - .withFixedDelay(2000) | |
| 167 | - .withRows(row("result", "result1")) | |
| 166 | + .withThen(then().withRows(row("result", "result1")).withFixedDelay(2000L)) | |
| 168 | 167 | .build()); |
| 169 | 168 | // at t=1000, execution1 moves to host3, which eventually succeeds at t=1500 |
| 170 | 169 | scassandras.node(3).primingClient() |
| 171 | 170 | .prime(PrimingRequest.queryBuilder() |
| 172 | 171 | .withQuery("mock query") |
| 173 | - .withFixedDelay(500) | |
| 174 | - .withRows(row("result", "result3")) | |
| 172 | + .withThen(then().withRows(row("result", "result3")).withFixedDelay(500L)) | |
| 175 | 173 | .build()); |
| 176 | 174 | // meanwhile, execution2 starts at t=200, using host2 which times out at t=1200 |
| 177 | 175 | // at that time, the query plan is empty so execution2 fails |
| @@ -179,8 +177,7 @@ | ||
| 179 | 177 | scassandras.node(2).primingClient() |
| 180 | 178 | .prime(PrimingRequest.queryBuilder() |
| 181 | 179 | .withQuery("mock query") |
| 182 | - .withFixedDelay(2000) | |
| 183 | - .withRows(row("result", "result2")) | |
| 180 | + .withThen(then().withRows(row("result", "result2")).withFixedDelay(2000L)) | |
| 184 | 181 | .build()); |
| 185 | 182 | long execStartCount = errors.getSpeculativeExecutions().getCount(); |
| 186 | 183 | |
| @@ -247,8 +244,7 @@ | ||
| 247 | 244 | // execution1 starts with host1, which will time out at t=1000 |
| 248 | 245 | .prime(PrimingRequest.queryBuilder() |
| 249 | 246 | .withQuery("mock query") |
| 250 | - .withFixedDelay(2000) | |
| 251 | - .withRows(row("result", "result1")) | |
| 247 | + .withThen(then().withRows(row("result", "result1")).withFixedDelay(2000L)) | |
| 252 | 248 | .build()); |
| 253 | 249 | |
| 254 | 250 | Session session = cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +3 −3
| @@ -129,13 +129,13 @@ | ||
| 129 | 129 | data.setUUID(i, (UUID) value); |
| 130 | 130 | break; |
| 131 | 131 | case LIST: |
| 132 | - data.setList(i, (List) value); | |
| 132 | + data.setList(i, (List<?>) value); | |
| 133 | 133 | break; |
| 134 | 134 | case SET: |
| 135 | - data.setSet(i, (Set) value); | |
| 135 | + data.setSet(i, (Set<?>) value); | |
| 136 | 136 | break; |
| 137 | 137 | case MAP: |
| 138 | - data.setMap(i, (Map) value); | |
| 138 | + data.setMap(i, (Map<?, ?>) value); | |
| 139 | 139 | break; |
| 140 | 140 | default: |
| 141 | 141 | throw new RuntimeException("Missing handling of " + type); |
modified driver-core/src/test/java/com/datastax/driver/core/exceptions/ExceptionsScassandraTest.java +2 −1
| @@ -30,6 +30,7 @@ | ||
| 30 | 30 | import static com.datastax.driver.core.ConsistencyLevel.LOCAL_ONE; |
| 31 | 31 | import static org.assertj.core.api.Assertions.assertThat; |
| 32 | 32 | import static org.assertj.core.api.Assertions.fail; |
| 33 | +import static org.scassandra.http.client.PrimingRequest.then; | |
| 33 | 34 | import static org.scassandra.http.client.Result.*; |
| 34 | 35 | |
| 35 | 36 | public class ExceptionsScassandraTest { |
| @@ -115,7 +116,7 @@ | ||
| 115 | 116 | protected void simulateError(int hostNumber, Result result) { |
| 116 | 117 | scassandras.node(hostNumber).primingClient().prime(PrimingRequest.queryBuilder() |
| 117 | 118 | .withQuery("mock query") |
| 118 | - .withResult(result) | |
| 119 | + .withThen(then().withResult(result)) | |
| 119 | 120 | .build()); |
| 120 | 121 | } |
| 121 | 122 |
modified driver-core/src/test/java/com/datastax/driver/core/policies/AbstractRetryPolicyIntegrationTest.java +7 −5
| @@ -39,6 +39,7 @@ | ||
| 39 | 39 | import static org.assertj.core.api.Assertions.assertThat; |
| 40 | 40 | import static org.mockito.Matchers.*; |
| 41 | 41 | import static org.mockito.Mockito.times; |
| 42 | +import static org.scassandra.http.client.PrimingRequest.then; | |
| 42 | 43 | import static org.scassandra.http.client.Result.overloaded; |
| 43 | 44 | import static org.scassandra.http.client.Result.server_error; |
| 44 | 45 | |
| @@ -111,12 +112,13 @@ | ||
| 111 | 112 | } |
| 112 | 113 | |
| 113 | 114 | protected void simulateError(int hostNumber, Result result, Config config) { |
| 114 | - PrimingRequestBuilder builder = PrimingRequest.queryBuilder() | |
| 115 | - .withQuery("mock query") | |
| 116 | - .withResult(result); | |
| 115 | + PrimingRequest.Then.ThenBuilder then = then().withResult(result); | |
| 116 | + PrimingRequestBuilder builder = PrimingRequest.queryBuilder().withQuery("mock query"); | |
| 117 | 117 | |
| 118 | 118 | if (config != null) |
| 119 | - builder = builder.withConfig(config); | |
| 119 | + then = then.withConfig(config); | |
| 120 | + | |
| 121 | + builder = builder.withThen(then); | |
| 120 | 122 | |
| 121 | 123 | scassandras.node(hostNumber).primingClient().prime(builder.build()); |
| 122 | 124 | } |
| @@ -124,7 +126,7 @@ | ||
| 124 | 126 | protected void simulateNormalResponse(int hostNumber) { |
| 125 | 127 | scassandras.node(hostNumber).primingClient().prime(PrimingRequest.queryBuilder() |
| 126 | 128 | .withQuery("mock query") |
| 127 | - .withRows(row("result", "result1")) | |
| 129 | + .withThen(then().withRows(row("result", "result1"))) | |
| 128 | 130 | .build()); |
| 129 | 131 | } |
| 130 | 132 |
modified driver-core/src/test/java/com/datastax/driver/core/policies/LatencyAwarePolicyTest.java +3 −2
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | import static org.assertj.core.api.Assertions.assertThat; |
| 28 | 28 | import static org.assertj.core.api.Assertions.fail; |
| 29 | 29 | import static org.scassandra.http.client.PrimingRequest.queryBuilder; |
| 30 | +import static org.scassandra.http.client.PrimingRequest.then; | |
| 30 | 31 | import static org.scassandra.http.client.Result.read_request_timeout; |
| 31 | 32 | import static org.scassandra.http.client.Result.unavailable; |
| 32 | 33 | |
| @@ -106,7 +107,7 @@ | ||
| 106 | 107 | primingClient.prime( |
| 107 | 108 | queryBuilder() |
| 108 | 109 | .withQuery(query) |
| 109 | - .withResult(unavailable) | |
| 110 | + .withThen(then().withResult(unavailable)) | |
| 110 | 111 | .build() |
| 111 | 112 | ); |
| 112 | 113 | LatencyAwarePolicy latencyAwarePolicy = LatencyAwarePolicy.builder(new RoundRobinPolicy()) |
| @@ -150,7 +151,7 @@ | ||
| 150 | 151 | primingClient.prime( |
| 151 | 152 | queryBuilder() |
| 152 | 153 | .withQuery(query) |
| 153 | - .withResult(read_request_timeout) | |
| 154 | + .withThen(then().withResult(read_request_timeout)) | |
| 154 | 155 | .build() |
| 155 | 156 | ); |
| 156 | 157 |
modified driver-dist/pom.xml +12 −39
| @@ -70,51 +70,13 @@ | ||
| 70 | 70 | </goals> |
| 71 | 71 | <configuration> |
| 72 | 72 | <includeDependencySources>true</includeDependencySources> |
| 73 | - <!-- optional dependencies from other modules (must be explicitly declared here in order to be correctly resolved) --> | |
| 74 | - <additionalDependencies> | |
| 75 | - <additionalDependency> | |
| 76 | - <groupId>org.xerial.snappy</groupId> | |
| 77 | - <artifactId>snappy-java</artifactId> | |
| 78 | - <version>${snappy.version}</version> | |
| 79 | - </additionalDependency> | |
| 80 | - <additionalDependency> | |
| 81 | - <groupId>net.jpountz.lz4</groupId> | |
| 82 | - <artifactId>lz4</artifactId> | |
| 83 | - <version>${lz4.version}</version> | |
| 84 | - </additionalDependency> | |
| 85 | - <additionalDependency> | |
| 86 | - <groupId>org.hdrhistogram</groupId> | |
| 87 | - <artifactId>HdrHistogram</artifactId> | |
| 88 | - <version>${hdr.version}</version> | |
| 89 | - </additionalDependency> | |
| 90 | - <additionalDependency> | |
| 91 | - <groupId>com.fasterxml.jackson.core</groupId> | |
| 92 | - <artifactId>jackson-core</artifactId> | |
| 93 | - <version>${jackson.version}</version> | |
| 94 | - </additionalDependency> | |
| 95 | - <additionalDependency> | |
| 96 | - <groupId>com.fasterxml.jackson.core</groupId> | |
| 97 | - <artifactId>jackson-databind</artifactId> | |
| 98 | - <version>${jackson.version}</version> | |
| 99 | - </additionalDependency> | |
| 100 | - <additionalDependency> | |
| 101 | - <groupId>joda-time</groupId> | |
| 102 | - <artifactId>joda-time</artifactId> | |
| 103 | - <version>${joda.version}</version> | |
| 104 | - </additionalDependency> | |
| 105 | - <additionalDependency> | |
| 106 | - <groupId>javax.json</groupId> | |
| 107 | - <artifactId>javax.json-api</artifactId> | |
| 108 | - <version>${jsr353-api.version}</version> | |
| 109 | - </additionalDependency> | |
| 110 | - </additionalDependencies> | |
| 111 | 73 | </configuration> |
| 112 | 74 | </execution> |
| 113 | 75 | </executions> |
| 114 | 76 | </plugin> |
| 115 | 77 | <plugin> |
| 116 | 78 | <artifactId>maven-assembly-plugin</artifactId> |
| 117 | - <version>2.6</version> | |
| 79 | + <version>3.0.0</version> | |
| 118 | 80 | <executions> |
| 119 | 81 | <execution> |
| 120 | 82 | <id>assemble-binary-tarball</id> |
| @@ -132,6 +94,17 @@ | ||
| 132 | 94 | <tarLongFileMode>posix</tarLongFileMode> |
| 133 | 95 | </configuration> |
| 134 | 96 | </plugin> |
| 97 | + <plugin> | |
| 98 | + <artifactId>maven-jar-plugin</artifactId> | |
| 99 | + <version>3.0.2</version> | |
| 100 | + <!-- http://stackoverflow.com/questions/13218313/unable-to-disable-generation-of-empty-jar-maven-jar-plugin --> | |
| 101 | + <executions> | |
| 102 | + <execution> | |
| 103 | + <id>default-jar</id> | |
| 104 | + <phase>none</phase> | |
| 105 | + </execution> | |
| 106 | + </executions> | |
| 107 | + </plugin> | |
| 135 | 108 | <plugin> |
| 136 | 109 | <groupId>org.apache.maven.plugins</groupId> |
| 137 | 110 | <artifactId>maven-install-plugin</artifactId> |
modified driver-dist/src/assembly/binary-tarball.xml +85 −5
| @@ -23,13 +23,14 @@ | ||
| 23 | 23 | <format>tar.gz</format> |
| 24 | 24 | </formats> |
| 25 | 25 | <includeBaseDirectory>true</includeBaseDirectory> |
| 26 | + | |
| 26 | 27 | <moduleSets> |
| 28 | + | |
| 29 | + <!-- dependencies of module cassandra-driver-core --> | |
| 27 | 30 | <moduleSet> |
| 28 | 31 | <useAllReactorProjects>true</useAllReactorProjects> |
| 29 | 32 | <includes> |
| 30 | 33 | <include>com.datastax.cassandra:cassandra-driver-core</include> |
| 31 | - <include>com.datastax.cassandra:cassandra-driver-mapping</include> | |
| 32 | - <include>com.datastax.cassandra:cassandra-driver-extras</include> | |
| 33 | 34 | </includes> |
| 34 | 35 | <binaries> |
| 35 | 36 | <unpack>false</unpack> |
| @@ -37,19 +38,75 @@ | ||
| 37 | 38 | <dependencySet> |
| 38 | 39 | <outputDirectory>lib</outputDirectory> |
| 39 | 40 | <excludes> |
| 40 | - <exclude>com.datastax.cassandra:*</exclude> | |
| 41 | + <!-- reactor projects --> | |
| 42 | + <exclude>com.datastax.cassandra:cassandra-driver-core</exclude> | |
| 43 | + <exclude>com.datastax.cassandra:cassandra-driver-mapping</exclude> | |
| 44 | + <exclude>com.datastax.cassandra:cassandra-driver-extras</exclude> | |
| 45 | + <!-- platform-dependent --> | |
| 41 | 46 | <exclude>io.netty:netty-transport-native-epoll:*</exclude> |
| 42 | 47 | </excludes> |
| 48 | + <useTransitiveFiltering>true</useTransitiveFiltering> | |
| 49 | + </dependencySet> | |
| 50 | + </dependencySets> | |
| 51 | + </binaries> | |
| 52 | + </moduleSet> | |
| 53 | + | |
| 54 | + <!-- dependencies of module cassandra-driver-mapping --> | |
| 55 | + <moduleSet> | |
| 56 | + <useAllReactorProjects>true</useAllReactorProjects> | |
| 57 | + <includes> | |
| 58 | + <include>com.datastax.cassandra:cassandra-driver-mapping</include> | |
| 59 | + </includes> | |
| 60 | + <binaries> | |
| 61 | + <unpack>false</unpack> | |
| 62 | + <dependencySets> | |
| 63 | + <dependencySet> | |
| 64 | + <outputDirectory>lib/mapping</outputDirectory> | |
| 65 | + <excludes> | |
| 66 | + <!-- reactor projects --> | |
| 67 | + <exclude>com.datastax.cassandra:cassandra-driver-core</exclude> | |
| 68 | + <exclude>com.datastax.cassandra:cassandra-driver-mapping</exclude> | |
| 69 | + <exclude>com.datastax.cassandra:cassandra-driver-extras</exclude> | |
| 70 | + </excludes> | |
| 71 | + <useTransitiveFiltering>true</useTransitiveFiltering> | |
| 72 | + </dependencySet> | |
| 73 | + </dependencySets> | |
| 74 | + </binaries> | |
| 75 | + </moduleSet> | |
| 76 | + | |
| 77 | + <!-- dependencies of module cassandra:cassandra-driver-extras --> | |
| 78 | + <moduleSet> | |
| 79 | + <useAllReactorProjects>true</useAllReactorProjects> | |
| 80 | + <includes> | |
| 81 | + <include>com.datastax.cassandra:cassandra-driver-extras</include> | |
| 82 | + </includes> | |
| 83 | + <binaries> | |
| 84 | + <unpack>false</unpack> | |
| 85 | + <dependencySets> | |
| 86 | + <dependencySet> | |
| 87 | + <outputDirectory>lib/extras</outputDirectory> | |
| 88 | + <excludes> | |
| 89 | + <!-- reactor projects --> | |
| 90 | + <exclude>com.datastax.cassandra:cassandra-driver-core</exclude> | |
| 91 | + <exclude>com.datastax.cassandra:cassandra-driver-mapping</exclude> | |
| 92 | + <exclude>com.datastax.cassandra:cassandra-driver-extras</exclude> | |
| 93 | + <!-- already included in lib/core --> | |
| 94 | + <exclude>com.google.guava:guava</exclude> | |
| 95 | + </excludes> | |
| 96 | + <useTransitiveFiltering>true</useTransitiveFiltering> | |
| 43 | 97 | </dependencySet> |
| 44 | 98 | </dependencySets> |
| 45 | 99 | </binaries> |
| 46 | 100 | </moduleSet> |
| 101 | + | |
| 102 | + <!-- sources for all modules --> | |
| 47 | 103 | <moduleSet> |
| 48 | 104 | <useAllReactorProjects>true</useAllReactorProjects> |
| 49 | 105 | <includes> |
| 50 | 106 | <include>com.datastax.cassandra:cassandra-driver-core</include> |
| 51 | 107 | <include>com.datastax.cassandra:cassandra-driver-mapping</include> |
| 52 | 108 | <include>com.datastax.cassandra:cassandra-driver-extras</include> |
| 109 | + <include>com.datastax.cassandra:cassandra-driver-examples</include> | |
| 53 | 110 | </includes> |
| 54 | 111 | <binaries> |
| 55 | 112 | <unpack>false</unpack> |
| @@ -61,18 +118,41 @@ | ||
| 61 | 118 | </excludes> |
| 62 | 119 | </binaries> |
| 63 | 120 | </moduleSet> |
| 121 | + | |
| 64 | 122 | </moduleSets> |
| 123 | + | |
| 65 | 124 | <fileSets> |
| 125 | + | |
| 66 | 126 | <fileSet> |
| 67 | 127 | <directory>target/apidocs</directory> |
| 68 | 128 | <outputDirectory>apidocs</outputDirectory> |
| 69 | 129 | </fileSet> |
| 130 | + | |
| 70 | 131 | <fileSet> |
| 71 | 132 | <directory>..</directory> |
| 133 | + <outputDirectory>.</outputDirectory> | |
| 72 | 134 | <includes> |
| 73 | - <include>changelog/README.md</include> | |
| 74 | - <include>upgrade_guide/README.md</include> | |
| 135 | + <include>README*</include> | |
| 136 | + <include>LICENSE*</include> | |
| 75 | 137 | </includes> |
| 76 | 138 | </fileSet> |
| 139 | + | |
| 140 | + <fileSet> | |
| 141 | + <directory>../changelog</directory> | |
| 142 | + </fileSet> | |
| 143 | + | |
| 144 | + <fileSet> | |
| 145 | + <directory>../faq</directory> | |
| 146 | + </fileSet> | |
| 147 | + | |
| 148 | + <fileSet> | |
| 149 | + <directory>../manual</directory> | |
| 150 | + </fileSet> | |
| 151 | + | |
| 152 | + <fileSet> | |
| 153 | + <directory>../upgrade_guide</directory> | |
| 154 | + </fileSet> | |
| 155 | + | |
| 77 | 156 | </fileSets> |
| 157 | + | |
| 78 | 158 | </assembly> |
modified driver-examples/pom.xml +9 −0
| @@ -152,6 +152,15 @@ | ||
| 152 | 152 | </configuration> |
| 153 | 153 | </plugin> |
| 154 | 154 | |
| 155 | + <plugin> | |
| 156 | + <groupId>org.codehaus.mojo</groupId> | |
| 157 | + <artifactId>clirr-maven-plugin</artifactId> | |
| 158 | + <version>2.7</version> | |
| 159 | + <configuration> | |
| 160 | + <skip>true</skip> | |
| 161 | + </configuration> | |
| 162 | + </plugin> | |
| 163 | + | |
| 155 | 164 | <plugin> |
| 156 | 165 | <groupId>org.apache.maven.plugins</groupId> |
| 157 | 166 | <artifactId>maven-install-plugin</artifactId> |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/AnnotationChecks.java +0 −2
| @@ -49,9 +49,7 @@ | ||
| 49 | 49 | return instance; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - @SuppressWarnings("unchecked") | |
| 53 | 52 | private static void validateAnnotations(Class<?> clazz, Class<? extends Annotation> allowed) { |
| 54 | - @SuppressWarnings("unchecked") | |
| 55 | 53 | Collection<Annotation> classAnnotations = new HashSet<Annotation>(); |
| 56 | 54 | Collections.addAll(classAnnotations, clazz.getAnnotations()); |
| 57 | 55 | Class<? extends Annotation> invalid = validateAnnotations(classAnnotations, Collections.singleton(allowed)); |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/AnnotationParser.java +1 −1
| @@ -36,12 +36,12 @@ | ||
| 36 | 36 | * - {@link #parseUDT(Class, MappingManager)}: UDT classes into {@link MappedUDTCodec} instances. |
| 37 | 37 | * - {@link #parseAccessor(Class, MappingManager)}: Accessor interfaces into {@link AccessorMapper} instances. |
| 38 | 38 | */ |
| 39 | -@SuppressWarnings({"unchecked", "WeakerAccess"}) | |
| 40 | 39 | class AnnotationParser { |
| 41 | 40 | |
| 42 | 41 | /** |
| 43 | 42 | * Annotations allowed on a property that maps to a table column. |
| 44 | 43 | */ |
| 44 | + @SuppressWarnings("unchecked") | |
| 45 | 45 | private static final Set<Class<? extends Annotation>> VALID_COLUMN_ANNOTATIONS = ImmutableSet.of( |
| 46 | 46 | Column.class, |
| 47 | 47 | Computed.class, |
modified driver-tests/osgi/pom.xml +14 −15
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | </parent> |
| 25 | 25 | |
| 26 | 26 | <artifactId>cassandra-driver-tests-osgi</artifactId> |
| 27 | - <packaging>bundle</packaging> | |
| 27 | + <packaging>jar</packaging> | |
| 28 | 28 | <name>DataStax Java Driver for Apache Cassandra Tests - OSGi</name> |
| 29 | 29 | <description>A test for the DataStax Java Driver in an OSGi container.</description> |
| 30 | 30 | <url>https://github.com/datastax/java-driver</url> |
| @@ -36,6 +36,7 @@ | ||
| 36 | 36 | <pax-exam.version>3.6.0</pax-exam.version> |
| 37 | 37 | <url.version>2.4.0</url.version> |
| 38 | 38 | <logback.version>1.1.3</logback.version> |
| 39 | + <slf4j.version>1.7.5</slf4j.version> | |
| 39 | 40 | <test.groups>none</test.groups> |
| 40 | 41 | <!-- |
| 41 | 42 | Skip tests by default, short or long profile is required to run tests in this module |
| @@ -75,7 +76,7 @@ | ||
| 75 | 76 | <dependency> |
| 76 | 77 | <groupId>org.slf4j</groupId> |
| 77 | 78 | <artifactId>slf4j-api</artifactId> |
| 78 | - <version>1.7.5</version> | |
| 79 | + <version>${slf4j.version}</version> | |
| 79 | 80 | </dependency> |
| 80 | 81 | |
| 81 | 82 | <dependency> |
| @@ -128,13 +129,6 @@ | ||
| 128 | 129 | <scope>test</scope> |
| 129 | 130 | </dependency> |
| 130 | 131 | |
| 131 | - <dependency> | |
| 132 | - <groupId>com.jcabi</groupId> | |
| 133 | - <artifactId>jcabi-manifests</artifactId> | |
| 134 | - <version>1.1</version> | |
| 135 | - <scope>test</scope> | |
| 136 | - </dependency> | |
| 137 | - | |
| 138 | 132 | <dependency> |
| 139 | 133 | <groupId>javax.servlet</groupId> |
| 140 | 134 | <artifactId>javax.servlet-api</artifactId> |
| @@ -203,6 +197,16 @@ | ||
| 203 | 197 | <groups>${test.groups}</groups> |
| 204 | 198 | <systemPropertyVariables> |
| 205 | 199 | <cassandra.version>${cassandra.version}</cassandra.version> |
| 200 | + <!-- pull in declared version properties, this ensures we test with the same versions used by the driver --> | |
| 201 | + <guava.version>${guava.version}</guava.version> | |
| 202 | + <lz4.version>${lz4.version}</lz4.version> | |
| 203 | + <snappy.version>${snappy.version}</snappy.version> | |
| 204 | + <hdr.version>${hdr.version}</hdr.version> | |
| 205 | + <netty.version>${netty.version}</netty.version> | |
| 206 | + <slf4j.version>${slf4j.version}</slf4j.version> | |
| 207 | + <logback.version>${logback.version}</logback.version> | |
| 208 | + <metrics.version>${metrics.version}</metrics.version> | |
| 209 | + <testng.version>${testng.version}</testng.version> | |
| 206 | 210 | <ipprefix>${ipprefix}</ipprefix> |
| 207 | 211 | </systemPropertyVariables> |
| 208 | 212 | </configuration> |
| @@ -229,13 +233,8 @@ | ||
| 229 | 233 | <Export-Package>com.datastax.driver.osgi.api,!com.datastax.driver.osgi.impl</Export-Package> |
| 230 | 234 | <Bundle-Activator>com.datastax.driver.osgi.impl.Activator</Bundle-Activator> |
| 231 | 235 | <_include>-osgi.bnd</_include> |
| 232 | - <Import-Package><![CDATA[com.google.common*;version="[16.0.1,20)",*]]></Import-Package> | |
| 236 | + <Import-Package><![CDATA[com.google.common.*;version="[16.0.1,20)",*]]></Import-Package> | |
| 233 | 237 | </instructions> |
| 234 | - <supportedProjectTypes> | |
| 235 | - <supportedProjectType>jar</supportedProjectType> | |
| 236 | - <supportedProjectType>bundle</supportedProjectType> | |
| 237 | - <supportedProjectType>pom</supportedProjectType> | |
| 238 | - </supportedProjectTypes> | |
| 239 | 238 | </configuration> |
| 240 | 239 | <executions> |
| 241 | 240 | <execution> |
modified driver-tests/osgi/src/test/java/com/datastax/driver/osgi/BundleOptions.java +22 −14
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | package com.datastax.driver.osgi; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.CCMBridge; |
| 19 | +import com.datastax.driver.core.Cluster; | |
| 19 | 20 | import com.datastax.driver.core.ProtocolOptions; |
| 20 | 21 | import com.datastax.driver.core.TestUtils; |
| 21 | 22 | import com.google.common.collect.Lists; |
| @@ -27,7 +28,6 @@ | ||
| 27 | 28 | |
| 28 | 29 | import java.util.List; |
| 29 | 30 | |
| 30 | -import static com.datastax.driver.osgi.VersionProvider.projectVersion; | |
| 31 | 31 | import static org.ops4j.pax.exam.CoreOptions.*; |
| 32 | 32 | |
| 33 | 33 | public class BundleOptions { |
| @@ -38,19 +38,19 @@ | ||
| 38 | 38 | |
| 39 | 39 | public static UrlProvisionOption driverBundle(boolean useShaded) { |
| 40 | 40 | String classifier = useShaded ? "-shaded" : ""; |
| 41 | - return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-core/target/cassandra-driver-core-" + projectVersion() + classifier + ".jar"); | |
| 41 | + return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-core/target/cassandra-driver-core-" + Cluster.getDriverVersion() + classifier + ".jar"); | |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | public static UrlProvisionOption mappingBundle() { |
| 45 | - return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-mapping/target/cassandra-driver-mapping-" + projectVersion() + ".jar"); | |
| 45 | + return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-mapping/target/cassandra-driver-mapping-" + Cluster.getDriverVersion() + ".jar"); | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | public static UrlProvisionOption extrasBundle() { |
| 49 | - return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-extras/target/cassandra-driver-extras-" + projectVersion() + ".jar"); | |
| 49 | + return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-extras/target/cassandra-driver-extras-" + Cluster.getDriverVersion() + ".jar"); | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | public static MavenArtifactProvisionOption guavaBundle() { |
| 53 | - return mavenBundle("com.google.guava", "guava", "16.0.1"); | |
| 53 | + return mavenBundle("com.google.guava", "guava", getVersion("guava.version")); | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | public static CompositeOption lz4Bundle() { |
| @@ -60,7 +60,7 @@ | ||
| 60 | 60 | public Option[] getOptions() { |
| 61 | 61 | return options( |
| 62 | 62 | systemProperty("cassandra.compression").value(ProtocolOptions.Compression.LZ4.name()), |
| 63 | - mavenBundle("net.jpountz.lz4", "lz4", "1.3.0") | |
| 63 | + mavenBundle("net.jpountz.lz4", "lz4", getVersion("lz4.version")) | |
| 64 | 64 | ); |
| 65 | 65 | } |
| 66 | 66 | }; |
| @@ -73,7 +73,7 @@ | ||
| 73 | 73 | public Option[] getOptions() { |
| 74 | 74 | return options( |
| 75 | 75 | systemProperty("cassandra.compression").value(ProtocolOptions.Compression.SNAPPY.name()), |
| 76 | - mavenBundle("org.xerial.snappy", "snappy-java", "1.1.2.6") | |
| 76 | + mavenBundle("org.xerial.snappy", "snappy-java", getVersion("snappy.version")) | |
| 77 | 77 | ); |
| 78 | 78 | } |
| 79 | 79 | }; |
| @@ -86,14 +86,14 @@ | ||
| 86 | 86 | public Option[] getOptions() { |
| 87 | 87 | return options( |
| 88 | 88 | systemProperty("cassandra.usePercentileSpeculativeExecutionPolicy").value("true"), |
| 89 | - mavenBundle("org.hdrhistogram", "HdrHistogram", "2.1.9") | |
| 89 | + mavenBundle("org.hdrhistogram", "HdrHistogram", getVersion("hdr.version")) | |
| 90 | 90 | ); |
| 91 | 91 | } |
| 92 | 92 | }; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | public static CompositeOption nettyBundles() { |
| 96 | - final String nettyVersion = "4.0.33.Final"; | |
| 96 | + final String nettyVersion = getVersion("netty.version"); | |
| 97 | 97 | return new CompositeOption() { |
| 98 | 98 | |
| 99 | 99 | @Override |
| @@ -125,11 +125,11 @@ | ||
| 125 | 125 | systemProperty("cassandra.version").value(CCMBridge.getGlobalCassandraVersion().toString()), |
| 126 | 126 | systemProperty("cassandra.contactpoints").value(TestUtils.IP_PREFIX + 1), |
| 127 | 127 | systemProperty("logback.configurationFile").value("file:" + PathUtils.getBaseDir() + "/src/test/resources/logback.xml"), |
| 128 | - mavenBundle("org.slf4j", "slf4j-api", "1.7.5"), | |
| 129 | - mavenBundle("ch.qos.logback", "logback-classic", "1.1.3"), | |
| 130 | - mavenBundle("ch.qos.logback", "logback-core", "1.1.3"), | |
| 131 | - mavenBundle("io.dropwizard.metrics", "metrics-core", "3.1.2"), | |
| 132 | - mavenBundle("org.testng", "testng", "6.8.8"), | |
| 128 | + mavenBundle("org.slf4j", "slf4j-api", getVersion("slf4j.version")), | |
| 129 | + mavenBundle("ch.qos.logback", "logback-classic", getVersion("logback.version")), | |
| 130 | + mavenBundle("ch.qos.logback", "logback-core", getVersion("logback.version")), | |
| 131 | + mavenBundle("io.dropwizard.metrics", "metrics-core", getVersion("metrics.version")), | |
| 132 | + mavenBundle("org.testng", "testng", getVersion("testng.version")), | |
| 133 | 133 | systemPackages("org.testng", "org.junit", "org.junit.runner", "org.junit.runner.manipulation", |
| 134 | 134 | "org.junit.runner.notification", "com.jcabi.manifests") |
| 135 | 135 | ); |
| @@ -145,4 +145,12 @@ | ||
| 145 | 145 | } |
| 146 | 146 | }; |
| 147 | 147 | } |
| 148 | + | |
| 149 | + private static String getVersion(String propertyName) { | |
| 150 | + String value = System.getProperty(propertyName); | |
| 151 | + if (value == null) { | |
| 152 | + throw new IllegalArgumentException(propertyName + " system property is not set."); | |
| 153 | + } | |
| 154 | + return value; | |
| 155 | + } | |
| 148 | 156 | } |
deleted driver-tests/osgi/src/test/java/com/datastax/driver/osgi/VersionProvider.java +0 −59
| @@ -1,59 +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.osgi; | |
| 17 | - | |
| 18 | -import com.jcabi.manifests.Manifests; | |
| 19 | - | |
| 20 | -import java.util.regex.Matcher; | |
| 21 | -import java.util.regex.Pattern; | |
| 22 | - | |
| 23 | -/** | |
| 24 | - * Attempts to resolve the project version from the Bundle manifest. If not present, will throw RuntimeException | |
| 25 | - * on initialization. If this happens, try building with 'mvn compile' to generate the Bundle manifest. | |
| 26 | - * <p/> | |
| 27 | - * In IntelliJ you can have compile run after make by right clicking on 'compile' in the 'Maven Projects' tool window. | |
| 28 | - */ | |
| 29 | -public class VersionProvider { | |
| 30 | - | |
| 31 | - private static final Pattern versionPattern = Pattern.compile(("(\\d+.\\d+\\.\\d+)(.*)")); | |
| 32 | - | |
| 33 | - private static final String PROJECT_VERSION; | |
| 34 | - | |
| 35 | - static { | |
| 36 | - String bundleName = Manifests.read("Bundle-SymbolicName"); | |
| 37 | - if (bundleName.equals("com.datastax.driver.osgi")) { | |
| 38 | - String bundleVersion = Manifests.read("Bundle-Version"); | |
| 39 | - Matcher matcher = versionPattern.matcher(bundleVersion); | |
| 40 | - if (matcher.matches()) { | |
| 41 | - String majorVersion = matcher.group(1); | |
| 42 | - // Replace all instances of '.' after the main version with '-' to properly | |
| 43 | - // resolve the correct version. | |
| 44 | - String rest = matcher.group(2).replaceAll("\\.", "-"); | |
| 45 | - PROJECT_VERSION = majorVersion + rest; | |
| 46 | - } else { | |
| 47 | - // This should never happen, but if we are using a non X.Y.Z version number | |
| 48 | - // we'll just back off to the bundle version. | |
| 49 | - PROJECT_VERSION = bundleVersion; | |
| 50 | - } | |
| 51 | - } else { | |
| 52 | - throw new RuntimeException("Couldn't resolve bundle manifest (try building with mvn compile)"); | |
| 53 | - } | |
| 54 | - } | |
| 55 | - | |
| 56 | - public static String projectVersion() { | |
| 57 | - return PROJECT_VERSION; | |
| 58 | - } | |
| 59 | -} |
modified driver-tests/pom.xml +15 −0
| @@ -61,7 +61,18 @@ | ||
| 61 | 61 | </developers> |
| 62 | 62 | |
| 63 | 63 | <build> |
| 64 | + | |
| 64 | 65 | <plugins> |
| 66 | + | |
| 67 | + <plugin> | |
| 68 | + <groupId>org.codehaus.mojo</groupId> | |
| 69 | + <artifactId>clirr-maven-plugin</artifactId> | |
| 70 | + <version>2.7</version> | |
| 71 | + <configuration> | |
| 72 | + <skip>true</skip> | |
| 73 | + </configuration> | |
| 74 | + </plugin> | |
| 75 | + | |
| 65 | 76 | <plugin> |
| 66 | 77 | <groupId>org.apache.maven.plugins</groupId> |
| 67 | 78 | <artifactId>maven-install-plugin</artifactId> |
| @@ -70,6 +81,7 @@ | ||
| 70 | 81 | <skip>true</skip> |
| 71 | 82 | </configuration> |
| 72 | 83 | </plugin> |
| 84 | + | |
| 73 | 85 | <plugin> |
| 74 | 86 | <groupId>org.apache.maven.plugins</groupId> |
| 75 | 87 | <artifactId>maven-deploy-plugin</artifactId> |
| @@ -78,6 +90,9 @@ | ||
| 78 | 90 | <skip>true</skip> |
| 79 | 91 | </configuration> |
| 80 | 92 | </plugin> |
| 93 | + | |
| 81 | 94 | </plugins> |
| 95 | + | |
| 82 | 96 | </build> |
| 97 | + | |
| 83 | 98 | </project> |
modified pom.xml +45 −1
| @@ -68,7 +68,7 @@ | ||
| 68 | 68 | <assertj.version>1.7.0</assertj.version> |
| 69 | 69 | <mockito.version>1.10.8</mockito.version> |
| 70 | 70 | <commons-exec.version>1.3</commons-exec.version> |
| 71 | - <scassandra.version>1.1.1</scassandra.version> | |
| 71 | + <scassandra.version>1.1.2</scassandra.version> | |
| 72 | 72 | <main.basedir>${project.basedir}</main.basedir> |
| 73 | 73 | <ipprefix>127.0.1.</ipprefix> |
| 74 | 74 | <test.groups>unit</test.groups> |
| @@ -228,6 +228,7 @@ | ||
| 228 | 228 | <version>2.9.1</version> |
| 229 | 229 | <inherited>true</inherited> |
| 230 | 230 | <configuration> |
| 231 | + <quiet>true</quiet> | |
| 231 | 232 | <verbose>false</verbose> |
| 232 | 233 | <additionalparam>${javadoc.opts}</additionalparam> |
| 233 | 234 | <links> |
| @@ -240,6 +241,49 @@ | ||
| 240 | 241 | <link>http://fasterxml.github.io/jackson-databind/javadoc/2.6/</link> |
| 241 | 242 | <link>https://javaee-spec.java.net/nonav/javadocs/</link> |
| 242 | 243 | </links> |
| 244 | + <!-- optional dependencies from other modules (must be explicitly declared here in order to be correctly resolved) --> | |
| 245 | + <additionalDependencies> | |
| 246 | + <additionalDependency> | |
| 247 | + <groupId>org.xerial.snappy</groupId> | |
| 248 | + <artifactId>snappy-java</artifactId> | |
| 249 | + <version>${snappy.version}</version> | |
| 250 | + </additionalDependency> | |
| 251 | + <additionalDependency> | |
| 252 | + <groupId>net.jpountz.lz4</groupId> | |
| 253 | + <artifactId>lz4</artifactId> | |
| 254 | + <version>${lz4.version}</version> | |
| 255 | + </additionalDependency> | |
| 256 | + <additionalDependency> | |
| 257 | + <groupId>org.hdrhistogram</groupId> | |
| 258 | + <artifactId>HdrHistogram</artifactId> | |
| 259 | + <version>${hdr.version}</version> | |
| 260 | + </additionalDependency> | |
| 261 | + <additionalDependency> | |
| 262 | + <groupId>com.fasterxml.jackson.core</groupId> | |
| 263 | + <artifactId>jackson-core</artifactId> | |
| 264 | + <version>${jackson.version}</version> | |
| 265 | + </additionalDependency> | |
| 266 | + <additionalDependency> | |
| 267 | + <groupId>com.fasterxml.jackson.core</groupId> | |
| 268 | + <artifactId>jackson-annotations</artifactId> | |
| 269 | + <version>${jackson.version}</version> | |
| 270 | + </additionalDependency> | |
| 271 | + <additionalDependency> | |
| 272 | + <groupId>com.fasterxml.jackson.core</groupId> | |
| 273 | + <artifactId>jackson-databind</artifactId> | |
| 274 | + <version>${jackson.version}</version> | |
| 275 | + </additionalDependency> | |
| 276 | + <additionalDependency> | |
| 277 | + <groupId>joda-time</groupId> | |
| 278 | + <artifactId>joda-time</artifactId> | |
| 279 | + <version>${joda.version}</version> | |
| 280 | + </additionalDependency> | |
| 281 | + <additionalDependency> | |
| 282 | + <groupId>javax.json</groupId> | |
| 283 | + <artifactId>javax.json-api</artifactId> | |
| 284 | + <version>${jsr353-api.version}</version> | |
| 285 | + </additionalDependency> | |
| 286 | + </additionalDependencies> | |
| 243 | 287 | </configuration> |
| 244 | 288 | <executions> |
| 245 | 289 | <execution> |