Search in sources :

Example 1 with TestingSourceSplit

use of org.apache.flink.connector.base.source.reader.mocks.TestingSourceSplit in project flink by apache.

the class SplitFetcherManagerTest method testExceptionPropagation.

// the final modifier is important so that '@SafeVarargs' is accepted on Java 8
@SuppressWarnings("FinalPrivateMethod")
@SafeVarargs
private final void testExceptionPropagation(final RecordsWithSplitIds<Integer>... fetchesBeforeError) throws Exception {
    final IOException testingException = new IOException("test");
    final FutureCompletingBlockingQueue<RecordsWithSplitIds<Integer>> queue = new FutureCompletingBlockingQueue<>(10);
    final AwaitingReader<Integer, TestingSourceSplit> reader = new AwaitingReader<>(testingException, fetchesBeforeError);
    final SplitFetcherManager<Integer, TestingSourceSplit> fetcher = createFetcher("testSplit", queue, reader);
    reader.awaitAllRecordsReturned();
    drainQueue(queue);
    assertFalse(queue.getAvailabilityFuture().isDone());
    reader.triggerThrowException();
    // await the error propagation
    queue.getAvailabilityFuture().get();
    try {
        fetcher.checkErrors();
        fail("expected exception");
    } catch (Exception e) {
        assertSame(testingException, e.getCause().getCause());
    } finally {
        fetcher.close(20_000L);
    }
}
Also used : FutureCompletingBlockingQueue(org.apache.flink.connector.base.source.reader.synchronization.FutureCompletingBlockingQueue) TestingSourceSplit(org.apache.flink.connector.base.source.reader.mocks.TestingSourceSplit) IOException(java.io.IOException) TestingRecordsWithSplitIds(org.apache.flink.connector.base.source.reader.mocks.TestingRecordsWithSplitIds) RecordsWithSplitIds(org.apache.flink.connector.base.source.reader.RecordsWithSplitIds) IOException(java.io.IOException)

Example 2 with TestingSourceSplit

use of org.apache.flink.connector.base.source.reader.mocks.TestingSourceSplit in project flink by apache.

the class SplitFetcherTest method testFetcherNotIdleAfterSplitAdded.

@Test
public void testFetcherNotIdleAfterSplitAdded() {
    final SplitFetcher<Object, TestingSourceSplit> fetcher = createFetcher(new TestingSplitReader<>());
    final TestingSourceSplit split = new TestingSourceSplit("test-split");
    fetcher.addSplits(Collections.singletonList(split));
    assertFalse(fetcher.isIdle());
    // need to loop here because the internal wakeup flag handling means we need multiple loops
    while (fetcher.assignedSplits().isEmpty()) {
        fetcher.runOnce();
        assertFalse(fetcher.isIdle());
    }
}
Also used : TestingSourceSplit(org.apache.flink.connector.base.source.reader.mocks.TestingSourceSplit) Test(org.junit.Test)

Example 3 with TestingSourceSplit

use of org.apache.flink.connector.base.source.reader.mocks.TestingSourceSplit in project flink by apache.

the class SourceReaderBaseTest method createReaderAndAwaitAvailable.

// ------------------------------------------------------------------------
// Testing Setup Helpers
// ------------------------------------------------------------------------
private static <E> SourceReader<E, ?> createReaderAndAwaitAvailable(final String splitId, final RecordsWithSplitIds<E> records) throws Exception {
    final FutureCompletingBlockingQueue<RecordsWithSplitIds<E>> elementsQueue = new FutureCompletingBlockingQueue<>();
    final SourceReader<E, TestingSourceSplit> reader = new SingleThreadMultiplexSourceReaderBase<E, E, TestingSourceSplit, TestingSourceSplit>(elementsQueue, () -> new TestingSplitReader<>(records), new PassThroughRecordEmitter<>(), new Configuration(), new TestingReaderContext()) {

        @Override
        public void notifyCheckpointComplete(long checkpointId) {
        }

        @Override
        protected void onSplitFinished(Map<String, TestingSourceSplit> finishedSplitIds) {
        }

        @Override
        protected TestingSourceSplit initializedState(TestingSourceSplit split) {
            return split;
        }

        @Override
        protected TestingSourceSplit toSplitType(String splitId, TestingSourceSplit splitState) {
            return splitState;
        }
    };
    reader.start();
    final List<TestingSourceSplit> splits = Collections.singletonList(new TestingSourceSplit(splitId));
    reader.addSplits(splits);
    reader.isAvailable().get();
    return reader;
}
Also used : Configuration(org.apache.flink.configuration.Configuration) TestingSourceSplit(org.apache.flink.connector.base.source.reader.mocks.TestingSourceSplit) TestingRecordsWithSplitIds(org.apache.flink.connector.base.source.reader.mocks.TestingRecordsWithSplitIds) FutureCompletingBlockingQueue(org.apache.flink.connector.base.source.reader.synchronization.FutureCompletingBlockingQueue) TestingReaderContext(org.apache.flink.connector.testutils.source.reader.TestingReaderContext) Map(java.util.Map)

Example 4 with TestingSourceSplit

use of org.apache.flink.connector.base.source.reader.mocks.TestingSourceSplit in project flink by apache.

the class SerdeUtilsTest method testSerdeSplitAssignments.

@Test
public void testSerdeSplitAssignments() throws IOException {
    final Map<Integer, Set<TestingSourceSplit>> splitAssignments = new HashMap<>();
    final HashSet<TestingSourceSplit> splitsForReader0 = new HashSet<>();
    splitsForReader0.add(new TestingSourceSplit("split-0"));
    splitsForReader0.add(new TestingSourceSplit("split-1"));
    splitsForReader0.add(new TestingSourceSplit("split-2"));
    final HashSet<TestingSourceSplit> splitsForReader1 = new HashSet<>();
    splitsForReader1.add(new TestingSourceSplit("split-3"));
    splitsForReader1.add(new TestingSourceSplit("split-4"));
    splitsForReader1.add(new TestingSourceSplit("split-5"));
    splitAssignments.put(READER0, splitsForReader0);
    splitAssignments.put(READER1, splitsForReader1);
    final byte[] serializedSplitAssignments = SerdeUtils.serializeSplitAssignments(splitAssignments, new TestingSourceSplitSerializer());
    final Map<Integer, HashSet<TestingSourceSplit>> deseredSplitAssignments = SerdeUtils.deserializeSplitAssignments(serializedSplitAssignments, new TestingSourceSplitSerializer(), HashSet::new);
    assertEquals(splitAssignments, deseredSplitAssignments);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) TestingSourceSplit(org.apache.flink.connector.base.source.reader.mocks.TestingSourceSplit) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

TestingSourceSplit (org.apache.flink.connector.base.source.reader.mocks.TestingSourceSplit)4 TestingRecordsWithSplitIds (org.apache.flink.connector.base.source.reader.mocks.TestingRecordsWithSplitIds)2 FutureCompletingBlockingQueue (org.apache.flink.connector.base.source.reader.synchronization.FutureCompletingBlockingQueue)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Configuration (org.apache.flink.configuration.Configuration)1 RecordsWithSplitIds (org.apache.flink.connector.base.source.reader.RecordsWithSplitIds)1 TestingReaderContext (org.apache.flink.connector.testutils.source.reader.TestingReaderContext)1