### Question:
NettyRemotingClient { public Command sendSync(final Host host, final Command command, final long timeoutMillis) throws InterruptedException, RemotingException { final Channel channel = getChannel(host); if (channel == null) { throw new RemotingException(String.format("connect to : %s fail", host)); } final long opaque = command.getOpaque(); final ResponseFuture responseFuture = new ResponseFuture(opaque, timeoutMillis, null, null); channel.writeAndFlush(command).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { responseFuture.setSendOk(true); return; } else { responseFuture.setSendOk(false); } responseFuture.setCause(future.cause()); responseFuture.putResponse(null); logger.error("send command {} to host {} failed", command, host); } }); Command result = responseFuture.waitResponse(); if (result == null) { if (responseFuture.isSendOK()) { throw new RemotingTimeoutException(host.toString(), timeoutMillis, responseFuture.getCause()); } else { throw new RemotingException(host.toString(), responseFuture.getCause()); } } return result; } NettyRemotingClient(final NettyClientConfig clientConfig); void sendAsync(final Host host, final Command command,
                          final long timeoutMillis,
                          final InvokeCallback invokeCallback); Command sendSync(final Host host, final Command command, final long timeoutMillis); void send(final Host host, final Command command); void registerProcessor(final CommandType commandType, final NettyRequestProcessor processor); void registerProcessor(final CommandType commandType, final NettyRequestProcessor processor, final ExecutorService executor); Channel getChannel(Host host); Channel createChannel(Host host, boolean isSync); void close(); void closeChannel(Host host);  }### Answer:
@Test public void testSendSync(){ NettyServerConfig serverConfig = new NettyServerConfig(); NettyRemotingServer server = new NettyRemotingServer(serverConfig); server.registerProcessor(CommandType.PING, new NettyRequestProcessor() { @Override public void process(Channel channel, Command command) { channel.writeAndFlush(Pong.create(command.getOpaque())); } }); server.start(); final NettyClientConfig clientConfig = new NettyClientConfig(); NettyRemotingClient client = new NettyRemotingClient(clientConfig); Command commandPing = Ping.create(); try { Command response = client.sendSync(new Host("127.0.0.1", serverConfig.getListenPort()), commandPing, 2000); Assert.assertEquals(commandPing.getOpaque(), response.getOpaque()); } catch (Exception e) { e.printStackTrace(); } server.close(); client.close(); }