use of com.hazelcast.jet.core.test.TestProcessorContext in project hazelcast-jet by hazelcast.
the class WriteSocketTest method unitTest.
@Test
public void unitTest() throws Exception {
AtomicInteger counter = new AtomicInteger();
ServerSocket serverSocket = new ServerSocket(0);
new Thread(() -> uncheckRun(() -> {
Socket socket = serverSocket.accept();
serverSocket.close();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
while (reader.readLine() != null) {
counter.incrementAndGet();
}
}
})).start();
TestInbox inbox = new TestInbox();
range(0, ITEM_COUNT).forEach(inbox::add);
Processor p = supplierFrom(writeSocketP("localhost", serverSocket.getLocalPort(), Object::toString, UTF_8)).get();
p.init(mock(Outbox.class), new TestProcessorContext());
p.process(0, inbox);
p.complete();
assertTrueEventually(() -> assertTrue(counter.get() >= ITEM_COUNT));
// wait a little to check, if the counter doesn't get too far
Thread.sleep(500);
assertEquals(ITEM_COUNT, counter.get());
}
use of com.hazelcast.jet.core.test.TestProcessorContext 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.TestProcessorContext 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.TestProcessorContext 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.TestProcessorContext 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");
}
Aggregations