Skip to content

Commit

Permalink
[Flapper] Reconnect test fix (#1189)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf authored Jul 29, 2024
1 parent 37d03e8 commit 376ba3b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/test/java/io/nats/client/impl/ReconnectTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,8 @@ public boolean includeAllServers() {
@Test
public void testForceReconnectQueueBehaviorCheck() throws Exception {
runInJsCluster((nc0, nc1, nc2) -> {
int pubCount = 1000000;
int subscribeTime = 4000;
int pubCount = 100_000;
int subscribeTime = 5000;
int flushWait = 2500;
int port = nc0.getServerInfo().getPort();

Expand Down Expand Up @@ -803,8 +803,11 @@ private static void _testForceReconnectQueueCheck(String subject, int pubCount,
froBuilder.forceClose();
}

ReconnectQueueCheckConnectionListener listener = new ReconnectQueueCheckConnectionListener();

Options options = Options.builder()
.server(getNatsLocalhostUri(port))
.connectionListener(listener)
.dataPortType(ForceReconnectQueueCheckDataPort.class.getCanonicalName())
.build();

Expand All @@ -815,6 +818,8 @@ private static void _testForceReconnectQueueCheck(String subject, int pubCount,

nc.forceReconnect(froBuilder.build());

assertTrue(listener.latch.await(subscribeTime, TimeUnit.MILLISECONDS));

long maxTime = subscribeTime;
while (!subscriber.subscriberDone.get() && maxTime > 0) {
//noinspection BusyWait
Expand All @@ -834,6 +839,17 @@ private static void _testForceReconnectQueueCheck(String subject, int pubCount,
}
}

static class ReconnectQueueCheckConnectionListener implements ConnectionListener {
public CountDownLatch latch = new CountDownLatch(1);

@Override
public void connectionEvent(Connection conn, Events type) {
if (type == Events.RECONNECTED) {
latch.countDown();
}
}
}

static class ReconnectQueueCheckSubscriber implements Runnable {
final AtomicBoolean subscriberDone;
final String subject;
Expand Down

0 comments on commit 376ba3b

Please sign in to comment.