Search in sources :

Example 61 with Pipeline

use of com.hazelcast.jet.pipeline.Pipeline 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();
}
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)

Example 62 with Pipeline

use of com.hazelcast.jet.pipeline.Pipeline 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");
    }
}
Also used : HelloRequest(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloRequest) HelloReply(com.hazelcast.jet.grpc.greeter.GreeterOuterClass.HelloReply) 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)

Example 63 with Pipeline

use of com.hazelcast.jet.pipeline.Pipeline 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 64 with Pipeline

use of com.hazelcast.jet.pipeline.Pipeline in project hazelcast by hazelcast.

the class AuthElasticSinksTest method given_clientWithWrongPassword_whenWriteToElasticSink_thenFailWithAuthenticationException.

@Test
public void given_clientWithWrongPassword_whenWriteToElasticSink_thenFailWithAuthenticationException() {
    ElasticsearchContainer container = ElasticSupport.secureElastic.get();
    String containerIp = container.getContainerIpAddress();
    Integer port = container.getMappedPort(PORT);
    Sink<TestItem> elasticSink = new ElasticSinkBuilder<>().clientFn(() -> client("elastic", "WrongPassword", containerIp, port)).bulkRequestFn(() -> new BulkRequest().setRefreshPolicy(RefreshPolicy.IMMEDIATE)).mapToRequestFn((TestItem item) -> new IndexRequest("my-index").source(item.asMap())).retries(0).build();
    Pipeline p = Pipeline.create();
    p.readFrom(TestSources.items(new TestItem("id", "Frantisek"))).writeTo(elasticSink);
    assertThatThrownBy(() -> submitJob(p)).hasRootCauseInstanceOf(ElasticsearchStatusException.class).hasStackTraceContaining("unable to authenticate user [elastic]");
}
Also used : BulkRequest(org.elasticsearch.action.bulk.BulkRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) ElasticsearchContainer(org.testcontainers.elasticsearch.ElasticsearchContainer) TestItem(com.hazelcast.jet.elastic.CommonElasticSinksTest.TestItem) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 65 with Pipeline

use of com.hazelcast.jet.pipeline.Pipeline in project hazelcast by hazelcast.

the class AuthElasticSinksTest method given_authenticatedClient_whenWriteToElasticSink_thenFinishSuccessfully.

@Test
public void given_authenticatedClient_whenWriteToElasticSink_thenFinishSuccessfully() throws IOException {
    Sink<TestItem> elasticSink = new ElasticSinkBuilder<>().clientFn(elasticClientSupplier()).bulkRequestFn(() -> new BulkRequest().setRefreshPolicy(RefreshPolicy.IMMEDIATE)).mapToRequestFn((TestItem item) -> new IndexRequest("my-index").source(item.asMap())).build();
    Pipeline p = Pipeline.create();
    p.readFrom(TestSources.items(new TestItem("id", "Frantisek"))).writeTo(elasticSink);
    submitJob(p);
    assertSingleDocument();
}
Also used : BulkRequest(org.elasticsearch.action.bulk.BulkRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) TestItem(com.hazelcast.jet.elastic.CommonElasticSinksTest.TestItem) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Aggregations

Pipeline (com.hazelcast.jet.pipeline.Pipeline)379 Test (org.junit.Test)300 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)142 QuickTest (com.hazelcast.test.annotation.QuickTest)142 Job (com.hazelcast.jet.Job)125 Sinks (com.hazelcast.jet.pipeline.Sinks)107 Category (org.junit.experimental.categories.Category)100 HazelcastInstance (com.hazelcast.core.HazelcastInstance)94 JobConfig (com.hazelcast.jet.config.JobConfig)86 Assert.assertEquals (org.junit.Assert.assertEquals)73 List (java.util.List)72 NightlyTest (com.hazelcast.test.annotation.NightlyTest)65 Before (org.junit.Before)64 Entry (java.util.Map.Entry)61 TestSources (com.hazelcast.jet.pipeline.test.TestSources)58 Assert.assertTrue (org.junit.Assert.assertTrue)50 Sources (com.hazelcast.jet.pipeline.Sources)49 IOException (java.io.IOException)48 BeforeClass (org.junit.BeforeClass)48 SimpleTestInClusterSupport (com.hazelcast.jet.SimpleTestInClusterSupport)42