@Override
  protected Promise<Void> doShutdown() {
    final Promise<Void> promise = Promises.ready();

    threadPool.shutdownNow();
    promise.onComplete();

    return promise;
  }
Example #2
0
  @SuppressWarnings("unchecked")
  protected <T> void assertTcpClientServerExchangedData(
      Class<? extends reactor.io.net.tcp.TcpServer> serverType,
      Class<? extends reactor.io.net.tcp.TcpClient> clientType,
      Codec<Buffer, T, T> codec,
      T data,
      Predicate<T> replyPredicate)
      throws InterruptedException {
    final Codec<Buffer, T, T> elCodec =
        codec == null ? (Codec<Buffer, T, T>) StandardCodecs.PASS_THROUGH_CODEC : codec;

    TcpServer<T, T> server =
        NetStreams.tcpServer(
            serverType, s -> s.env(env1).listen(LOCALHOST, getPort()).codec(elCodec));

    server.start(ch -> ch.writeWith(ch.take(1))).await();

    TcpClient<T, T> client =
        NetStreams.tcpClient(
            clientType, s -> s.env(env2).connect(LOCALHOST, getPort()).codec(elCodec));

    final Promise<T> p = Promises.prepare();

    client
        .start(
            input -> {
              input.log("echo-in").subscribe(p);
              return input.writeWith(Streams.just(data).log("echo-out")).log("echo.close");
            })
        .await();

    T reply = p.await(50, TimeUnit.SECONDS);

    assertTrue("reply was correct", replyPredicate.test(reply));

    //		assertServerStopped(server);
    //		assertClientStopped(client);
  }