Search in sources :

Example 21 with MockPS

use of com.hazelcast.jet.core.TestProcessors.MockPS in project hazelcast-jet 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
    dropOperationsBetween(instance1.getHazelcastInstance(), instance2.getHazelcastInstance(), SpiDataSerializerHook.F_ID, singletonList(SpiDataSerializerHook.NORMAL_RESPONSE));
    String jobName = "job1";
    Future<Job> future = spawn(() -> {
        DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, 1)));
        return instance2.newJob(dag, new JobConfig().setName(jobName));
    });
    StuckProcessor.executionStarted.await();
    Job submittedJob = instance1.getJob(jobName);
    assertNotNull(submittedJob);
    StuckProcessor.proceedLatch.countDown();
    submittedJob.join();
    // When the coordinator leaves before the submission response is received
    instance1.getHazelcastInstance().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) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) Test(org.junit.Test)

Example 22 with MockPS

use of com.hazelcast.jet.core.TestProcessors.MockPS in project hazelcast-jet 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(StuckProcessor::new, nodeCount)));
    // When
    Job job = instances[0].newJob(dag);
    StuckProcessor.executionStarted.await();
    JetInstance instance = createJetMember();
    instance.shutdown();
    StuckProcessor.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) JetInstance(com.hazelcast.jet.JetInstance) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 23 with MockPS

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

the class TopologyChangeTest method when_coordinatorLeavesDuringExecution_then_jobCompletes.

@Test
public void when_coordinatorLeavesDuringExecution_then_jobCompletes() throws Throwable {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, nodeCount)));
    // When
    Long jobId = null;
    try {
        Job job = instances[0].newJob(dag);
        Future<Void> future = job.getFuture();
        jobId = job.getId();
        StuckProcessor.executionStarted.await();
        instances[0].getHazelcastInstance().getLifecycleService().terminate();
        StuckProcessor.proceedLatch.countDown();
        future.get();
        fail();
    } catch (ExecutionException expected) {
        assertTrue(expected.getCause() instanceof HazelcastInstanceNotActiveException);
    }
    // Then
    assertNotNull(jobId);
    final long completedJobId = jobId;
    JobRepository jobRepository = getJetService(instances[1]).getJobRepository();
    assertTrueEventually(() -> {
        JobResult jobResult = jobRepository.getJobResult(completedJobId);
        assertNotNull(jobResult);
        assertTrue(jobResult.isSuccessful());
    });
    final int count = liteMemberFlags[0] ? (2 * nodeCount) : (2 * nodeCount - 1);
    assertEquals(count, MockPS.initCount.get());
    assertTrueEventually(() -> {
        assertEquals(count, MockPS.closeCount.get());
        assertEquals(nodeCount, MockPS.receivedCloseErrors.size());
        for (int i = 0; i < MockPS.receivedCloseErrors.size(); i++) {
            Throwable error = MockPS.receivedCloseErrors.get(i);
            assertTrue(error instanceof TopologyChangedException || error instanceof HazelcastInstanceNotActiveException);
        }
    });
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) JobResult(com.hazelcast.jet.impl.JobResult) JobRepository(com.hazelcast.jet.impl.JobRepository) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 24 with MockPS

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

the class TopologyChangeTest method when_coordinatorLeavesDuringExecution_then_clientStillGetsJobResult.

@Test
public void when_coordinatorLeavesDuringExecution_then_clientStillGetsJobResult() throws Throwable {
    // Given
    JetInstance client = createJetClient();
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, nodeCount)));
    // When
    Job job = client.newJob(dag);
    StuckProcessor.executionStarted.await();
    instances[0].getHazelcastInstance().getLifecycleService().terminate();
    StuckProcessor.proceedLatch.countDown();
    // Then
    job.join();
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) JetInstance(com.hazelcast.jet.JetInstance) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 25 with MockPS

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

the class TopologyChangeTest method when_nodeIsShuttingDownAfterInit_then_jobRestarts.

@Test
public void when_nodeIsShuttingDownAfterInit_then_jobRestarts() {
    // Given that the second node has not received ExecuteOperation yet
    for (JetInstance instance : instances) {
        warmUpPartitions(instance.getHazelcastInstance());
    }
    rejectOperationsBetween(instances[0].getHazelcastInstance(), instances[2].getHazelcastInstance(), JetInitDataSerializerHook.FACTORY_ID, singletonList(START_EXECUTION_OP));
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(TestProcessors.Identity::new, nodeCount - 1)));
    Job job = instances[0].newJob(dag);
    assertTrueEventually(() -> assertEquals(RUNNING, job.getStatus()));
    // When a participant shuts down during execution
    instances[2].shutdown();
    // Then, the job restarts and successfully completes
    job.join();
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) JetInstance(com.hazelcast.jet.JetInstance) Job(com.hazelcast.jet.Job) 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