kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 1c2a711506e859be713954517f3b72ecba4dc408ba22fe1e75af62638b1dbc02 |
|---|---|
| Author | GregBestland <Greg.Bestland@datastax.com> · 2017-02-21 16:33 -06:00 |
| Committer | GregBestland <Greg.Bestland@datastax.com> · 2017-02-24 16:21 -06:00 |
| Parents | 73adafb103cb |
2 files changed
modified driver-core/src/test/java/com/datastax/driver/core/ConsistencyTest.java +274 −650
| @@ -15,716 +15,340 @@ | ||
| 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 | + | |
| 19 | +import org.scassandra.Scassandra; | |
| 20 | +import org.scassandra.http.client.BatchExecution; | |
| 21 | +import org.scassandra.http.client.PreparedStatementExecution; | |
| 22 | +import org.scassandra.http.client.Query; | |
| 27 | 23 | import org.slf4j.Logger; |
| 28 | 24 | import org.slf4j.LoggerFactory; |
| 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 { | |
| 30 | + | |
| 31 | +import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; | |
| 32 | +import static org.testng.Assert.*; | |
| 33 | + | |
| 34 | +public class ConsistencyTest { | |
| 35 | + | |
| 58 | 36 | |
| 59 | 37 | private static final Logger logger = LoggerFactory.getLogger(ConsistencyTest.class); |
| 38 | + private ScassandraCluster sCluster; | |
| 60 | 39 | |
| 61 | - private Cluster.Builder tokenAwareRoundRobin() { | |
| 62 | - return Cluster.builder() | |
| 63 | - .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000)) | |
| 64 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())); | |
| 65 | - } | |
| 40 | + @BeforeClass | |
| 41 | + public void setUp() { | |
| 42 | + sCluster = ScassandraCluster.builder().withNodes(1).build(); | |
| 43 | + sCluster.init(); | |
| 66 | 44 | |
| 67 | - private Cluster.Builder tokenAwareRoundRobinNoShuffle() { | |
| 68 | - return Cluster.builder() | |
| 69 | - .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000)) | |
| 70 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)); | |
| 71 | 45 | } |
| 72 | 46 | |
| 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); | |
| 47 | + @AfterMethod | |
| 48 | + public void tearDown() { | |
| 49 | + clearActivityLog(); | |
| 78 | 50 | } |
| 79 | 51 | |
| 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 | - } | |
| 86 | 52 | |
| 87 | - private Cluster.Builder roundRobinDowngrading() { | |
| 88 | - return Cluster.builder() | |
| 89 | - .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000)) | |
| 90 | - .withLoadBalancingPolicy(new RoundRobinPolicy()) | |
| 91 | - .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 53 | + public void clearActivityLog() { | |
| 54 | + for (Scassandra node : sCluster.nodes()) { | |
| 55 | + node.activityClient().clearAllRecordedActivity(); | |
| 56 | + } | |
| 92 | 57 | } |
| 93 | 58 | |
| 94 | - private Cluster.Builder tokenAwareDCAwareRoundRobinNoShuffleDowngrading() { | |
| 59 | + public Cluster.Builder builder() { | |
| 60 | + //Note: nonQuietClusterCloseOptions is used to speed up tests | |
| 95 | 61 | return Cluster.builder() |
| 96 | - .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000)) | |
| 97 | - .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().withLocalDc("dc2").build(), false)) | |
| 98 | - .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 62 | + .addContactPoints(sCluster.address(1).getAddress()) | |
| 63 | + .withPort(sCluster.getBinaryPort()).withNettyOptions(nonQuietClusterCloseOptions); | |
| 99 | 64 | } |
| 100 | 65 | |
| 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 | - } | |
| 66 | + public void checkSerialCLMatch(ConsistencyLevel expected, String received) { | |
| 67 | + /** | |
| 68 | + * This method checks the expected/sent serial consistency level against that which is received. | |
| 69 | + * ConsistencyLevel.SERIAL is the default serial consistency level, so even when sent it will return | |
| 70 | + * as null. | |
| 71 | + */ | |
| 72 | + if (expected.equals(ConsistencyLevel.SERIAL)) { | |
| 73 | + assertNull(received); | |
| 137 | 74 | |
| 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 | - } | |
| 75 | + } else { | |
| 76 | + assertTrue(received.equals(expected.toString())); | |
| 147 | 77 | } |
| 78 | + } | |
| 148 | 79 | |
| 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 | - } | |
| 80 | + public PreparedStatementExecution executePrepared(Session session, String statement, ConsistencyLevel level, ConsistencyLevel serialLevel) { | |
| 81 | + PreparedStatement ps = session.prepare(statement); | |
| 82 | + BoundStatement bound = ps.bind(); | |
| 83 | + if (level != null) { | |
| 84 | + bound.setConsistencyLevel(level); | |
| 166 | 85 | } |
| 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 | - } | |
| 86 | + if (serialLevel != null) { | |
| 87 | + bound.setSerialConsistencyLevel(serialLevel); | |
| 185 | 88 | } |
| 89 | + session.execute(bound); | |
| 90 | + List<PreparedStatementExecution> pses = sCluster.node(1).activityClient().retrievePreparedStatementExecutions(); | |
| 91 | + PreparedStatementExecution pse = pses.get(0); | |
| 92 | + assertTrue(pse.getPreparedStatementText().equals(statement)); | |
| 93 | + return pse; | |
| 186 | 94 | } |
| 187 | 95 | |
| 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 | - } | |
| 96 | + public BatchExecution executeBatch(Session session, String statement, ConsistencyLevel level, ConsistencyLevel serialLevel) { | |
| 97 | + BatchStatement batch = new BatchStatement(); | |
| 98 | + batch.add(new SimpleStatement(statement)); | |
| 235 | 99 | |
| 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 | - } | |
| 100 | + if (level != null) { | |
| 101 | + batch.setConsistencyLevel(level); | |
| 253 | 102 | } |
| 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 | - } | |
| 103 | + if (serialLevel != null) { | |
| 104 | + batch.setSerialConsistencyLevel(serialLevel); | |
| 272 | 105 | } |
| 106 | + session.execute(batch); | |
| 107 | + List<BatchExecution> batches = sCluster.node(1).activityClient().retrieveBatches(); | |
| 108 | + assertEquals(batches.size(), 1); | |
| 109 | + return batches.get(0); | |
| 273 | 110 | } |
| 274 | 111 | |
| 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 | - } | |
| 112 | + public Query executeSimple(Session session, String statement, ConsistencyLevel level, ConsistencyLevel serialLevel) { | |
| 113 | + SimpleStatement simpleStatement = new SimpleStatement(statement); | |
| 114 | + if (level != null) { | |
| 115 | + simpleStatement.setConsistencyLevel(level); | |
| 317 | 116 | } |
| 117 | + if (serialLevel != null) { | |
| 118 | + simpleStatement.setSerialConsistencyLevel(serialLevel); | |
| 119 | + } | |
| 120 | + session.execute(simpleStatement); | |
| 121 | + //Find the unique query in the activity log. | |
| 122 | + List<Query> queries = sCluster.node(1).activityClient().retrieveQueries(); | |
| 123 | + for (Query query : queries) { | |
| 124 | + if (query.getQuery().equals(statement)) | |
| 125 | + return query; | |
| 126 | + } | |
| 127 | + return null; | |
| 128 | + } | |
| 129 | + | |
| 130 | + /** | |
| 131 | + * When no consistency level is defined the default of LOCAL_ONE should be used. | |
| 132 | + * | |
| 133 | + * @test_category consistency | |
| 134 | + */ | |
| 135 | + @Test(groups = "short") | |
| 136 | + public void should_use_global_default_cl_when_none_specified() throws Throwable { | |
| 137 | + | |
| 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 | + | |
| 159 | + | |
| 160 | + } finally { | |
| 161 | + cluster.close(); | |
| 162 | + } | |
| 163 | + } | |
| 164 | + | |
| 165 | + /** | |
| 166 | + * Exhaustively tests all consistency levels when they are set via QueryOptions. | |
| 167 | + * | |
| 168 | + * @test_category consistency | |
| 169 | + */ | |
| 170 | + @Test(groups = "short", dataProvider = "consistencyLevels", dataProviderClass = DataProviders.class) | |
| 171 | + public void should_use_query_option_cl(ConsistencyLevel cl) throws Throwable { | |
| 172 | + //Build a cluster with a CL level set in the query options. | |
| 173 | + Cluster cluster = builder().withQueryOptions(new QueryOptions().setConsistencyLevel(cl)).build(); | |
| 174 | + try { | |
| 175 | + Session session = cluster.connect(); | |
| 176 | + //Construct unique query, with no CL defined. | |
| 177 | + String queryString = "query_cl"; | |
| 178 | + Query clQuery = executeSimple(session, queryString, null, null); | |
| 179 | + assertTrue(clQuery.getConsistency().equals(cl.toString())); | |
| 180 | + | |
| 181 | + //Check prepared statement CL | |
| 182 | + String prepareString = "preapred_query_cl"; | |
| 183 | + PreparedStatementExecution pse = executePrepared(session, prepareString, null, null); | |
| 184 | + assertTrue(pse.getConsistency().equals(cl.toString())); | |
| 185 | + | |
| 186 | + //Check batch statement CL | |
| 187 | + String batchStateString = "batch_query_cl"; | |
| 188 | + BatchExecution batch = executeBatch(session, batchStateString, null, null); | |
| 189 | + assertTrue(batch.getConsistency().equals(cl.toString())); | |
| 190 | + | |
| 191 | + } finally { | |
| 192 | + cluster.close(); | |
| 193 | + } | |
| 194 | + | |
| 195 | + } | |
| 196 | + | |
| 197 | + /** | |
| 198 | + * Exhaustively tests all consistency levels when they are set at the statement level. | |
| 199 | + * | |
| 200 | + * @test_category consistency | |
| 201 | + */ | |
| 202 | + @Test(groups = "short", dataProvider = "consistencyLevels", dataProviderClass = DataProviders.class) | |
| 203 | + public void should_use_statement_cl(ConsistencyLevel cl) throws Throwable { | |
| 204 | + //Build a cluster with no CL set in the query options. | |
| 205 | + //Note: nonQuietClusterCloseOptions is used to speed up tests | |
| 206 | + Cluster cluster = builder().build(); | |
| 207 | + try { | |
| 208 | + Session session = cluster.connect(); | |
| 209 | + //Construct unique query statement with a CL defined. | |
| 210 | + String queryString = "statement_cl"; | |
| 211 | + Query clQuery = executeSimple(session, queryString, cl, null); | |
| 212 | + assertTrue(clQuery.getConsistency().equals(cl.toString())); | |
| 213 | + | |
| 214 | + //Check prepared statement CL | |
| 215 | + String prepareString = "preapred_statement_cl"; | |
| 216 | + PreparedStatementExecution pse = executePrepared(session, prepareString, cl, null); | |
| 217 | + assertTrue(pse.getConsistency().equals(cl.toString())); | |
| 218 | + | |
| 219 | + //Check batch statement CL | |
| 220 | + String batchStateString = "batch_statement_cl"; | |
| 221 | + BatchExecution batch = executeBatch(session, batchStateString, cl, null); | |
| 222 | + assertTrue(batch.getConsistency().equals(cl.toString())); | |
| 223 | + } finally { | |
| 224 | + cluster.close(); | |
| 225 | + } | |
| 226 | + | |
| 227 | + } | |
| 228 | + | |
| 229 | + /** | |
| 230 | + * Tests that order of precedence is followed when defining CLs. | |
| 231 | + * Statement level CL should be honored above QueryOptions. | |
| 232 | + * QueryOptions should be honored above default CL. | |
| 233 | + * | |
| 234 | + * @test_category consistency | |
| 235 | + */ | |
| 236 | + @Test(groups = "short") | |
| 237 | + public void should_use_appropriate_cl_when_multiple_defined() throws Throwable { | |
| 238 | + ConsistencyLevel cl_one = ConsistencyLevel.ONE; | |
| 239 | + //Build a cluster with no CL set in the query options. | |
| 240 | + Cluster cluster = builder().withQueryOptions(new QueryOptions().setConsistencyLevel(cl_one)).build(); | |
| 241 | + try { | |
| 318 | 242 | |
| 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 | 243 | |
| 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 | - } | |
| 244 | + Session session = cluster.connect(); | |
| 345 | 245 | |
| 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 | - } | |
| 358 | - } | |
| 359 | - } | |
| 246 | + //Check order of precedence for simple statements | |
| 247 | + //Construct unique query statement with no CL defined. | |
| 248 | + String queryString = "opts_cl"; | |
| 249 | + Query clQuery = executeSimple(session, queryString, null, null); | |
| 250 | + assertTrue(clQuery.getConsistency().equals(cl_one.toString())); | |
| 360 | 251 | |
| 252 | + //Construct unique query statement with a CL defined. | |
| 253 | + ConsistencyLevel cl_all = ConsistencyLevel.ALL; | |
| 254 | + queryString = "stm_cl"; | |
| 255 | + clQuery = executeSimple(session, queryString, cl_all, null); | |
| 256 | + assertTrue(clQuery.getConsistency().equals(cl_all.toString())); | |
| 361 | 257 | |
| 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 | - } | |
| 258 | + //Check order of precedence for prepared statements | |
| 259 | + //Construct unique prepared statement with no CL defined. | |
| 260 | + String prepareString = "prep_opts_cl"; | |
| 261 | + PreparedStatementExecution pse = executePrepared(session, prepareString, null, null); | |
| 262 | + assertTrue(pse.getConsistency().equals(cl_one.toString())); | |
| 263 | + clearActivityLog(); | |
| 398 | 264 | |
| 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 | - } | |
| 265 | + //Construct unique prepared statement with a CL defined. | |
| 266 | + prepareString = "prep_stm_cl"; | |
| 267 | + pse = executePrepared(session, prepareString, cl_all, null); | |
| 268 | + assertTrue(pse.getConsistency().equals(cl_all.toString())); | |
| 409 | 269 | |
| 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 | 270 | |
| 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 | - } | |
| 442 | - } | |
| 271 | + //Check order of precedence for batch statements | |
| 272 | + //Construct unique batch statement with no CL defined. | |
| 273 | + String batchString = "batch_opts_cl"; | |
| 274 | + BatchExecution batch = executeBatch(session, batchString, null, null); | |
| 275 | + assertTrue(batch.getConsistency().equals(cl_one.toString())); | |
| 276 | + clearActivityLog(); | |
| 443 | 277 | |
| 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 | - } | |
| 471 | - } | |
| 278 | + //Construct unique prepared statement with a CL defined. | |
| 279 | + batchString = "prep_stm_cl"; | |
| 280 | + batch = executeBatch(session, batchString, cl_all, null); | |
| 281 | + assertTrue(batch.getConsistency().equals(cl_all.toString())); | |
| 472 | 282 | |
| 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 | - } | |
| 283 | + } finally { | |
| 284 | + cluster.close(); | |
| 484 | 285 | } |
| 485 | - } | |
| 486 | 286 | |
| 487 | - @Test(groups = "long") | |
| 488 | - @CCMConfig(numberOfNodes = 3, | |
| 489 | - clusterProvider = "roundRobinDowngrading") | |
| 490 | - public void testRFThreeRoundRobinDowngradingCL() throws Throwable { | |
| 491 | - testRFThreeDowngradingCL(); | |
| 492 | 287 | } |
| 493 | 288 | |
| 494 | - @Test(groups = "long") | |
| 495 | - @CCMConfig(numberOfNodes = 3, | |
| 496 | - clusterProvider = "tokenAwareRoundRobinNoShuffleDowngrading") | |
| 497 | - public void testRFThreeTokenAwareDowngradingCL() throws Throwable { | |
| 498 | - testRFThreeDowngradingCL(); | |
| 499 | - } | |
| 500 | - | |
| 501 | - private void testRFThreeDowngradingCL() throws Throwable { | |
| 502 | - | |
| 503 | - createSchema(3); | |
| 504 | - init(12, ConsistencyLevel.ALL); | |
| 505 | - query(12, ConsistencyLevel.ALL); | |
| 506 | - | |
| 289 | + /** | |
| 290 | + * Exhaustively tests all serial consistency levels when they are set via QueryOptions. | |
| 291 | + * | |
| 292 | + * @test_category consistency | |
| 293 | + */ | |
| 294 | + @Test(groups = "short", dataProvider = "serialConsistencyLevels", dataProviderClass = DataProviders.class) | |
| 295 | + public void should_use_query_option_serial_cl(ConsistencyLevel cl) throws Throwable { | |
| 296 | + //Build a cluster with a CL level set in the query options. | |
| 297 | + Cluster cluster = builder().withQueryOptions(new QueryOptions().setSerialConsistencyLevel(cl)).build(); | |
| 507 | 298 | 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 | - } | |
| 535 | - } | |
| 299 | + Session session = cluster.connect(); | |
| 300 | + //Construct unique query, with no CL defined. | |
| 301 | + String queryString = "serial_query_cl"; | |
| 302 | + Query clQuery = executeSimple(session, queryString, null, cl); | |
| 303 | + checkSerialCLMatch(cl, clQuery.getSerialConsistency()); | |
| 536 | 304 | |
| 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 | - } | |
| 548 | - } | |
| 549 | - } | |
| 550 | 305 | |
| 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 | - } | |
| 306 | + //Check prepared statement CL | |
| 307 | + String prepareString = "preapred_statement_serial_cl"; | |
| 308 | + PreparedStatementExecution pse = executePrepared(session, prepareString, null, null); | |
| 309 | + checkSerialCLMatch(cl, pse.getSerialConsistency()); | |
| 593 | 310 | |
| 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 | - } | |
| 311 | + //Check batch statement CL | |
| 312 | + String batchStateString = "batch_statement_serial_cl"; | |
| 313 | + BatchExecution batch = executeBatch(session, batchStateString, null, null); | |
| 314 | + checkSerialCLMatch(cl, batch.getSerialConsistency()); | |
| 606 | 315 | |
| 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 | - } | |
| 316 | + } finally { | |
| 317 | + cluster.close(); | |
| 620 | 318 | } |
| 621 | 319 | |
| 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 | - } | |
| 635 | - } | |
| 636 | 320 | } |
| 637 | 321 | |
| 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 | - } | |
| 322 | + /** | |
| 323 | + * Exhaustively tests all serial consistency levels when they are set at the statement level. | |
| 324 | + * | |
| 325 | + * @test_category consistency | |
| 326 | + */ | |
| 327 | + @Test(groups = "short", dataProvider = "serialConsistencyLevels", dataProviderClass = DataProviders.class) | |
| 328 | + public void should_use_statement_serial_cl(ConsistencyLevel cl) throws Throwable { | |
| 329 | + //Build a cluster with no CL set in the query options. | |
| 330 | + Cluster cluster = builder().build(); | |
| 331 | + try { | |
| 332 | + Session session = cluster.connect(); | |
| 333 | + //Construct unique query statement with a CL defined. | |
| 334 | + String queryString = "statement_serial_cl"; | |
| 335 | + Query clQuery = executeSimple(session, queryString, null, cl); | |
| 336 | + checkSerialCLMatch(cl, clQuery.getSerialConsistency()); | |
| 679 | 337 | |
| 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 | - } | |
| 338 | + //Check prepared statement CL | |
| 339 | + String prepareString = "preapred_statement_serial_cl"; | |
| 340 | + PreparedStatementExecution pse = executePrepared(session, prepareString, null, cl); | |
| 341 | + checkSerialCLMatch(cl, pse.getSerialConsistency()); | |
| 691 | 342 | |
| 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 | - } | |
| 704 | - } | |
| 343 | + //Check batch statement CL | |
| 344 | + String batchStateString = "batch_statement_serial_cl"; | |
| 345 | + BatchExecution batch = executeBatch(session, batchStateString, null, cl); | |
| 346 | + checkSerialCLMatch(cl, batch.getSerialConsistency()); | |
| 705 | 347 | |
| 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 | - } | |
| 348 | + } finally { | |
| 349 | + cluster.close(); | |
| 718 | 350 | } |
| 719 | - } | |
| 720 | 351 | |
| 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 | 352 | } |
| 729 | 353 | |
| 730 | 354 | } |
modified pom.xml +1 −1
| @@ -66,7 +66,7 @@ | ||
| 66 | 66 | <assertj.version>1.7.0</assertj.version> |
| 67 | 67 | <mockito.version>1.10.8</mockito.version> |
| 68 | 68 | <commons-exec.version>1.3</commons-exec.version> |
| 69 | - <scassandra.version>1.1.1</scassandra.version> | |
| 69 | + <scassandra.version>1.1.2</scassandra.version> | |
| 70 | 70 | <main.basedir>${project.basedir}</main.basedir> |
| 71 | 71 | <ipprefix>127.0.1.</ipprefix> |
| 72 | 72 | <test.groups>unit</test.groups> |