Search in sources :

Example 6 with SourceEventWrapper

use of org.apache.flink.runtime.source.event.SourceEventWrapper in project flink by apache.

the class SourceCoordinatorContext method sendEventToSourceReader.

@Override
public void sendEventToSourceReader(int subtaskId, SourceEvent event) {
    checkSubtaskIndex(subtaskId);
    callInCoordinatorThread(() -> {
        final OperatorCoordinator.SubtaskGateway gateway = getGatewayAndCheckReady(subtaskId);
        gateway.sendEvent(new SourceEventWrapper(event));
        return null;
    }, String.format("Failed to send event %s to subtask %d", event, subtaskId));
}
Also used : SourceEventWrapper(org.apache.flink.runtime.source.event.SourceEventWrapper) OperatorCoordinator(org.apache.flink.runtime.operators.coordination.OperatorCoordinator)

Example 7 with SourceEventWrapper

use of org.apache.flink.runtime.source.event.SourceEventWrapper in project flink by apache.

the class SourceOperatorTest method testHandleAddSourceEvent.

@Test
public void testHandleAddSourceEvent() throws Exception {
    operator.initializeState(context.createStateContext());
    operator.open();
    SourceEvent event = new SourceEvent() {
    };
    operator.handleOperatorEvent(new SourceEventWrapper(event));
    // The source reader should have been assigned two splits.
    assertEquals(Collections.singletonList(event), mockSourceReader.getReceivedSourceEvents());
}
Also used : SourceEventWrapper(org.apache.flink.runtime.source.event.SourceEventWrapper) SourceEvent(org.apache.flink.api.connector.source.SourceEvent) Test(org.junit.Test)

Aggregations

SourceEventWrapper (org.apache.flink.runtime.source.event.SourceEventWrapper)7 SourceEvent (org.apache.flink.api.connector.source.SourceEvent)6 Test (org.junit.Test)4 HashSet (java.util.HashSet)2 Set (java.util.Set)2 SourceReaderContext (org.apache.flink.api.connector.source.SourceReaderContext)2 MockSourceSplit (org.apache.flink.api.connector.source.mocks.MockSourceSplit)2 MockSplitEnumerator (org.apache.flink.api.connector.source.mocks.MockSplitEnumerator)2 MockSplitEnumeratorContext (org.apache.flink.api.connector.source.mocks.MockSplitEnumeratorContext)2 CoordinatorStoreImpl (org.apache.flink.runtime.operators.coordination.CoordinatorStoreImpl)2 OperatorCoordinator (org.apache.flink.runtime.operators.coordination.OperatorCoordinator)2 RequestSplitEvent (org.apache.flink.runtime.source.event.RequestSplitEvent)2 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 Duration (java.time.Duration)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1