Search in sources :

Example 26 with StuckProcessor

use of com.hazelcast.jet.core.TestProcessors.StuckProcessor in project hazelcast-jet by hazelcast.

the class JobTest method when_jobIsCancelled_then_jobStatusIsCompletedEventually.

@Test
public void when_jobIsCancelled_then_jobStatusIsCompletedEventually() throws InterruptedException {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, NODE_COUNT)));
    // When
    Job job = instance1.newJob(dag);
    StuckProcessor.executionStarted.await();
    // Then
    job.cancel();
    joinAndExpectCancellation(job);
    StuckProcessor.proceedLatch.countDown();
    assertCompletedEventually(job);
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 27 with StuckProcessor

use of com.hazelcast.jet.core.TestProcessors.StuckProcessor in project hazelcast-jet by hazelcast.

the class JobTest method when_jobsAreCompleted_then_lastSubmittedJobIsQueriedByName.

@Test
public void when_jobsAreCompleted_then_lastSubmittedJobIsQueriedByName() {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, NODE_COUNT * 2)));
    JobConfig config = new JobConfig();
    String jobName = "job1";
    config.setName(jobName);
    // When
    Job job1 = instance1.newJob(dag, config);
    sleepAtLeastMillis(1);
    Job job2 = instance1.newJob(dag, config);
    StuckProcessor.proceedLatch.countDown();
    job1.join();
    job2.join();
    // Then
    Job trackedJob = instance1.getJob(jobName);
    assertNotNull(trackedJob);
    assertEquals(jobName, trackedJob.getName());
    assertNotEquals(job1.getId(), trackedJob.getId());
    assertEquals(job2.getId(), trackedJob.getId());
    assertEquals(COMPLETED, trackedJob.getStatus());
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) Test(org.junit.Test)

Example 28 with StuckProcessor

use of com.hazelcast.jet.core.TestProcessors.StuckProcessor in project hazelcast-jet by hazelcast.

the class JobTest method when_jobIsCancelled_then_trackedJobCanQueryJobResult.

@Test
public void when_jobIsCancelled_then_trackedJobCanQueryJobResult() throws InterruptedException {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, NODE_COUNT)));
    // When
    Job submittedJob = instance1.newJob(dag);
    StuckProcessor.executionStarted.await();
    Collection<Job> trackedJobs = instance2.getJobs();
    assertEquals(1, trackedJobs.size());
    Job trackedJob = trackedJobs.iterator().next();
    submittedJob.cancel();
    // Then
    joinAndExpectCancellation(trackedJob);
    StuckProcessor.proceedLatch.countDown();
    assertCompletedEventually(trackedJob);
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 29 with StuckProcessor

use of com.hazelcast.jet.core.TestProcessors.StuckProcessor in project hazelcast-jet by hazelcast.

the class JobTest method when_trackedJobCancels_then_jobCompletes.

@Test
public void when_trackedJobCancels_then_jobCompletes() {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, NODE_COUNT)));
    Job submittedJob = instance1.newJob(dag);
    Collection<Job> trackedJobs = instance2.getJobs();
    assertEquals(1, trackedJobs.size());
    Job trackedJob = trackedJobs.iterator().next();
    // When
    trackedJob.cancel();
    // Then
    joinAndExpectCancellation(trackedJob);
    joinAndExpectCancellation(submittedJob);
    StuckProcessor.proceedLatch.countDown();
    assertCompletedEventually(trackedJob);
    assertCompletedEventually(submittedJob);
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 30 with StuckProcessor

use of com.hazelcast.jet.core.TestProcessors.StuckProcessor in project hazelcast-jet by hazelcast.

the class SplitBrainTest method when_jobIsSubmittedToMinoritySide_then_jobIsCancelledDuringMerge.

@Test
public void when_jobIsSubmittedToMinoritySide_then_jobIsCancelledDuringMerge() {
    int firstSubClusterSize = 3;
    int secondSubClusterSize = 2;
    int clusterSize = firstSubClusterSize + secondSubClusterSize;
    StuckProcessor.executionStarted = new CountDownLatch(secondSubClusterSize * PARALLELISM);
    Job[] jobRef = new Job[1];
    BiConsumer<JetInstance[], JetInstance[]> onSplit = (firstSubCluster, secondSubCluster) -> {
        MockPS processorSupplier = new MockPS(StuckProcessor::new, clusterSize);
        DAG dag = new DAG().vertex(new Vertex("test", processorSupplier));
        jobRef[0] = secondSubCluster[1].newJob(dag, new JobConfig().setSplitBrainProtection(true));
        assertOpenEventually(StuckProcessor.executionStarted);
    };
    Consumer<JetInstance[]> afterMerge = instances -> {
        assertEquals(secondSubClusterSize, MockPS.receivedCloseErrors.size());
        MockPS.receivedCloseErrors.forEach(t -> assertTrue(t instanceof TopologyChangedException));
        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) JetInstance(com.hazelcast.jet.JetInstance) RunWith(org.junit.runner.RunWith) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) 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) JetConfig(com.hazelcast.jet.config.JetConfig) MAX_BACKUP_COUNT(com.hazelcast.spi.partition.IPartition.MAX_BACKUP_COUNT) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) CancellationException(java.util.concurrent.CancellationException) RESTARTING(com.hazelcast.jet.core.JobStatus.RESTARTING) Assert.assertNotNull(org.junit.Assert.assertNotNull) JobConfig(com.hazelcast.jet.config.JobConfig) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) Rule(org.junit.Rule) JetService(com.hazelcast.jet.impl.JetService) COMPLETED(com.hazelcast.jet.core.JobStatus.COMPLETED) JobRecord(com.hazelcast.jet.impl.JobRecord) Assert.assertEquals(org.junit.Assert.assertEquals) 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) Test(org.junit.Test)

Aggregations

MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)37 StuckProcessor (com.hazelcast.jet.core.TestProcessors.StuckProcessor)37 Job (com.hazelcast.jet.Job)36 Test (org.junit.Test)32 JobConfig (com.hazelcast.jet.config.JobConfig)20 JetInstance (com.hazelcast.jet.JetInstance)12 JetConfig (com.hazelcast.jet.config.JetConfig)8 JobRepository (com.hazelcast.jet.impl.JobRepository)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 JetService (com.hazelcast.jet.impl.JetService)7 STARTING (com.hazelcast.jet.core.JobStatus.STARTING)6 MasterContext (com.hazelcast.jet.impl.MasterContext)6 Future (java.util.concurrent.Future)6 Assert.assertEquals (org.junit.Assert.assertEquals)6 Assert.assertNotNull (org.junit.Assert.assertNotNull)6 Assert.assertTrue (org.junit.Assert.assertTrue)6 Assert.fail (org.junit.Assert.fail)6 Rule (org.junit.Rule)6 ExpectedException (org.junit.rules.ExpectedException)6 RunWith (org.junit.runner.RunWith)6