Search in sources :

Example 6 with JobRepository

use of com.hazelcast.jet.impl.JobRepository in project hazelcast by hazelcast.

the class SourceBuilderTest method test_nonFaultTolerantSource_processingGuaranteeOn.

@Test
public void test_nonFaultTolerantSource_processingGuaranteeOn() {
    StreamSource<Integer> source = SourceBuilder.stream("src", procCtx -> "foo").<Integer>fillBufferFn((ctx, buffer) -> {
        buffer.add(0);
        Thread.sleep(100);
    }).build();
    Pipeline p = Pipeline.create();
    IList<Integer> result = hz().getList("result-" + UuidUtil.newUnsecureUuidString());
    p.readFrom(source).withoutTimestamps().writeTo(Sinks.list(result));
    Job job = hz().getJet().newJob(p, new JobConfig().setProcessingGuarantee(EXACTLY_ONCE).setSnapshotIntervalMillis(100));
    JobRepository jr = new JobRepository(hz());
    waitForFirstSnapshot(jr, job.getId(), 10, true);
    job.restart();
    assertJobStatusEventually(job, JobStatus.RUNNING);
    int currentSize = result.size();
    assertTrueEventually(() -> assertTrue(result.size() > currentSize), 5);
}
Also used : IntStream(java.util.stream.IntStream) Socket(java.net.Socket) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) ArrayList(java.util.ArrayList) ServerSocket(java.net.ServerSocket) WindowDefinition.tumbling(com.hazelcast.jet.pipeline.WindowDefinition.tumbling) Map(java.util.Map) UuidUtil(com.hazelcast.internal.util.UuidUtil) OutputStreamWriter(java.io.OutputStreamWriter) JobStatus(com.hazelcast.jet.core.JobStatus) Job(com.hazelcast.jet.Job) IList(com.hazelcast.collection.IList) JobRepository(com.hazelcast.jet.impl.JobRepository) PrintWriter(java.io.PrintWriter) FunctionEx(com.hazelcast.function.FunctionEx) LongStream(java.util.stream.LongStream) Iterator(java.util.Iterator) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) JobConfig(com.hazelcast.jet.config.JobConfig) FileWriter(java.io.FileWriter) AggregateOperations(com.hazelcast.jet.aggregate.AggregateOperations) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Serializable(java.io.Serializable) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ToLongFunctionEx(com.hazelcast.function.ToLongFunctionEx) Assert.assertFalse(org.junit.Assert.assertFalse) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Assert.assertEquals(org.junit.Assert.assertEquals) WindowResult(com.hazelcast.jet.datamodel.WindowResult) Job(com.hazelcast.jet.Job) JobRepository(com.hazelcast.jet.impl.JobRepository) JobConfig(com.hazelcast.jet.config.JobConfig) Test(org.junit.Test)

Example 7 with JobRepository

use of com.hazelcast.jet.impl.JobRepository 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)

Example 8 with JobRepository

use of com.hazelcast.jet.impl.JobRepository in project hazelcast by hazelcast.

the class JobTimeoutClusterTest method when_masterFails_timedOutJobIsCancelled.

@Test
public void when_masterFails_timedOutJobIsCancelled() {
    final HazelcastInstance[] instances = createHazelcastInstances(2);
    final HazelcastInstance oldMaster = instances[0];
    final HazelcastInstance newMaster = instances[1];
    assertClusterSizeEventually(2, newMaster);
    assertClusterStateEventually(ClusterState.ACTIVE, newMaster);
    final DAG dag = new DAG();
    dag.newVertex("stuck", () -> new MockP().streaming());
    final JobConfig jobConfig = new JobConfig().setTimeoutMillis(10000L).setSnapshotIntervalMillis(1L).setProcessingGuarantee(ProcessingGuarantee.EXACTLY_ONCE);
    final Job job = oldMaster.getJet().newJob(dag, jobConfig);
    final long jobId = job.getId();
    // start and wait for the job to start running
    assertJobStatusEventually(job, JobStatus.RUNNING);
    final JobRepository oldJobRepository = new JobRepository(oldMaster);
    assertTrueEventually(() -> {
        final JobExecutionRecord record = oldJobRepository.getJobExecutionRecord(jobId);
        assertTrue(record.snapshotId() > 0);
    });
    // kill old master and wait for the cluster to reconfigure
    oldMaster.getLifecycleService().terminate();
    assertClusterStateEventually(ClusterState.ACTIVE, newMaster);
    assertClusterSize(1, newMaster);
    // wait for the job to be restarted and cancelled due to timeout
    final Job restartedJob = newMaster.getJet().getJob(jobId);
    assertNotNull(restartedJob);
    assertJobStatusEventually(restartedJob, JobStatus.FAILED);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MockP(com.hazelcast.jet.core.TestProcessors.MockP) Job(com.hazelcast.jet.Job) JobRepository(com.hazelcast.jet.impl.JobRepository) JobExecutionRecord(com.hazelcast.jet.impl.JobExecutionRecord) JobConfig(com.hazelcast.jet.config.JobConfig) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 9 with JobRepository

use of com.hazelcast.jet.impl.JobRepository in project hazelcast by hazelcast.

the class SplitBrainTest method when_newMemberJoinsToCluster_then_jobQuorumSizeIsUpdated.

@Test
public void when_newMemberJoinsToCluster_then_jobQuorumSizeIsUpdated() {
    int clusterSize = 3;
    HazelcastInstance[] instances = new HazelcastInstance[clusterSize];
    for (int i = 0; i < clusterSize; i++) {
        instances[i] = createHazelcastInstance(createConfig());
    }
    NoOutputSourceP.executionStarted = new CountDownLatch(clusterSize * PARALLELISM);
    MockPS processorSupplier = new MockPS(NoOutputSourceP::new, clusterSize);
    DAG dag = new DAG().vertex(new Vertex("test", processorSupplier).localParallelism(PARALLELISM));
    Job job = instances[0].getJet().newJob(dag, new JobConfig().setSplitBrainProtection(true));
    assertOpenEventually(NoOutputSourceP.executionStarted);
    createHazelcastInstance(createConfig());
    assertTrueEventually(() -> {
        JetServiceBackend service = getJetServiceBackend(instances[0]);
        JobRepository jobRepository = service.getJobRepository();
        JobExecutionRecord record = jobRepository.getJobExecutionRecord(job.getId());
        assertEquals(3, record.getQuorumSize());
        MasterContext masterContext = service.getJobCoordinationService().getMasterContext(job.getId());
        assertEquals(3, masterContext.jobExecutionRecord().getQuorumSize());
    });
    NoOutputSourceP.proceedLatch.countDown();
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) CountDownLatch(java.util.concurrent.CountDownLatch) JobRepository(com.hazelcast.jet.impl.JobRepository) JobExecutionRecord(com.hazelcast.jet.impl.JobExecutionRecord) JobConfig(com.hazelcast.jet.config.JobConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) Job(com.hazelcast.jet.Job) MasterContext(com.hazelcast.jet.impl.MasterContext) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 10 with JobRepository

use of com.hazelcast.jet.impl.JobRepository in project hazelcast by hazelcast.

the class PostponedSnapshotTest method when_jobHasHigherPriorityEdge_then_noSnapshotUntilEdgeDone.

@Test
public void when_jobHasHigherPriorityEdge_then_noSnapshotUntilEdgeDone() {
    Job job = startJob(100);
    latches.set(0, 1);
    JobRepository jr = new JobRepository(instance);
    assertTrueEventually(() -> assertTrue(jr.getJobExecutionRecord(job.getId()).dataMapIndex() != NO_SNAPSHOT));
    // finish the job
    latches.set(1, 1);
    job.join();
}
Also used : Job(com.hazelcast.jet.Job) JobRepository(com.hazelcast.jet.impl.JobRepository) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Job (com.hazelcast.jet.Job)26 JobRepository (com.hazelcast.jet.impl.JobRepository)26 JobConfig (com.hazelcast.jet.config.JobConfig)22 Test (org.junit.Test)22 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)14 QuickTest (com.hazelcast.test.annotation.QuickTest)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)8 EXACTLY_ONCE (com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE)7 JobExecutionRecord (com.hazelcast.jet.impl.JobExecutionRecord)7 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)5 NoOutputSourceP (com.hazelcast.jet.core.TestProcessors.NoOutputSourceP)5 SlowTest (com.hazelcast.test.annotation.SlowTest)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 Category (org.junit.experimental.categories.Category)5 Config (com.hazelcast.config.Config)4 Edge.between (com.hazelcast.jet.core.Edge.between)4 RUNNING (com.hazelcast.jet.core.JobStatus.RUNNING)4