kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 7c15143a8bff9807bad29086a67f0ea75f94ada43e302827bf82413d1acafdbb |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2016-03-06 19:41 -06:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2016-03-11 13:41 -06:00 |
| Parents | 064e9c2c7850 |
13 files changed
modified driver-core/src/test/java/com/datastax/driver/core/QueryLoggerErrorsTest.java +3 −3
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | import com.google.common.util.concurrent.Uninterruptibles; |
| 20 | 20 | import org.apache.log4j.Level; |
| 21 | 21 | import org.apache.log4j.Logger; |
| 22 | -import org.scassandra.http.client.PrimingRequest; | |
| 22 | +import org.scassandra.http.client.Result; | |
| 23 | 23 | import org.testng.annotations.AfterMethod; |
| 24 | 24 | import org.testng.annotations.BeforeMethod; |
| 25 | 25 | import org.testng.annotations.DataProvider; |
| @@ -32,9 +32,9 @@ | ||
| 32 | 32 | import static org.apache.log4j.Level.INFO; |
| 33 | 33 | import static org.assertj.core.api.Assertions.assertThat; |
| 34 | 34 | import static org.assertj.core.api.Assertions.fail; |
| 35 | -import static org.scassandra.http.client.PrimingRequest.Result.*; | |
| 36 | 35 | import static org.scassandra.http.client.PrimingRequest.queryBuilder; |
| 37 | 36 | import static org.scassandra.http.client.PrimingRequest.then; |
| 37 | +import static org.scassandra.http.client.Result.*; | |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Tests for {@link QueryLogger} using Scassandra. |
| @@ -210,7 +210,7 @@ | ||
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | @Test(groups = "short", dataProvider = "errors") |
| 213 | - public void should_log_exception_from_the_given_result(PrimingRequest.Result result, Class<? extends Exception> expectedException, Class<? extends Exception> loggedException) throws Exception { | |
| 213 | + public void should_log_exception_from_the_given_result(Result result, Class<? extends Exception> expectedException, Class<? extends Exception> loggedException) throws Exception { | |
| 214 | 214 | // given |
| 215 | 215 | error.setLevel(DEBUG); |
| 216 | 216 | queryLogger = builder(cluster).build(); |
modified driver-core/src/test/java/com/datastax/driver/core/SpeculativeExecutionTest.java +17 −15
| @@ -20,7 +20,9 @@ | ||
| 20 | 20 | import com.datastax.driver.core.policies.SpeculativeExecutionPolicy; |
| 21 | 21 | import com.google.common.collect.ImmutableList; |
| 22 | 22 | import com.google.common.collect.ImmutableMap; |
| 23 | +import org.scassandra.http.client.Consistency; | |
| 23 | 24 | import org.scassandra.http.client.PrimingRequest; |
| 25 | +import org.scassandra.http.client.Result; | |
| 24 | 26 | import org.testng.annotations.AfterMethod; |
| 25 | 27 | import org.testng.annotations.BeforeMethod; |
| 26 | 28 | import org.testng.annotations.Test; |
| @@ -99,17 +101,17 @@ | ||
| 99 | 101 | public void should_not_start_speculative_execution_if_first_execution_retries_but_is_still_fast_enough() { |
| 100 | 102 | // will retry once on this node: |
| 101 | 103 | scassandras.node(1).primingClient().prime(PrimingRequest.queryBuilder() |
| 102 | - .withQuery("mock query") | |
| 103 | - .withConsistency(PrimingRequest.Consistency.TWO) | |
| 104 | - .withResult(PrimingRequest.Result.read_request_timeout) | |
| 105 | - .build() | |
| 104 | + .withQuery("mock query") | |
| 105 | + .withConsistency(Consistency.TWO) | |
| 106 | + .withResult(Result.read_request_timeout) | |
| 107 | + .build() | |
| 106 | 108 | ); |
| 107 | 109 | |
| 108 | 110 | scassandras.node(1).primingClient().prime(PrimingRequest.queryBuilder() |
| 109 | - .withQuery("mock query") | |
| 110 | - .withConsistency(PrimingRequest.Consistency.ONE) | |
| 111 | - .withRows(row("result", "result1")) | |
| 112 | - .build() | |
| 111 | + .withQuery("mock query") | |
| 112 | + .withConsistency(Consistency.ONE) | |
| 113 | + .withRows(row("result", "result1")) | |
| 114 | + .build() | |
| 113 | 115 | ); |
| 114 | 116 | |
| 115 | 117 | long execStartCount = errors.getSpeculativeExecutions().getCount(); |
| @@ -129,16 +131,16 @@ | ||
| 129 | 131 | @Test(groups = "short") |
| 130 | 132 | public void should_start_speculative_execution_if_first_execution_takes_too_long() { |
| 131 | 133 | scassandras.node(1).primingClient().prime(PrimingRequest.queryBuilder() |
| 132 | - .withQuery("mock query") | |
| 133 | - .withFixedDelay(400) | |
| 134 | - .withRows(row("result", "result1")) | |
| 135 | - .build() | |
| 134 | + .withQuery("mock query") | |
| 135 | + .withFixedDelay(400) | |
| 136 | + .withRows(row("result", "result1")) | |
| 137 | + .build() | |
| 136 | 138 | ); |
| 137 | 139 | |
| 138 | 140 | scassandras.node(2).primingClient().prime(PrimingRequest.queryBuilder() |
| 139 | - .withQuery("mock query") | |
| 140 | - .withRows(row("result", "result2")) | |
| 141 | - .build() | |
| 141 | + .withQuery("mock query") | |
| 142 | + .withRows(row("result", "result2")) | |
| 143 | + .build() | |
| 142 | 144 | ); |
| 143 | 145 | long execStartCount = errors.getSpeculativeExecutions().getCount(); |
| 144 | 146 |
modified driver-core/src/test/java/com/datastax/driver/core/exceptions/ExceptionsScassandraTest.java +3 −2
| @@ -21,6 +21,7 @@ | ||
| 21 | 21 | import com.google.common.collect.ImmutableMap; |
| 22 | 22 | import org.scassandra.Scassandra; |
| 23 | 23 | import org.scassandra.http.client.PrimingRequest; |
| 24 | +import org.scassandra.http.client.Result; | |
| 24 | 25 | import org.testng.annotations.*; |
| 25 | 26 | |
| 26 | 27 | import java.util.List; |
| @@ -29,7 +30,7 @@ | ||
| 29 | 30 | import static com.datastax.driver.core.ConsistencyLevel.ONE; |
| 30 | 31 | import static org.assertj.core.api.Assertions.assertThat; |
| 31 | 32 | import static org.assertj.core.api.Assertions.fail; |
| 32 | -import static org.scassandra.http.client.PrimingRequest.Result.*; | |
| 33 | +import static org.scassandra.http.client.Result.*; | |
| 33 | 34 | |
| 34 | 35 | public class ExceptionsScassandraTest { |
| 35 | 36 | |
| @@ -111,7 +112,7 @@ | ||
| 111 | 112 | } |
| 112 | 113 | } |
| 113 | 114 | |
| 114 | - protected void simulateError(int hostNumber, PrimingRequest.Result result) { | |
| 115 | + protected void simulateError(int hostNumber, Result result) { | |
| 115 | 116 | scassandras.node(hostNumber).primingClient().prime(PrimingRequest.queryBuilder() |
| 116 | 117 | .withQuery("mock query") |
| 117 | 118 | .withResult(result) |
modified driver-core/src/test/java/com/datastax/driver/core/policies/AbstractRetryPolicyIntegrationTest.java +5 −4
| @@ -26,6 +26,7 @@ | ||
| 26 | 26 | import org.scassandra.http.client.Config; |
| 27 | 27 | import org.scassandra.http.client.PrimingRequest; |
| 28 | 28 | import org.scassandra.http.client.PrimingRequest.PrimingRequestBuilder; |
| 29 | +import org.scassandra.http.client.Result; | |
| 29 | 30 | import org.testng.annotations.AfterMethod; |
| 30 | 31 | import org.testng.annotations.BeforeMethod; |
| 31 | 32 | import org.testng.annotations.DataProvider; |
| @@ -37,8 +38,8 @@ | ||
| 37 | 38 | import static org.assertj.core.api.Assertions.assertThat; |
| 38 | 39 | import static org.mockito.Matchers.*; |
| 39 | 40 | import static org.mockito.Mockito.times; |
| 40 | -import static org.scassandra.http.client.PrimingRequest.Result.overloaded; | |
| 41 | -import static org.scassandra.http.client.PrimingRequest.Result.server_error; | |
| 41 | +import static org.scassandra.http.client.Result.overloaded; | |
| 42 | +import static org.scassandra.http.client.Result.server_error; | |
| 42 | 43 | |
| 43 | 44 | /** |
| 44 | 45 | * Base class for retry policy integration tests. |
| @@ -104,11 +105,11 @@ | ||
| 104 | 105 | } |
| 105 | 106 | } |
| 106 | 107 | |
| 107 | - protected void simulateError(int hostNumber, PrimingRequest.Result result) { | |
| 108 | + protected void simulateError(int hostNumber, Result result) { | |
| 108 | 109 | simulateError(hostNumber, result, null); |
| 109 | 110 | } |
| 110 | 111 | |
| 111 | - protected void simulateError(int hostNumber, PrimingRequest.Result result, Config config) { | |
| 112 | + protected void simulateError(int hostNumber, Result result, Config config) { | |
| 112 | 113 | PrimingRequestBuilder builder = PrimingRequest.queryBuilder() |
| 113 | 114 | .withQuery("mock query") |
| 114 | 115 | .withResult(result); |
deleted driver-core/src/test/java/com/datastax/driver/core/policies/CASRetryPolicyIntegrationTest.java +0 −108
| @@ -1,108 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | - * | |
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | - * you may not use this file except in compliance with the License. | |
| 6 | - * You may obtain a copy of the License at | |
| 7 | - * | |
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | - * | |
| 10 | - * Unless required by applicable law or agreed to in writing, software | |
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | - * See the License for the specific language governing permissions and | |
| 14 | - * limitations under the License. | |
| 15 | - */ | |
| 16 | -package com.datastax.driver.core.policies; | |
| 17 | - | |
| 18 | -import com.datastax.driver.core.*; | |
| 19 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 20 | -import com.datastax.driver.core.exceptions.UnavailableException; | |
| 21 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 22 | -import org.testng.annotations.Test; | |
| 23 | - | |
| 24 | -import static com.datastax.driver.core.Assertions.assertThat; | |
| 25 | -import static com.datastax.driver.core.ConsistencyLevel.ANY; | |
| 26 | -import static com.datastax.driver.core.ConsistencyLevel.SERIAL; | |
| 27 | -import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD; | |
| 28 | -import static org.assertj.core.api.Assertions.fail; | |
| 29 | -import static org.mockito.Matchers.eq; | |
| 30 | -import static org.mockito.Mockito.*; | |
| 31 | - | |
| 32 | -/** | |
| 33 | - * Tests for retry policies in combination with lightweight transactions. | |
| 34 | - * <p/> | |
| 35 | - * Note: we can't extend {@link AbstractRetryPolicyIntegrationTest} here, because we are | |
| 36 | - * testing LWT statements and Scassandra doesn't support priming consistency levels yet. | |
| 37 | - * | |
| 38 | - * @jira_ticket JAVA-764 | |
| 39 | - */ | |
| 40 | -@CCMConfig( | |
| 41 | - numberOfNodes = 3, | |
| 42 | - dirtiesContext = true, | |
| 43 | - createCluster = false | |
| 44 | -) | |
| 45 | -@CreateCCM(PER_METHOD) | |
| 46 | -@CassandraVersion(major = 2.0) | |
| 47 | -public class CASRetryPolicyIntegrationTest extends CCMTestsSupport { | |
| 48 | - | |
| 49 | - @Test(groups = "long") | |
| 50 | - public void should_rethrow_on_unavailable_with_default_policy_if_CAS() { | |
| 51 | - testLWT(spy(DefaultRetryPolicy.INSTANCE)); | |
| 52 | - } | |
| 53 | - | |
| 54 | - @Test(groups = "long") | |
| 55 | - public void should_rethrow_on_unavailable_with_downgrading_policy_if_CAS() { | |
| 56 | - testLWT(spy(DowngradingConsistencyRetryPolicy.INSTANCE)); | |
| 57 | - } | |
| 58 | - | |
| 59 | - private void testLWT(RetryPolicy retryPolicy) { | |
| 60 | - | |
| 61 | - Cluster cluster = register(Cluster.builder() | |
| 62 | - .addContactPoints(getContactPoints().get(0)) | |
| 63 | - .withPort(ccm().getBinaryPort()) | |
| 64 | - .withSocketOptions(new SocketOptions().setReadTimeoutMillis(120000)) | |
| 65 | - .withRetryPolicy(retryPolicy) | |
| 66 | - .build()); | |
| 67 | - | |
| 68 | - Session session = cluster.connect(); | |
| 69 | - | |
| 70 | - String ks = TestUtils.generateIdentifier("ks_"); | |
| 71 | - session.execute(String.format("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3}", ks)); | |
| 72 | - useKeyspace(session, ks); | |
| 73 | - session.execute("CREATE TABLE IF NOT EXISTS foo (k int primary key, c int)"); | |
| 74 | - | |
| 75 | - session.execute("INSERT INTO foo(k, c) VALUES (0, 0)"); | |
| 76 | - | |
| 77 | - ccm().stop(1); | |
| 78 | - ccm().waitForDown(1); | |
| 79 | - TestUtils.waitForDown(ccm().addressOfNode(1).getHostName(), cluster); | |
| 80 | - | |
| 81 | - ccm().stop(2); | |
| 82 | - ccm().waitForDown(2); | |
| 83 | - TestUtils.waitForDown(ccm().addressOfNode(2).getHostName(), cluster); | |
| 84 | - | |
| 85 | - Statement s = new SimpleStatement("UPDATE foo SET c = 1 WHERE k = 0 IF c = 0") | |
| 86 | - // the following will cause the paxos phase to fail | |
| 87 | - // given the number of available replicas (1) | |
| 88 | - .setConsistencyLevel(ANY) | |
| 89 | - .setSerialConsistencyLevel(SERIAL); | |
| 90 | - | |
| 91 | - try { | |
| 92 | - session.execute(s); | |
| 93 | - // Expect a NHAE since a retry should have been attempted on unavailable error with CL SERIAL. | |
| 94 | - fail("Expected NoHostAvailableException"); | |
| 95 | - } catch (NoHostAvailableException e) { | |
| 96 | - Throwable error = e.getErrors().values().iterator().next(); | |
| 97 | - assertThat(error).isInstanceOf(UnavailableException.class); | |
| 98 | - UnavailableException unavailable = (UnavailableException) error; | |
| 99 | - assertThat(unavailable.getConsistencyLevel()).isEqualTo(SERIAL); | |
| 100 | - assertThat(unavailable.getRequiredReplicas()).isEqualTo(2); | |
| 101 | - assertThat(unavailable.getAliveReplicas()).isEqualTo(1); | |
| 102 | - } | |
| 103 | - | |
| 104 | - verify(retryPolicy, times(1)).onUnavailable( | |
| 105 | - eq(s), eq(SERIAL), eq(2), eq(1), eq(0)); | |
| 106 | - } | |
| 107 | - | |
| 108 | -} |
modified driver-core/src/test/java/com/datastax/driver/core/policies/CustomRetryPolicyIntegrationTest.java +4 −4
| @@ -22,13 +22,13 @@ | ||
| 22 | 22 | import org.scassandra.http.client.ClosedConnectionConfig; |
| 23 | 23 | import org.scassandra.http.client.ClosedConnectionConfig.CloseType; |
| 24 | 24 | import org.scassandra.http.client.PrimingRequest; |
| 25 | +import org.scassandra.http.client.Result; | |
| 25 | 26 | import org.testng.annotations.Test; |
| 26 | 27 | |
| 27 | 28 | import static com.datastax.driver.core.Assertions.assertThat; |
| 28 | 29 | import static org.assertj.core.api.Fail.fail; |
| 29 | -import static org.scassandra.http.client.PrimingRequest.Result.read_request_timeout; | |
| 30 | -import static org.scassandra.http.client.PrimingRequest.Result.unavailable; | |
| 31 | 30 | import static org.scassandra.http.client.PrimingRequest.then; |
| 31 | +import static org.scassandra.http.client.Result.*; | |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Integration test with a custom implementation, to test retry and ignore decisions. |
| @@ -104,7 +104,7 @@ | ||
| 104 | 104 | |
| 105 | 105 | |
| 106 | 106 | @Test(groups = "short", dataProvider = "serverSideErrors") |
| 107 | - public void should_rethrow_on_server_side_error(PrimingRequest.Result error, Class<? extends DriverException> exception) { | |
| 107 | + public void should_rethrow_on_server_side_error(Result error, Class<? extends DriverException> exception) { | |
| 108 | 108 | simulateError(1, error); |
| 109 | 109 | try { |
| 110 | 110 | query(); |
| @@ -124,7 +124,7 @@ | ||
| 124 | 124 | |
| 125 | 125 | @Test(groups = "short", dataProvider = "connectionErrors") |
| 126 | 126 | public void should_rethrow_on_connection_error(CloseType closeType) { |
| 127 | - simulateError(1, PrimingRequest.Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 127 | + simulateError(1, closed_connection, new ClosedConnectionConfig(closeType)); | |
| 128 | 128 | try { |
| 129 | 129 | query(); |
| 130 | 130 | fail("expected an error"); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DefaultRetryPolicyIntegrationTest.java +31 −9
| @@ -15,10 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import com.datastax.driver.core.Cluster; | |
| 19 | -import com.datastax.driver.core.Metrics; | |
| 20 | -import com.datastax.driver.core.Session; | |
| 21 | -import com.datastax.driver.core.SocketOptions; | |
| 18 | +import com.datastax.driver.core.*; | |
| 22 | 19 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| 23 | 20 | import com.datastax.driver.core.exceptions.ReadTimeoutException; |
| 24 | 21 | import com.datastax.driver.core.exceptions.UnavailableException; |
| @@ -29,6 +26,9 @@ | ||
| 29 | 26 | import org.scassandra.Scassandra; |
| 30 | 27 | import org.scassandra.http.client.ClosedConnectionConfig; |
| 31 | 28 | import org.scassandra.http.client.PrimingRequest; |
| 29 | +import org.scassandra.http.client.Result; | |
| 30 | +import org.scassandra.http.client.UnavailableConfig; | |
| 31 | +import org.testng.Assert; | |
| 32 | 32 | import org.testng.annotations.Test; |
| 33 | 33 | |
| 34 | 34 | import java.util.Collection; |
| @@ -36,8 +36,9 @@ | ||
| 36 | 36 | |
| 37 | 37 | import static org.assertj.core.api.Assertions.assertThat; |
| 38 | 38 | import static org.assertj.core.api.Assertions.fail; |
| 39 | -import static org.scassandra.http.client.PrimingRequest.Result.*; | |
| 39 | +import static org.scassandra.http.client.Consistency.LOCAL_SERIAL; | |
| 40 | 40 | import static org.scassandra.http.client.PrimingRequest.then; |
| 41 | +import static org.scassandra.http.client.Result.*; | |
| 41 | 42 | |
| 42 | 43 | public class DefaultRetryPolicyIntegrationTest extends AbstractRetryPolicyIntegrationTest { |
| 43 | 44 | public DefaultRetryPolicyIntegrationTest() { |
| @@ -212,7 +213,7 @@ | ||
| 212 | 213 | |
| 213 | 214 | |
| 214 | 215 | @Test(groups = "short", dataProvider = "serverSideErrors") |
| 215 | - public void should_try_next_host_on_server_side_error(PrimingRequest.Result error, Class<?> exception) { | |
| 216 | + public void should_try_next_host_on_server_side_error(Result error, Class<?> exception) { | |
| 216 | 217 | simulateError(1, error); |
| 217 | 218 | simulateError(2, error); |
| 218 | 219 | simulateError(3, error); |
| @@ -238,9 +239,9 @@ | ||
| 238 | 239 | |
| 239 | 240 | @Test(groups = "short", dataProvider = "connectionErrors") |
| 240 | 241 | public void should_try_next_host_on_connection_error(ClosedConnectionConfig.CloseType closeType) { |
| 241 | - simulateError(1, PrimingRequest.Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 242 | - simulateError(2, PrimingRequest.Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 243 | - simulateError(3, PrimingRequest.Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 242 | + simulateError(1, closed_connection, new ClosedConnectionConfig(closeType)); | |
| 243 | + simulateError(2, closed_connection, new ClosedConnectionConfig(closeType)); | |
| 244 | + simulateError(3, closed_connection, new ClosedConnectionConfig(closeType)); | |
| 244 | 245 | try { |
| 245 | 246 | query(); |
| 246 | 247 | Fail.fail("expected a NoHostAvailableException"); |
| @@ -259,4 +260,25 @@ | ||
| 259 | 260 | assertQueried(2, 1); |
| 260 | 261 | assertQueried(3, 1); |
| 261 | 262 | } |
| 263 | + | |
| 264 | + @Test(groups = "short") | |
| 265 | + public void should_rethrow_on_unavailable_if_CAS() { | |
| 266 | + simulateError(1, unavailable, new UnavailableConfig(1, 0, LOCAL_SERIAL)); | |
| 267 | + simulateError(2, unavailable, new UnavailableConfig(1, 0, LOCAL_SERIAL)); | |
| 268 | + | |
| 269 | + try { | |
| 270 | + query(); | |
| 271 | + Assert.fail("expected an UnavailableException"); | |
| 272 | + } catch (UnavailableException e) { | |
| 273 | + assertThat(e.getConsistencyLevel()).isEqualTo(ConsistencyLevel.LOCAL_SERIAL); | |
| 274 | + } | |
| 275 | + | |
| 276 | + assertOnUnavailableWasCalled(2); | |
| 277 | + assertThat(errors.getRetries().getCount()).isEqualTo(1); | |
| 278 | + assertThat(errors.getUnavailables().getCount()).isEqualTo(2); | |
| 279 | + assertThat(errors.getRetriesOnUnavailable().getCount()).isEqualTo(1); | |
| 280 | + assertQueried(1, 1); | |
| 281 | + assertQueried(2, 1); | |
| 282 | + assertQueried(3, 0); | |
| 283 | + } | |
| 262 | 284 | } |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DowngradingConsistencyRetryPolicyIntegrationTest.java +27 −5
| @@ -30,8 +30,9 @@ | ||
| 30 | 30 | import java.util.Collection; |
| 31 | 31 | |
| 32 | 32 | import static org.assertj.core.api.Assertions.assertThat; |
| 33 | -import static org.scassandra.http.client.PrimingRequest.Result.*; | |
| 33 | +import static org.scassandra.http.client.Consistency.SERIAL; | |
| 34 | 34 | import static org.scassandra.http.client.PrimingRequest.then; |
| 35 | +import static org.scassandra.http.client.Result.*; | |
| 35 | 36 | import static org.scassandra.http.client.WriteTypePrime.UNLOGGED_BATCH; |
| 36 | 37 | import static org.testng.Assert.fail; |
| 37 | 38 | |
| @@ -391,7 +392,7 @@ | ||
| 391 | 392 | * @test_category retry_policy |
| 392 | 393 | */ |
| 393 | 394 | @Test(groups = "short", dataProvider = "serverSideErrors") |
| 394 | - public void should_try_next_host_on_server_side_error(PrimingRequest.Result error, Class<? extends DriverException> exception) { | |
| 395 | + public void should_try_next_host_on_server_side_error(Result error, Class<? extends DriverException> exception) { | |
| 395 | 396 | simulateError(1, error); |
| 396 | 397 | simulateError(2, error); |
| 397 | 398 | simulateError(3, error); |
| @@ -423,9 +424,9 @@ | ||
| 423 | 424 | */ |
| 424 | 425 | @Test(groups = "short", dataProvider = "connectionErrors") |
| 425 | 426 | public void should_try_next_host_on_connection_error(ClosedConnectionConfig.CloseType closeType) { |
| 426 | - simulateError(1, PrimingRequest.Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 427 | - simulateError(2, PrimingRequest.Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 428 | - simulateError(3, PrimingRequest.Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 427 | + simulateError(1, closed_connection, new ClosedConnectionConfig(closeType)); | |
| 428 | + simulateError(2, closed_connection, new ClosedConnectionConfig(closeType)); | |
| 429 | + simulateError(3, closed_connection, new ClosedConnectionConfig(closeType)); | |
| 429 | 430 | try { |
| 430 | 431 | query(); |
| 431 | 432 | Fail.fail("expected a NoHostAvailableException"); |
| @@ -444,4 +445,25 @@ | ||
| 444 | 445 | assertQueried(2, 1); |
| 445 | 446 | assertQueried(3, 1); |
| 446 | 447 | } |
| 448 | + | |
| 449 | + @Test(groups = "short") | |
| 450 | + public void should_rethrow_on_unavailable_if_CAS() { | |
| 451 | + simulateError(1, unavailable, new UnavailableConfig(1, 0, SERIAL)); | |
| 452 | + simulateError(2, unavailable, new UnavailableConfig(1, 0, SERIAL)); | |
| 453 | + | |
| 454 | + try { | |
| 455 | + query(); | |
| 456 | + fail("expected an UnavailableException"); | |
| 457 | + } catch (UnavailableException e) { | |
| 458 | + assertThat(e.getConsistencyLevel()).isEqualTo(ConsistencyLevel.SERIAL); | |
| 459 | + } | |
| 460 | + | |
| 461 | + assertOnUnavailableWasCalled(2); | |
| 462 | + assertThat(errors.getRetries().getCount()).isEqualTo(1); | |
| 463 | + assertThat(errors.getUnavailables().getCount()).isEqualTo(2); | |
| 464 | + assertThat(errors.getRetriesOnUnavailable().getCount()).isEqualTo(1); | |
| 465 | + assertQueried(1, 1); | |
| 466 | + assertQueried(2, 1); | |
| 467 | + assertQueried(3, 0); | |
| 468 | + } | |
| 447 | 469 | } |
modified driver-core/src/test/java/com/datastax/driver/core/policies/FallthroughRetryPolicyIntegrationTest.java +4 −3
| @@ -20,12 +20,13 @@ | ||
| 20 | 20 | import org.scassandra.http.client.ClosedConnectionConfig; |
| 21 | 21 | import org.scassandra.http.client.ClosedConnectionConfig.CloseType; |
| 22 | 22 | import org.scassandra.http.client.PrimingRequest; |
| 23 | +import org.scassandra.http.client.Result; | |
| 23 | 24 | import org.testng.annotations.Test; |
| 24 | 25 | |
| 25 | 26 | import static org.assertj.core.api.Assertions.assertThat; |
| 26 | 27 | import static org.assertj.core.api.Assertions.fail; |
| 27 | -import static org.scassandra.http.client.PrimingRequest.Result.*; | |
| 28 | 28 | import static org.scassandra.http.client.PrimingRequest.then; |
| 29 | +import static org.scassandra.http.client.Result.*; | |
| 29 | 30 | |
| 30 | 31 | public class FallthroughRetryPolicyIntegrationTest extends AbstractRetryPolicyIntegrationTest { |
| 31 | 32 | public FallthroughRetryPolicyIntegrationTest() { |
| @@ -111,7 +112,7 @@ | ||
| 111 | 112 | |
| 112 | 113 | |
| 113 | 114 | @Test(groups = "short", dataProvider = "serverSideErrors") |
| 114 | - public void should_rethrow_on_server_side_error(PrimingRequest.Result error, Class<? extends DriverException> exception) { | |
| 115 | + public void should_rethrow_on_server_side_error(Result error, Class<? extends DriverException> exception) { | |
| 115 | 116 | simulateError(1, error); |
| 116 | 117 | try { |
| 117 | 118 | query(); |
| @@ -131,7 +132,7 @@ | ||
| 131 | 132 | |
| 132 | 133 | @Test(groups = "short", dataProvider = "connectionErrors") |
| 133 | 134 | public void should_rethrow_on_connection_error(CloseType closeType) { |
| 134 | - simulateError(1, PrimingRequest.Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 135 | + simulateError(1, Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 135 | 136 | try { |
| 136 | 137 | query(); |
| 137 | 138 | fail("expected an error"); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/IdempotenceAwareRetryPolicyIntegrationTest.java +11 −9
| @@ -23,12 +23,14 @@ | ||
| 23 | 23 | import org.assertj.core.api.Fail; |
| 24 | 24 | import org.scassandra.http.client.ClosedConnectionConfig; |
| 25 | 25 | import org.scassandra.http.client.PrimingRequest; |
| 26 | +import org.scassandra.http.client.Result; | |
| 26 | 27 | import org.testng.annotations.Test; |
| 27 | 28 | |
| 28 | 29 | import static org.assertj.core.api.Assertions.assertThat; |
| 29 | 30 | import static org.assertj.core.api.Assertions.fail; |
| 30 | -import static org.scassandra.http.client.PrimingRequest.Result.write_request_timeout; | |
| 31 | 31 | import static org.scassandra.http.client.PrimingRequest.then; |
| 32 | +import static org.scassandra.http.client.Result.closed_connection; | |
| 33 | +import static org.scassandra.http.client.Result.write_request_timeout; | |
| 32 | 34 | |
| 33 | 35 | /** |
| 34 | 36 | * Integration test with an IdempotenceAwareRetryPolicy. |
| @@ -121,7 +123,7 @@ | ||
| 121 | 123 | |
| 122 | 124 | |
| 123 | 125 | @Test(groups = "short", dataProvider = "serverSideErrors") |
| 124 | - public void should_not_retry_on_server_error_if_statement_non_idempotent(PrimingRequest.Result error, Class<? extends DriverException> exception) { | |
| 126 | + public void should_not_retry_on_server_error_if_statement_non_idempotent(Result error, Class<? extends DriverException> exception) { | |
| 125 | 127 | simulateError(1, error); |
| 126 | 128 | try { |
| 127 | 129 | query(); |
| @@ -140,7 +142,7 @@ | ||
| 140 | 142 | |
| 141 | 143 | @SuppressWarnings("UnusedParameters") |
| 142 | 144 | @Test(groups = "short", dataProvider = "serverSideErrors") |
| 143 | - public void should_retry_on_server_error_if_statement_idempotent(PrimingRequest.Result error, Class<? extends DriverException> exception) { | |
| 145 | + public void should_retry_on_server_error_if_statement_idempotent(Result error, Class<? extends DriverException> exception) { | |
| 144 | 146 | simulateError(1, error); |
| 145 | 147 | simulateError(2, error); |
| 146 | 148 | simulateError(3, error); |
| @@ -166,9 +168,9 @@ | ||
| 166 | 168 | |
| 167 | 169 | @Test(groups = "short", dataProvider = "connectionErrors") |
| 168 | 170 | public void should_not_retry_on_connection_error_if_statement_non_idempotent(ClosedConnectionConfig.CloseType closeType) { |
| 169 | - simulateError(1, PrimingRequest.Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 170 | - simulateError(2, PrimingRequest.Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 171 | - simulateError(3, PrimingRequest.Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 171 | + simulateError(1, closed_connection, new ClosedConnectionConfig(closeType)); | |
| 172 | + simulateError(2, closed_connection, new ClosedConnectionConfig(closeType)); | |
| 173 | + simulateError(3, closed_connection, new ClosedConnectionConfig(closeType)); | |
| 172 | 174 | try { |
| 173 | 175 | query(); |
| 174 | 176 | Fail.fail("expected an error"); |
| @@ -190,9 +192,9 @@ | ||
| 190 | 192 | |
| 191 | 193 | @Test(groups = "short", dataProvider = "connectionErrors") |
| 192 | 194 | public void should_retry_on_connection_error_if_statement_idempotent(ClosedConnectionConfig.CloseType closeType) { |
| 193 | - simulateError(1, PrimingRequest.Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 194 | - simulateError(2, PrimingRequest.Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 195 | - simulateError(3, PrimingRequest.Result.closed_connection, new ClosedConnectionConfig(closeType)); | |
| 195 | + simulateError(1, closed_connection, new ClosedConnectionConfig(closeType)); | |
| 196 | + simulateError(2, closed_connection, new ClosedConnectionConfig(closeType)); | |
| 197 | + simulateError(3, closed_connection, new ClosedConnectionConfig(closeType)); | |
| 196 | 198 | try { |
| 197 | 199 | session.execute(new SimpleStatement("mock query").setIdempotent(true)); |
| 198 | 200 | Fail.fail("expected a NoHostAvailableException"); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/LatencyAwarePolicyTest.java +2 −2
| @@ -26,9 +26,9 @@ | ||
| 26 | 26 | import static java.util.concurrent.TimeUnit.SECONDS; |
| 27 | 27 | import static org.assertj.core.api.Assertions.assertThat; |
| 28 | 28 | import static org.assertj.core.api.Assertions.fail; |
| 29 | -import static org.scassandra.http.client.PrimingRequest.Result.read_request_timeout; | |
| 30 | -import static org.scassandra.http.client.PrimingRequest.Result.unavailable; | |
| 31 | 29 | import static org.scassandra.http.client.PrimingRequest.queryBuilder; |
| 30 | +import static org.scassandra.http.client.Result.read_request_timeout; | |
| 31 | +import static org.scassandra.http.client.Result.unavailable; | |
| 32 | 32 | |
| 33 | 33 | public class LatencyAwarePolicyTest extends ScassandraTestBase { |
| 34 | 34 |
modified driver-core/src/test/java/com/datastax/driver/core/policies/LoggingRetryPolicyIntegrationTest.java +1 −1
| @@ -35,7 +35,7 @@ | ||
| 35 | 35 | import static com.datastax.driver.core.policies.RetryPolicy.RetryDecision.ignore; |
| 36 | 36 | import static com.datastax.driver.core.policies.RetryPolicy.RetryDecision.tryNextHost; |
| 37 | 37 | import static org.apache.log4j.Level.INFO; |
| 38 | -import static org.scassandra.http.client.PrimingRequest.Result.*; | |
| 38 | +import static org.scassandra.http.client.Result.*; | |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Integration tests with LoggingRetryPolicy. |
modified pom.xml +1 −1
| @@ -62,7 +62,7 @@ | ||
| 62 | 62 | <testng.version>6.8.8</testng.version> |
| 63 | 63 | <assertj.version>1.7.0</assertj.version> |
| 64 | 64 | <mockito.version>1.10.8</mockito.version> |
| 65 | - <scassandra.version>0.11.0</scassandra.version> | |
| 65 | + <scassandra.version>1.0.3</scassandra.version> | |
| 66 | 66 | <main.basedir>${project.basedir}</main.basedir> |
| 67 | 67 | </properties> |
| 68 | 68 |