Search in sources :

Example 16 with MockP

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

the class JobTimeoutTest method when_jobIsCompletedBeforeTimeout_jobIsNotCancelled.

@Test
public void when_jobIsCompletedBeforeTimeout_jobIsNotCancelled() {
    final HazelcastInstance hz = createHazelcastInstance();
    final DAG dag = new DAG();
    dag.newVertex("normal", MockP::new);
    final JobConfig jobConfig = new JobConfig().setTimeoutMillis(1000L);
    final Job job = hz.getJet().newJob(dag, jobConfig);
    job.join();
    assertEquals(JobStatus.COMPLETED, job.getStatus());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MockP(com.hazelcast.jet.core.TestProcessors.MockP) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with MockP

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

the class JobMetrics_MiscTest method when_jobMetricsDisabled_then_emptyMetrics.

@Test
public void when_jobMetricsDisabled_then_emptyMetrics() throws Throwable {
    DAG dag = new DAG();
    dag.newVertex("v1", MockP::new);
    dag.newVertex("v2", (SupplierEx<Processor>) NoOutputSourceP::new);
    // init
    JobConfig config = new JobConfig().setMetricsEnabled(// enable metric collection
    true).setStoreMetricsAfterJobCompletion(// disable metric saving on completion
    false);
    Job job = hz().getJet().newJob(dag, config);
    // when
    NoOutputSourceP.executionStarted.await();
    assertJobStatusEventually(job, JobStatus.RUNNING);
    // then
    assertTrueEventually(() -> assertJobHasMetrics(job, false));
    // when
    NoOutputSourceP.proceedLatch.countDown();
    job.join();
    // then
    assertJobStatusEventually(job, JobStatus.COMPLETED);
    assertEmptyJobMetrics(job, false);
}
Also used : Processor(com.hazelcast.jet.core.Processor) MockP(com.hazelcast.jet.core.TestProcessors.MockP) DAG(com.hazelcast.jet.core.DAG) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with MockP

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

the class JobMetrics_MiscTest method when_jobRunning_then_nonEmptyMetrics.

@Test
public void when_jobRunning_then_nonEmptyMetrics() throws Throwable {
    DAG dag = new DAG();
    dag.newVertex("v1", MockP::new);
    dag.newVertex("v2", (SupplierEx<Processor>) NoOutputSourceP::new);
    Job job = hz().getJet().newJob(dag, JOB_CONFIG_WITH_METRICS);
    // when
    NoOutputSourceP.executionStarted.await();
    assertJobStatusEventually(job, JobStatus.RUNNING);
    // then
    assertTrueEventually(() -> assertJobHasMetrics(job, false));
    // when
    NoOutputSourceP.proceedLatch.countDown();
    job.join();
    // then
    assertJobStatusEventually(job, JobStatus.COMPLETED);
    assertJobHasMetrics(job, true);
    assertTrue(hz().getMap(JobRepository.JOB_METRICS_MAP_NAME).containsKey(job.getId()));
}
Also used : Processor(com.hazelcast.jet.core.Processor) MockP(com.hazelcast.jet.core.TestProcessors.MockP) DAG(com.hazelcast.jet.core.DAG) Job(com.hazelcast.jet.Job) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with MockP

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

the class MemberReconnectionStressTest method test.

@Test
public void test() {
    /*
        The test will start 2 thread:
        - one will submit short batch jobs, serially, after joining the previous job
        - the other will keep dropping the member-to-member connection.

        The small jobs will often fail due to the reconnection, we check
        that the job completes in a limited time. We drop the connection
        at a rate lower than the normal job duration so there's
        typically at most 1 restart per job. We assert that the jobs
        eventually successfully complete.
         */
    Config config = defaultInstanceConfigWithJetEnabled();
    // The connection drop often causes regular IMap operations to fail - shorten the timeout so that
    // it recovers more quickly
    config.setProperty(ClusterProperty.OPERATION_CALL_TIMEOUT_MILLIS.getName(), "2000");
    config.setClusterName(randomName());
    HazelcastInstance inst1 = createHazelcastInstance(config);
    HazelcastInstance inst2 = createHazelcastInstance(config);
    logger.info("Instances started");
    new Thread(() -> {
        while (!terminated.get()) {
            Connection connection = null;
            while (connection == null) {
                connection = ImdgUtil.getMemberConnection(getNodeEngineImpl(inst1), getNodeEngineImpl(inst2).getThisAddress());
            }
            connection.close("test", new Exception("test failure"));
            logger.info("connection closed");
            sleepMillis(300);
        }
    }).start();
    DAG dag = new DAG();
    Vertex v1 = dag.newVertex("v1", () -> new MockP()).localParallelism(2);
    Vertex v2 = dag.newVertex("v2", () -> new MockP()).localParallelism(2);
    dag.edge(between(v1, v2).distributed());
    AtomicInteger jobCount = new AtomicInteger();
    new Thread(() -> {
        while (!terminated.get()) {
            try {
                inst1.getJet().newJob(dag).getFuture().join();
                logger.info("job completed");
                jobCount.incrementAndGet();
            } catch (Exception e) {
                logger.info("Job failed, ignoring it", e);
            }
        }
    }).start();
    // in a loop check that the `jobCount` is incremented at least every N seconds
    long lastIncrement = System.nanoTime();
    long lastJobCount = 0;
    long testEndTime = System.nanoTime() + MINUTES.toNanos(3);
    for (long now; (now = System.nanoTime()) < testEndTime; ) {
        if (jobCount.get() > lastJobCount) {
            lastIncrement = now;
            lastJobCount++;
        }
        if (NANOSECONDS.toSeconds(now - lastIncrement) > 30) {
            fail("jobCount didn't increment for 30 seconds");
        }
        sleepMillis(100);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Config(com.hazelcast.config.Config) MockP(com.hazelcast.jet.core.TestProcessors.MockP) Connection(com.hazelcast.internal.nio.Connection) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 20 with MockP

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

the class OperationLossTest method lightJob_when_terminateExecutionOperationLost_then_jobTerminates.

@Test
public void lightJob_when_terminateExecutionOperationLost_then_jobTerminates() {
    DAG dag = new DAG();
    dag.newVertex("v", () -> new MockP().streaming());
    Job job = instance().getJet().newLightJob(dag);
    // When
    PacketFiltersUtil.dropOperationsFrom(instance(), JetInitDataSerializerHook.FACTORY_ID, singletonList(JetInitDataSerializerHook.TERMINATE_EXECUTION_OP));
    job.cancel();
    // Then
    assertThatThrownBy(job::join).isInstanceOf(CancellationException.class);
}
Also used : MockP(com.hazelcast.jet.core.TestProcessors.MockP) Job(com.hazelcast.jet.Job) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

MockP (com.hazelcast.jet.core.TestProcessors.MockP)56 Test (org.junit.Test)54 Job (com.hazelcast.jet.Job)49 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)35 QuickTest (com.hazelcast.test.annotation.QuickTest)35 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)30 MockPMS (com.hazelcast.jet.core.TestProcessors.MockPMS)26 HazelcastInstance (com.hazelcast.core.HazelcastInstance)14 JobConfig (com.hazelcast.jet.config.JobConfig)11 DAG (com.hazelcast.jet.core.DAG)9 ExecutionException (java.util.concurrent.ExecutionException)8 ExpectedException (org.junit.rules.ExpectedException)5 JetException (com.hazelcast.jet.JetException)4 Processor (com.hazelcast.jet.core.Processor)4 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)4 NoOutputSourceP (com.hazelcast.jet.core.TestProcessors.NoOutputSourceP)3 Config (com.hazelcast.config.Config)2 JetInstance (com.hazelcast.jet.JetInstance)2 StuckProcessor (com.hazelcast.jet.core.TestProcessors.StuckProcessor)2 NightlyTest (com.hazelcast.test.annotation.NightlyTest)2