use of org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService in project flink by apache.
the class AsyncSinkWriterTest method writeTwoElementsAndInterleaveTheNextTwoElements.
private void writeTwoElementsAndInterleaveTheNextTwoElements(AsyncSinkWriterImpl sink, CountDownLatch blockedWriteLatch, CountDownLatch delayedStartLatch) throws Exception {
TestProcessingTimeService tpts = sinkInitContext.getTestProcessingTimeService();
ExecutorService es = Executors.newFixedThreadPool(4);
tpts.setCurrentTime(0L);
sink.write("1");
sink.write("2");
es.submit(() -> {
try {
sink.write("3");
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
});
delayedStartLatch.await();
sink.write("4");
tpts.setCurrentTime(100L);
blockedWriteLatch.countDown();
es.shutdown();
assertTrue(es.awaitTermination(500, TimeUnit.MILLISECONDS), "Executor Service stuck at termination, not terminated after 500ms!");
}
use of org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService in project flink by apache.
the class AsyncSinkWriterTest method testThatFlushingAnEmptyBufferDoesNotResultInErrorOrFailure.
@Test
public void testThatFlushingAnEmptyBufferDoesNotResultInErrorOrFailure() throws Exception {
AsyncSinkWriterImpl sink = new AsyncSinkWriterImplBuilder().context(sinkInitContext).maxBatchSize(10).maxInFlightRequests(20).maxBatchSizeInBytes(10_000).maxTimeInBufferMS(100).maxRecordSizeInBytes(10_000).simulateFailures(true).build();
TestProcessingTimeService tpts = sinkInitContext.getTestProcessingTimeService();
tpts.setCurrentTime(0L);
sink.write("1");
tpts.setCurrentTime(50L);
sink.flush(true);
assertEquals(1, res.size());
tpts.setCurrentTime(200L);
}
use of org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService in project flink by apache.
the class NonBufferOverWindowOperatorTest method test.
private void test(boolean[] resetAccumulators, GenericRowData[] expect) throws Exception {
operator = new NonBufferOverWindowOperator(functions, comparator, resetAccumulators) {
{
output = new ConsumerOutput(new Consumer<RowData>() {
@Override
public void accept(RowData r) {
collect.add(GenericRowData.of(r.getInt(0), r.getLong(1), r.getLong(2), r.getLong(3), r.getLong(4)));
}
});
}
@Override
public ClassLoader getUserCodeClassloader() {
return Thread.currentThread().getContextClassLoader();
}
@Override
public StreamConfig getOperatorConfig() {
StreamConfig conf = mock(StreamConfig.class);
when(conf.<RowData>getTypeSerializerIn1(getUserCodeClassloader())).thenReturn(inputSer);
return conf;
}
@Override
public StreamingRuntimeContext getRuntimeContext() {
return mock(StreamingRuntimeContext.class);
}
};
operator.setProcessingTimeService(new TestProcessingTimeService());
operator.open();
addRow(0, 1L, 4L);
addRow(0, 1L, 1L);
addRow(1, 5L, 2L);
addRow(2, 5L, 4L);
addRow(2, 6L, 2L);
GenericRowData[] outputs = this.collect.toArray(new GenericRowData[0]);
Assert.assertArrayEquals(expect, outputs);
}
Aggregations