Search in sources :

Example 6 with HelloRequest

use of com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest 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();
}
Also used : AssertionSinks(com.hazelcast.jet.pipeline.test.AssertionSinks) IntStream(java.util.stream.IntStream) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BindableService(io.grpc.BindableService) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BatchStage(com.hazelcast.jet.pipeline.BatchStage) StreamObserver(io.grpc.stub.StreamObserver) HelloReply(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReply) ServerBuilder(io.grpc.ServerBuilder) After(org.junit.After) GreeterGrpc(com.hazelcast.jet.grpc.greeter.GreeterGrpc) ServiceFactory(com.hazelcast.jet.pipeline.ServiceFactory) Assert.fail(org.junit.Assert.fail) HelloRequestList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequestList) Server(io.grpc.Server) ExceptionUtil(com.hazelcast.jet.impl.util.ExceptionUtil) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) GrpcServices.unaryService(com.hazelcast.jet.grpc.GrpcServices.unaryService) Pipeline(com.hazelcast.jet.pipeline.Pipeline) HelloReplyList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReplyList) HelloRequest(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) IOException(java.io.IOException) GrpcServices.bidirectionalStreamingService(com.hazelcast.jet.grpc.GrpcServices.bidirectionalStreamingService) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) BatchStageWithKey(com.hazelcast.jet.pipeline.BatchStageWithKey) Assert.assertEquals(org.junit.Assert.assertEquals) HelloRequest(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest) HelloReply(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReply) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with HelloRequest

use of com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest in project hazelcast by hazelcast.

the class GrpcServiceTest method when_bidirectionalStreaming.

@Test
public void when_bidirectionalStreaming() throws IOException {
    // Given
    server = createServer(new GreeterServiceImpl());
    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
    List<String> expected = Arrays.asList("Hello one", "Hello two", "Hello three", "Hello four");
    mapped.writeTo(AssertionSinks.assertAnyOrder(expected));
    instance().getJet().newJob(p).join();
}
Also used : HelloRequest(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest) HelloReply(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReply) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with HelloRequest

use of com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest 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();
}
Also used : AssertionSinks(com.hazelcast.jet.pipeline.test.AssertionSinks) IntStream(java.util.stream.IntStream) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BindableService(io.grpc.BindableService) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BatchStage(com.hazelcast.jet.pipeline.BatchStage) StreamObserver(io.grpc.stub.StreamObserver) HelloReply(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReply) ServerBuilder(io.grpc.ServerBuilder) After(org.junit.After) GreeterGrpc(com.hazelcast.jet.grpc.greeter.GreeterGrpc) ServiceFactory(com.hazelcast.jet.pipeline.ServiceFactory) Assert.fail(org.junit.Assert.fail) HelloRequestList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequestList) Server(io.grpc.Server) ExceptionUtil(com.hazelcast.jet.impl.util.ExceptionUtil) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) GrpcServices.unaryService(com.hazelcast.jet.grpc.GrpcServices.unaryService) Pipeline(com.hazelcast.jet.pipeline.Pipeline) HelloReplyList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReplyList) HelloRequest(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) IOException(java.io.IOException) GrpcServices.bidirectionalStreamingService(com.hazelcast.jet.grpc.GrpcServices.bidirectionalStreamingService) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) BatchStageWithKey(com.hazelcast.jet.pipeline.BatchStageWithKey) Assert.assertEquals(org.junit.Assert.assertEquals) HelloRequest(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HelloReply (com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReply)8 HelloRequest (com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest)8 Pipeline (com.hazelcast.jet.pipeline.Pipeline)8 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 IOException (java.io.IOException)6 SimpleTestInClusterSupport (com.hazelcast.jet.SimpleTestInClusterSupport)4 GrpcServices.bidirectionalStreamingService (com.hazelcast.jet.grpc.GrpcServices.bidirectionalStreamingService)4 GrpcServices.unaryService (com.hazelcast.jet.grpc.GrpcServices.unaryService)4 GreeterGrpc (com.hazelcast.jet.grpc.greeter.GreeterGrpc)4 HelloReplyList (com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReplyList)4 HelloRequestList (com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequestList)4 ExceptionUtil (com.hazelcast.jet.impl.util.ExceptionUtil)4 BatchStage (com.hazelcast.jet.pipeline.BatchStage)4 BatchStageWithKey (com.hazelcast.jet.pipeline.BatchStageWithKey)4 ServiceFactory (com.hazelcast.jet.pipeline.ServiceFactory)4 Sinks (com.hazelcast.jet.pipeline.Sinks)4 AssertionSinks (com.hazelcast.jet.pipeline.test.AssertionSinks)4 TestSources (com.hazelcast.jet.pipeline.test.TestSources)4