### Question:
Rpc implements Closeable { public Future<Void> call(Object msg) { return call(msg, Void.class); } private  Rpc(RpcConfiguration config, Channel channel, EventExecutorGroup egroup); static Promise<Rpc> createClient(
      Map<String, String> config,
      final NioEventLoopGroup eloop,
      String host,
      int port,
      final String clientId,
      final String secret,
      final RpcDispatcher dispatcher); void addListener(Listener l); Future<Void> call(Object msg); Future<T> call(Object msg, Class<T> retType); Promise<T> createPromise(); @Override void close();  }### Answer:
@Test public void testClientServer() throws Exception { RpcServer server = autoClose(new RpcServer(emptyConfig)); Rpc[] rpcs = createRpcConnection(server); Rpc serverRpc = rpcs[0]; Rpc client = rpcs[1]; TestMessage outbound = new TestMessage("Hello World!"); Future<TestMessage> call = client.call(outbound, TestMessage.class); TestMessage reply = call.get(10, TimeUnit.SECONDS); assertEquals(outbound.message, reply.message); TestMessage another = new TestMessage("Hello again!"); Future<TestMessage> anotherCall = client.call(another, TestMessage.class); TestMessage anotherReply = anotherCall.get(10, TimeUnit.SECONDS); assertEquals(another.message, anotherReply.message); String errorMsg = "This is an error."; try { client.call(new ErrorCall(errorMsg)).get(10, TimeUnit.SECONDS); } catch (ExecutionException ee) { assertTrue(ee.getCause() instanceof RpcException); assertTrue(ee.getCause().getMessage().indexOf(errorMsg) >= 0); } TestMessage serverMsg = new TestMessage("Hello from the server!"); Future<TestMessage> serverCall = serverRpc.call(serverMsg, TestMessage.class); TestMessage serverReply = serverCall.get(10, TimeUnit.SECONDS); assertEquals(serverMsg.message, serverReply.message); }
@Test public void testNotDeserializableRpc() throws Exception { RpcServer server = autoClose(new RpcServer(emptyConfig)); Rpc[] rpcs = createRpcConnection(server); Rpc client = rpcs[1]; try { client.call(new NotDeserializable(42)).get(10, TimeUnit.SECONDS); } catch (ExecutionException ee) { assertTrue(ee.getCause() instanceof RpcException); assertTrue(ee.getCause().getMessage().indexOf("KryoException") >= 0); } }
@Test public void testEncryption() throws Exception { Map<String, String> eConf = ImmutableMap.<String,String>builder() .putAll(emptyConfig) .put(RpcConfiguration.RPC_SASL_OPT_PREFIX + "qop", Rpc.SASL_AUTH_CONF) .build(); RpcServer server = autoClose(new RpcServer(eConf)); Rpc[] rpcs = createRpcConnection(server, eConf); Rpc client = rpcs[1]; TestMessage outbound = new TestMessage("Hello World!"); Future<TestMessage> call = client.call(outbound, TestMessage.class); TestMessage reply = call.get(10, TimeUnit.SECONDS); assertEquals(outbound.message, reply.message); }