Exemplo n.º 1
0
 protected void tearDown() throws Exception {
   client.close();
   if (server != null) {
     CountDownLatch latch = new CountDownLatch(1);
     server.close(
         ar -> {
           assertTrue(ar.succeeded());
           latch.countDown();
         });
     awaitLatch(latch);
   }
   super.tearDown();
 }
Exemplo n.º 2
0
 @Test
 public void testWebsocketPauseAndResume() {
   client.close();
   client = vertx.createHttpClient(new HttpClientOptions().setConnectTimeout(1000));
   String path = "/some/path";
   this.server =
       vertx.createHttpServer(
           new HttpServerOptions().setAcceptBacklog(1).setPort(HttpTestBase.DEFAULT_HTTP_PORT));
   AtomicBoolean paused = new AtomicBoolean();
   ReadStream<ServerWebSocket> stream = server.websocketStream();
   stream.handler(
       ws -> {
         assertFalse(paused.get());
         ws.writeMessage(Buffer.buffer("whatever"));
         ws.close();
       });
   server.listen(
       listenAR -> {
         assertTrue(listenAR.succeeded());
         stream.pause();
         paused.set(true);
         client
             .websocket(HttpTestBase.DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, path)
             .exceptionHandler(
                 err -> {
                   assertTrue(paused.get());
                   assertTrue(err instanceof WebSocketHandshakeException);
                   paused.set(false);
                   stream.resume();
                   client.connectWebsocket(
                       HttpTestBase.DEFAULT_HTTP_PORT,
                       HttpTestBase.DEFAULT_HTTP_HOST,
                       path,
                       ws -> {
                         ws.handler(
                             buffer -> {
                               assertEquals("whatever", buffer.toString("UTF-8"));
                               ws.closeHandler(
                                   v2 -> {
                                     testComplete();
                                   });
                             });
                       });
                 })
             .handler(ws -> fail());
       });
   await();
 }