use of com.hazelcast.jet.pipeline.BatchStageWithKey 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.pipeline.BatchStageWithKey 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.pipeline.BatchStageWithKey in project hazelcast by hazelcast.
the class GrpcServiceTest method when_bidirectionalStreaming_distributed.
@Test
public void when_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.mapUsingServiceAsync(bidirectionalStreaming(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.pipeline.BatchStageWithKey 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.pipeline.BatchStageWithKey in project hazelcast by hazelcast.
the class GrpcServiceTest method whenNotAsync_unary_distributed.
@Test
public void whenNotAsync_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.mapUsingService(unary(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();
}
Aggregations