Search in sources :

Example 16 with StuckProcessor

use of com.hazelcast.jet.core.TestProcessors.StuckProcessor 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 17 with StuckProcessor

use of com.hazelcast.jet.core.TestProcessors.StuckProcessor 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 18 with StuckProcessor

use of com.hazelcast.jet.core.TestProcessors.StuckProcessor 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 19 with StuckProcessor

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

the class TopologyChangeTest method when_nonCoordinatorLeavesDuringExecution_then_jobRestarts.

@Test
public void when_nonCoordinatorLeavesDuringExecution_then_jobRestarts() 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();
    instances[2].getHazelcastInstance().getLifecycleService().terminate();
    StuckProcessor.proceedLatch.countDown();
    job.join();
    // upon non-coordinator member leave, remaining members restart and complete the job
    final int count = nodeCount * 2 - 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 : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 20 with StuckProcessor

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

the class ExecutionLifecycleTest method when_executionCancelledBeforeStart_then_jobFutureIsCancelledOnExecute.

@Test
public void when_executionCancelledBeforeStart_then_jobFutureIsCancelledOnExecute() {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, NODE_COUNT)));
    NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(instance.getHazelcastInstance());
    Address localAddress = nodeEngineImpl.getThisAddress();
    ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngineImpl.getClusterService();
    MembersView membersView = clusterService.getMembershipManager().getMembersView();
    int memberListVersion = membersView.getVersion();
    JetService jetService = getJetService(instance);
    final Map<MemberInfo, ExecutionPlan> executionPlans = ExecutionPlanBuilder.createExecutionPlans(nodeEngineImpl, membersView, dag, new JobConfig(), NO_SNAPSHOT);
    ExecutionPlan executionPlan = executionPlans.get(membersView.getMember(localAddress));
    long jobId = 0;
    long executionId = 1;
    Set<MemberInfo> participants = new HashSet<>(membersView.getMembers());
    jetService.getJobExecutionService().initExecution(jobId, executionId, localAddress, memberListVersion, participants, executionPlan);
    ExecutionContext executionContext = jetService.getJobExecutionService().getExecutionContext(executionId);
    executionContext.cancelExecution();
    // When
    CompletableFuture<Void> future = executionContext.beginExecution();
    // Then
    expectedException.expect(CancellationException.class);
    future.join();
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) JetService(com.hazelcast.jet.impl.JetService) Address(com.hazelcast.nio.Address) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) MembersView(com.hazelcast.internal.cluster.impl.MembersView) JobConfig(com.hazelcast.jet.config.JobConfig) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) HashSet(java.util.HashSet) 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