kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 454582a51f311dad5fbd597172a7e9a70abd2aec4bec7ed8b9105896f8fa4f4b |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-06-29 22:06 +02:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-06-29 22:06 +02:00 |
| Parents | abc58841fcf3, c8257c424597 |
5 files changed
modified driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java +2 −0
| @@ -579,6 +579,8 @@ | ||
| 579 | 579 | logger.debug("Doing retry {} for query {} at consistency {}", retriesByPolicy, statement, retry.getRetryConsistencyLevel()); |
| 580 | 580 | if (metricsEnabled()) |
| 581 | 581 | metrics().getErrorMetrics().getRetries().inc(); |
| 582 | + if (!retry.isRetryCurrent()) | |
| 583 | + logError(connection.address, exceptionToReport); | |
| 582 | 584 | retry(retry.isRetryCurrent(), retry.getRetryConsistencyLevel()); |
| 583 | 585 | break; |
| 584 | 586 | case RETHROW: |
modified driver-core/src/test/java/com/datastax/driver/core/QueryLoggerErrorsTest.java +6 −2
| @@ -214,11 +214,15 @@ | ||
| 214 | 214 | .build() |
| 215 | 215 | ); |
| 216 | 216 | // when |
| 217 | + // when | |
| 217 | 218 | try { |
| 218 | 219 | session.execute(query); |
| 219 | - fail("Should have thrown UnavailableException"); | |
| 220 | - } catch (UnavailableException e) { | |
| 220 | + fail("Should have thrown NoHostAvailableException"); | |
| 221 | + } catch(NoHostAvailableException e) { | |
| 221 | 222 | // ok |
| 223 | + Throwable error = e.getErrors().get(hostAddress); | |
| 224 | + assertThat(error).isNotNull(); | |
| 225 | + assertThat(error).isInstanceOf(UnavailableException.class); | |
| 222 | 226 | } |
| 223 | 227 | // then |
| 224 | 228 | String line = errorAppender.waitAndGet(5000); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/AbstractRetryPolicyIntegrationTest.java +4 −0
| @@ -105,6 +105,10 @@ | ||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | protected ResultSet query() { |
| 108 | + return query(session); | |
| 109 | + } | |
| 110 | + | |
| 111 | + protected ResultSet query(Session session) { | |
| 108 | 112 | return session.execute("mock query"); |
| 109 | 113 | } |
| 110 | 114 |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DefaultRetryPolicyIntegrationTest.java +48 −0
| @@ -15,6 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.CCMBridge; | |
| 19 | +import com.datastax.driver.core.Cluster; | |
| 20 | +import com.datastax.driver.core.Metrics; | |
| 21 | +import com.datastax.driver.core.Session; | |
| 22 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 18 | 23 | import org.testng.annotations.Test; |
| 19 | 24 | |
| 20 | 25 | import static org.assertj.core.api.Assertions.assertThat; |
| @@ -27,6 +32,8 @@ | ||
| 27 | 32 | import com.datastax.driver.core.exceptions.UnavailableException; |
| 28 | 33 | import com.datastax.driver.core.exceptions.WriteTimeoutException; |
| 29 | 34 | |
| 35 | +import java.util.Collections; | |
| 36 | + | |
| 30 | 37 | public class DefaultRetryPolicyIntegrationTest extends AbstractRetryPolicyIntegrationTest { |
| 31 | 38 | public DefaultRetryPolicyIntegrationTest() { |
| 32 | 39 | super(DefaultRetryPolicy.INSTANCE); |
| @@ -94,4 +101,45 @@ | ||
| 94 | 101 | assertQueried(2, 1); |
| 95 | 102 | assertQueried(3, 0); |
| 96 | 103 | } |
| 104 | + | |
| 105 | + @Test(groups = "short") | |
| 106 | + public void should_rethrow_unavailable_in_no_host_available_exception() { | |
| 107 | + LoadBalancingPolicy firstHostOnlyPolicy = | |
| 108 | + new WhiteListPolicy(Policies.defaultLoadBalancingPolicy(), | |
| 109 | + Collections.singletonList(host1.getSocketAddress())); | |
| 110 | + | |
| 111 | + Cluster whiteListedCluster = Cluster.builder() | |
| 112 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 113 | + .withRetryPolicy(retryPolicy) | |
| 114 | + .withLoadBalancingPolicy(firstHostOnlyPolicy) | |
| 115 | + .build(); | |
| 116 | + | |
| 117 | + try { | |
| 118 | + Session whiteListedSession = whiteListedCluster.connect(); | |
| 119 | + // Clear all activity as result of connect. | |
| 120 | + scassandras.clearAllRecordedActivity(); | |
| 121 | + | |
| 122 | + simulateError(1, unavailable); | |
| 123 | + | |
| 124 | + try { | |
| 125 | + query(whiteListedSession); | |
| 126 | + fail("expected an NoHostAvailableException"); | |
| 127 | + } catch(NoHostAvailableException e) { | |
| 128 | + // ok | |
| 129 | + Throwable error = e.getErrors().get(host1.getSocketAddress()); | |
| 130 | + assertThat(error).isNotNull(); | |
| 131 | + assertThat(error).isInstanceOf(UnavailableException.class); | |
| 132 | + } | |
| 133 | + | |
| 134 | + assertOnUnavailableWasCalled(1); | |
| 135 | + // We expect a retry, but it was never sent because there were no more hosts. | |
| 136 | + Metrics.Errors whiteListErrors = whiteListedCluster.getMetrics().getErrorMetrics(); | |
| 137 | + assertThat(whiteListErrors.getRetriesOnUnavailable().getCount()).isEqualTo(1); | |
| 138 | + assertQueried(1, 1); | |
| 139 | + assertQueried(2, 0); | |
| 140 | + assertQueried(3, 0); | |
| 141 | + } finally { | |
| 142 | + whiteListedCluster.close(); | |
| 143 | + } | |
| 144 | + } | |
| 97 | 145 | } |
modified driver-core/src/test/java/com/datastax/driver/core/policies/LatencyAwarePolicyTest.java +6 −2
| @@ -19,6 +19,7 @@ | ||
| 19 | 19 | |
| 20 | 20 | import static java.util.concurrent.TimeUnit.SECONDS; |
| 21 | 21 | |
| 22 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 22 | 23 | import org.testng.annotations.Test; |
| 23 | 24 | |
| 24 | 25 | import static org.assertj.core.api.Assertions.assertThat; |
| @@ -111,9 +112,12 @@ | ||
| 111 | 112 | // when |
| 112 | 113 | try { |
| 113 | 114 | session.execute(query); |
| 114 | - fail("Should have thrown UnavailableException"); | |
| 115 | - } catch(UnavailableException e) { | |
| 115 | + fail("Should have thrown NoHostAvailableException"); | |
| 116 | + } catch(NoHostAvailableException e) { | |
| 116 | 117 | // ok |
| 118 | + Throwable error = e.getErrors().get(hostAddress); | |
| 119 | + assertThat(error).isNotNull(); | |
| 120 | + assertThat(error).isInstanceOf(UnavailableException.class); | |
| 117 | 121 | } |
| 118 | 122 | // then |
| 119 | 123 | // wait until trackers have been notified |