use of com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest in project hazelcast by hazelcast.
the class GrpcServiceTest method when_unary_distributed.
@Test
public void when_unary_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.mapUsingServiceAsync(unary(port), (service, key, item) -> {
HelloRequest req = HelloRequest.newBuilder().setName(item).build();
return service.call(req).thenApply(HelloReply::getMessage);
});
// 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.HelloRequest in project hazelcast by hazelcast.
the class GrpcServiceTest method when_unary_with_faultyService.
@Test
public void when_unary_with_faultyService() throws IOException {
// Given
server = createServer(new FaultyGreeterServiceImpl());
final int port = server.getPort();
Pipeline p = Pipeline.create();
BatchStage<String> source = p.readFrom(TestSources.items("one", "two", "three", "four"));
// When
BatchStage<String> mapped = source.mapUsingServiceAsync(unary(port), (service, input) -> {
HelloRequest request = HelloRequest.newBuilder().setName(input).build();
return service.call(request).thenApply(HelloReply::getMessage);
});
// 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");
}
}
use of com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest in project hazelcast by hazelcast.
the class GrpcServiceTest method whenNotAsync_bidirectionalStreaming_distributed.
@Test
public void whenNotAsync_bidirectionalStreaming_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.mapUsingService(bidirectionalStreaming(port), (service, key, item) -> {
HelloRequest req = HelloRequest.newBuilder().setName(item).build();
return service.call(req).thenApply(HelloReply::getMessage).get();
});
// 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.HelloRequest in project hazelcast by hazelcast.
the class GrpcServiceTest method when_bidirectionalStreaming_withFaultyService.
@Test
public void when_bidirectionalStreaming_withFaultyService() throws IOException {
// Given
server = createServer(new FaultyGreeterServiceImpl());
final int port = server.getPort();
Pipeline p = Pipeline.create();
BatchStage<String> stage = p.readFrom(TestSources.items("one", "two", "three", "four"));
// When
BatchStage<String> mapped = stage.mapUsingServiceAsync(bidirectionalStreaming(port), (service, item) -> {
HelloRequest req = HelloRequest.newBuilder().setName(item).build();
return service.call(req).thenApply(HelloReply::getMessage);
});
// 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");
}
}
use of com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest in project hazelcast by hazelcast.
the class GrpcServiceTest method when_unary.
@Test
public void when_unary() throws IOException {
// Given
server = createServer(new GreeterServiceImpl());
final int port = server.getPort();
Pipeline p = Pipeline.create();
BatchStage<String> source = p.readFrom(TestSources.items("one", "two", "three", "four"));
// When
BatchStage<String> mapped = source.mapUsingServiceAsync(unary(port), (service, input) -> {
HelloRequest request = HelloRequest.newBuilder().setName(input).build();
return service.call(request).thenApply(HelloReply::getMessage);
});
// Then
List<String> expected = Arrays.asList("Hello one", "Hello two", "Hello three", "Hello four");
mapped.writeTo(AssertionSinks.assertAnyOrder(expected));
instance().getJet().newJob(p).join();
}
Aggregations