Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flapper] Reconnect test fix #1189

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading