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();
}
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());
}
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);
}
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);
}
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);
}
Aggregations