Java Code Examples for org.kurento.jsonrpc.client.JsonRpcClient#close()

The following examples show how to use org.kurento.jsonrpc.client.JsonRpcClient#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BidirectionalMultiTest.java    From kurento-java with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws IOException, InterruptedException {

  log.debug("Client started");

  JsonRpcClient client = createJsonRpcClient("/BidirectionalMultiTest");

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

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

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

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

  client.close();

  log.debug("Client finished");
}
 
Example 2
Source File: BasicAsyncClientEchoTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws IOException, InterruptedException {

  log.debug("Client started");

  JsonRpcClient client = createJsonRpcClient("/jsonrpc");

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

  CountDownLatch finishTestLatch = new CountDownLatch(1);

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

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

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

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

  finishTestLatch.await(5, TimeUnit.SECONDS);

  client.close();

  log.debug("Client finished");
}
 
Example 3
Source File: AbstractRomTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void test() throws IOException {

  LOG.info("Starting server");

  RomServerJsonRpcHandler jsonRpcHandler = new RomServerJsonRpcHandler(
      "org.kurento.client.internal.test.model.server", "Impl");

  startJsonRpcServer(jsonRpcHandler);

  LOG.info("Server started");

  LOG.info("Starting client");

  JsonRpcClient client = createJsonRpcClient();
  useRom(client);

  client.close();

  destroyJsonRpcServer();
}
 
Example 4
Source File: CloseSessionTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void test() throws IOException, InterruptedException {

  JsonRpcClient client = createJsonRpcClient("/close_session_handler");

  Assert.assertEquals("new", client.sendRequest("sessiontest", String.class));
  Assert.assertEquals("old", client.sendRequest("sessiontest", String.class));
  Assert.assertEquals("old", client.sendRequest("sessiontest", String.class));

  client = createJsonRpcClient("/close_session_handler");

  Assert.assertEquals("new", client.sendRequest("sessiontest", String.class));
  Assert.assertEquals("old", client.sendRequest("sessiontest", String.class));
  Assert.assertEquals("old", client.sendRequest("sessiontest", String.class));

  client.close();

}
 
Example 5
Source File: BasicEchoTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void test() throws IOException {

  log.debug("Client started");

  JsonRpcClient client = createJsonRpcClient("/jsonrpc");
  Params params = new Params();
  params.param1 = "Value1";
  params.param2 = "Value2";

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

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

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

  client.close();

  log.debug("Client finished");

}
 
Example 6
Source File: MultipleSessionsTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
private void counterSession() {

    JsonRpcClient client = createJsonRpcClient("/jsonrpc_multiple");

    try {

      for (int i = 0; i < 5; i++) {

        int counter = client.sendRequest("count", null, Integer.class);
        Assert.assertEquals(i, counter);
      }

      client.close();

    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
 
Example 7
Source File: JsonRpcClientLocalTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@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");

}
 
Example 8
Source File: ServerEventsTest.java    From kurento-java with Apache License 2.0 3 votes vote down vote up
@Test
public void test() throws IOException, InterruptedException {

  log.debug("Client started");

  JsonRpcClient client = createJsonRpcClient("/serverevents");

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

  Assert.assertTrue("The method 'afterConnectionEstablished' is not invoked",
      afterConnectionEstablishedLatch.await(TIMEOUT, TimeUnit.MILLISECONDS));

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

  Assert.assertEquals("params", result);

  Assert.assertTrue("The method 'handleRequest' is not invoked",
      requestLatch.await(TIMEOUT, TimeUnit.MILLISECONDS));

  client.close();

  Assert.assertTrue("The method 'afterConnectionClosed' is not invoked",
      afterConnectionClosedLatch.await(TIMEOUT, TimeUnit.MILLISECONDS));

  log.debug("Client finished");

}
 
Example 9
Source File: NotificationTest.java    From kurento-java with Apache License 2.0 3 votes vote down vote up
@Test
public void test() throws IOException, InterruptedException {

  serverRequestLatch = new CountDownLatch(3);

  JsonRpcClient client = createJsonRpcClient("/notification");

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

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

      serverRequestLatch.countDown();
    }
  });

  client.sendNotification("echo", 1);
  client.sendNotification("echo", 2);
  client.sendNotification("echo", 3);

  Assert.assertTrue("The server has not invoked requests",
      serverRequestLatch.await(5000, TimeUnit.MILLISECONDS));

  client.close();

}
 
Example 10
Source File: NewSessionTest.java    From kurento-java with Apache License 2.0 3 votes vote down vote up
@Test
public void test() throws IOException, InterruptedException {

  JsonRpcClient client = createJsonRpcClient("/new_session_handler");

  Assert.assertEquals("new", client.sendRequest("sessiontest", String.class));
  Assert.assertEquals("old", client.sendRequest("sessiontest", String.class));
  Assert.assertEquals("old", client.sendRequest("sessiontest", String.class));

  client.close();

}
 
Example 11
Source File: AsyncServerTest.java    From kurento-java with Apache License 2.0 3 votes vote down vote up
@Test
public void test() throws IOException, InterruptedException {

  JsonRpcClient client = createJsonRpcClient("/async_handler");

  String response = client.sendRequest("count", "fakeparams", String.class);

  Assert.assertEquals("AsyncHello", response);

  client.close();

}
 
Example 12
Source File: LargePackageTest.java    From kurento-java with Apache License 2.0 3 votes vote down vote up
@Test
public void test() throws IOException, InterruptedException {

  JsonRpcClient client = createJsonRpcClient("/largepackage");

  String largePackage = client.sendRequest("echo", String.class);

  System.out.println(largePackage);

  Thread.sleep(2000);

  client.close();

}
 
Example 13
Source File: BidirectionalTest.java    From kurento-java with Apache License 2.0 2 votes vote down vote up
@Test
public void test() throws IOException, InterruptedException {

  log.debug("Client started");

  JsonRpcClient client = createJsonRpcClient("/jsonrpcreverse");

  final CountDownLatch inverseRequestLatch = new CountDownLatch(2);
  final Params[] inverseRequestParams = new Params[1];

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

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

      log.debug("Reverse request: " + request);

      transaction.sendResponse(request.getParams());
      inverseRequestParams[0] = request.getParams();

      inverseRequestLatch.countDown();
    }
  });

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

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

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

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

  inverseRequestLatch.await();

  Params newResult = inverseRequestParams[0];

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

  client.close();

  log.debug("Client finished");

}
 
Example 14
Source File: ReconnectionFromServerTest.java    From kurento-java with Apache License 2.0 2 votes vote down vote up
@Test
public void test() throws IOException, InterruptedException {

  JsonRpcClient client = new JsonRpcClientWebSocket(
      "ws://localhost:" + getPort() + "/reconnection2");
  client.setServerRequestHandler(new DefaultJsonRpcHandler<JsonElement>() {

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

      log.debug("Receive request in client: " + request);
      transaction.sendResponse("world");
      log.debug("Response sent from client");
    }
  });

  Assert.assertEquals("new", client.sendRequest("sessiontest", String.class));

  waitForServer();

  Assert.assertEquals("old", client.sendRequest("sessiontest", String.class));

  waitForServer();

  log.debug("SessionId: " + client.getSession().getSessionId());

  JsonRpcClientWebSocket webSocketClient = (JsonRpcClientWebSocket) client;

  webSocketClient.closeNativeClient();

  Thread.sleep(100);

  Assert.assertEquals("old", client.sendRequest("sessiontest", String.class));

  waitForServer();

  log.debug("Acquired");

  client.close();

}