Search in sources :

Example 16 with Processor

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

the class AsyncTransformUsingServicePTest method test_watermarksConflated.

@Test
public void test_watermarksConflated() 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();
    // i have to add an item first because otherwise the WMs are forwarded right away
    inbox.add("foo");
    processor.process(0, inbox);
    assertTrue("inbox not empty", inbox.isEmpty());
    assertTrue("wm rejected", processor.tryProcessWatermark(wm(0)));
    assertTrue("wm rejected", processor.tryProcessWatermark(wm(1)));
    assertTrue("wm rejected", processor.tryProcessWatermark(wm(2)));
}
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)

Example 17 with Processor

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

the class SinksTest method mapWithMerging_when_multipleValuesForSingleKeyInABatch.

@Test
public void mapWithMerging_when_multipleValuesForSingleKeyInABatch() throws Exception {
    ProcessorMetaSupplier metaSupplier = adaptSupplier(SinkProcessors.<Entry<String, Integer>, String, Integer>mergeMapP(sinkName, Entry::getKey, Entry::getValue, Integer::sum));
    TestProcessorSupplierContext psContext = new TestProcessorSupplierContext().setHazelcastInstance(member);
    Processor p = TestSupport.supplierFrom(metaSupplier, psContext).get();
    TestOutbox outbox = new TestOutbox();
    p.init(outbox, new TestProcessorContext().setHazelcastInstance(member));
    TestInbox inbox = new TestInbox();
    inbox.add(entry("k", 1));
    inbox.add(entry("k", 2));
    p.process(0, inbox);
    assertTrue("inbox.isEmpty()", inbox.isEmpty());
    assertTrueEventually(() -> {
        assertTrue("p.complete()", p.complete());
    }, 10);
    p.close();
    // assert the output map contents
    IMap<Object, Object> actual = member.getMap(sinkName);
    assertEquals(1, actual.size());
    assertEquals(3, actual.get("k"));
}
Also used : Processor(com.hazelcast.jet.core.Processor) EntryProcessor(com.hazelcast.map.EntryProcessor) TestInbox(com.hazelcast.jet.core.test.TestInbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) TestProcessorSupplierContext(com.hazelcast.jet.core.test.TestProcessorSupplierContext) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 18 with Processor

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

the class JobMetrics_MiscTest method when_metricsForJobDisabled_then_emptyMetrics.

@Test
public void when_metricsForJobDisabled_then_emptyMetrics() throws Throwable {
    DAG dag = new DAG();
    dag.newVertex("v1", MockP::new);
    dag.newVertex("v2", (SupplierEx<Processor>) NoOutputSourceP::new);
    JobConfig config = new JobConfig().setMetricsEnabled(false).setStoreMetricsAfterJobCompletion(true);
    Job job = hz().getJet().newJob(dag, config);
    // when
    NoOutputSourceP.executionStarted.await();
    assertJobStatusEventually(job, JobStatus.RUNNING);
    // then
    assertTrueAllTheTime(() -> assertEmptyJobMetrics(job, false), 2);
    // when
    NoOutputSourceP.proceedLatch.countDown();
    job.join();
    assertJobStatusEventually(job, JobStatus.COMPLETED);
    // then
    assertEmptyJobMetrics(job, true);
}
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 19 with Processor

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

the class JobMetrics_StressTest method buildDag.

private DAG buildDag() {
    DAG dag = new DAG();
    dag.newVertex("p", (SupplierEx<Processor>) IncrementingProcessor::new);
    return dag;
}
Also used : AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) Processor(com.hazelcast.jet.core.Processor) DAG(com.hazelcast.jet.core.DAG)

Example 20 with Processor

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

the class StreamEventJournalPTest method when_lostItems.

@Test
public void when_lostItems() throws Exception {
    TestOutbox outbox = new TestOutbox(new int[] { 16 }, 16);
    Processor p = supplier.get();
    p.init(outbox, new TestProcessorContext().setHazelcastInstance(instance));
    // overflow the journal
    fillJournal(CAPACITY_PER_PARTITION + 1);
    // fill and consume
    List<Object> actual = new ArrayList<>();
    assertTrueEventually(() -> {
        assertFalse("Processor should never complete", p.complete());
        outbox.drainQueueAndReset(0, actual, true);
        assertTrue("consumed different number of items than expected", actual.size() == JOURNAL_CAPACITY);
    }, 3);
}
Also used : Processor(com.hazelcast.jet.core.Processor) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) ArrayList(java.util.ArrayList) 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