Search in sources :

Example 36 with MockPS

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

the class TopologyChangeTest method when_nonCoordinatorLeavesDuringExecution_then_clientStillGetsJobResult.

@Test
public void when_nonCoordinatorLeavesDuringExecution_then_clientStillGetsJobResult() throws Throwable {
    // Given
    HazelcastInstance client = createHazelcastClient();
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, nodeCount)));
    // When
    Job job = client.getJet().newJob(dag);
    NoOutputSourceP.executionStarted.await();
    instances[2].getLifecycleService().terminate();
    NoOutputSourceP.proceedLatch.countDown();
    job.join();
}
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 37 with MockPS

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

the class TopologyChangeTest method when_addNodeDuringExecution_then_completeSuccessfully.

@Test
public void when_addNodeDuringExecution_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();
    createHazelcastInstance(config);
    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) 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 38 with MockPS

use of com.hazelcast.jet.core.TestProcessors.MockPS in project hazelcast 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 (HazelcastInstance instance : instances) {
        warmUpPartitions(instance);
    }
    rejectOperationsBetween(instances[0], instances[2], 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].getJet().newJob(dag);
    assertJobStatusEventually(job, RUNNING);
    // When a participant shuts down during execution
    instances[2].getLifecycleService().terminate();
    // Then, the job restarts and successfully completes
    job.join();
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Job(com.hazelcast.jet.Job) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 39 with MockPS

use of com.hazelcast.jet.core.TestProcessors.MockPS in project hazelcast 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(NoOutputSourceP::new, nodeCount)));
    // When
    Long jobId = null;
    try {
        Job job = instances[0].getJet().newJob(dag);
        Future<Void> future = job.getFuture();
        jobId = job.getId();
        NoOutputSourceP.executionStarted.await();
        instances[0].getLifecycleService().terminate();
        // Processor#close.
        for (int i = 1; i < instances.length; i++) {
            JetServiceBackend jetServiceBackend = getJetServiceBackend(instances[i]);
            jetServiceBackend.getJobExecutionService().waitAllExecutionsTerminated();
        }
        NoOutputSourceP.proceedLatch.countDown();
        future.get();
        fail();
    } catch (ExecutionException expected) {
        assertTrue(expected.getCause() instanceof HazelcastInstanceNotActiveException);
    }
    // Then
    assertNotNull(jobId);
    final long completedJobId = jobId;
    JobRepository jobRepository = getJetServiceBackend(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 (Throwable error : MockPS.receivedCloseErrors) {
            assertTrue("unexpected exc: " + error, error instanceof CancellationException);
        }
    });
}
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) CancellationException(java.util.concurrent.CancellationException) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) Job(com.hazelcast.jet.Job) ExecutionException(java.util.concurrent.ExecutionException) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 40 with MockPS

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

the class ExecutionLifecycleTest method when_jobCompletesSuccessfully_then_closeCalled.

@Test
public void when_jobCompletesSuccessfully_then_closeCalled() {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPMS(() -> new MockPS(MockP::new, MEMBER_COUNT))));
    // When
    Job job = newJob(dag);
    job.join();
    // Then
    assertPClosedWithoutError();
    assertPsClosedWithoutError();
    assertPmsClosedWithoutError();
    assertJobSucceeded(job);
}
Also used : MockPMS(com.hazelcast.jet.core.TestProcessors.MockPMS) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) Job(com.hazelcast.jet.Job) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) 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