@@ -1477,33 +1477,44 @@ public HttpCore.Response onRawHttpRequest(String id, HttpRequest request, String
14771477
14781478 // req3: fire in background — hits pinned fallback, sleeps 200 ms inside listener
14791479 ExecutorService executor = Executors .newSingleThreadExecutor ();
1480- Future <Long > requestFuture = executor .submit (() -> {
1481- try { return client .time (); }
1482- catch (AblyException e ) { throw new RuntimeException (e ); }
1483- });
1484-
1485- // Wait until req3 has actually entered the listener before starting the clock
1486- assertTrue ("Delayed request must start within 5 s" , delayedRequestStarted .await (5 , TimeUnit .SECONDS ));
1487-
1488- // Wait 150 ms so that fallbackRetryTimeout (100 ms) expires
1489- Thread .sleep (150L );
1490-
1491- // req4: timeout expired → primary tried again
1492- client .time ();
1493-
1494- // Wait for req3's delayed response to arrive (late fallback success)
1495- requestFuture .get (5 , TimeUnit .SECONDS );
1496-
1497- // req5: late success from req3 must NOT have re-pinned the fallback
1498- client .time ();
1499-
1500- executor .shutdown ();
1501-
1502- assertEquals (5 , capturedHosts .size ());
1503- assertEquals (primaryHost , capturedHosts .get (0 )); // req1 – primary fails
1504- assertEquals (fallbackHost , capturedHosts .get (1 )); // req2 – fallback pins
1505- assertEquals (fallbackHost , capturedHosts .get (2 )); // req3 – in-flight fallback
1506- assertEquals (primaryHost , capturedHosts .get (3 )); // req4 – timeout expired
1507- assertEquals (primaryHost , capturedHosts .get (4 )); // req5 – late success did not re-pin
1480+ try {
1481+ Future <Long > requestFuture = executor .submit (() -> {
1482+ try { return client .time (); }
1483+ catch (AblyException e ) { throw new RuntimeException (e ); }
1484+ });
1485+
1486+ // Wait until req3 has actually entered the listener before starting the clock
1487+ assertTrue ("Delayed request must start within 5 s" , delayedRequestStarted .await (5 , TimeUnit .SECONDS ));
1488+
1489+ // Wait 150 ms so that fallbackRetryTimeout (100 ms) expires
1490+ Thread .sleep (150L );
1491+
1492+ // req4: timeout expired → primary tried again
1493+ client .time ();
1494+
1495+ // Wait for req3's delayed response to arrive (late fallback success)
1496+ requestFuture .get (5 , TimeUnit .SECONDS );
1497+
1498+ // req5: late success from req3 must NOT have re-pinned the fallback
1499+ client .time ();
1500+
1501+ assertEquals (5 , capturedHosts .size ());
1502+ assertEquals (primaryHost , capturedHosts .get (0 )); // req1 – primary fails
1503+ assertEquals (fallbackHost , capturedHosts .get (1 )); // req2 – fallback pins
1504+ assertEquals (fallbackHost , capturedHosts .get (2 )); // req3 – in-flight fallback
1505+ assertEquals (primaryHost , capturedHosts .get (3 )); // req4 – timeout expired
1506+ assertEquals (primaryHost , capturedHosts .get (4 )); // req5 – late success did not re-pin
1507+ } finally {
1508+ executor .shutdown ();
1509+ try {
1510+ if (!executor .awaitTermination (5 , TimeUnit .SECONDS )) {
1511+ executor .shutdownNow ();
1512+ executor .awaitTermination (5 , TimeUnit .SECONDS );
1513+ }
1514+ } catch (InterruptedException e ) {
1515+ executor .shutdownNow ();
1516+ Thread .currentThread ().interrupt ();
1517+ }
1518+ }
15081519 }
15091520}
0 commit comments