use of com.hazelcast.jet.core.test.TestProcessorContext in project hazelcast by hazelcast.
the class StreamEventJournalPTest method when_lostItems_afterRestore.
@Test
public void when_lostItems_afterRestore() throws Exception {
TestOutbox outbox = new TestOutbox(new int[] { 16 }, 16);
final Processor p = supplier.get();
p.init(outbox, new TestProcessorContext().setHazelcastInstance(instance));
List<Object> output = new ArrayList<>();
assertTrueEventually(() -> {
assertFalse("Processor should never complete", p.complete());
outbox.drainQueueAndReset(0, output, true);
assertTrue("consumed different number of items than expected", output.size() == 0);
}, 3);
assertTrueEventually(() -> {
assertTrue("Processor did not finish snapshot", p.saveToSnapshot());
}, 3);
// overflow journal
fillJournal(CAPACITY_PER_PARTITION + 1);
List<Entry> snapshotItems = new ArrayList<>();
outbox.drainSnapshotQueueAndReset(snapshotItems, false);
logger.info("Restoring journal");
// restore from snapshot
assertRestore(snapshotItems);
}
use of com.hazelcast.jet.core.test.TestProcessorContext in project hazelcast by hazelcast.
the class StreamEventJournalPTest method when_futureSequence_thenResetOffset.
@Test
public void when_futureSequence_thenResetOffset() throws Exception {
TestOutbox outbox = new TestOutbox(new int[] { 16 }, 16);
StreamEventJournalP p = (StreamEventJournalP) supplier.get();
// fill journal so that it overflows
fillJournal(CAPACITY_PER_PARTITION + 1);
// initial offsets will be 5, since capacity per partition is 5
p.init(outbox, new TestProcessorContext().setHazelcastInstance(instance));
// clear partitions before doing any read, but after initializing offsets
map.destroy();
// when we consume, we should not retrieve anything because we will ask for
// offset 5, but current head is 0. This should not cause any error
List<Object> actual = new ArrayList<>();
// we should not receive any items, but the offset should be reset back to 0
assertTrueFiveSeconds(() -> {
assertFalse("Processor should never complete", p.complete());
outbox.drainQueueAndReset(0, actual, true);
assertTrue("consumed different number of items than expected", actual.size() == 0);
});
// add one item to each partition
fillJournal(1);
// receive the items we just added
assertTrueEventually(() -> {
assertFalse("Processor should never complete", p.complete());
outbox.drainQueueAndReset(0, actual, true);
assertTrue("consumed different number of items than expected", actual.size() == 2);
});
}
use of com.hazelcast.jet.core.test.TestProcessorContext in project hazelcast by hazelcast.
the class StreamFilesPTest method when_metaSupplier_then_returnsCorrectProcessors.
@Test
public void when_metaSupplier_then_returnsCorrectProcessors() throws Exception {
ProcessorMetaSupplier metaSupplier = streamFilesP(workDir.getAbsolutePath(), UTF_8, "*", false, Util::entry);
Address a = new Address();
ProcessorSupplier supplier = metaSupplier.get(singletonList(a)).apply(a);
supplier.init(new TestProcessorContext());
assertEquals(1, supplier.get(1).size());
supplier.close(null);
}
use of com.hazelcast.jet.core.test.TestProcessorContext in project hazelcast by hazelcast.
the class SlidingWindowP_failoverTest method init.
private void init(ProcessingGuarantee guarantee) throws Exception {
SlidingWindowPolicy wDef = SlidingWindowPolicy.tumblingWinPolicy(1);
AggregateOperation1<Object, LongAccumulator, Long> aggrOp = counting();
p = new SlidingWindowP<>(singletonList(entryKey()), singletonList((ToLongFunctionEx<Entry<?, Long>>) Entry::getValue), wDef, 0L, aggrOp, KeyedWindowResult::new, true);
Outbox outbox = new TestOutbox(128);
Context context = new TestProcessorContext().setProcessingGuarantee(guarantee);
p.init(outbox, context);
}
use of com.hazelcast.jet.core.test.TestProcessorContext in project hazelcast-jet by hazelcast.
the class SessionWindowP_failoverTest method init.
private void init(ProcessingGuarantee guarantee) {
AggregateOperation1<Object, LongAccumulator, Long> aggrOp = counting();
p = new SessionWindowP<>(5000, singletonList((DistributedToLongFunction<Entry<?, Long>>) Entry::getValue), singletonList(entryKey()), aggrOp, WindowResult::new);
Outbox outbox = new TestOutbox(128);
Context context = new TestProcessorContext().setProcessingGuarantee(guarantee);
p.init(outbox, context);
}
Aggregations