Search in sources :

Example 11 with StreamSource

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

the class JobExecutionMetricsTest method snapshotPipeline.

private Pipeline snapshotPipeline() {
    Pipeline p = Pipeline.create();
    StreamSource<Long> source = SourceBuilder.stream("src", procCtx -> new long[1]).<Long>fillBufferFn((ctx, buf) -> {
        buf.add(ctx[0]++);
        Thread.sleep(5);
    }).createSnapshotFn(ctx -> ctx[0]).restoreSnapshotFn((ctx, state) -> ctx[0] = state.get(0)).build();
    p.readFrom(source).withoutTimestamps().writeTo(Sinks.logger());
    return p;
}
Also used : SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) JobRepository(com.hazelcast.jet.impl.JobRepository) Config(com.hazelcast.config.Config) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BeforeClass(org.junit.BeforeClass) Pipeline(com.hazelcast.jet.pipeline.Pipeline) QuickTest(com.hazelcast.test.annotation.QuickTest) JobConfig(com.hazelcast.jet.config.JobConfig) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) StreamSource(com.hazelcast.jet.pipeline.StreamSource) Category(org.junit.experimental.categories.Category) TestSources(com.hazelcast.jet.pipeline.test.TestSources) EXECUTION_START_TIME(com.hazelcast.jet.core.metrics.MetricNames.EXECUTION_START_TIME) EXECUTION_COMPLETION_TIME(com.hazelcast.jet.core.metrics.MetricNames.EXECUTION_COMPLETION_TIME) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) Job(com.hazelcast.jet.Job) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 12 with StreamSource

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

the class JobSnapshotMetricsTest method pipeline.

private Pipeline pipeline() {
    Pipeline p = Pipeline.create();
    StreamSource<Long> source = SourceBuilder.stream(SOURCE_VERTEX_NAME, procCtx -> new long[1]).<Long>fillBufferFn((ctx, buf) -> {
        buf.add(ctx[0]++);
        Thread.sleep(5);
    }).createSnapshotFn(ctx -> ctx[0]).restoreSnapshotFn((ctx, state) -> ctx[0] = state.get(0)).build();
    p.readFrom(source).withoutTimestamps().filter(t -> t % 2 == 0).writeTo(Sinks.noop());
    return p;
}
Also used : SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) JobRepository(com.hazelcast.jet.impl.JobRepository) Config(com.hazelcast.config.Config) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BeforeClass(org.junit.BeforeClass) Pipeline(com.hazelcast.jet.pipeline.Pipeline) QuickTest(com.hazelcast.test.annotation.QuickTest) JobConfig(com.hazelcast.jet.config.JobConfig) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) StreamSource(com.hazelcast.jet.pipeline.StreamSource) Category(org.junit.experimental.categories.Category) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) Job(com.hazelcast.jet.Job) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 13 with StreamSource

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

the class SuspendExecutionOnFailureTest method when_jobSuspendedDueToFailure_then_canBeResumed.

@Test
public void when_jobSuspendedDueToFailure_then_canBeResumed() {
    int numItems = 100;
    int interruptItem = 50;
    StreamSource<Integer> source = SourceBuilder.stream("src", procCtx -> new int[1]).<Integer>fillBufferFn((ctx, buf) -> {
        if (ctx[0] < numItems) {
            buf.add(ctx[0]++);
            sleepMillis(5);
        }
    }).createSnapshotFn(ctx -> ctx[0]).restoreSnapshotFn((ctx, state) -> ctx[0] = state.get(0)).build();
    Pipeline p = Pipeline.create();
    p.readFrom(source).withoutTimestamps().<String, Boolean, Map.Entry<Integer, Integer>>mapUsingIMap("SuspendExecutionOnFailureTest_failureMap", item -> "key", (item, value) -> {
        if (value && item == interruptItem) {
            throw new RuntimeException("Fail deliberately");
        }
        return entry(item, item);
    }).setLocalParallelism(1).writeTo(Sinks.map("SuspendExecutionOnFailureTest_sinkMap"));
    IMap<String, Boolean> counterMap = hz().getMap("SuspendExecutionOnFailureTest_failureMap");
    counterMap.put("key", true);
    jobConfig.setProcessingGuarantee(ProcessingGuarantee.AT_LEAST_ONCE).setSnapshotIntervalMillis(50);
    Job job = hz().getJet().newJob(p, jobConfig);
    assertJobStatusEventually(job, SUSPENDED);
    IMap<Integer, Integer> sinkMap = hz().getMap("SuspendExecutionOnFailureTest_sinkMap");
    counterMap.put("key", false);
    job.resume();
    // sinkMap is an idempotent sink, so even though we're using at-least-once, no key will be duplicated, so it
    // must contain the expected number of items.
    assertTrueEventually(() -> assertEquals(numItems, sinkMap.size()));
    assertTrueEventually(() -> assertEquals(JobStatus.RUNNING, job.getStatus()));
    cancelAndJoin(job);
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Processors(com.hazelcast.jet.core.processor.Processors) StreamSource(com.hazelcast.jet.pipeline.StreamSource) MockP(com.hazelcast.jet.core.TestProcessors.MockP) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Util.entry(com.hazelcast.jet.Util.entry) Map(java.util.Map) SUSPENDED(com.hazelcast.jet.core.JobStatus.SUSPENDED) Job(com.hazelcast.jet.Job) TestInClusterSupport(com.hazelcast.jet.TestInClusterSupport) Before(org.junit.Before) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JobConfig(com.hazelcast.jet.config.JobConfig) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) FAILED(com.hazelcast.jet.core.JobStatus.FAILED) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) COMPLETED(com.hazelcast.jet.core.JobStatus.COMPLETED) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) Job(com.hazelcast.jet.Job) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with StreamSource

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

the class JmsSourceIntegrationTestBase method when_messageIdFn_then_used.

@Test
public void when_messageIdFn_then_used() throws JMSException {
    StreamSource<String> source = Sources.jmsQueueBuilder(getConnectionFactory()).destinationName(destinationName).messageIdFn(m -> {
        throw new RuntimeException("mock exception");
    }).build(TEXT_MESSAGE_FN);
    p.readFrom(source).withoutTimestamps().writeTo(Sinks.logger());
    Job job = instance().getJet().newJob(p, new JobConfig().setProcessingGuarantee(EXACTLY_ONCE));
    sendMessages(true);
    try {
        job.join();
        fail("job didn't fail");
    } catch (Exception e) {
        assertContains(e.toString(), "mock exception");
    }
}
Also used : AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) Mockito.doThrow(org.mockito.Mockito.doThrow) Session(javax.jms.Session) Future(java.util.concurrent.Future) WindowDefinition.tumbling(com.hazelcast.jet.pipeline.WindowDefinition.tumbling) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) MessageProducer(javax.jms.MessageProducer) JobStatus(com.hazelcast.jet.core.JobStatus) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) FunctionEx(com.hazelcast.function.FunctionEx) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JobConfig(com.hazelcast.jet.config.JobConfig) PredicateEx.alwaysFalse(com.hazelcast.function.PredicateEx.alwaysFalse) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Instant(java.time.Instant) DUPS_OK_ACKNOWLEDGE(javax.jms.Session.DUPS_OK_ACKNOWLEDGE) JMSException(javax.jms.JMSException) Collectors(java.util.stream.Collectors) SupplierEx(com.hazelcast.function.SupplierEx) ZoneId(java.time.ZoneId) Sources(com.hazelcast.jet.pipeline.Sources) List(java.util.List) MessageConsumer(javax.jms.MessageConsumer) Assert.assertFalse(org.junit.Assert.assertFalse) WindowResult(com.hazelcast.jet.datamodel.WindowResult) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeClass(org.junit.BeforeClass) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) AUTO_ACKNOWLEDGE(javax.jms.Session.AUTO_ACKNOWLEDGE) MINUTES(java.util.concurrent.TimeUnit.MINUTES) JobProxy(com.hazelcast.jet.impl.JobProxy) StreamSource(com.hazelcast.jet.pipeline.StreamSource) ExceptionUtil.sneakyThrow(com.hazelcast.jet.impl.util.ExceptionUtil.sneakyThrow) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) MapWatermarksToString.mapWatermarksToString(com.hazelcast.jet.core.TestProcessors.MapWatermarksToString.mapWatermarksToString) JmsSourceBuilder(com.hazelcast.jet.pipeline.JmsSourceBuilder) Message(javax.jms.Message) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Job(com.hazelcast.jet.Job) Before(org.junit.Before) IList(com.hazelcast.collection.IList) JobRepository(com.hazelcast.jet.impl.JobRepository) Connection(javax.jms.Connection) TextMessage(javax.jms.TextMessage) 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) Mockito.when(org.mockito.Mockito.when) NONE(com.hazelcast.jet.config.ProcessingGuarantee.NONE) TreeMap(java.util.TreeMap) JmsTestUtil.consumeMessages(com.hazelcast.jet.impl.connector.JmsTestUtil.consumeMessages) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) AT_LEAST_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.AT_LEAST_ONCE) ConnectionFactory(javax.jms.ConnectionFactory) Assert.assertEquals(org.junit.Assert.assertEquals) MapWatermarksToString.mapWatermarksToString(com.hazelcast.jet.core.TestProcessors.MapWatermarksToString.mapWatermarksToString) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) JMSException(javax.jms.JMSException) Test(org.junit.Test)

Aggregations

Pipeline (com.hazelcast.jet.pipeline.Pipeline)14 StreamSource (com.hazelcast.jet.pipeline.StreamSource)14 Job (com.hazelcast.jet.Job)13 Sinks (com.hazelcast.jet.pipeline.Sinks)13 Test (org.junit.Test)13 Category (org.junit.experimental.categories.Category)12 List (java.util.List)11 JobStatus (com.hazelcast.jet.core.JobStatus)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)8 NightlyTest (com.hazelcast.test.annotation.NightlyTest)8 Util.entry (com.hazelcast.jet.Util.entry)7 Arrays (java.util.Arrays)7 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)6 JobConfig (com.hazelcast.jet.config.JobConfig)6 ProcessingGuarantee (com.hazelcast.jet.config.ProcessingGuarantee)6 Connection (java.sql.Connection)6 Statement (java.sql.Statement)6 ArrayList (java.util.ArrayList)6 Before (org.junit.Before)6 ChangeRecord (com.hazelcast.jet.cdc.ChangeRecord)5