Search in sources :

Example 41 with NoOutputSourceP

use of com.hazelcast.jet.core.TestProcessors.NoOutputSourceP in project hazelcast by hazelcast.

the class SplitBrainTest method when_minorityMasterBecomesMajorityMaster_then_jobKeepsRunning.

@Test
public void when_minorityMasterBecomesMajorityMaster_then_jobKeepsRunning() {
    int firstSubClusterSize = 2;
    int secondSubClusterSize = 1;
    int clusterSize = firstSubClusterSize + secondSubClusterSize;
    NoOutputSourceP.executionStarted = new CountDownLatch(secondSubClusterSize * PARALLELISM);
    Job[] jobRef = new Job[1];
    Consumer<HazelcastInstance[]> beforeSplit = instances -> {
        MockPS processorSupplier = new MockPS(NoOutputSourceP::new, clusterSize);
        DAG dag = new DAG().vertex(new Vertex("test", processorSupplier));
        jobRef[0] = instances[2].getJet().newJob(dag);
        assertOpenEventually(NoOutputSourceP.executionStarted);
    };
    Consumer<HazelcastInstance[]> afterMerge = instances -> {
        assertEquals(clusterSize, instances.length);
        logger.info("Shutting down 1st instance");
        instances[0].shutdown();
        logger.info("1st instance down, starting another instance");
        createHazelcastInstance(createConfig());
        logger.info("Shutting down 2nd instance");
        instances[1].shutdown();
        assertTrue(((ClusterService) instances[2].getCluster()).isMaster());
        assertJobStatusEventually(jobRef[0], RUNNING, 10);
        assertTrueAllTheTime(() -> assertEquals(RUNNING, jobRef[0].getStatus()), 5);
    };
    testSplitBrain(firstSubClusterSize, secondSubClusterSize, beforeSplit, null, afterMerge);
}
Also used : MasterContext(com.hazelcast.jet.impl.MasterContext) NOT_RUNNING(com.hazelcast.jet.core.JobStatus.NOT_RUNNING) RunWith(org.junit.runner.RunWith) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) ClusterService(com.hazelcast.internal.cluster.ClusterService) Future(java.util.concurrent.Future) STARTING(com.hazelcast.jet.core.JobStatus.STARTING) BiConsumer(java.util.function.BiConsumer) Assert.fail(org.junit.Assert.fail) ExpectedException(org.junit.rules.ExpectedException) Job(com.hazelcast.jet.Job) JobRepository(com.hazelcast.jet.impl.JobRepository) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) NightlyTest(com.hazelcast.test.annotation.NightlyTest) CancellationException(java.util.concurrent.CancellationException) Assert.assertNotNull(org.junit.Assert.assertNotNull) JobConfig(com.hazelcast.jet.config.JobConfig) MAX_BACKUP_COUNT(com.hazelcast.internal.partition.IPartition.MAX_BACKUP_COUNT) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) Rule(org.junit.Rule) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) JobExecutionRecord(com.hazelcast.jet.impl.JobExecutionRecord) COMPLETED(com.hazelcast.jet.core.JobStatus.COMPLETED) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) Assert.assertEquals(org.junit.Assert.assertEquals) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) ClusterService(com.hazelcast.internal.cluster.ClusterService) CountDownLatch(java.util.concurrent.CountDownLatch) Job(com.hazelcast.jet.Job) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 42 with NoOutputSourceP

use of com.hazelcast.jet.core.TestProcessors.NoOutputSourceP in project hazelcast by hazelcast.

the class OperationLossTest method when_terminateExecutionOperationLost_then_jobTerminates.

@Test
public void when_terminateExecutionOperationLost_then_jobTerminates() {
    PacketFiltersUtil.dropOperationsFrom(instance(), JetInitDataSerializerHook.FACTORY_ID, singletonList(JetInitDataSerializerHook.TERMINATE_EXECUTION_OP));
    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);
    assertJobStatusEventually(job, RUNNING);
    job.cancel();
    // sleep so that the TerminateExecutionOperation is sent out, but lost
    sleepSeconds(1);
    // reset filters so that the situation can resolve
    PacketFiltersUtil.resetPacketFiltersFrom(instance());
    try {
        // Then
        job.join();
    } catch (CancellationException ignored) {
    }
}
Also used : CancellationException(java.util.concurrent.CancellationException) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) Job(com.hazelcast.jet.Job) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 43 with NoOutputSourceP

use of com.hazelcast.jet.core.TestProcessors.NoOutputSourceP in project hazelcast by hazelcast.

the class OperationLossTest method when_connectionDroppedWithoutMemberLeaving_then_jobRestarts.

private void when_connectionDroppedWithoutMemberLeaving_then_jobRestarts(boolean useLightJob) {
    DAG dag = new DAG();
    Vertex source = dag.newVertex("source", () -> new NoOutputSourceP()).localParallelism(1);
    Vertex sink = dag.newVertex("sink", DiagnosticProcessors.writeLoggerP());
    dag.edge(between(source, sink).distributed());
    Job job = useLightJob ? instance().getJet().newLightJob(dag) : instance().getJet().newJob(dag);
    assertTrueEventually(() -> assertEquals(2, NoOutputSourceP.initCount.get()));
    Connection connection = ImdgUtil.getMemberConnection(getNodeEngineImpl(instance()), getAddress(instances()[1]));
    // When
    connection.close(null, null);
    System.out.println("connection closed");
    sleepSeconds(1);
    // Then
    NoOutputSourceP.proceedLatch.countDown();
    if (useLightJob) {
        assertThatThrownBy(job::join).hasMessageContaining("The member was reconnected");
    } else {
        job.join();
        assertEquals(4, NoOutputSourceP.initCount.get());
    }
}
Also used : NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) Connection(com.hazelcast.internal.nio.Connection) Job(com.hazelcast.jet.Job)

Example 44 with NoOutputSourceP

use of com.hazelcast.jet.core.TestProcessors.NoOutputSourceP in project hazelcast by hazelcast.

the class SuspendExecutionOnFailureTest method when_jobSuspendedByUser_then_suspensionCauseSaysSo.

@Test
public void when_jobSuspendedByUser_then_suspensionCauseSaysSo() {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, MEMBER_COUNT)));
    // When
    Job job = hz().getJet().newJob(dag, jobConfig);
    assertJobStatusEventually(job, RUNNING);
    job.suspend();
    assertJobStatusEventually(job, SUSPENDED);
    assertThat(job.getSuspensionCause()).matches(JobSuspensionCause::requestedByUser);
    assertThat(job.getSuspensionCause().description()).isEqualTo("Requested by user");
    assertThatThrownBy(job.getSuspensionCause()::errorCause).isInstanceOf(IllegalStateException.class).hasMessage("Suspension not caused by an error");
    cancelAndJoin(job);
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) Job(com.hazelcast.jet.Job) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 45 with NoOutputSourceP

use of com.hazelcast.jet.core.TestProcessors.NoOutputSourceP in project hazelcast by hazelcast.

the class TopologyChangeDuringJobSubmissionTest method when_jobIsCompletedBeforeSubmissionCallReturns_then_jobRunsOnlyOnce.

@Test
public void when_jobIsCompletedBeforeSubmissionCallReturns_then_jobRunsOnlyOnce() throws Throwable {
    // Given that the job is already completed
    String jobName = "job1";
    Future<Job> future = spawn(() -> {
        DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, 1)));
        return instance2.getJet().newJob(dag, new JobConfig().setName(jobName));
    });
    NoOutputSourceP.executionStarted.await();
    dropOperationsBetween(instance1, instance2, SpiDataSerializerHook.F_ID, singletonList(SpiDataSerializerHook.NORMAL_RESPONSE));
    Job submittedJob = instance1.getJet().getJob(jobName);
    assertNotNull(submittedJob);
    NoOutputSourceP.proceedLatch.countDown();
    submittedJob.join();
    // When the coordinator leaves before the submission response is received
    instance1.getLifecycleService().terminate();
    Job job = future.get();
    // Then the job does not run for the second time
    job.join();
    assertEquals(1, MockPS.initCount.get());
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

NoOutputSourceP (com.hazelcast.jet.core.TestProcessors.NoOutputSourceP)68 Job (com.hazelcast.jet.Job)64 Test (org.junit.Test)54 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)52 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)43 QuickTest (com.hazelcast.test.annotation.QuickTest)33 JobConfig (com.hazelcast.jet.config.JobConfig)31 HazelcastInstance (com.hazelcast.core.HazelcastInstance)22 NightlyTest (com.hazelcast.test.annotation.NightlyTest)11 CancellationException (java.util.concurrent.CancellationException)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 SlowTest (com.hazelcast.test.annotation.SlowTest)10 Config (com.hazelcast.config.Config)9 JetServiceBackend (com.hazelcast.jet.impl.JetServiceBackend)9 JobRepository (com.hazelcast.jet.impl.JobRepository)9 Future (java.util.concurrent.Future)8 ExpectedException (org.junit.rules.ExpectedException)8 JobExecutionRecord (com.hazelcast.jet.impl.JobExecutionRecord)7 MasterContext (com.hazelcast.jet.impl.MasterContext)7 ClusterService (com.hazelcast.internal.cluster.ClusterService)6