Search in sources :

Example 96 with MockPS

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

the class TopologyChangeTest method when_addAndRemoveNodeDuringExecution_then_completeSuccessfully.

@Test
public void when_addAndRemoveNodeDuringExecution_then_completeSuccessfully() throws Throwable {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, nodeCount)));
    // When
    Job job = instances[0].getJet().newJob(dag);
    NoOutputSourceP.executionStarted.await();
    HazelcastInstance instance = createHazelcastInstance(config);
    instance.shutdown();
    NoOutputSourceP.proceedLatch.countDown();
    job.join();
    // Then
    assertEquals(nodeCount, MockPS.initCount.get());
    assertTrueEventually(() -> {
        assertEquals(nodeCount, MockPS.closeCount.get());
        assertThat(MockPS.receivedCloseErrors, empty());
    });
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) Job(com.hazelcast.jet.Job) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 97 with MockPS

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

the class TopologyChangeTest method when_nonCoordinatorLeaves_AutoScalingOff_then_jobFailsOrSuspends.

private void when_nonCoordinatorLeaves_AutoScalingOff_then_jobFailsOrSuspends(boolean snapshotted) throws Throwable {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, nodeCount)));
    JobConfig config = new JobConfig();
    config.setAutoScaling(false);
    config.setProcessingGuarantee(snapshotted ? EXACTLY_ONCE : NONE);
    // When
    Job job = instances[0].getJet().newJob(dag, config);
    NoOutputSourceP.executionStarted.await();
    instances[2].getLifecycleService().terminate();
    NoOutputSourceP.proceedLatch.countDown();
    assertJobStatusEventually(job, snapshotted ? SUSPENDED : FAILED, 10);
    if (!snapshotted) {
        try {
            job.join();
            fail("join didn't fail");
        } catch (Exception e) {
            assertContains(e.getMessage(), TopologyChangedException.class.getName());
            assertContains(e.getMessage(), "[127.0.0.1]:5703=" + MemberLeftException.class.getName());
        }
    }
}
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) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) CancellationException(java.util.concurrent.CancellationException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) ExpectedException(org.junit.rules.ExpectedException) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 98 with MockPS

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

the class ScaleUpTest method setup.

private void setup(long scaleUpDelay) {
    TestProcessors.reset(NODE_COUNT * LOCAL_PARALLELISM);
    dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, NODE_COUNT)));
    config = smallInstanceConfig();
    config.getJetConfig().setScaleUpDelayMillis(scaleUpDelay);
    instances = createHazelcastInstances(config, NODE_COUNT);
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS)

Example 99 with MockPS

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

the class SplitBrainTest method when_quorumIsLostOnBothSides_then_jobRestartsAfterMerge.

@Test
public void when_quorumIsLostOnBothSides_then_jobRestartsAfterMerge() {
    int firstSubClusterSize = 2;
    int secondSubClusterSize = 2;
    int clusterSize = firstSubClusterSize + secondSubClusterSize;
    NoOutputSourceP.executionStarted = new CountDownLatch(clusterSize * 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[0].getJet().newJob(dag, new JobConfig().setSplitBrainProtection(true));
        assertOpenEventually(NoOutputSourceP.executionStarted);
    };
    BiConsumer<HazelcastInstance[], HazelcastInstance[]> onSplit = (firstSubCluster, secondSubCluster) -> {
        NoOutputSourceP.proceedLatch.countDown();
        long jobId = jobRef[0].getId();
        assertTrueEventually(() -> {
            JetServiceBackend service1 = getJetServiceBackend(firstSubCluster[0]);
            JetServiceBackend service2 = getJetServiceBackend(secondSubCluster[0]);
            MasterContext masterContext = service1.getJobCoordinationService().getMasterContext(jobId);
            assertNotNull(masterContext);
            masterContext = service2.getJobCoordinationService().getMasterContext(jobId);
            assertNotNull(masterContext);
        });
        assertTrueAllTheTime(() -> {
            JetServiceBackend service1 = getJetServiceBackend(firstSubCluster[0]);
            JetServiceBackend service2 = getJetServiceBackend(secondSubCluster[0]);
            JobStatus status1 = service1.getJobCoordinationService().getJobStatus(jobId).get();
            JobStatus status2 = service2.getJobCoordinationService().getJobStatus(jobId).get();
            assertStatusNotRunningOrStarting(status1);
            assertStatusNotRunningOrStarting(status2);
        }, 20);
    };
    Consumer<HazelcastInstance[]> afterMerge = instances -> {
        assertTrueEventually(() -> {
            assertEquals(clusterSize * 2, MockPS.initCount.get());
            assertEquals(clusterSize * 2, MockPS.closeCount.get());
        });
        assertEquals(clusterSize, MockPS.receivedCloseErrors.size());
        MockPS.receivedCloseErrors.forEach(t -> assertTrue("received " + t, t instanceof CancellationException));
    };
    testSplitBrain(firstSubClusterSize, secondSubClusterSize, beforeSplit, onSplit, 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) CountDownLatch(java.util.concurrent.CountDownLatch) JobConfig(com.hazelcast.jet.config.JobConfig) CancellationException(java.util.concurrent.CancellationException) 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 100 with MockPS

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

the class SplitBrainTest method when_newMemberIsAddedAfterClusterSizeFallsBelowQuorumSize_then_jobRestartDoesNotSucceed.

@Test
public void when_newMemberIsAddedAfterClusterSizeFallsBelowQuorumSize_then_jobRestartDoesNotSucceed() {
    int clusterSize = 5;
    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);
    for (int i = 1; i < clusterSize; i++) {
        instances[i].shutdown();
    }
    NoOutputSourceP.proceedLatch.countDown();
    assertJobStatusEventually(job, NOT_RUNNING, 10);
    HazelcastInstance instance6 = createHazelcastInstance(createConfig());
    assertTrueAllTheTime(() -> assertStatusNotRunningOrStarting(job.getStatus()), 5);
    // The test ends with a cluster size 2, which is below quorum
    // Start another instance so the job can restart and be cleaned up correctly
    HazelcastInstance instance7 = createHazelcastInstance(createConfig());
    waitAllForSafeState(newArrayList(instances[0], instance6, instance7));
    assertTrueEventually(() -> assertStatusRunningOrCompleted(job.getStatus()), 5);
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) CountDownLatch(java.util.concurrent.CountDownLatch) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)135 Job (com.hazelcast.jet.Job)127 Test (org.junit.Test)115 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)56 NoOutputSourceP (com.hazelcast.jet.core.TestProcessors.NoOutputSourceP)53 JobConfig (com.hazelcast.jet.config.JobConfig)49 QuickTest (com.hazelcast.test.annotation.QuickTest)42 StuckProcessor (com.hazelcast.jet.core.TestProcessors.StuckProcessor)40 MockPMS (com.hazelcast.jet.core.TestProcessors.MockPMS)31 MockP (com.hazelcast.jet.core.TestProcessors.MockP)30 HazelcastInstance (com.hazelcast.core.HazelcastInstance)21 CountDownLatch (java.util.concurrent.CountDownLatch)21 JobRepository (com.hazelcast.jet.impl.JobRepository)18 CancellationException (java.util.concurrent.CancellationException)16 Future (java.util.concurrent.Future)16 JetInstance (com.hazelcast.jet.JetInstance)15 MasterContext (com.hazelcast.jet.impl.MasterContext)15 ExpectedException (org.junit.rules.ExpectedException)15 STARTING (com.hazelcast.jet.core.JobStatus.STARTING)14 SlowTest (com.hazelcast.test.annotation.SlowTest)14