@@ -765,8 +765,8 @@ public boolean includeAllServers() {
765765 @ Test
766766 public void testForceReconnectQueueBehaviorCheck () throws Exception {
767767 runInJsCluster ((nc0 , nc1 , nc2 ) -> {
768- int pubCount = 1000000 ;
769- int subscribeTime = 4000 ;
768+ int pubCount = 100_000 ;
769+ int subscribeTime = 5000 ;
770770 int flushWait = 2500 ;
771771 int port = nc0 .getServerInfo ().getPort ();
772772
@@ -803,8 +803,11 @@ private static void _testForceReconnectQueueCheck(String subject, int pubCount,
803803 froBuilder .forceClose ();
804804 }
805805
806+ ReconnectQueueCheckConnectionListener listener = new ReconnectQueueCheckConnectionListener ();
807+
806808 Options options = Options .builder ()
807809 .server (getNatsLocalhostUri (port ))
810+ .connectionListener (listener )
808811 .dataPortType (ForceReconnectQueueCheckDataPort .class .getCanonicalName ())
809812 .build ();
810813
@@ -815,6 +818,8 @@ private static void _testForceReconnectQueueCheck(String subject, int pubCount,
815818
816819 nc .forceReconnect (froBuilder .build ());
817820
821+ assertTrue (listener .latch .await (subscribeTime , TimeUnit .MILLISECONDS ));
822+
818823 long maxTime = subscribeTime ;
819824 while (!subscriber .subscriberDone .get () && maxTime > 0 ) {
820825 //noinspection BusyWait
@@ -834,6 +839,17 @@ private static void _testForceReconnectQueueCheck(String subject, int pubCount,
834839 }
835840 }
836841
842+ static class ReconnectQueueCheckConnectionListener implements ConnectionListener {
843+ public CountDownLatch latch = new CountDownLatch (1 );
844+
845+ @ Override
846+ public void connectionEvent (Connection conn , Events type ) {
847+ if (type == Events .RECONNECTED ) {
848+ latch .countDown ();
849+ }
850+ }
851+ }
852+
837853 static class ReconnectQueueCheckSubscriber implements Runnable {
838854 final AtomicBoolean subscriberDone ;
839855 final String subject ;
0 commit comments