Search in sources :

Example 81 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class JobRestartWithSnapshotTest method when_jobRestartedGracefully_then_noOutputDuplicated.

@Test
public void when_jobRestartedGracefully_then_noOutputDuplicated() {
    DAG dag = new DAG();
    int elementsInPartition = 100;
    SupplierEx<Processor> sup = () -> new SequencesInPartitionsGeneratorP(3, elementsInPartition, true);
    Vertex generator = dag.newVertex("generator", throttle(sup, 30)).localParallelism(1);
    Vertex sink = dag.newVertex("sink", writeListP("sink"));
    dag.edge(between(generator, sink));
    JobConfig config = new JobConfig();
    config.setProcessingGuarantee(EXACTLY_ONCE);
    // set long interval so that the first snapshot does not execute
    config.setSnapshotIntervalMillis(3600_000);
    Job job = instance1.getJet().newJob(dag, config);
    // wait for the job to start producing output
    List<Entry<Integer, Integer>> sinkList = instance1.getList("sink");
    assertTrueEventually(() -> assertTrue(sinkList.size() > 10));
    // When
    job.restart();
    job.join();
    // Then
    Set<Entry<Integer, Integer>> expected = IntStream.range(0, elementsInPartition).boxed().flatMap(i -> IntStream.range(0, 3).mapToObj(p -> entry(p, i))).collect(Collectors.toSet());
    assertEquals(expected, new HashSet<>(sinkList));
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) Traverser(com.hazelcast.jet.Traverser) Arrays(java.util.Arrays) PacketFiltersUtil.delayOperationsFrom(com.hazelcast.test.PacketFiltersUtil.delayOperationsFrom) KeyedWindowResult(com.hazelcast.jet.datamodel.KeyedWindowResult) Processors.mapP(com.hazelcast.jet.core.processor.Processors.mapP) Collections.singletonList(java.util.Collections.singletonList) Functions.entryKey(com.hazelcast.function.Functions.entryKey) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) FunctionEx(com.hazelcast.function.FunctionEx) JobConfig(com.hazelcast.jet.config.JobConfig) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) SupplierEx(com.hazelcast.function.SupplierEx) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) BroadcastKey.broadcastKey(com.hazelcast.jet.core.BroadcastKey.broadcastKey) SinkProcessors(com.hazelcast.jet.core.processor.SinkProcessors) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) Entry(java.util.Map.Entry) JobExecutionRecord(com.hazelcast.jet.impl.JobExecutionRecord) Util.arrayIndexOf(com.hazelcast.jet.impl.util.Util.arrayIndexOf) IntStream(java.util.stream.IntStream) RunWith(org.junit.runner.RunWith) Processors(com.hazelcast.jet.core.processor.Processors) HashMap(java.util.HashMap) JetInitDataSerializerHook(com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook) HashSet(java.util.HashSet) TestUtil.throttle(com.hazelcast.jet.core.TestUtil.throttle) Util.entry(com.hazelcast.jet.Util.entry) Processors.combineToSlidingWindowP(com.hazelcast.jet.core.processor.Processors.combineToSlidingWindowP) ExpectedException(org.junit.rules.ExpectedException) Nonnull(javax.annotation.Nonnull) Processors.insertWatermarksP(com.hazelcast.jet.core.processor.Processors.insertWatermarksP) Job(com.hazelcast.jet.Job) Before(org.junit.Before) JobRepository(com.hazelcast.jet.impl.JobRepository) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Assert.assertNotNull(org.junit.Assert.assertNotNull) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AggregateOperation1(com.hazelcast.jet.aggregate.AggregateOperation1) SlowTest(com.hazelcast.test.annotation.SlowTest) WatermarkPolicy.limitingLag(com.hazelcast.jet.core.WatermarkPolicy.limitingLag) Traversers(com.hazelcast.jet.Traversers) Rule(org.junit.Rule) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) EventTimePolicy.eventTimePolicy(com.hazelcast.jet.core.EventTimePolicy.eventTimePolicy) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) Edge.between(com.hazelcast.jet.core.Edge.between) SinkProcessors.writeListP(com.hazelcast.jet.core.processor.SinkProcessors.writeListP) JobConfig(com.hazelcast.jet.config.JobConfig) Entry(java.util.Map.Entry) Job(com.hazelcast.jet.Job) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 82 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class JobRestartWithSnapshotTest method when_snapshotStartedBeforeExecution_then_firstSnapshotIsSuccessful.

@Test
public void when_snapshotStartedBeforeExecution_then_firstSnapshotIsSuccessful() {
    // instance1 is always coordinator
    // delay ExecuteOperation so that snapshot is started before execution is started on the worker member
    delayOperationsFrom(instance1, JetInitDataSerializerHook.FACTORY_ID, singletonList(JetInitDataSerializerHook.START_EXECUTION_OP));
    DAG dag = new DAG();
    dag.newVertex("p", FirstSnapshotProcessor::new).localParallelism(1);
    JobConfig config = new JobConfig();
    config.setProcessingGuarantee(EXACTLY_ONCE);
    config.setSnapshotIntervalMillis(0);
    Job job = instance1.getJet().newJob(dag, config);
    JobRepository repository = new JobRepository(instance1);
    // the first snapshot should succeed
    assertTrueEventually(() -> {
        JobExecutionRecord record = repository.getJobExecutionRecord(job.getId());
        assertNotNull("null JobRecord", record);
        assertEquals(0, record.snapshotId());
    }, 30);
}
Also used : Job(com.hazelcast.jet.Job) JobRepository(com.hazelcast.jet.impl.JobRepository) JobExecutionRecord(com.hazelcast.jet.impl.JobExecutionRecord) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 83 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class ExecutionLifecycleTest method when_executionCancelledBeforeStart_then_jobFutureIsCancelledOnExecute.

@Test
public void when_executionCancelledBeforeStart_then_jobFutureIsCancelledOnExecute() {
    // not applicable to light jobs - we hack around with ExecutionContext
    assumeFalse(useLightJob);
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, MEMBER_COUNT)));
    NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(instance());
    Address localAddress = nodeEngineImpl.getThisAddress();
    ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngineImpl.getClusterService();
    MembersView membersView = clusterService.getMembershipManager().getMembersView();
    int memberListVersion = membersView.getVersion();
    JetServiceBackend jetServiceBackend = getJetServiceBackend(instance());
    long jobId = 0;
    long executionId = 1;
    JobConfig jobConfig = new JobConfig();
    final Map<MemberInfo, ExecutionPlan> executionPlans = ExecutionPlanBuilder.createExecutionPlans(nodeEngineImpl, membersView.getMembers(), dag, jobId, executionId, jobConfig, NO_SNAPSHOT, false, null);
    ExecutionPlan executionPlan = executionPlans.get(membersView.getMember(localAddress));
    jetServiceBackend.getJobClassLoaderService().getOrCreateClassLoader(jobConfig, jobId, COORDINATOR);
    Set<MemberInfo> participants = new HashSet<>(membersView.getMembers());
    jetServiceBackend.getJobExecutionService().initExecution(jobId, executionId, localAddress, memberListVersion, participants, executionPlan);
    ExecutionContext executionContext = jetServiceBackend.getJobExecutionService().getExecutionContext(executionId);
    executionContext.terminateExecution(null);
    // When
    CompletableFuture<Void> future = executionContext.beginExecution(jetServiceBackend.getTaskletExecutionService());
    // Then
    expectedException.expect(CancellationException.class);
    future.join();
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) Address(com.hazelcast.cluster.Address) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) MembersView(com.hazelcast.internal.cluster.impl.MembersView) JobConfig(com.hazelcast.jet.config.JobConfig) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 84 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class OperationLossTest method when_terminalSnapshotOperationLost_then_jobRestarts.

@Test
public void when_terminalSnapshotOperationLost_then_jobRestarts() {
    PacketFiltersUtil.dropOperationsFrom(instance(), JetInitDataSerializerHook.FACTORY_ID, singletonList(JetInitDataSerializerHook.SNAPSHOT_PHASE1_OPERATION));
    DAG dag = new DAG();
    Vertex v1 = dag.newVertex("v1", () -> new NoOutputSourceP()).localParallelism(1);
    Vertex v2 = dag.newVertex("v2", mapP(identity())).localParallelism(1);
    dag.edge(between(v1, v2).distributed());
    Job job = instance().getJet().newJob(dag, new JobConfig().setProcessingGuarantee(EXACTLY_ONCE));
    assertJobStatusEventually(job, RUNNING, 20);
    job.restart();
    // sleep so that the SnapshotOperation is sent out, but lost
    sleepSeconds(1);
    // reset filters so that the situation can resolve
    PacketFiltersUtil.resetPacketFiltersFrom(instance());
    // Then
    assertTrueEventually(() -> assertEquals(4, NoOutputSourceP.initCount.get()));
    NoOutputSourceP.proceedLatch.countDown();
    job.join();
}
Also used : NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 85 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class OperationLossTest method when_snapshotOperationLost_then_retried.

@Test
public void when_snapshotOperationLost_then_retried() {
    PacketFiltersUtil.dropOperationsFrom(instance(), JetInitDataSerializerHook.FACTORY_ID, singletonList(JetInitDataSerializerHook.SNAPSHOT_PHASE1_OPERATION));
    DAG dag = new DAG();
    Vertex v1 = dag.newVertex("v1", () -> new DummyStatefulP()).localParallelism(1);
    Vertex v2 = dag.newVertex("v2", mapP(identity())).localParallelism(1);
    dag.edge(between(v1, v2).distributed());
    Job job = instance().getJet().newJob(dag, new JobConfig().setProcessingGuarantee(EXACTLY_ONCE).setSnapshotIntervalMillis(100));
    assertJobStatusEventually(job, RUNNING);
    JobRepository jobRepository = new JobRepository(instance());
    assertTrueEventually(() -> {
        JobExecutionRecord record = jobRepository.getJobExecutionRecord(job.getId());
        assertNotNull("null JobExecutionRecord", record);
        assertEquals("ongoingSnapshotId", 0, record.ongoingSnapshotId());
    }, 20);
    sleepSeconds(1);
    // now lift the filter and check that a snapshot is done
    logger.info("Lifting the packet filter...");
    PacketFiltersUtil.resetPacketFiltersFrom(instance());
    waitForFirstSnapshot(jobRepository, job.getId(), 10, false);
    cancelAndJoin(job);
}
Also used : DummyStatefulP(com.hazelcast.jet.core.TestProcessors.DummyStatefulP) Job(com.hazelcast.jet.Job) JobRepository(com.hazelcast.jet.impl.JobRepository) JobExecutionRecord(com.hazelcast.jet.impl.JobExecutionRecord) JobConfig(com.hazelcast.jet.config.JobConfig) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

JobConfig (com.hazelcast.jet.config.JobConfig)254 Test (org.junit.Test)196 Job (com.hazelcast.jet.Job)160 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)111 QuickTest (com.hazelcast.test.annotation.QuickTest)109 Pipeline (com.hazelcast.jet.pipeline.Pipeline)70 HazelcastInstance (com.hazelcast.core.HazelcastInstance)64 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)46 Category (org.junit.experimental.categories.Category)45 Assert.assertEquals (org.junit.Assert.assertEquals)43 DAG (com.hazelcast.jet.core.DAG)41 JobRepository (com.hazelcast.jet.impl.JobRepository)40 List (java.util.List)36 NoOutputSourceP (com.hazelcast.jet.core.TestProcessors.NoOutputSourceP)35 Config (com.hazelcast.config.Config)33 Assert.assertTrue (org.junit.Assert.assertTrue)32 ArrayList (java.util.ArrayList)31 Sinks (com.hazelcast.jet.pipeline.Sinks)28 RUNNING (com.hazelcast.jet.core.JobStatus.RUNNING)27 RunWith (org.junit.runner.RunWith)27