Search in sources :

Example 31 with Processor

use of com.hazelcast.jet.core.Processor 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 32 with Processor

use of com.hazelcast.jet.core.Processor in project hazelcast by hazelcast.

the class JobMetrics_MiscTest method when_jobRestarted_then_metricsRepopulate.

@Test
public void when_jobRestarted_then_metricsRepopulate() throws Throwable {
    DAG dag = new DAG();
    Vertex v1 = dag.newVertex("v1", TestProcessors.MockP::new);
    Vertex v2 = dag.newVertex("v2", (SupplierEx<Processor>) TestProcessors.NoOutputSourceP::new);
    dag.edge(between(v1, v2));
    Job job = hz().getJet().newJob(dag, JOB_CONFIG_WITH_METRICS);
    TestProcessors.NoOutputSourceP.executionStarted.await();
    assertJobStatusEventually(job, JobStatus.RUNNING);
    job.restart();
    assertJobStatusEventually(job, JobStatus.RUNNING);
    assertTrueEventually(() -> assertJobHasMetrics(job, false));
    TestProcessors.NoOutputSourceP.proceedLatch.countDown();
    job.join();
    assertJobStatusEventually(job, JobStatus.COMPLETED);
    assertJobHasMetrics(job, true);
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) TestProcessors(com.hazelcast.jet.core.TestProcessors) 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 33 with Processor

use of com.hazelcast.jet.core.Processor 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 34 with Processor

use of com.hazelcast.jet.core.Processor in project hazelcast by hazelcast.

the class TestSupportTest method test_processorSupplierHasJetInstance.

@Test
public void test_processorSupplierHasJetInstance() {
    HazelcastInstance hazelcastInstance = mockHazelcastInstance();
    boolean[] called = { false };
    verifyProcessor(new ProcessorSupplier() {

        @Override
        public void init(@Nonnull Context context) {
            assertSame(context.hazelcastInstance(), hazelcastInstance);
            called[0] = true;
        }

        @Nonnull
        @Override
        public Collection<? extends Processor> get(int count) {
            assertEquals(1, count);
            return singletonList(new MockP());
        }
    }).hazelcastInstance(hazelcastInstance).expectOutput(emptyList());
    assertTrue(called[0]);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Processor(com.hazelcast.jet.core.Processor) TestSupport.verifyProcessor(com.hazelcast.jet.core.test.TestSupport.verifyProcessor) Nonnull(javax.annotation.Nonnull) MockP(com.hazelcast.jet.core.TestProcessors.MockP) Collection(java.util.Collection) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 35 with Processor

use of com.hazelcast.jet.core.Processor in project hazelcast by hazelcast.

the class AsyncTransformUsingServicePTest method test_wmNotCountedToParallelOps.

@Test
public void test_wmNotCountedToParallelOps() throws Exception {
    Processor processor = getSupplier(2, (ctx, item) -> new CompletableFuture<>()).get(1).iterator().next();
    processor.init(new TestOutbox(128), new TestProcessorContext());
    TestInbox inbox = new TestInbox();
    inbox.add("foo");
    processor.process(0, inbox);
    assertTrue("inbox not empty", inbox.isEmpty());
    assertTrue("wm rejected", processor.tryProcessWatermark(wm(0)));
    inbox.add("bar");
    processor.process(0, inbox);
    assertTrue("2nd item rejected even though max parallel ops is 1", inbox.isEmpty());
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Traverser(com.hazelcast.jet.Traverser) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Processor(com.hazelcast.jet.core.Processor) CompletableFuture(java.util.concurrent.CompletableFuture) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) HazelcastSerialParametersRunnerFactory(com.hazelcast.test.HazelcastSerialParametersRunnerFactory) Util.exceptionallyCompletedFuture(com.hazelcast.jet.impl.util.Util.exceptionallyCompletedFuture) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Collections.singletonList(java.util.Collections.singletonList) JetException(com.hazelcast.jet.JetException) DEFAULT_MAX_CONCURRENT_OPS(com.hazelcast.jet.pipeline.GeneralStage.DEFAULT_MAX_CONCURRENT_OPS) BiFunctionEx(com.hazelcast.function.BiFunctionEx) Watermark(com.hazelcast.jet.core.Watermark) Arrays.asList(java.util.Arrays.asList) ServiceFactory(com.hazelcast.jet.pipeline.ServiceFactory) ServiceFactories(com.hazelcast.jet.pipeline.ServiceFactories) ExpectedException(org.junit.rules.ExpectedException) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Parameterized(org.junit.runners.Parameterized) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) TestInbox(com.hazelcast.jet.core.test.TestInbox) FunctionEx(com.hazelcast.function.FunctionEx) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) Parameter(org.junit.runners.Parameterized.Parameter) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Traversers.traverseItems(com.hazelcast.jet.Traversers.traverseItems) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Rule(org.junit.Rule) TestSupport(com.hazelcast.jet.core.test.TestSupport) CompletableFuture(java.util.concurrent.CompletableFuture) Processor(com.hazelcast.jet.core.Processor) TestInbox(com.hazelcast.jet.core.test.TestInbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Processor (com.hazelcast.jet.core.Processor)49 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)22 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)17 QuickTest (com.hazelcast.test.annotation.QuickTest)17 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)16 TestOutbox (com.hazelcast.jet.core.test.TestOutbox)14 List (java.util.List)13 Nonnull (javax.annotation.Nonnull)13 TestInbox (com.hazelcast.jet.core.test.TestInbox)11 Watermark (com.hazelcast.jet.core.Watermark)10 Collection (java.util.Collection)9 Collections.singletonList (java.util.Collections.singletonList)9 Entry (java.util.Map.Entry)9 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)8 FunctionEx (com.hazelcast.function.FunctionEx)7 Job (com.hazelcast.jet.Job)7 JobConfig (com.hazelcast.jet.config.JobConfig)7 DAG (com.hazelcast.jet.core.DAG)7 Arrays (java.util.Arrays)6