kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 87dc28d80ecc720f07062707295ce32a8c7bdcfcaba89e22a6017567dcde52bb |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2016-07-19 12:53 -05:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2016-07-19 10:53 -07:00 |
| Parents | 465ac6b8b47f |
5 files changed
modified driver-core/src/test/java/com/datastax/driver/core/QueryLoggerErrorsTest.java +28 −24
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.exceptions.*; |
| 19 | +import com.datastax.driver.core.policies.FallthroughRetryPolicy; | |
| 19 | 20 | import com.google.common.util.concurrent.Uninterruptibles; |
| 20 | 21 | import org.apache.log4j.Level; |
| 21 | 22 | import org.apache.log4j.Logger; |
| @@ -66,7 +67,7 @@ | ||
| 66 | 67 | |
| 67 | 68 | queryLogger = null; |
| 68 | 69 | |
| 69 | - cluster = createClusterBuilder().build(); | |
| 70 | + cluster = createClusterBuilder().withRetryPolicy(FallthroughRetryPolicy.INSTANCE).build(); | |
| 70 | 71 | session = cluster.connect(); |
| 71 | 72 | } |
| 72 | 73 | |
| @@ -175,8 +176,8 @@ | ||
| 175 | 176 | // when |
| 176 | 177 | try { |
| 177 | 178 | session.execute(query); |
| 178 | - fail("Should have thrown NoHostAvailableException"); | |
| 179 | - } catch (NoHostAvailableException e) { | |
| 179 | + fail("Should have thrown OperationTimedOutException"); | |
| 180 | + } catch (OperationTimedOutException e) { | |
| 180 | 181 | // ok |
| 181 | 182 | } |
| 182 | 183 | // then |
| @@ -192,25 +193,25 @@ | ||
| 192 | 193 | @DataProvider(name = "errors") |
| 193 | 194 | public static Object[][] createErrors() { |
| 194 | 195 | return new Object[][]{ |
| 195 | - {unavailable, NoHostAvailableException.class, UnavailableException.class}, | |
| 196 | - {write_request_timeout, WriteTimeoutException.class, WriteTimeoutException.class}, | |
| 197 | - {read_request_timeout, ReadTimeoutException.class, ReadTimeoutException.class}, | |
| 198 | - {server_error, NoHostAvailableException.class, ServerError.class}, | |
| 199 | - {protocol_error, ProtocolError.class, ProtocolError.class}, | |
| 200 | - {bad_credentials, AuthenticationException.class, AuthenticationException.class}, | |
| 201 | - {overloaded, NoHostAvailableException.class, OverloadedException.class}, | |
| 202 | - {is_bootstrapping, NoHostAvailableException.class, BootstrappingException.class}, | |
| 203 | - {truncate_error, TruncateException.class, TruncateException.class}, | |
| 204 | - {syntax_error, SyntaxError.class, SyntaxError.class}, | |
| 205 | - {invalid, InvalidQueryException.class, InvalidQueryException.class}, | |
| 206 | - {config_error, InvalidConfigurationInQueryException.class, InvalidConfigurationInQueryException.class}, | |
| 207 | - {already_exists, AlreadyExistsException.class, AlreadyExistsException.class}, | |
| 208 | - {unprepared, DriverInternalError.class, UnpreparedException.class} | |
| 196 | + {unavailable, UnavailableException.class}, | |
| 197 | + {write_request_timeout, WriteTimeoutException.class}, | |
| 198 | + {read_request_timeout, ReadTimeoutException.class}, | |
| 199 | + {server_error, ServerError.class}, | |
| 200 | + {protocol_error, ProtocolError.class}, | |
| 201 | + {bad_credentials, AuthenticationException.class}, | |
| 202 | + {overloaded, OverloadedException.class}, | |
| 203 | + {is_bootstrapping, BootstrappingException.class}, | |
| 204 | + {truncate_error, TruncateException.class}, | |
| 205 | + {syntax_error, SyntaxError.class}, | |
| 206 | + {invalid, InvalidQueryException.class}, | |
| 207 | + {config_error, InvalidConfigurationInQueryException.class}, | |
| 208 | + {already_exists, AlreadyExistsException.class}, | |
| 209 | + {unprepared, UnpreparedException.class} | |
| 209 | 210 | }; |
| 210 | 211 | } |
| 211 | 212 | |
| 212 | 213 | @Test(groups = "short", dataProvider = "errors") |
| 213 | - public void should_log_exception_from_the_given_result(Result result, Class<? extends Exception> expectedException, Class<? extends Exception> loggedException) throws Exception { | |
| 214 | + public void should_log_exception_from_the_given_result(Result result, Class<? extends Exception> expectedException) throws Exception { | |
| 214 | 215 | // given |
| 215 | 216 | error.setLevel(DEBUG); |
| 216 | 217 | queryLogger = builder().build(); |
| @@ -225,12 +226,15 @@ | ||
| 225 | 226 | // when |
| 226 | 227 | try { |
| 227 | 228 | session.execute(query); |
| 228 | - fail("Should have thrown NoHostAvailableException"); | |
| 229 | + fail("Should have thrown Exception"); | |
| 229 | 230 | } catch (Exception e) { |
| 230 | - if (e instanceof NoHostAvailableException) { | |
| 231 | - assertThat(expectedException).isEqualTo(NoHostAvailableException.class); | |
| 232 | - Throwable error = ((NoHostAvailableException) e).getErrors().get(hostAddress); | |
| 233 | - assertThat(error).isNotNull().isOfAnyClassIn(loggedException); | |
| 231 | + if (expectedException == UnpreparedException.class) { | |
| 232 | + // Special case UnpreparedException, it raises DriverInternalError instead. | |
| 233 | + assertThat(e).isInstanceOf(DriverInternalError.class); | |
| 234 | + } else if (expectedException == BootstrappingException.class) { | |
| 235 | + // Special case BootstrappingException, it's wrapped in NHAE since it's always retried. | |
| 236 | + assertThat(e).isInstanceOf(NoHostAvailableException.class); | |
| 237 | + assertThat(((NoHostAvailableException) e).getErrors().get(hostAddress)).isInstanceOf(expectedException); | |
| 234 | 238 | } else { |
| 235 | 239 | assertThat(e).isInstanceOf(expectedException); |
| 236 | 240 | } |
| @@ -242,7 +246,7 @@ | ||
| 242 | 246 | .contains(ip) |
| 243 | 247 | .contains(Integer.toString(scassandra.getBinaryPort())) |
| 244 | 248 | .contains(query) |
| 245 | - .contains(loggedException.getName()); | |
| 249 | + .contains(expectedException.getName()); | |
| 246 | 250 | } |
| 247 | 251 | |
| 248 | 252 | } |
modified driver-core/src/test/java/com/datastax/driver/core/ReadTimeoutTest.java +2 −11
| @@ -15,13 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 19 | 18 | import com.datastax.driver.core.exceptions.OperationTimedOutException; |
| 20 | 19 | import org.testng.annotations.BeforeMethod; |
| 21 | 20 | import org.testng.annotations.Test; |
| 22 | 21 | |
| 23 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 24 | -import static org.assertj.core.api.Assertions.fail; | |
| 25 | 22 | import static org.scassandra.http.client.PrimingRequest.queryBuilder; |
| 26 | 23 | import static org.scassandra.http.client.PrimingRequest.then; |
| 27 | 24 | |
| @@ -42,15 +39,9 @@ | ||
| 42 | 39 | cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(10); |
| 43 | 40 | } |
| 44 | 41 | |
| 45 | - @Test(groups = "short") | |
| 42 | + @Test(groups = "short", expectedExceptions = OperationTimedOutException.class) | |
| 46 | 43 | public void should_use_default_timeout_if_not_overridden_by_statement() { |
| 47 | - try { | |
| 48 | - session.execute(query); | |
| 49 | - fail("expected a timeout"); | |
| 50 | - } catch (NoHostAvailableException e) { | |
| 51 | - Throwable t = e.getErrors().values().iterator().next(); | |
| 52 | - assertThat(t).isInstanceOf(OperationTimedOutException.class); | |
| 53 | - } | |
| 44 | + session.execute(query); | |
| 54 | 45 | } |
| 55 | 46 | |
| 56 | 47 | @Test(groups = "short") |
modified driver-core/src/test/java/com/datastax/driver/core/ReusedStreamIdTest.java +3 −3
| @@ -15,7 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 18 | +import com.datastax.driver.core.exceptions.OperationTimedOutException; | |
| 19 | 19 | import com.google.common.util.concurrent.FutureCallback; |
| 20 | 20 | import com.google.common.util.concurrent.Futures; |
| 21 | 21 | import com.google.common.util.concurrent.Uninterruptibles; |
| @@ -116,8 +116,8 @@ | ||
| 116 | 116 | @Override |
| 117 | 117 | public void onFailure(Throwable t) { |
| 118 | 118 | semaphore.release(); |
| 119 | - // NHAEs are inevitable because of low query timeouts and blocked threads. | |
| 120 | - if (!(t instanceof NoHostAvailableException)) { | |
| 119 | + // Timeouts are inevitable because of low query timeouts and blocked threads. | |
| 120 | + if (!(t instanceof OperationTimedOutException)) { | |
| 121 | 121 | logger.error("Unexpected error encountered.", t); |
| 122 | 122 | errorTrigger.countDown(); |
| 123 | 123 | } |
modified driver-core/src/test/java/com/datastax/driver/core/policies/AbstractRetryPolicyIntegrationTest.java +2 −0
| @@ -89,6 +89,8 @@ | ||
| 89 | 89 | .setMaxConnectionsPerHost(HostDistance.LOCAL, 1) |
| 90 | 90 | .setHeartbeatIntervalSeconds(0)) |
| 91 | 91 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 92 | + // Mark everything as idempotent by default so RetryPolicy is exercised. | |
| 93 | + .withQueryOptions(new QueryOptions().setDefaultIdempotence(true)) | |
| 92 | 94 | .build(); |
| 93 | 95 | |
| 94 | 96 | session = cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/IdempotenceAwareRetryPolicyIntegrationTest.java +8 −4
| @@ -52,7 +52,8 @@ | ||
| 52 | 52 | query(); |
| 53 | 53 | fail("expected an WriteTimeoutException"); |
| 54 | 54 | } catch (WriteTimeoutException e) {/* expected */} |
| 55 | - assertOnWriteTimeoutWasCalled(1); | |
| 55 | + // Should not have even been called as statement was not idempotent. | |
| 56 | + assertOnWriteTimeoutWasCalled(0); | |
| 56 | 57 | assertThat(errors.getWriteTimeouts().getCount()).isEqualTo(1); |
| 57 | 58 | assertThat(errors.getRetries().getCount()).isEqualTo(0); |
| 58 | 59 | assertThat(errors.getRetriesOnWriteTimeout().getCount()).isEqualTo(0); |
| @@ -91,7 +92,8 @@ | ||
| 91 | 92 | String.format("[%s] Timed out waiting for server response", host1.getSocketAddress()) |
| 92 | 93 | ); |
| 93 | 94 | } |
| 94 | - assertOnRequestErrorWasCalled(1, OperationTimedOutException.class); | |
| 95 | + // Should not have even been called as statement was not idempotent. | |
| 96 | + assertOnRequestErrorWasCalled(0, OperationTimedOutException.class); | |
| 95 | 97 | assertThat(errors.getClientTimeouts().getCount()).isEqualTo(1); |
| 96 | 98 | assertThat(errors.getRetries().getCount()).isEqualTo(0); |
| 97 | 99 | assertThat(errors.getRetriesOnClientTimeout().getCount()).isEqualTo(0); |
| @@ -135,7 +137,8 @@ | ||
| 135 | 137 | } catch (DriverException e) { |
| 136 | 138 | assertThat(e).isInstanceOf(exception); |
| 137 | 139 | } |
| 138 | - assertOnRequestErrorWasCalled(1, ServerError.class); | |
| 140 | + // Should not have even been called as statement was not idempotent. | |
| 141 | + assertOnRequestErrorWasCalled(0, ServerError.class); | |
| 139 | 142 | assertThat(errors.getOthers().getCount()).isEqualTo(1); |
| 140 | 143 | assertThat(errors.getRetries().getCount()).isEqualTo(0); |
| 141 | 144 | assertThat(errors.getRetriesOnOtherErrors().getCount()).isEqualTo(0); |
| @@ -183,7 +186,8 @@ | ||
| 183 | 186 | String.format("[%s] Connection has been closed", host1.getSocketAddress()) |
| 184 | 187 | ); |
| 185 | 188 | } |
| 186 | - assertOnRequestErrorWasCalled(1, TransportException.class); | |
| 189 | + // Should not have even been called as statement was not idempotent. | |
| 190 | + assertOnRequestErrorWasCalled(0, TransportException.class); | |
| 187 | 191 | assertThat(errors.getRetries().getCount()).isEqualTo(0); |
| 188 | 192 | assertThat(errors.getConnectionErrors().getCount()).isEqualTo(1); |
| 189 | 193 | assertThat(errors.getIgnoresOnConnectionError().getCount()).isEqualTo(0); |