use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast by hazelcast.
the class StreamKafkaPTest method when_eventsInSinglePartition_then_watermarkAfterIdleTime.
@Test
public void when_eventsInSinglePartition_then_watermarkAfterIdleTime() throws Exception {
// When
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());
kafkaTestSupport.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);
assertBetween("elapsed time", elapsedMs, 3000, 30_000);
}
use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast by hazelcast.
the class StreamKafkaPTest method when_customProjectionToNull_then_filteredOut.
@Test
public void when_customProjectionToNull_then_filteredOut() throws Exception {
// When
EventTimePolicy<String> eventTimePolicy = eventTimePolicy(Long::parseLong, limitingLag(0), 1, 0, 0);
StreamKafkaP processor = new StreamKafkaP<Integer, String, String>(properties(), singletonList(topic1Name), r -> "0".equals(r.value()) ? null : r.value(), eventTimePolicy);
TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
processor.init(outbox, new TestProcessorContext());
kafkaTestSupport.produce(topic1Name, 0, "0");
kafkaTestSupport.produce(topic1Name, 0, "1");
// Then
assertTrueEventually(() -> {
assertFalse(processor.complete());
assertFalse("no item in outbox", outbox.queue(0).isEmpty());
}, 3);
assertEquals("1", outbox.queue(0).poll());
assertNull(outbox.queue(0).poll());
}
use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast by hazelcast.
the class StreamKafkaPTest method when_customProjection_then_used.
@Test
public void when_customProjection_then_used() throws Exception {
// When
StreamKafkaP processor = createProcessor(properties(), 2, r -> r.key() + "=" + r.value(), 10_000);
TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
processor.init(outbox, new TestProcessorContext());
kafkaTestSupport.produce(topic1Name, 0, "0");
// Then
assertEquals("0=0", consumeEventually(processor, outbox));
}
use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast by hazelcast.
the class StreamSocketPTest method before.
@Before
public void before() {
outbox = new TestOutbox(10);
context = new TestProcessorContext();
bucket = outbox.queue(0);
input = input.replaceAll("%n", "\n").replaceAll("%r", "\r");
}
use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast by hazelcast.
the class SlidingWindowP_changeWindowSizeTest method test.
private static void test(@Nonnull SlidingWindowPolicy policy1, @Nonnull SlidingWindowPolicy policy2, @Nullable List expectedOutboxAfterRestore) throws Exception {
SlidingWindowP p = createProcessor(policy1);
TestOutbox outbox = new TestOutbox(new int[] { 1024 }, 1024);
p.init(outbox, new TestProcessorContext());
TestInbox inbox = new TestInbox();
inbox.addAll(asList(0, 1, 2, 3));
p.process(0, inbox);
p.tryProcessWatermark(wm(2));
outbox.drainQueueAndReset(0, new ArrayList<>(), false);
// take a snapshot and restore to a new processor with different window size
p.saveToSnapshot();
TestInbox snapshotInbox = new TestInbox();
outbox.drainSnapshotQueueAndReset(snapshotInbox.queue(), false);
p = createProcessor(policy2);
p.init(outbox, new TestProcessorContext());
for (Object o : snapshotInbox.queue()) {
Entry e = (Entry) o;
p.restoreFromSnapshot(e.getKey(), e.getValue());
}
p.finishSnapshotRestore();
while (!p.complete()) {
}
if (expectedOutboxAfterRestore != null) {
assertEquals(expectedOutboxAfterRestore, new ArrayList<>(outbox.queue(0)));
}
assertTrue("tsToKeyToAcc not empty", p.tsToKeyToAcc.isEmpty());
assertTrue("slidingWindow not empty", p.slidingWindow == null || p.slidingWindow.isEmpty());
}
Aggregations