Package com.kurento.kmf.jsonrpcconnector.client

Examples of com.kurento.kmf.jsonrpcconnector.client.JsonRpcClient


  @Test
  public void test() throws IOException, InterruptedException {

    log.info("Client started");

    JsonRpcClient client = createJsonRpcClient("/BidirectionalMultiTest");

    client.setServerRequestHandler(new DefaultJsonRpcHandler<Integer>() {

      @Override
      public void handleRequest(Transaction transaction,
          Request<Integer> request) throws Exception {

        log.info("Reverse request: " + request);
        transaction.sendResponse(request.getParams()+1);
      }
    });

    for (int i = 0; i < 60; i++) {
      client.sendRequest("echo", i, Integer.class);
    }

    client.close();

    log.info("Client finished");
  }
View Full Code Here


  @Test
  public void echoTest() throws Exception {

    LOG.info("Client started");

    JsonRpcClient client = new JsonRpcClientLocal(new EchoJsonRpcHandler());

    Params params = new Params();
    params.param1 = "Value1";
    params.param2 = "Value2";

    Params result = client.sendRequest("echo", params, Params.class);

    LOG.info("Response:" + result);

    Assert.assertEquals(params.param1, result.param1);
    Assert.assertEquals(params.param2, result.param2);

    client.close();

    LOG.info("Client finished");

  }
View Full Code Here

      ThriftInterfaceExecutorService executorService = new ThriftInterfaceExecutorService(
          thriftInterfaceConfiguration());

      MediaApiConfiguration mediaApiConfiguration = mediaApiConfiguration();

      JsonRpcClient client = new JsonRpcClientThrift(clientPool,
          executorService, new InetSocketAddress(
              mediaApiConfiguration.getHandlerAddress(),
              mediaApiConfiguration.getHandlerPort()));

      return new MediaPipelineFactory(client);
View Full Code Here

    server.start();
    log.info("Server started");

    log.info("Starting client");

    JsonRpcClient client = new JsonRpcClientThrift("127.0.0.1", 19292,
        "127.0.0.1", 7979);

    Params params = new Params();
    params.param1 = "Value1";
    params.param2 = "Value2";

    Params result = client.sendRequest("echo", params, Params.class);

    log.info("Response:" + result);

    Assert.assertEquals(params.param1, result.param1);
    Assert.assertEquals(params.param2, result.param2);

    client.close();

    log.info("Client finished");

    server.destroy();
View Full Code Here

  @Test
  public void test() throws IOException, InterruptedException {

    log.info("Client started");

    final JsonRpcClient client = createJsonRpcClient();

    final JsonObject params = new JsonObject();
    params.addProperty("param1", "Value1");
    params.addProperty("param2", "Value2");

    final CountDownLatch secondResponseRecLatch = new CountDownLatch(1);

    client.sendRequest("echo", params, new Continuation<JsonElement>() {

      @Override
      public void onSuccess(JsonElement result) {
        log.info("Response:" + result);

        JsonObject jsonResult = (JsonObject) result;

        Assert.assertEquals(jsonResult.get("param1").getAsString(),
            "Value1");
        Assert.assertEquals(jsonResult.get("param2").getAsString(),
            "Value2");

        final JsonObject params2 = new JsonObject();
        params2.addProperty("param3", "Value3");
        params2.addProperty("param4", "Value4");

        client.sendRequest("echo", params2,
            new Continuation<JsonElement>() {

              @Override
              public void onSuccess(JsonElement result) {
                log.info("Response:" + result);

                JsonObject jsonResult2 = (JsonObject) result;

                Assert.assertEquals(jsonResult2.get("param3")
                    .getAsString(), "Value3");
                Assert.assertEquals(jsonResult2.get("param4")
                    .getAsString(), "Value4");

                secondResponseRecLatch.countDown();
              }

              @Override
              public void onError(Throwable cause) {
                cause.printStackTrace();
              }
            });
      }

      @Override
      public void onError(Throwable cause) {
        cause.printStackTrace();
      }
    });

    Assert.assertTrue("Response not received in 5s",
        secondResponseRecLatch.await(5, TimeUnit.SECONDS));

    client.close();

    log.info("Client finished");
  }
View Full Code Here

  @Test
  public void test() throws IOException, InterruptedException {

    log.info("Client started");

    JsonRpcClient client = createJsonRpcClient();

    final JsonObject params = new JsonObject();
    params.addProperty("param1", "Value1");
    params.addProperty("param2", "Value2");

    final CountDownLatch responseRecLatch = new CountDownLatch(1);

    client.sendRequest("echo", params, new Continuation<JsonElement>() {

      @Override
      public void onSuccess(JsonElement result) {
        log.info("Response:" + result);

        Assert.assertEquals(params.get("param1").getAsString(),
            "Value1");
        Assert.assertEquals(params.get("param2").getAsString(),
            "Value2");

        responseRecLatch.countDown();
      }

      @Override
      public void onError(Throwable cause) {
        cause.printStackTrace();
      }
    });

    Assert.assertTrue("Response not received in 5s",
        responseRecLatch.await(5, TimeUnit.SECONDS));

    client.close();

    log.info("Client finished");
  }
View Full Code Here

    log.info("Server started");

    long initTime = System.nanoTime();

    log.info("Starting client");
    JsonRpcClient client = new JsonRpcClientThrift("127.0.0.1", 19292,
        "127.0.0.1", 7979);

    if (!latch.await(15, TimeUnit.SECONDS)) {
      Assert.fail("Timeout of 15s waiting for keepAlives");
    } else {
      long duration = ((System.nanoTime() - initTime) / 1000000);

      Assert.assertTrue(
          "Waiting time should be greather than estimated keepAlive time ("
              + duration + " > " + (NUM_KEEP_ALIVES * 1000) + ")",
          duration > NUM_KEEP_ALIVES * 1000);

      Assert.assertTrue("Waiting time should be a bit more than "
          + NUM_KEEP_ALIVES + " keepAlive times (" + duration + " < "
          + ((NUM_KEEP_ALIVES + 3) * 1000) + ")",
          duration < (NUM_KEEP_ALIVES + 3) * 1000);

    }

    client.close();

    log.info("Client finished");

    server.destroy();

View Full Code Here

TOP

Related Classes of com.kurento.kmf.jsonrpcconnector.client.JsonRpcClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.