use of com.hazelcast.jet.core.test.TestProcessorContext in project hazelcast-jet by hazelcast.
the class StreamEventJournalPTest method when_newData.
@Test
public void when_newData() {
TestOutbox outbox = new TestOutbox(new int[] { 16 }, 16);
List<Object> actual = new ArrayList<>();
Processor p = supplier.get();
p.init(outbox, new TestProcessorContext());
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);
}
use of com.hazelcast.jet.core.test.TestProcessorContext in project hazelcast-jet by hazelcast.
the class StreamFilesPTest method when_metaSupplier_then_returnsCorrectProcessors.
@Test
public void when_metaSupplier_then_returnsCorrectProcessors() {
ProcessorMetaSupplier metaSupplier = streamFilesP(workDir.getAbsolutePath(), UTF_8, "*", 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-jet by hazelcast.
the class StreamFilesPTest method initializeProcessor.
private void initializeProcessor(String glob) {
if (glob == null) {
glob = "*";
}
processor = new StreamFilesP(workDir.getAbsolutePath(), UTF_8, glob, 1, 0, Util::entry);
outbox = new TestOutbox(1);
Context ctx = new TestProcessorContext().setLogger(Logger.getLogger(StreamFilesP.class));
processor.init(outbox, ctx);
}
use of com.hazelcast.jet.core.test.TestProcessorContext in project hazelcast-jet by hazelcast.
the class StreamKafkaPTest method when_eventsInSinglePartition_then_watermarkAfterIdleTime.
@Test
public void when_eventsInSinglePartition_then_watermarkAfterIdleTime() {
// When
StreamKafkaP processor = createProcessor(2, StreamKafkaP::recordToEntry, 10_000);
TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
processor.init(outbox, new TestProcessorContext());
produce(topic1Name, 10, "foo");
// Then
assertEquals(entry(10, "foo"), consumeEventually(processor, outbox));
long time1 = System.nanoTime();
assertEquals(new Watermark(10 - LAG), consumeEventually(processor, outbox));
long time2 = System.nanoTime();
long elapsedMs = NANOSECONDS.toMillis(time2 - time1);
assertTrue("elapsed time: " + elapsedMs + " ms, should be larger", elapsedMs > 3000 && elapsedMs <= 10_000);
}
use of com.hazelcast.jet.core.test.TestProcessorContext in project hazelcast-jet by hazelcast.
the class StreamKafkaPTest method when_customProjection_then_used.
@Test
public void when_customProjection_then_used() {
// When
StreamKafkaP processor = createProcessor(2, r -> r.key() + "=" + r.value(), 10_000);
TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
processor.init(outbox, new TestProcessorContext());
produce(topic1Name, 0, "0");
// Then
assertEquals("0=0", consumeEventually(processor, outbox));
}
Aggregations