Search in sources :

Example 6 with TestInbox

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

use of com.hazelcast.jet.core.test.TestInbox 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 8 with TestInbox

use of com.hazelcast.jet.core.test.TestInbox in project hazelcast by hazelcast.

the class WriteKafkaPTest method when_transactionRolledBackHeuristically_then_sinkIgnoresIt.

@Test
public void when_transactionRolledBackHeuristically_then_sinkIgnoresIt() throws Exception {
    /*
        Design of the test:
        We'll create a processor, process 1 item and do phase-1 of the snapshot and then throw
        it away. Then we'll create a new processor and will try to restore the snapshot. It should
        try to commit the transaction from the previous processor, but that transaction timed out,
        which should be logged and ignored.
         */
    int txnTimeout = 2000;
    properties.setProperty("transaction.timeout.ms", String.valueOf(txnTimeout));
    Processor processor = WriteKafkaP.supplier(properties, o -> new ProducerRecord<>(topic, o), true).get();
    TestOutbox outbox = new TestOutbox(new int[0], 1024);
    TestProcessorContext procContext = new TestProcessorContext().setProcessingGuarantee(ProcessingGuarantee.EXACTLY_ONCE);
    processor.init(outbox, procContext);
    TestInbox inbox = new TestInbox();
    inbox.add("foo");
    processor.process(0, inbox);
    assertEquals("inbox size", 0, inbox.size());
    assertTrue(processor.saveToSnapshot());
    processor.close();
    inbox.addAll(outbox.snapshotQueue());
    // transaction.abort.timed.out.transaction.cleanup.interval.ms is set to 200, allow it to kick in
    sleepMillis(txnTimeout + 1000);
    // create the 2nd processor
    processor = WriteKafkaP.supplier(properties, o -> new ProducerRecord<>(topic, o), true).get();
    processor.init(outbox, procContext);
    processor.restoreFromSnapshot(inbox);
    processor.finishSnapshotRestore();
}
Also used : AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Traverser(com.hazelcast.jet.Traverser) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) Processor(com.hazelcast.jet.core.Processor) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) ConsumerRecords(org.apache.kafka.clients.consumer.ConsumerRecords) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ArrayList(java.util.ArrayList) KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) Util.entry(com.hazelcast.jet.Util.entry) Duration(java.time.Duration) IntegerSerializer(org.apache.kafka.common.serialization.IntegerSerializer) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) Collections.singletonMap(java.util.Collections.singletonMap) KafkaSinks(com.hazelcast.jet.kafka.KafkaSinks) Job(com.hazelcast.jet.Job) Before(org.junit.Before) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) TestInbox(com.hazelcast.jet.core.test.TestInbox) AfterClass(org.junit.AfterClass) Properties(java.util.Properties) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) JobConfig(com.hazelcast.jet.config.JobConfig) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Traversers(com.hazelcast.jet.Traversers) Category(org.junit.experimental.categories.Category) Sources(com.hazelcast.jet.pipeline.Sources) List(java.util.List) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Entry(java.util.Map.Entry) HOURS(java.util.concurrent.TimeUnit.HOURS) SinkStressTestUtil(com.hazelcast.jet.impl.connector.SinkStressTestUtil) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) Sink(com.hazelcast.jet.pipeline.Sink) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) Processor(com.hazelcast.jet.core.Processor) TestInbox(com.hazelcast.jet.core.test.TestInbox) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) 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 9 with TestInbox

use of com.hazelcast.jet.core.test.TestInbox in project hazelcast by hazelcast.

the class StreamKafkaPTest method saveSnapshot.

private TestInbox saveSnapshot(StreamKafkaP streamKafkaP, TestOutbox outbox) {
    TestInbox snapshot = new TestInbox();
    assertTrue(streamKafkaP.saveToSnapshot());
    outbox.drainSnapshotQueueAndReset(snapshot.queue(), false);
    return snapshot;
}
Also used : TestInbox(com.hazelcast.jet.core.test.TestInbox)

Example 10 with TestInbox

use of com.hazelcast.jet.core.test.TestInbox in project hazelcast by hazelcast.

the class StreamKafkaPTest method when_snapshotSaved_then_offsetsRestored.

@Test
public void when_snapshotSaved_then_offsetsRestored() throws Exception {
    StreamKafkaP processor = createProcessor(properties(), 2, r -> entry(r.key(), r.value()), 10_000);
    TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
    processor.init(outbox, new TestProcessorContext().setProcessingGuarantee(EXACTLY_ONCE));
    kafkaTestSupport.produce(topic1Name, 0, "0");
    assertEquals(entry(0, "0"), consumeEventually(processor, outbox));
    // create snapshot
    TestInbox snapshot = saveSnapshot(processor, outbox);
    Set<Entry<Object, Object>> snapshotItems = unwrapBroadcastKey(snapshot.queue());
    // consume one more item
    kafkaTestSupport.produce(topic1Name, 1, "1");
    assertEquals(entry(1, "1"), consumeEventually(processor, outbox));
    // create new processor and restore snapshot
    processor = createProcessor(properties(), 2, r -> entry(r.key(), r.value()), 10_000);
    outbox = new TestOutbox(new int[] { 10 }, 10);
    processor.init(outbox, new TestProcessorContext().setProcessingGuarantee(EXACTLY_ONCE));
    // restore snapshot
    processor.restoreFromSnapshot(snapshot);
    assertTrue("snapshot not fully processed", snapshot.isEmpty());
    TestInbox snapshot2 = saveSnapshot(processor, outbox);
    assertEquals("new snapshot not equal after restore", snapshotItems, unwrapBroadcastKey(snapshot2.queue()));
    // the second item should be produced one more time
    assertEquals(entry(1, "1"), consumeEventually(processor, outbox));
    assertNoMoreItems(processor, outbox);
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Arrays(java.util.Arrays) IntStream.range(java.util.stream.IntStream.range) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Processor(com.hazelcast.jet.core.Processor) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Collections.singletonList(java.util.Collections.singletonList) Future(java.util.concurrent.Future) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) Map(java.util.Map) JobStatus(com.hazelcast.jet.core.JobStatus) Collectors.toSet(java.util.stream.Collectors.toSet) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) FunctionEx(com.hazelcast.function.FunctionEx) AfterClass(org.junit.AfterClass) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Collection(java.util.Collection) JobConfig(com.hazelcast.jet.config.JobConfig) Set(java.util.Set) RecordMetadata(org.apache.kafka.clients.producer.RecordMetadata) Category(org.junit.experimental.categories.Category) BroadcastKey(com.hazelcast.jet.core.BroadcastKey) List(java.util.List) IDLE_MESSAGE(com.hazelcast.jet.impl.execution.WatermarkCoalescer.IDLE_MESSAGE) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Assert.assertFalse(org.junit.Assert.assertFalse) Entry(java.util.Map.Entry) JobExecutionRecord(com.hazelcast.jet.impl.JobExecutionRecord) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) BeforeClass(org.junit.BeforeClass) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) HashMap(java.util.HashMap) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) HashSet(java.util.HashSet) Watermark(com.hazelcast.jet.core.Watermark) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Util.entry(com.hazelcast.jet.Util.entry) UuidUtil(com.hazelcast.internal.util.UuidUtil) Nonnull(javax.annotation.Nonnull) Job(com.hazelcast.jet.Job) Before(org.junit.Before) IList(com.hazelcast.collection.IList) TestInbox(com.hazelcast.jet.core.test.TestInbox) JobRepository(com.hazelcast.jet.impl.JobRepository) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ByteArrayDeserializer(org.apache.kafka.common.serialization.ByteArrayDeserializer) TimeoutException(org.apache.kafka.common.errors.TimeoutException) Properties(java.util.Properties) Assert.assertNotNull(org.junit.Assert.assertNotNull) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) Sinks(com.hazelcast.jet.pipeline.Sinks) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) KafkaSources(com.hazelcast.jet.kafka.KafkaSources) WatermarkPolicy.limitingLag(com.hazelcast.jet.core.WatermarkPolicy.limitingLag) ToLongFunctionEx(com.hazelcast.function.ToLongFunctionEx) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) IntegerDeserializer(org.apache.kafka.common.serialization.IntegerDeserializer) EventTimePolicy.eventTimePolicy(com.hazelcast.jet.core.EventTimePolicy.eventTimePolicy) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) Assert.assertEquals(org.junit.Assert.assertEquals) Entry(java.util.Map.Entry) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) 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

TestInbox (com.hazelcast.jet.core.test.TestInbox)22 TestOutbox (com.hazelcast.jet.core.test.TestOutbox)16 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)16 Test (org.junit.Test)13 Processor (com.hazelcast.jet.core.Processor)11 QuickTest (com.hazelcast.test.annotation.QuickTest)8 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 Watermark (com.hazelcast.jet.core.Watermark)6 SimpleTestInClusterSupport (com.hazelcast.jet.SimpleTestInClusterSupport)4 Outbox (com.hazelcast.jet.core.Outbox)4 Before (org.junit.Before)4 FunctionEx (com.hazelcast.function.FunctionEx)3 Traverser (com.hazelcast.jet.Traverser)3 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)3 ILogger (com.hazelcast.logging.ILogger)3 ArrayList (java.util.ArrayList)3 Arrays.asList (java.util.Arrays.asList)3 Collection (java.util.Collection)3 Collections.singletonList (java.util.Collections.singletonList)3 Entry (java.util.Map.Entry)3