Search in sources :

Example 21 with NoOutputSourceP

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

the class JobTest method when_jobIsSubmitted_then_jobSubmissionTimeIsQueried.

private void when_jobIsSubmitted_then_jobSubmissionTimeIsQueried(HazelcastInstance instance, boolean useLightJob) throws Exception {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, NODE_COUNT)));
    // When
    Job job = useLightJob ? instances()[1].getJet().newLightJob(dag) : instance().getJet().newJob(dag);
    NoOutputSourceP.executionStarted.await();
    Job trackedJob = instance.getJet().getJob(job.getId());
    // Then
    assertNotNull(trackedJob);
    long submissionTime = job.getSubmissionTime();
    long trackedJobSubmissionTime = trackedJob.getSubmissionTime();
    assertNotEquals(0, submissionTime);
    assertNotEquals(0, trackedJobSubmissionTime);
    assertEquals(submissionTime, trackedJobSubmissionTime);
    assertBetween("submissionTime", submissionTime, System.currentTimeMillis() - MINUTES.toMillis(10), System.currentTimeMillis() + SECONDS.toMillis(1));
    NoOutputSourceP.proceedLatch.countDown();
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) Job(com.hazelcast.jet.Job)

Example 22 with NoOutputSourceP

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

the class ExecutionLifecycleTest method when_executionCancelledBeforeStart_then_jobIsCancelled.

@Test
public void when_executionCancelledBeforeStart_then_jobIsCancelled() {
    // not applicable to light jobs - light jobs don't use the StartExecutionOperation
    assumeFalse(useLightJob);
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, MEMBER_COUNT)));
    delayOperationsFrom(instance(), JetInitDataSerializerHook.FACTORY_ID, singletonList(JetInitDataSerializerHook.START_EXECUTION_OP));
    Job job = instance().getJet().newJob(dag);
    // RUNNING status is set on master before sending the StartOp
    assertJobStatusEventually(job, RUNNING);
    job.cancel();
    assertThatThrownBy(() -> job.join()).isInstanceOf(CancellationException.class);
}
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) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with NoOutputSourceP

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

the class ExecutionLifecycleTest method when_jobCancelled_then_psCloseNotCalledBeforeTaskletsDone.

@Test
public void when_jobCancelled_then_psCloseNotCalledBeforeTaskletsDone() {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(() -> new NoOutputSourceP(10_000), MEMBER_COUNT)));
    Job job = newJob(dag);
    assertOpenEventually(NoOutputSourceP.executionStarted);
    // When
    job.cancel();
    assertTrueAllTheTime(() -> {
        // Then
        assertEquals("PS.close called before execution finished", 0, MockPS.closeCount.get());
    }, 1);
    NoOutputSourceP.proceedLatch.countDown();
    expectedException.expect(CancellationException.class);
    job.join();
    assertEquals("PS.close not called after execution finished", MEMBER_COUNT, MockPS.closeCount.get());
}
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) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with NoOutputSourceP

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

the class ExecutionLifecycleTest method when_executionCancelledBeforeStart_then_jobFutureIsCancelledOnExecute.

@Test
public void when_executionCancelledBeforeStart_then_jobFutureIsCancelledOnExecute() {
    // not applicable to light jobs - we hack around with ExecutionContext
    assumeFalse(useLightJob);
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, MEMBER_COUNT)));
    NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(instance());
    Address localAddress = nodeEngineImpl.getThisAddress();
    ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngineImpl.getClusterService();
    MembersView membersView = clusterService.getMembershipManager().getMembersView();
    int memberListVersion = membersView.getVersion();
    JetServiceBackend jetServiceBackend = getJetServiceBackend(instance());
    long jobId = 0;
    long executionId = 1;
    JobConfig jobConfig = new JobConfig();
    final Map<MemberInfo, ExecutionPlan> executionPlans = ExecutionPlanBuilder.createExecutionPlans(nodeEngineImpl, membersView.getMembers(), dag, jobId, executionId, jobConfig, NO_SNAPSHOT, false, null);
    ExecutionPlan executionPlan = executionPlans.get(membersView.getMember(localAddress));
    jetServiceBackend.getJobClassLoaderService().getOrCreateClassLoader(jobConfig, jobId, COORDINATOR);
    Set<MemberInfo> participants = new HashSet<>(membersView.getMembers());
    jetServiceBackend.getJobExecutionService().initExecution(jobId, executionId, localAddress, memberListVersion, participants, executionPlan);
    ExecutionContext executionContext = jetServiceBackend.getJobExecutionService().getExecutionContext(executionId);
    executionContext.terminateExecution(null);
    // When
    CompletableFuture<Void> future = executionContext.beginExecution(jetServiceBackend.getTaskletExecutionService());
    // Then
    expectedException.expect(CancellationException.class);
    future.join();
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) Address(com.hazelcast.cluster.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) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with NoOutputSourceP

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

the class JobTest method when_jobSubmitted_then_trackedJobCanQueryJobStatus.

@Test
public void when_jobSubmitted_then_trackedJobCanQueryJobStatus() throws InterruptedException {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, NODE_COUNT)));
    // When
    Job submittedJob = instance().getJet().newJob(dag);
    NoOutputSourceP.executionStarted.await();
    Collection<Job> trackedJobs = instances()[1].getJet().getJobs();
    Job trackedJob = trackedJobs.stream().filter(j -> j.getId() == submittedJob.getId()).findFirst().orElse(null);
    assertNotNull(trackedJob);
    // Then
    assertJobStatusEventually(trackedJob, RUNNING);
    cancelAndJoin(submittedJob);
}
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) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

NoOutputSourceP (com.hazelcast.jet.core.TestProcessors.NoOutputSourceP)68 Job (com.hazelcast.jet.Job)64 Test (org.junit.Test)54 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)52 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)43 QuickTest (com.hazelcast.test.annotation.QuickTest)33 JobConfig (com.hazelcast.jet.config.JobConfig)31 HazelcastInstance (com.hazelcast.core.HazelcastInstance)22 NightlyTest (com.hazelcast.test.annotation.NightlyTest)11 CancellationException (java.util.concurrent.CancellationException)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 SlowTest (com.hazelcast.test.annotation.SlowTest)10 Config (com.hazelcast.config.Config)9 JetServiceBackend (com.hazelcast.jet.impl.JetServiceBackend)9 JobRepository (com.hazelcast.jet.impl.JobRepository)9 Future (java.util.concurrent.Future)8 ExpectedException (org.junit.rules.ExpectedException)8 JobExecutionRecord (com.hazelcast.jet.impl.JobExecutionRecord)7 MasterContext (com.hazelcast.jet.impl.MasterContext)7 ClusterService (com.hazelcast.internal.cluster.ClusterService)6