use of com.google.showcase.v1beta1.EchoResponse in project toolkit by googleapis.
the class ShowcaseTest method canCollectAStreamOfRequests.
@Test
public void canCollectAStreamOfRequests() throws InterruptedException {
List<String> collections = new ArrayList<>();
CountDownLatch latch = new CountDownLatch(1);
ApiStreamObserver<EchoRequest> requestStream = client.collectCallable().clientStreamingCall(new ApiStreamObserver<EchoResponse>() {
@Override
public void onNext(EchoResponse value) {
collections.add(value.getContent());
}
@Override
public void onError(Throwable t) {
fail("error not expected");
}
@Override
public void onCompleted() {
latch.countDown();
}
});
for (String request : new String[] { "a", "b", "c", "done" }) {
requestStream.onNext(EchoRequest.newBuilder().setContent(request).build());
}
requestStream.onCompleted();
latch.await(7, TimeUnit.SECONDS);
assertThat(collections).containsExactly("a b c done");
}
use of com.google.showcase.v1beta1.EchoResponse in project toolkit by googleapis.
the class ShowcaseTest method canHaveARandomChat.
@Test
public void canHaveARandomChat() throws InterruptedException {
List<String> responses = new ArrayList<>();
CountDownLatch latch = new CountDownLatch(1);
List<String> inputs = IntStream.range(0, 5).mapToObj(idx -> new Random().ints(20).mapToObj(Integer::toString).collect(Collectors.joining("->"))).collect(Collectors.toList());
client.chatCallable().call(new BidiStreamObserver<EchoRequest, EchoResponse>() {
@Override
public void onReady(ClientStream<EchoRequest> stream) {
inputs.forEach(message -> stream.send(EchoRequest.newBuilder().setContent(message).build()));
stream.closeSend();
}
@Override
public void onStart(StreamController controller) {
// skip...
}
@Override
public void onResponse(EchoResponse response) {
responses.add(response.getContent());
}
@Override
public void onError(Throwable t) {
fail("error not expected");
}
@Override
public void onComplete() {
latch.countDown();
}
});
latch.await(7, TimeUnit.SECONDS);
assertThat(responses).containsExactlyElementsIn(inputs).inOrder();
}
use of com.google.showcase.v1beta1.EchoResponse in project toolkit by googleapis.
the class ShowcaseTest method echosTheRequest.
@Test
public void echosTheRequest() {
EchoResponse result = client.echo(EchoRequest.newBuilder().setContent("Hi there!").build());
assertThat(result.getContent()).isEqualTo("Hi there!");
}
Aggregations