Search in sources :

Example 61 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.

the class CancellationTest method when_jobCancelledOnSingleNode_then_terminatedEventually.

@Test
public void when_jobCancelledOnSingleNode_then_terminatedEventually() {
    // Given
    JetInstance instance = newInstance();
    DAG dag = new DAG();
    dag.newVertex("slow", StuckSource::new);
    Job job = instance.newJob(dag);
    assertExecutionStarted();
    // When
    job.cancel();
    // Then
    assertExecutionTerminated();
    expectedException.expect(CancellationException.class);
    job.join();
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 62 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.

the class CancellationTest method when_jobCancelled_then_jobStatusIsSetDuringCancellation.

@Test
public void when_jobCancelled_then_jobStatusIsSetDuringCancellation() {
    // Given
    JetInstance instance1 = newInstance();
    JetInstance instance2 = newInstance();
    rejectOperationsBetween(instance1.getHazelcastInstance(), instance2.getHazelcastInstance(), JetInitDataSerializerHook.FACTORY_ID, singletonList(JetInitDataSerializerHook.COMPLETE_EXECUTION_OP));
    DAG dag = new DAG();
    dag.newVertex("slow", StuckSource::new);
    Job job = instance1.newJob(dag);
    assertExecutionStarted();
    // When
    job.cancel();
    // Then
    assertTrueEventually(() -> assertEquals(JobStatus.COMPLETING, job.getStatus()), 3);
    resetPacketFiltersFrom(instance1.getHazelcastInstance());
    assertTrueEventually(() -> assertEquals(JobStatus.COMPLETED, job.getStatus()), 3);
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 63 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.

the class CancellationTest method when_jobCanceled_then_jobFutureCanceled.

@Test
public void when_jobCanceled_then_jobFutureCanceled() {
    JetInstance jet = newInstance();
    DAG dag = new DAG();
    dag.newVertex("blocking", BlockingProcessor::new).localParallelism(1);
    Job job = jet.newJob(dag);
    assertTrueEventually(() -> assertTrue(BlockingProcessor.hasStarted), 3);
    job.cancel();
    assertBlockingProcessorEventuallyNotRunning();
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 64 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.

the class CancellationTest method when_jobCancelledFromClient_then_terminatedEventually.

@Test
public void when_jobCancelledFromClient_then_terminatedEventually() {
    // Given
    newInstance();
    newInstance();
    JetInstance client = createJetClient();
    DAG dag = new DAG();
    dag.newVertex("slow", StuckSource::new);
    Job job = client.newJob(dag);
    assertExecutionStarted();
    // When
    job.cancel();
    // Then
    assertExecutionTerminated();
    expectedException.expect(CancellationException.class);
    job.join();
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 65 with JetInstance

use of com.hazelcast.jet.JetInstance 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

JetInstance (com.hazelcast.jet.JetInstance)84 Test (org.junit.Test)45 Job (com.hazelcast.jet.Job)32 JetConfig (com.hazelcast.jet.config.JetConfig)22 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)14 Pipeline (com.hazelcast.jet.pipeline.Pipeline)14 JobConfig (com.hazelcast.jet.config.JobConfig)13 StuckProcessor (com.hazelcast.jet.core.TestProcessors.StuckProcessor)12 DAG (com.hazelcast.jet.core.DAG)10 ExpectedException (org.junit.rules.ExpectedException)10 Jet (com.hazelcast.jet.Jet)9 Assert.assertEquals (org.junit.Assert.assertEquals)9 JetService (com.hazelcast.jet.impl.JetService)8 Map (java.util.Map)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 JobRepository (com.hazelcast.jet.impl.JobRepository)7 Sources (com.hazelcast.jet.pipeline.Sources)7 CancellationException (java.util.concurrent.CancellationException)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7 Before (org.junit.Before)7