Search in sources :

Example 36 with TestOutbox

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

the class StreamEventJournalP_WmCoalescingTest method when_allPartitionsIdleAndThenRecover_then_wmOutput.

@Test
public void when_allPartitionsIdleAndThenRecover_then_wmOutput() throws Exception {
    // Insert to map in parallel to verifyProcessor.
    CountDownLatch latch = new CountDownLatch(1);
    Thread updatingThread = new Thread(() -> uncheckRun(() -> {
        // We will start after a delay so that the source will first become idle and then recover.
        latch.await();
        for (; ; ) {
            map.put(partitionKeys[0], 12);
            Thread.sleep(100);
        }
    }));
    updatingThread.start();
    Processor processor = createSupplier(asList(0, 1), 2000).get();
    TestOutbox outbox = new TestOutbox(1024);
    Queue<Object> outbox0 = outbox.queue(0);
    processor.init(outbox, new TestProcessorContext().setHazelcastInstance(instance));
    assertTrueEventually(() -> {
        processor.complete();
        // after we have the IDLE_MESSAGE, release the latch to let the other thread produce events
        if (IDLE_MESSAGE.equals(outbox0.peek())) {
            latch.countDown();
        }
        assertEquals(asList(IDLE_MESSAGE, wm(12), 12), outbox0.stream().distinct().collect(toList()));
    });
    updatingThread.interrupt();
    updatingThread.join();
}
Also used : Processor(com.hazelcast.jet.core.Processor) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 37 with TestOutbox

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

the class StreamJmsPTest method initializeProcessor.

private void initializeProcessor(String destinationName, boolean isQueue, FunctionEx<Message, String> projectionFn) throws Exception {
    processorConnection = getConnectionFactory().createConnection();
    processorConnection.start();
    FunctionEx<Session, MessageConsumer> consumerFn = s -> s.createConsumer(isQueue ? s.createQueue(destinationName) : s.createTopic(destinationName));
    if (projectionFn == null) {
        projectionFn = m -> ((TextMessage) m).getText();
    }
    processor = new StreamJmsP<>(processorConnection, consumerFn, Message::getJMSMessageID, projectionFn, noEventTime(), NONE);
    outbox = new TestOutbox(1);
    processor.init(outbox, new TestProcessorContext());
}
Also used : Address(com.hazelcast.cluster.Address) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) StreamSource(com.hazelcast.jet.pipeline.StreamSource) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) Function(java.util.function.Function) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Session(javax.jms.Session) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) MessageProducer(javax.jms.MessageProducer) ClassRule(org.junit.ClassRule) Message(javax.jms.Message) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) EventTimePolicy.noEventTime(com.hazelcast.jet.core.EventTimePolicy.noEventTime) FunctionEx(com.hazelcast.function.FunctionEx) Connection(javax.jms.Connection) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) TextMessage(javax.jms.TextMessage) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) EmbeddedActiveMQResource(org.apache.activemq.artemis.junit.EmbeddedActiveMQResource) NONE(com.hazelcast.jet.config.ProcessingGuarantee.NONE) Sources(com.hazelcast.jet.pipeline.Sources) List(java.util.List) MessageConsumer(javax.jms.MessageConsumer) Destination(javax.jms.Destination) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) StreamSourceTransform(com.hazelcast.jet.impl.pipeline.transform.StreamSourceTransform) Queue(java.util.Queue) ConnectionFactory(javax.jms.ConnectionFactory) Assert.assertEquals(org.junit.Assert.assertEquals) MessageConsumer(javax.jms.MessageConsumer) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Session(javax.jms.Session)

Example 38 with TestOutbox

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

the class WriteFilePTest method test_abortUnfinishedTransaction_whenNoItemsProcessed.

@Test
public void test_abortUnfinishedTransaction_whenNoItemsProcessed() throws Exception {
    // test for https://github.com/hazelcast/hazelcast/issues/19774
    ProcessorMetaSupplier metaSupplier = writeFileP(directory.toString(), StandardCharsets.UTF_8, null, DISABLE_ROLLING, true, Objects::toString);
    TestProcessorContext processorContext = new TestProcessorContext().setProcessingGuarantee(EXACTLY_ONCE);
    @SuppressWarnings("unchecked") WriteFileP<Integer> processor = (WriteFileP<Integer>) TestSupport.supplierFrom(metaSupplier).get();
    processor.init(new TestOutbox(new int[] { 128 }, 128), processorContext);
    processor.process(0, new TestInbox(singletonList(42)));
    assertTrue(processor.snapshotCommitPrepare());
    checkFileContents(0, 0, true, true, true);
    // Now a tmp file is created. Let's simulate that the prepared snapshot wasn't successful and
    // the job restarted
    @SuppressWarnings("unchecked") WriteFileP<Integer> processor2 = (WriteFileP<Integer>) TestSupport.supplierFrom(metaSupplier).get();
    processor2.init(new TestOutbox(128), processorContext);
    processor2.close();
    // now there should be no temp files
    checkFileContents(0, 0, true, false, true);
}
Also used : TestInbox(com.hazelcast.jet.core.test.TestInbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) Objects(java.util.Objects) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 39 with TestOutbox

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

the class StreamEventJournalPTest method assertRestore.

private void assertRestore(List<Entry> snapshotItems) throws Exception {
    Processor p = supplier.get();
    TestOutbox newOutbox = new TestOutbox(new int[] { 16 }, 16);
    List<Object> output = new ArrayList<>();
    p.init(newOutbox, new TestProcessorContext().setHazelcastInstance(instance));
    TestInbox inbox = new TestInbox();
    inbox.addAll(snapshotItems);
    p.restoreFromSnapshot(inbox);
    p.finishSnapshotRestore();
    assertTrueEventually(() -> {
        assertFalse("Processor should never complete", p.complete());
        newOutbox.drainQueueAndReset(0, output, true);
        assertEquals("consumed different number of items than expected", JOURNAL_CAPACITY, output.size());
    }, 3);
}
Also used : Processor(com.hazelcast.jet.core.Processor) TestInbox(com.hazelcast.jet.core.test.TestInbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) ArrayList(java.util.ArrayList) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext)

Example 40 with TestOutbox

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

the class StreamEventJournalPTest method when_newData.

@Test
public void when_newData() throws Exception {
    TestOutbox outbox = new TestOutbox(new int[] { 16 }, 16);
    List<Object> actual = new ArrayList<>();
    Processor p = supplier.get();
    p.init(outbox, new TestProcessorContext().setHazelcastInstance(instance));
    fillJournal(CAPACITY_PER_PARTITION);
    // consume
    assertTrueEventually(() -> {
        assertFalse("Processor should never complete", p.complete());
        outbox.drainQueueAndReset(0, actual, true);
        assertEquals("consumed different number of items than expected", JOURNAL_CAPACITY, actual.size());
        assertEquals(IntStream.range(0, JOURNAL_CAPACITY).boxed().collect(Collectors.toSet()), new HashSet<>(actual));
    }, 3);
    fillJournal(CAPACITY_PER_PARTITION);
    // consume again
    assertTrueEventually(() -> {
        assertFalse("Processor should never complete", p.complete());
        outbox.drainQueueAndReset(0, actual, true);
        assertEquals("consumed different number of items than expected", JOURNAL_CAPACITY + 2, actual.size());
        assertEquals(IntStream.range(0, JOURNAL_CAPACITY).boxed().collect(Collectors.toSet()), new HashSet<>(actual));
    }, 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

TestOutbox (com.hazelcast.jet.core.test.TestOutbox)56 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)50 Test (org.junit.Test)35 QuickTest (com.hazelcast.test.annotation.QuickTest)20 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 Processor (com.hazelcast.jet.core.Processor)14 TestInbox (com.hazelcast.jet.core.test.TestInbox)14 ArrayList (java.util.ArrayList)12 Watermark (com.hazelcast.jet.core.Watermark)11 Entry (java.util.Map.Entry)10 Before (org.junit.Before)8 Context (com.hazelcast.jet.core.Processor.Context)6 FunctionEx (com.hazelcast.function.FunctionEx)4 SimpleTestInClusterSupport (com.hazelcast.jet.SimpleTestInClusterSupport)4 Traverser (com.hazelcast.jet.Traverser)4 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)4 Outbox (com.hazelcast.jet.core.Outbox)4 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)4 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)4 HashSet (java.util.HashSet)4