@Test public void testConnectionClosedAfterPingTimeout() throws Exception { sockJSHandler.bridge(allAccessOptions.setPingTimeout(1000)); CountDownLatch latch = new CountDownLatch(1); long start = System.currentTimeMillis(); client.websocket(websocketURI, ws -> ws.closeHandler(v -> latch.countDown())); awaitLatch(latch); long dur = System.currentTimeMillis() - start; assertTrue(dur > 1000 && dur < 3000); }
@Test public void testTimeoutCloseCode() { router.route("/ws-timeout/*").handler(SockJSHandler .create(vertx) .bridge(new BridgeOptions().setPingTimeout(1)) ); client.websocket("/ws-timeout/websocket", ws -> ws.frameHandler(frame -> { if (frame.isClose()) { assertEquals(1001, frame.closeStatusCode()); assertEquals("Session expired", frame.closeReason()); testComplete(); } })); await(); }
/** * Configures and binds the SockJS bridge to an HttpServer. * * @param router router */ public void install(Router router) { BridgeOptions bridgeOptions = new BridgeOptions() .addOutboundPermitted(new PermittedOptions().setAddressRegex(addressPrefix + "(.*)")); if (eventbusBridgePingInterval != null) { bridgeOptions = bridgeOptions.setPingTimeout(eventbusBridgePingInterval); } router.route(sockPath).handler(SockJSHandler.create(vertx).bridge(bridgeOptions)); log.info("Installed SockJS endpoint on " + sockPath); log.info("Listening to requests on " + adressPathPattern.pattern()); log.info("Using address prefix " + addressPrefix); }
@Test public void testConnectionClosedAfterPingTimeout() throws Exception { sockJSHandler.bridge(allAccessOptions.setPingTimeout(1000)); CountDownLatch latch = new CountDownLatch(1); long start = System.currentTimeMillis(); client.websocket(websocketURI, ws -> ws.closeHandler(v -> latch.countDown())); awaitLatch(latch); long dur = System.currentTimeMillis() - start; assertTrue(dur > 1000 && dur < 3000); }
@Test public void testTimeoutCloseCode() { router.route("/ws-timeout/*").handler(SockJSHandler .create(vertx) .bridge(new BridgeOptions().setPingTimeout(1)) ); client.websocket("/ws-timeout/websocket", ws -> ws.frameHandler(frame -> { if (frame.isClose()) { assertEquals(1001, frame.closeStatusCode()); assertEquals("Session expired", frame.closeReason()); testComplete(); } })); await(); }