Search in sources :

Example 56 with Pipeline

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

the class ReadHadoopPTest method testReadHdfs.

@Test
public void testReadHdfs() {
    IList<Object> sinkList = instance().getList(randomName());
    Pipeline p = Pipeline.create();
    p.readFrom(HadoopSources.inputFormat(jobConf, projectionType.mapper)).setLocalParallelism(4).writeTo(Sinks.list(sinkList)).setLocalParallelism(1);
    instance().getJet().newJob(p).join();
    int expected = paths.size() * ENTRIES.length * (sharedFileSystem ? 1 : 2);
    assertEquals(projectionType == CUSTOM_WITH_NULLS ? expected / 2 : expected, sinkList.size());
    assertTrue(sinkList.get(0).toString().contains("value"));
}
Also used : Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 57 with Pipeline

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

the class Hz3EnrichmentTest method testMapUsingReplicatedMap.

@Test
public void testMapUsingReplicatedMap() {
    ReplicatedMap<Object, Object> map = hz3.getReplicatedMap("test-replicated-map");
    map.put(1, "a");
    map.put(2, "b");
    HazelcastInstance hz = createHazelcastInstance();
    IList<String> results = hz.getList("result-list");
    Pipeline p = Pipeline.create();
    ServiceFactory<Hz3MapAdapter, Map<Integer, String>> hz3MapSF = hz3ReplicatedMapServiceFactory("test-replicated-map", HZ3_CLIENT_CONFIG);
    BiFunctionEx<? super Map<Integer, String>, ? super Integer, String> mapFn = mapUsingIMap(FunctionEx.identity(), (Integer i, String s) -> s);
    BatchStage<String> mapStage = p.readFrom(TestSources.items(1, 2, 3)).mapUsingService(hz3MapSF, mapFn);
    mapStage.writeTo(Sinks.list(results));
    JobConfig config = getJobConfig(mapStage.name());
    hz.getJet().newJob(p, config).join();
    assertThat(results).containsOnly("a", "b");
}
Also used : JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Hz3MapAdapter(com.hazelcast.connector.map.Hz3MapAdapter) Map(java.util.Map) ReplicatedMap(com.hazelcast.replicatedmap.ReplicatedMap) AsyncMap(com.hazelcast.connector.map.AsyncMap) Hz3Enrichment.mapUsingIMap(com.hazelcast.connector.Hz3Enrichment.mapUsingIMap) IMap(com.hazelcast.map.IMap) Test(org.junit.Test)

Example 58 with Pipeline

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

the class Hz3SinksTest method testMapSink.

@Test
public void testMapSink() {
    HazelcastInstance hz = createHazelcastInstance();
    Pipeline p = Pipeline.create();
    BatchSource<SimpleEntry<Integer, String>> source = TestSources.items(new SimpleEntry<>(1, "a"), new SimpleEntry<>(2, "b"));
    Sink<Map.Entry<Integer, String>> sink = Hz3Sinks.remoteMap("test-map", HZ3_CLIENT_CONFIG);
    p.readFrom(source).writeTo(sink);
    JobConfig config = getJobConfig(sink.name());
    hz.getJet().newJob(p, config).join();
    Map<Integer, String> testMap = hz3.getMap("test-map");
    assertThat(testMap).containsOnly(entry(1, "a"), entry(2, "b"));
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SimpleEntry(java.util.AbstractMap.SimpleEntry) JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 59 with Pipeline

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

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

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