use of org.apache.flink.runtime.operators.coordination.OperatorEvent in project flink by apache.
the class SourceOperatorTest method testOpen.
@Test
public void testOpen() throws Exception {
// Initialize the operator.
operator.initializeState(context.createStateContext());
// Open the operator.
operator.open();
// The source reader should have been assigned a split.
assertEquals(Collections.singletonList(SourceOperatorTestContext.MOCK_SPLIT), mockSourceReader.getAssignedSplits());
// The source reader should have started.
assertTrue(mockSourceReader.isStarted());
// A ReaderRegistrationRequest should have been sent.
assertEquals(1, mockGateway.getEventsSent().size());
OperatorEvent operatorEvent = mockGateway.getEventsSent().get(0);
assertTrue(operatorEvent instanceof ReaderRegistrationEvent);
assertEquals(SourceOperatorTestContext.SUBTASK_INDEX, ((ReaderRegistrationEvent) operatorEvent).subtaskId());
}
use of org.apache.flink.runtime.operators.coordination.OperatorEvent in project flink by apache.
the class OperatorEventDispatcherImpl method dispatchEventToHandlers.
void dispatchEventToHandlers(OperatorID operatorID, SerializedValue<OperatorEvent> serializedEvent) throws FlinkException {
final OperatorEvent evt;
try {
evt = serializedEvent.deserializeValue(classLoader);
} catch (IOException | ClassNotFoundException e) {
throw new FlinkException("Could not deserialize operator event", e);
}
final OperatorEventHandler handler = handlers.get(operatorID);
if (handler != null) {
handler.handleOperatorEvent(evt);
} else {
throw new FlinkException("Operator not registered for operator events");
}
}
use of org.apache.flink.runtime.operators.coordination.OperatorEvent in project flink by apache.
the class JobMaster method sendOperatorEventToCoordinator.
@Override
public CompletableFuture<Acknowledge> sendOperatorEventToCoordinator(final ExecutionAttemptID task, final OperatorID operatorID, final SerializedValue<OperatorEvent> serializedEvent) {
try {
final OperatorEvent evt = serializedEvent.deserializeValue(userCodeLoader);
schedulerNG.deliverOperatorEventToCoordinator(task, operatorID, evt);
return CompletableFuture.completedFuture(Acknowledge.get());
} catch (Exception e) {
return FutureUtils.completedExceptionally(e);
}
}
use of org.apache.flink.runtime.operators.coordination.OperatorEvent in project flink by apache.
the class SourceCoordinatorContextTest method testAssignSplits.
@SuppressWarnings("unchecked")
private void testAssignSplits(boolean fromCoordinatorExecutor) throws Exception {
sourceReady();
registerReaders();
// Assign splits to the readers.
SplitsAssignment<MockSourceSplit> splitsAssignment = getSplitsAssignment(2, 0);
if (fromCoordinatorExecutor) {
coordinatorExecutor.submit(() -> context.assignSplits(splitsAssignment)).get();
} else {
context.assignSplits(splitsAssignment);
}
// The tracker should have recorded the assignments.
verifyAssignment(Collections.singletonList("0"), splitSplitAssignmentTracker.uncheckpointedAssignments().get(0));
verifyAssignment(Arrays.asList("1", "2"), splitSplitAssignmentTracker.uncheckpointedAssignments().get(1));
// The OperatorCoordinatorContext should have received the event sending call.
assertEquals("There should be two events sent to the subtasks.", 2, receivingTasks.getNumberOfSentEvents());
// Assert the events to subtask0.
List<OperatorEvent> eventsToSubtask0 = receivingTasks.getSentEventsForSubtask(0);
assertEquals(1, eventsToSubtask0.size());
OperatorEvent event = eventsToSubtask0.get(0);
assertTrue(event instanceof AddSplitEvent);
verifyAssignment(Collections.singletonList("0"), ((AddSplitEvent<MockSourceSplit>) event).splits(new MockSourceSplitSerializer()));
}
use of org.apache.flink.runtime.operators.coordination.OperatorEvent in project flink by apache.
the class SourceCoordinatorAlignmentTest method assertLatestWatermarkAlignmentEvent.
private void assertLatestWatermarkAlignmentEvent(int subtask, long expectedWatermark) {
List<OperatorEvent> events = receivingTasks.getSentEventsForSubtask(subtask);
assertFalse(events.isEmpty());
assertEquals(new WatermarkAlignmentEvent(expectedWatermark), events.get(events.size() - 1));
}
Aggregations