use of com.hazelcast.jet.core.Processor 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.Processor in project hazelcast by hazelcast.
the class StreamSocketPTest method runTest.
private void runTest(byte[] inputBytes, int inputSplitAfter) throws Exception {
try (ServerSocket serverSocket = new ServerSocket(0)) {
CountDownLatch firstPartWritten = new CountDownLatch(1);
CountDownLatch readyForSecondPart = new CountDownLatch(1);
Thread thread = new Thread(() -> uncheckRun(() -> {
Socket socket = serverSocket.accept();
OutputStream outputStream = socket.getOutputStream();
outputStream.write(inputBytes, 0, inputSplitAfter);
firstPartWritten.countDown();
readyForSecondPart.await();
outputStream.write(inputBytes, inputSplitAfter, inputBytes.length - inputSplitAfter);
outputStream.close();
socket.close();
}));
thread.start();
Processor processor = supplierFrom(streamSocketP("localhost", serverSocket.getLocalPort(), UTF_16)).get();
processor.init(outbox, context);
firstPartWritten.await();
for (int i = 0; i < 10; i++) {
processor.complete();
// sleep a little so that the processor has a chance to read the part of the data
sleepMillis(1);
}
readyForSecondPart.countDown();
while (!processor.complete()) {
sleepMillis(1);
}
for (String s : output) {
assertEquals(s, bucket.poll());
}
assertEquals(null, bucket.poll());
assertTrueEventually(() -> assertFalse(thread.isAlive()));
}
}
use of com.hazelcast.jet.core.Processor 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.Processor 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);
}
use of com.hazelcast.jet.core.Processor in project hazelcast by hazelcast.
the class WriteLoggerPTest method test.
@Test
public void test() throws Exception {
// Given
Processor p = supplierFrom(writeLoggerP()).get();
TestInbox inbox = new TestInbox();
Outbox outbox = mock(Outbox.class);
ILogger logger = mock(ILogger.class);
p.init(outbox, new TestProcessorContext().setLogger(logger));
// When
inbox.add(1);
p.process(0, inbox);
Watermark wm = new Watermark(2);
p.tryProcessWatermark(wm);
// Then
verifyZeroInteractions(outbox);
verify(logger).info("1");
verify(logger).fine(wm.toString());
verifyZeroInteractions(logger);
}
Aggregations