use of com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequestList in project hazelcast by hazelcast.
the class GrpcServiceTest method when_repeatedBidirectionalStreaming.
@Test
public void when_repeatedBidirectionalStreaming() throws IOException {
// Given
server = createServer(new GreeterServiceImpl());
final int port = server.getPort();
List<String> items = IntStream.range(0, ITEM_COUNT).mapToObj(Integer::toString).collect(toList());
Pipeline p = Pipeline.create();
BatchStage<String> stage = p.readFrom(TestSources.items(items));
// When
BatchStage<String> mapped = stage.mapUsingServiceAsyncBatched(repeatedBidirectionalStreaming(port), 128, (service, itemList) -> {
HelloRequestList req = HelloRequestList.newBuilder().addAllName(itemList).build();
return service.call(req).thenApply(HelloReplyList::getMessageList);
});
// Then
List<String> expected = IntStream.range(0, ITEM_COUNT).boxed().map(t -> "Hello " + Integer.toString(t)).collect(toList());
mapped.writeTo(AssertionSinks.assertAnyOrder(expected));
instance().getJet().newJob(p).join();
}
use of com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequestList in project hazelcast by hazelcast.
the class GrpcServiceTest method when_repeatedBidirectionalStreaming_distributed.
@Test
public void when_repeatedBidirectionalStreaming_distributed() throws IOException {
// Given
server = createServer(new GreeterServiceImpl());
final int port = server.getPort();
List<String> items = IntStream.range(0, ITEM_COUNT).mapToObj(Integer::toString).collect(toList());
Pipeline p = Pipeline.create();
BatchStageWithKey<String, String> stage = p.readFrom(TestSources.items(items)).groupingKey(i -> i);
// When
BatchStage<String> mapped = stage.mapUsingServiceAsyncBatched(repeatedBidirectionalStreaming(port), 128, (service, itemList) -> {
HelloRequestList req = HelloRequestList.newBuilder().addAllName(itemList).build();
return service.call(req).thenApply(HelloReplyList::getMessageList);
});
// Then
mapped.writeTo(AssertionSinks.assertCollected(e -> {
assertEquals("unexpected number of items received", ITEM_COUNT, e.size());
}));
instance().getJet().newJob(p).join();
}
use of com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequestList in project hazelcast by hazelcast.
the class GrpcServiceTest method when_repeatedBidirectionalStreaming_withFaultyService.
@Test
public void when_repeatedBidirectionalStreaming_withFaultyService() throws IOException {
// Given
server = createServer(new FaultyGreeterServiceImpl());
final int port = server.getPort();
List<String> items = IntStream.range(0, ITEM_COUNT).mapToObj(Integer::toString).collect(toList());
Pipeline p = Pipeline.create();
BatchStage<String> stage = p.readFrom(TestSources.items(items));
// When
BatchStage<String> mapped = stage.mapUsingServiceAsyncBatched(repeatedBidirectionalStreaming(port), 128, (service, itemList) -> {
HelloRequestList req = HelloRequestList.newBuilder().addAllName(itemList).build();
return service.call(req).thenApply(HelloReplyList::getMessageList);
});
// Then
mapped.writeTo(Sinks.noop());
try {
instance().getJet().newJob(p).join();
fail("Job should have failed");
} catch (Exception e) {
Throwable ex = ExceptionUtil.peel(e);
assertThat(ex.getMessage()).contains("com.hazelcast.jet.grpc.impl.StatusRuntimeExceptionJet");
}
}
Aggregations