Elffuss BraidHub

kikocis/java-driver public

Delay and retry if reconnection attempt hasn't started after onDown.
Changesetd49ddcef7ef272d74bfd143ec2e890bdcb0594e42bce5cf58d2d3dbd6f9143c6
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-11-04 21:16 -06:00
Committerolim7t <omichallat+github@gmail.com> · 2015-11-05 18:37 +01:00
Parents8b3f03416ef1

Browse the files at this changeset

1 file changed

modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +9 −0
@@ -27,6 +27,7 @@
2727 import com.google.common.collect.ImmutableMap;
2828 import com.google.common.collect.ImmutableSet;
2929 import com.google.common.collect.Lists;
30+import com.google.common.util.concurrent.Uninterruptibles;
3031 import org.scassandra.Scassandra;
3132 import org.scassandra.http.client.PrimingClient;
3233 import org.scassandra.http.client.PrimingRequest;
@@ -132,6 +133,14 @@
132133 // called and submit a task that marks the host down.
133134 for (FakeHost failingHost : failingHosts) {
134135 assertThat(cluster).host(failingHost.address).goesDownWithin(10, TimeUnit.SECONDS);
136+ Host host = TestUtils.findHost(cluster, failingHost.address);
137+ // There is a possible race here in that the host is marked down in a separate Executor in onDown
138+ // and then starts a periodic reconnection attempt shortly after. Since setDown is called before
139+ // startPeriodicReconnectionAttempt, we add a slight delay here if the future isn't set yet.
140+ if(host.getReconnectionAttemptFuture() == null || host.getReconnectionAttemptFuture().isDone()) {
141+ logger.warn("Periodic Reconnection Attempt hasn't started yet for {}, waiting 1 second and then checking.", host);
142+ Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
143+ }
135144 assertThat(cluster).host(failingHost.address).isReconnectingFromDown();
136145 }
137146 assertThat(cluster).host(missingHostAddress).isNull();