Search in sources :

Example 76 with TestProcessingTimeService

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!");
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) TestProcessingTimeService(org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService) IOException(java.io.IOException)

Example 77 with TestProcessingTimeService

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);
}
Also used : TestProcessingTimeService(org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService) Test(org.junit.Test)

Example 78 with TestProcessingTimeService

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);
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) StreamingRuntimeContext(org.apache.flink.streaming.api.operators.StreamingRuntimeContext) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) TestProcessingTimeService(org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService) GenericRowData(org.apache.flink.table.data.GenericRowData)

Aggregations

TestProcessingTimeService (org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService)78 Test (org.junit.Test)66 KeyGroupRange (org.apache.flink.runtime.state.KeyGroupRange)17 HashMap (java.util.HashMap)16 UnregisteredMetricsGroup (org.apache.flink.metrics.groups.UnregisteredMetricsGroup)15 ArrayList (java.util.ArrayList)14 CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)11 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 Watermark (org.apache.flink.streaming.api.watermark.Watermark)9 List (java.util.List)8 JobID (org.apache.flink.api.common.JobID)8 MockEnvironment (org.apache.flink.runtime.operators.testutils.MockEnvironment)8 VoidNamespace (org.apache.flink.runtime.state.VoidNamespace)8 VoidNamespaceSerializer (org.apache.flink.runtime.state.VoidNamespaceSerializer)8 Arrays (java.util.Arrays)6 Collections (java.util.Collections)6 Properties (java.util.Properties)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 BiConsumer (java.util.function.BiConsumer)5