Search in sources :

Example 1 with HelloReplyList

use of com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReplyList 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();
}
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) HelloRequestList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequestList) HelloReplyList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReplyList) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with HelloReplyList

use of com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReplyList 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();
}
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) HelloRequestList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequestList) HelloReplyList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReplyList) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with HelloReplyList

use of com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReplyList 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");
    }
}
Also used : HelloRequestList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequestList) HelloReplyList(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReplyList) IOException(java.io.IOException) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

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