Skip to content

Commit d0d394d

Browse files
tolbertamolim7t
authored andcommitted
Handle case where [UP, ADDED] are coalesced together.
1 parent 671e38d commit d0d394d

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

driver-core/src/main/java/com/datastax/driver/core/Cluster.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2448,8 +2448,15 @@ public ListenableFuture<?> deliver(List<NodeRefreshRequest> events) {
24482448
break;
24492449
case ADDED:
24502450
Host newHost = metadata.add(address);
2451-
if (newHost != null)
2451+
if (newHost != null) {
24522452
futures.add(schedule(hostAdded(newHost)));
2453+
} else {
2454+
// If host already existed, retrieve it and check its state, if it's not up schedule a
2455+
// hostUp event.
2456+
Host existingHost = metadata.getHost(address);
2457+
if(!existingHost.isUp())
2458+
futures.add(schedule(hostUp(existingHost)));
2459+
}
24532460
break;
24542461
case DOWN:
24552462
// Note that there is a slight risk we can receive the event late and thus

driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void should_reconnect_after_full_connectivity_loss() throws InterruptedEx
6969
ccm.start(2);
7070
ccm.waitForUp(2);
7171

72-
assertThat(cluster).host(2).comesUpWithin(120, SECONDS);
72+
assertThat(cluster).host(2).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS*2, SECONDS);
7373

7474
// Give the control connection a few moments to reconnect
7575
TimeUnit.MILLISECONDS.sleep(reconnectionDelay * 2);
@@ -128,7 +128,7 @@ public void should_keep_reconnecting_on_authentication_error() throws Interrupte
128128
authProvider.setPassword("cassandra");
129129

130130
// The driver should eventually reconnect to the node
131-
assertThat(cluster).host(1).comesUpWithin(120, SECONDS);
131+
assertThat(cluster).host(1).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS*2, SECONDS);
132132
} finally {
133133
if (cluster != null)
134134
cluster.close();
@@ -168,7 +168,7 @@ public void should_cancel_reconnection_attempts() throws InterruptedException {
168168
ccm.waitForUp(2);
169169

170170
// The driver should now see the node as UP again
171-
assertThat(cluster).host(2).comesUpWithin(120, SECONDS);
171+
assertThat(cluster).host(2).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS*2, SECONDS);
172172

173173
} finally {
174174
if (cluster != null)
@@ -229,7 +229,7 @@ public void should_trigger_one_time_reconnect() throws InterruptedException, IOE
229229
// Trigger another one-time reconnection attempt (this will succeed). The
230230
// host should be back up.
231231
host1.tryReconnectOnce();
232-
assertThat(cluster).host(1).comesUpWithin(120, SECONDS);
232+
assertThat(cluster).host(1).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS*2, SECONDS);
233233
} finally {
234234
if (cluster != null)
235235
cluster.close();
@@ -285,7 +285,7 @@ public void should_use_connection_from_reconnection_in_pool() {
285285
// Reset the spy and count the number of connections attempts for 1 reconnect
286286
reset(socketOptions);
287287
host1.tryReconnectOnce();
288-
assertThat(cluster).host(1).comesUpWithin(120, SECONDS);
288+
assertThat(cluster).host(1).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS*2, SECONDS);
289289
// Expect 1 connection from the reconnection attempt 3 for the pools (we need 4
290290
// but the one from the reconnection attempt gets reused).
291291
verify(socketOptions, times(4)).getKeepAlive();

0 commit comments

Comments
 (0)