@Test public void testCloseSessionFactory() throws Exception { ServerLocator locator = createInVMNonHALocator().setReconnectAttempts(-1).setConnectionTTL(1000).setClientFailureCheckPeriod(100).setConsumerWindowSize(10 * 1024 * 1024).setCallTimeout(1000); ClientSessionFactory sf = locator.createSessionFactory(); final CountDownLatch latch = new CountDownLatch(1); sf.addFailoverListener(eventType -> { if (eventType == FailoverEventType.FAILURE_DETECTED) { try { /** * We close client session factory during this period and * expect reconnection stopped without exception which notifies * FAILOVER_FAILED event. See ARTEMIS-1949. */ Thread.sleep(1000L); } catch (InterruptedException e) { e.printStackTrace(); } } else if (eventType == FailoverEventType.FAILOVER_FAILED) { latch.countDown(); } }); server.stop(); Thread.sleep(600); sf.close(); assertTrue(latch.await(1000, TimeUnit.MILLISECONDS)); } }