Search in sources :

Example 1 with MockSplitEnumerator

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

the class HybridSourceTest method testBuilderWithEnumeratorSuperclass.

@Test
public void testBuilderWithEnumeratorSuperclass() {
    HybridSource.SourceFactory<Integer, Source<Integer, ?, ?>, MockSplitEnumerator> sourceFactory = (HybridSource.SourceFactory<Integer, Source<Integer, ?, ?>, MockSplitEnumerator>) context -> {
        MockSplitEnumerator enumerator = context.getPreviousEnumerator();
        return new MockBaseSource(1, 1, Boundedness.BOUNDED);
    };
    HybridSource<Integer> source = new HybridSource.HybridSourceBuilder<Integer, MockSplitEnumerator>().<ExtendedMockSplitEnumerator, Source<Integer, ?, ?>>addSource(new MockBaseSource(1, 1, Boundedness.BOUNDED)).addSource(sourceFactory, Boundedness.BOUNDED).build();
    assertNotNull(source);
}
Also used : MockBaseSource(org.apache.flink.connector.base.source.reader.mocks.MockBaseSource) MockBaseSource(org.apache.flink.connector.base.source.reader.mocks.MockBaseSource) Source(org.apache.flink.api.connector.source.Source) MockSplitEnumerator(org.apache.flink.connector.base.source.reader.mocks.MockSplitEnumerator) Test(org.junit.Test)

Example 2 with MockSplitEnumerator

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

the class HybridSourceSplitEnumeratorTest method testRestoreEnumerator.

@Test
public void testRestoreEnumerator() throws Exception {
    setupEnumeratorAndTriggerSourceSwitch();
    enumerator = (HybridSourceSplitEnumerator) source.createEnumerator(context);
    enumerator.start();
    HybridSourceEnumeratorState enumeratorState = enumerator.snapshotState(0);
    MockSplitEnumerator underlyingEnumerator = getCurrentEnumerator(enumerator);
    Assert.assertThat((List<MockSourceSplit>) Whitebox.getInternalState(underlyingEnumerator, "splits"), Matchers.iterableWithSize(1));
    enumerator = (HybridSourceSplitEnumerator) source.restoreEnumerator(context, enumeratorState);
    enumerator.start();
    underlyingEnumerator = getCurrentEnumerator(enumerator);
    Assert.assertThat((List<MockSourceSplit>) Whitebox.getInternalState(underlyingEnumerator, "splits"), Matchers.iterableWithSize(1));
}
Also used : MockSourceSplit(org.apache.flink.api.connector.source.mocks.MockSourceSplit) MockSplitEnumerator(org.apache.flink.connector.base.source.reader.mocks.MockSplitEnumerator) Test(org.junit.Test)

Example 3 with MockSplitEnumerator

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

the class HybridSourceTest method testBuilderWithSourceFactory.

@Test
public void testBuilderWithSourceFactory() {
    HybridSource.SourceFactory<Integer, Source<Integer, ?, ?>, MockSplitEnumerator> sourceFactory = new HybridSource.SourceFactory<Integer, Source<Integer, ?, ?>, MockSplitEnumerator>() {

        @Override
        public Source<Integer, ?, ?> create(HybridSource.SourceSwitchContext<MockSplitEnumerator> context) {
            MockSplitEnumerator enumerator = context.getPreviousEnumerator();
            return new MockBaseSource(1, 1, Boundedness.BOUNDED);
        }
    };
    HybridSource<Integer> source = new HybridSource.HybridSourceBuilder<Integer, MockSplitEnumerator>().<MockSplitEnumerator, Source<Integer, ?, ?>>addSource(new MockBaseSource(1, 1, Boundedness.BOUNDED)).addSource(sourceFactory, Boundedness.BOUNDED).build();
    assertNotNull(source);
}
Also used : MockBaseSource(org.apache.flink.connector.base.source.reader.mocks.MockBaseSource) MockBaseSource(org.apache.flink.connector.base.source.reader.mocks.MockBaseSource) Source(org.apache.flink.api.connector.source.Source) MockSplitEnumerator(org.apache.flink.connector.base.source.reader.mocks.MockSplitEnumerator) Test(org.junit.Test)

Aggregations

MockSplitEnumerator (org.apache.flink.connector.base.source.reader.mocks.MockSplitEnumerator)3 Test (org.junit.Test)3 Source (org.apache.flink.api.connector.source.Source)2 MockBaseSource (org.apache.flink.connector.base.source.reader.mocks.MockBaseSource)2 MockSourceSplit (org.apache.flink.api.connector.source.mocks.MockSourceSplit)1