// Create a client-side stub for talking to the server.
WaveClientRpc.ProtocolWaveClientRpc.Stub stub =
WaveClientRpc.ProtocolWaveClientRpc.newStub(client);
// Create a controller, set up request, wait for responses.
RpcController controller = client.newRpcController();
ProtocolOpenRequest request =
ProtocolOpenRequest.newBuilder().setParticipantId("").setWaveId("").build();
stub.open(controller, request, new RpcCallback<ProtocolWaveletUpdate>() {
@Override
public void run(ProtocolWaveletUpdate response) {
if (response != null) {
responseLatch.countDown();
} else {
finishedLatch.countDown();
}
}
});
// Wait for all pending responses.
responseLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
assertEquals(0, responseLatch.getCount());
assertEquals(1, finishedLatch.getCount());
// Cancel the RPC and wait for it to finish.
controller.startCancel();
finishedLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
assertEquals(0, finishedLatch.getCount());
assertFalse(controller.failed());
}