Example #1
0
  @Test
  public void testVoidMessageCompressed() {
    serviceA.registerHandler(
        "sayHello",
        new BaseTransportRequestHandler<TransportRequest.Empty>() {
          @Override
          public TransportRequest.Empty newInstance() {
            return TransportRequest.Empty.INSTANCE;
          }

          @Override
          public String executor() {
            return ThreadPool.Names.GENERIC;
          }

          @Override
          public void messageReceived(TransportRequest.Empty request, TransportChannel channel) {
            try {
              channel.sendResponse(
                  TransportResponse.Empty.INSTANCE,
                  TransportResponseOptions.options().withCompress(true));
            } catch (IOException e) {
              e.printStackTrace();
              assertThat(e.getMessage(), false, equalTo(true));
            }
          }
        });

    TransportFuture<TransportResponse.Empty> res =
        serviceB.submitRequest(
            nodeA,
            "sayHello",
            TransportRequest.Empty.INSTANCE,
            TransportRequestOptions.options().withCompress(true),
            new BaseTransportResponseHandler<TransportResponse.Empty>() {
              @Override
              public TransportResponse.Empty newInstance() {
                return TransportResponse.Empty.INSTANCE;
              }

              @Override
              public String executor() {
                return ThreadPool.Names.GENERIC;
              }

              @Override
              public void handleResponse(TransportResponse.Empty response) {}

              @Override
              public void handleException(TransportException exp) {
                exp.printStackTrace();
                assertThat(
                    "got exception instead of a response: " + exp.getMessage(),
                    false,
                    equalTo(true));
              }
            });

    try {
      TransportResponse.Empty message = res.get();
      assertThat(message, notNullValue());
    } catch (Exception e) {
      assertThat(e.getMessage(), false, equalTo(true));
    }

    serviceA.removeHandler("sayHello");
  }
Example #2
0
  @Test
  public void testHelloWorldCompressed() {
    serviceA.registerHandler(
        "sayHello",
        new BaseTransportRequestHandler<StringMessageRequest>() {
          @Override
          public StringMessageRequest newInstance() {
            return new StringMessageRequest();
          }

          @Override
          public String executor() {
            return ThreadPool.Names.GENERIC;
          }

          @Override
          public void messageReceived(StringMessageRequest request, TransportChannel channel) {
            assertThat("moshe", equalTo(request.message));
            try {
              channel.sendResponse(
                  new StringMessageResponse("hello " + request.message),
                  TransportResponseOptions.options().withCompress(true));
            } catch (IOException e) {
              e.printStackTrace();
              assertThat(e.getMessage(), false, equalTo(true));
            }
          }
        });

    TransportFuture<StringMessageResponse> res =
        serviceB.submitRequest(
            nodeA,
            "sayHello",
            new StringMessageRequest("moshe"),
            TransportRequestOptions.options().withCompress(true),
            new BaseTransportResponseHandler<StringMessageResponse>() {
              @Override
              public StringMessageResponse newInstance() {
                return new StringMessageResponse();
              }

              @Override
              public String executor() {
                return ThreadPool.Names.GENERIC;
              }

              @Override
              public void handleResponse(StringMessageResponse response) {
                assertThat("hello moshe", equalTo(response.message));
              }

              @Override
              public void handleException(TransportException exp) {
                exp.printStackTrace();
                assertThat(
                    "got exception instead of a response: " + exp.getMessage(),
                    false,
                    equalTo(true));
              }
            });

    try {
      StringMessageResponse message = res.get();
      assertThat("hello moshe", equalTo(message.message));
    } catch (Exception e) {
      assertThat(e.getMessage(), false, equalTo(true));
    }

    serviceA.removeHandler("sayHello");
  }
  @Test
  public void testHelloWorld() {
    serviceA.registerHandler(
        "sayHello",
        new BaseTransportRequestHandler<StringMessage>() {
          @Override
          public StringMessage newInstance() {
            return new StringMessage();
          }

          @Override
          public void messageReceived(StringMessage request, TransportChannel channel) {
            System.out.println("got message: " + request.message);
            assertThat("moshe", equalTo(request.message));
            try {
              channel.sendResponse(new StringMessage("hello " + request.message));
            } catch (IOException e) {
              e.printStackTrace();
              assertThat(e.getMessage(), false, equalTo(true));
            }
          }
        });

    TransportFuture<StringMessage> res =
        serviceB.submitRequest(
            serviceANode,
            "sayHello",
            new StringMessage("moshe"),
            new BaseTransportResponseHandler<StringMessage>() {
              @Override
              public StringMessage newInstance() {
                return new StringMessage();
              }

              @Override
              public void handleResponse(StringMessage response) {
                System.out.println("got response: " + response.message);
                assertThat("hello moshe", equalTo(response.message));
              }

              @Override
              public void handleException(RemoteTransportException exp) {
                exp.printStackTrace();
                assertThat(
                    "got exception instead of a response: " + exp.getMessage(),
                    false,
                    equalTo(true));
              }
            });

    try {
      StringMessage message = res.get();
      assertThat("hello moshe", equalTo(message.message));
    } catch (Exception e) {
      assertThat(e.getMessage(), false, equalTo(true));
    }

    serviceA.removeHandler("sayHello");

    System.out.println("after ...");
  }