Search in sources :

Example 36 with JobConfig

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

the class SplitBrainTest method when_jobIsSubmittedToMinoritySide_then_jobIsCancelledDuringMerge.

@Test
public void when_jobIsSubmittedToMinoritySide_then_jobIsCancelledDuringMerge() {
    int firstSubClusterSize = 3;
    int secondSubClusterSize = 2;
    NoOutputSourceP.executionStarted = new CountDownLatch(secondSubClusterSize * PARALLELISM);
    Job[] jobRef = new Job[1];
    BiConsumer<HazelcastInstance[], HazelcastInstance[]> onSplit = (firstSubCluster, secondSubCluster) -> {
        MockPS processorSupplier = new MockPS(NoOutputSourceP::new, secondSubClusterSize);
        DAG dag = new DAG().vertex(new Vertex("test", processorSupplier));
        jobRef[0] = secondSubCluster[0].getJet().newJob(dag, new JobConfig().setSplitBrainProtection(true));
        assertOpenEventually(NoOutputSourceP.executionStarted);
    };
    Consumer<HazelcastInstance[]> afterMerge = instances -> {
        assertTrueEventually(() -> assertEquals(secondSubClusterSize, MockPS.receivedCloseErrors.size()), 20);
        MockPS.receivedCloseErrors.forEach(t -> assertTrue("received: " + t, t instanceof CancellationException));
        try {
            jobRef[0].getFuture().get(30, TimeUnit.SECONDS);
            fail();
        } catch (CancellationException ignored) {
        } catch (Exception e) {
            throw new AssertionError(e);
        }
    };
    testSplitBrain(firstSubClusterSize, secondSubClusterSize, null, 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) ExpectedException(org.junit.rules.ExpectedException) CancellationException(java.util.concurrent.CancellationException) CancellationException(java.util.concurrent.CancellationException) Job(com.hazelcast.jet.Job) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 37 with JobConfig

use of com.hazelcast.jet.config.JobConfig 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 38 with JobConfig

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

the class SplitBrainTest method when_quorumIsLostOnMinority_then_jobDoesNotRestartOnMinorityAndCancelledAfterMerge.

@Test
public void when_quorumIsLostOnMinority_then_jobDoesNotRestartOnMinorityAndCancelledAfterMerge() {
    int firstSubClusterSize = 3;
    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);
    };
    Future[] minorityJobFutureRef = new Future[1];
    BiConsumer<HazelcastInstance[], HazelcastInstance[]> onSplit = (firstSubCluster, secondSubCluster) -> {
        NoOutputSourceP.proceedLatch.countDown();
        assertTrueEventually(() -> assertEquals(clusterSize + firstSubClusterSize, MockPS.initCount.get()));
        long jobId = jobRef[0].getId();
        assertTrueEventually(() -> {
            JetServiceBackend service = getJetServiceBackend(firstSubCluster[0]);
            assertEquals(COMPLETED, service.getJobCoordinationService().getJobStatus(jobId).get());
        });
        JetServiceBackend service2 = getJetServiceBackend(secondSubCluster[0]);
        assertTrueEventually(() -> {
            MasterContext masterContext = service2.getJobCoordinationService().getMasterContext(jobId);
            assertNotNull(masterContext);
            minorityJobFutureRef[0] = masterContext.jobContext().jobCompletionFuture();
        });
        assertTrueAllTheTime(() -> {
            assertStatusNotRunningOrStarting(service2.getJobCoordinationService().getJobStatus(jobId).get());
        }, 20);
    };
    Consumer<HazelcastInstance[]> afterMerge = instances -> {
        assertTrueEventually(() -> {
            assertEquals(clusterSize + firstSubClusterSize, MockPS.initCount.get());
            assertEquals(clusterSize + firstSubClusterSize, MockPS.closeCount.get());
        });
        assertEquals(clusterSize, MockPS.receivedCloseErrors.size());
        MockPS.receivedCloseErrors.forEach(t -> assertTrue("received " + t, t instanceof CancellationException));
        try {
            minorityJobFutureRef[0].get();
            fail();
        } catch (CancellationException expected) {
        } catch (Exception e) {
            throw new AssertionError(e);
        }
    };
    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) ExpectedException(org.junit.rules.ExpectedException) CancellationException(java.util.concurrent.CancellationException) CancellationException(java.util.concurrent.CancellationException) Future(java.util.concurrent.Future) 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 39 with JobConfig

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

the class TerminalSnapshotSynchronizationTest method setup.

private Job setup(boolean snapshotting) {
    HazelcastInstance[] instances = createHazelcastInstances(NODE_COUNT);
    DAG dag = new DAG();
    dag.newVertex("generator", () -> new NoOutputSourceP()).localParallelism(1);
    JobConfig config = new JobConfig().setProcessingGuarantee(snapshotting ? EXACTLY_ONCE : NONE).setSnapshotIntervalMillis(DAYS.toMillis(1));
    Job job = instances[0].getJet().newJob(dag, config);
    assertJobStatusEventually(job, RUNNING);
    return job;
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig)

Example 40 with JobConfig

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

the class TopologyChangeTest method when_nodeIsNotJobParticipant_then_initFails.

@Test
public void when_nodeIsNotJobParticipant_then_initFails() throws Throwable {
    final long jobId = 1;
    final long executionId = 1;
    HazelcastInstance master = instances[0];
    int memberListVersion = Accessors.getClusterService(master).getMemberListVersion();
    Set<MemberInfo> memberInfos = new HashSet<>();
    for (int i = 1; i < instances.length; i++) {
        memberInfos.add(new MemberInfo(getNode(instances[i]).getLocalMember()));
    }
    Version version = instances[0].getCluster().getLocalMember().getVersion().asVersion();
    JobRecord jobRecord = new JobRecord(version, jobId, null, "", new JobConfig(), Collections.emptySet(), null);
    instances[0].getMap(JOB_RECORDS_MAP_NAME).put(jobId, jobRecord);
    InitExecutionOperation op = new InitExecutionOperation(jobId, executionId, memberListVersion, version, memberInfos, null, false);
    Future<Object> future = Accessors.getOperationService(master).createInvocationBuilder(JetServiceBackend.SERVICE_NAME, op, Accessors.getAddress(master)).invoke();
    try {
        future.get();
        fail();
    } catch (ExecutionException e) {
        assertInstanceOf(IllegalArgumentException.class, e.getCause());
        assertTrue("Expected: contains 'is not in participants'\nActual: '" + e.getMessage() + "'", e.getMessage().contains("is not in participants"));
    }
}
Also used : JobConfig(com.hazelcast.jet.config.JobConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Version(com.hazelcast.version.Version) JobRecord(com.hazelcast.jet.impl.JobRecord) InitExecutionOperation(com.hazelcast.jet.impl.operation.InitExecutionOperation) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

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