Search in sources :

Example 41 with Pipeline

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

the class SpringServiceFactoriesTest method testMapBatchUsingSpringBean.

@Test
public void testMapBatchUsingSpringBean() {
    Pipeline pipeline = Pipeline.create();
    pipeline.readFrom(TestSources.items(1L, 2L, 3L, 4L, 5L, 6L)).mapUsingService(bean("calculator"), Calculator::multiply).writeTo(assertAnyOrder(asList(-1L, -2L, -3L, -4L, -5L, -6L)));
    jet.newJob(pipeline).join();
}
Also used : Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 42 with Pipeline

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

the class SpringServiceFactoriesTest method testFilterStreamUsingSpringBean.

@Test
public void testFilterStreamUsingSpringBean() {
    Pipeline pipeline = Pipeline.create();
    pipeline.readFrom(TestSources.itemStream(100)).withNativeTimestamps(0).map(SimpleEvent::sequence).filterUsingService(bean("calculator"), Calculator::filter).writeTo(assertCollectedEventually(10, c -> {
        assertTrue(c.size() > 100);
        c.forEach(i -> assertEquals(0, i % 2));
    }));
    Job job = jet.newJob(pipeline);
    assertJobCompleted(job);
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Pipeline(com.hazelcast.jet.pipeline.Pipeline) SimpleEvent(com.hazelcast.jet.pipeline.test.SimpleEvent) CustomSpringJUnit4ClassRunner(com.hazelcast.spring.CustomSpringJUnit4ClassRunner) AssertionSinks.assertCollectedEventually(com.hazelcast.jet.pipeline.test.AssertionSinks.assertCollectedEventually) RunWith(org.junit.runner.RunWith) Resource(javax.annotation.Resource) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CompletionException(java.util.concurrent.CompletionException) JetService(com.hazelcast.jet.JetService) AssertionSinks.assertAnyOrder(com.hazelcast.jet.pipeline.test.AssertionSinks.assertAnyOrder) TestSources(com.hazelcast.jet.pipeline.test.TestSources) Hazelcast(com.hazelcast.core.Hazelcast) Arrays.asList(java.util.Arrays.asList) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Assert.fail(org.junit.Assert.fail) JetSpringServiceFactories.bean(com.hazelcast.spring.jet.JetSpringServiceFactories.bean) Assert.assertEquals(org.junit.Assert.assertEquals) Job(com.hazelcast.jet.Job) SimpleEvent(com.hazelcast.jet.pipeline.test.SimpleEvent) Job(com.hazelcast.jet.Job) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 43 with Pipeline

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

the class SpringServiceFactoriesTest method testFilterBatchUsingSpringBean.

@Test
public void testFilterBatchUsingSpringBean() {
    Pipeline pipeline = Pipeline.create();
    pipeline.readFrom(TestSources.items(1L, 2L, 3L, 4L, 5L, 6L)).filterUsingService(bean("calculator"), Calculator::filter).writeTo(assertAnyOrder(asList(2L, 4L, 6L)));
    jet.newJob(pipeline).join();
}
Also used : Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 44 with Pipeline

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

the class StreamKafkaPTest method when_duplicateTopicsProvide_then_uniqueTopicsSubscribed.

@Test
public void when_duplicateTopicsProvide_then_uniqueTopicsSubscribed() {
    HazelcastInstance[] instances = instances();
    assertClusterSizeEventually(2, instances);
    // need new topic because we want 2 partitions only
    String topic = randomString();
    kafkaTestSupport.createTopic(topic, 2);
    Pipeline p = Pipeline.create();
    // Pass the same topic twice
    p.readFrom(KafkaSources.kafka(properties(), topic, topic)).withoutTimestamps().setLocalParallelism(1).writeTo(Sinks.list("sink"));
    JobConfig config = new JobConfig();
    Job job = instances[0].getJet().newJob(p, config);
    assertJobStatusEventually(job, JobStatus.RUNNING, 10);
    int messageCount = 1000;
    for (int i = 0; i < messageCount; i++) {
        kafkaTestSupport.produce(topic, i, Integer.toString(i));
    }
    IList<Object> list = instances[0].getList("sink");
    try {
        // Wait for all messages
        assertTrueEventually(() -> assertThat(list).hasSize(messageCount), 15);
        // Check there are no more messages (duplicates..)
        assertTrueAllTheTime(() -> assertThat(list).hasSize(messageCount), 1);
    } finally {
        job.cancel();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 45 with Pipeline

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

the class StreamKafkaPTest method when_projectionFunctionProvided_thenAppliedToReadRecords.

@Test
public void when_projectionFunctionProvided_thenAppliedToReadRecords() {
    int messageCount = 20;
    Pipeline p = Pipeline.create();
    p.readFrom(KafkaSources.<Integer, String, String>kafka(properties(), rec -> rec.value() + "-x", topic1Name)).withoutTimestamps().writeTo(Sinks.list("sink"));
    instance().getJet().newJob(p);
    sleepAtLeastSeconds(3);
    for (int i = 0; i < messageCount; i++) {
        kafkaTestSupport.produce(topic1Name, i, Integer.toString(i));
    }
    IList<String> list = instance().getList("sink");
    assertTrueEventually(() -> {
        assertEquals(messageCount, list.size());
        for (int i = 0; i < messageCount; i++) {
            String value = i + "-x";
            assertTrue("missing entry: " + value, list.contains(value));
        }
    }, 5);
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Arrays(java.util.Arrays) IntStream.range(java.util.stream.IntStream.range) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Processor(com.hazelcast.jet.core.Processor) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Collections.singletonList(java.util.Collections.singletonList) Future(java.util.concurrent.Future) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) Map(java.util.Map) JobStatus(com.hazelcast.jet.core.JobStatus) Collectors.toSet(java.util.stream.Collectors.toSet) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) FunctionEx(com.hazelcast.function.FunctionEx) AfterClass(org.junit.AfterClass) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Collection(java.util.Collection) JobConfig(com.hazelcast.jet.config.JobConfig) Set(java.util.Set) RecordMetadata(org.apache.kafka.clients.producer.RecordMetadata) Category(org.junit.experimental.categories.Category) BroadcastKey(com.hazelcast.jet.core.BroadcastKey) List(java.util.List) IDLE_MESSAGE(com.hazelcast.jet.impl.execution.WatermarkCoalescer.IDLE_MESSAGE) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Assert.assertFalse(org.junit.Assert.assertFalse) Entry(java.util.Map.Entry) JobExecutionRecord(com.hazelcast.jet.impl.JobExecutionRecord) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) BeforeClass(org.junit.BeforeClass) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) HashMap(java.util.HashMap) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) HashSet(java.util.HashSet) Watermark(com.hazelcast.jet.core.Watermark) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Util.entry(com.hazelcast.jet.Util.entry) UuidUtil(com.hazelcast.internal.util.UuidUtil) Nonnull(javax.annotation.Nonnull) Job(com.hazelcast.jet.Job) Before(org.junit.Before) IList(com.hazelcast.collection.IList) TestInbox(com.hazelcast.jet.core.test.TestInbox) JobRepository(com.hazelcast.jet.impl.JobRepository) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ByteArrayDeserializer(org.apache.kafka.common.serialization.ByteArrayDeserializer) TimeoutException(org.apache.kafka.common.errors.TimeoutException) Properties(java.util.Properties) Assert.assertNotNull(org.junit.Assert.assertNotNull) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) Sinks(com.hazelcast.jet.pipeline.Sinks) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) KafkaSources(com.hazelcast.jet.kafka.KafkaSources) WatermarkPolicy.limitingLag(com.hazelcast.jet.core.WatermarkPolicy.limitingLag) ToLongFunctionEx(com.hazelcast.function.ToLongFunctionEx) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) IntegerDeserializer(org.apache.kafka.common.serialization.IntegerDeserializer) EventTimePolicy.eventTimePolicy(com.hazelcast.jet.core.EventTimePolicy.eventTimePolicy) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) Assert.assertEquals(org.junit.Assert.assertEquals) 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