Class FakeSplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
- Type Parameters:
SplitT- the split type the enumerator assigns
- All Implemented Interfaces:
org.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT>
SplitEnumeratorContext for the tests of a pull-assignment enumerator —
one whose readers ask for work through handleSplitRequest.
Assignments and no-more-splits signals are recorded in one ordered list as well as per subtask, because with pull assignment the order is the thing that can go wrong: a subtask told there are no more splits and then handed one is a lost-split bug expressed as a sequence.
A push-assigned source's enumerator wants its own fake rather than this one, and the
Pub/Sub source keeps one for that reason: its coordinator-facing methods throw where these
record, which is what makes a test fail if that source ever starts requesting splits (
docs/adr/0050).
The unsupported operations throw rather than silently accepting work, so the first enumerator that needs one has to come here and decide what it should do. Reader-directed source events are recorded because restore validation may have to release or replace reader-owned splits.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionassignedSplits(int subtaskId) Returns a copy: a caller that fed this straight back in would otherwise mutate it.voidassignSplits(org.apache.flink.api.connector.source.SplitsAssignment<SplitT> newSplitAssignments) <T> voidcallAsync(Callable<T> callable, BiConsumer<T, Throwable> handler) Records the call instead of running it, so a test decides when the enumerator's planning step completes.<T> voidcallAsync(Callable<T> callable, BiConsumer<T, Throwable> handler, long initialDelayMillis, long periodMillis) longReturns a counter the enumerator registered.intevents()Returns every assignment and signal in the order it happened, as"verb:subtask".<T> TReturns the value of a gauge the enumerator registered.org.apache.flink.metrics.groups.SplitEnumeratorMetricGroupvoidputMetricVariable(String key, String value) Puts a variable into what the metric group'sgetAllVariables()answers.voidregisterReader(int subtaskId) Registers a reader, as the coordinator does before callingaddReader.voidRuns every async call recorded so far, including any a handler enqueues.voidrunInCoordinatorThread(Runnable runnable) voidRuns each registered periodic async callback once, without waiting for wall-clock time.voidsendEventToSourceReader(int subtaskId, org.apache.flink.api.connector.source.SourceEvent event) voidsignalNoMoreSplits(int subtask) List<org.apache.flink.api.connector.source.SourceEvent>sourceEvents(int subtaskId) Returns the coordinator events sent to one source reader, in order.voidunregisterReader(int subtaskId) Drops a reader, as the coordinator does when its last attempt goes away.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.flink.api.connector.source.SplitEnumeratorContext
assignSplit, registeredReadersOfAttempts, sendEventToSourceReader, setIsProcessingBacklog
-
Constructor Details
-
FakeSplitEnumeratorContext
public FakeSplitEnumeratorContext(int parallelism)
-
-
Method Details
-
registerReader
public void registerReader(int subtaskId) Registers a reader, as the coordinator does before callingaddReader. -
unregisterReader
public void unregisterReader(int subtaskId) Drops a reader, as the coordinator does when its last attempt goes away. -
assignedSplits
Returns a copy: a caller that fed this straight back in would otherwise mutate it. -
readersToldNoMoreSplits
-
events
Returns every assignment and signal in the order it happened, as"verb:subtask". -
metricGroup
public org.apache.flink.metrics.groups.SplitEnumeratorMetricGroup metricGroup()- Specified by:
metricGroupin interfaceorg.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
-
putMetricVariable
Puts a variable into what the metric group'sgetAllVariables()answers.By default the map is empty —
MetricListener's root group has no parent, so nothing populates the variables Flink's own hierarchy would carry (<job_name>and its siblings). A test of code reading them injects what its job would have had.- Parameters:
key- the variable key, in Flink's bracketed spelling, for example<job_name>value- the value
-
sendEventToSourceReader
public void sendEventToSourceReader(int subtaskId, org.apache.flink.api.connector.source.SourceEvent event) - Specified by:
sendEventToSourceReaderin interfaceorg.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
-
sourceEvents
Returns the coordinator events sent to one source reader, in order. -
currentParallelism
public int currentParallelism()- Specified by:
currentParallelismin interfaceorg.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
-
registeredReaders
- Specified by:
registeredReadersin interfaceorg.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
-
assignSplits
public void assignSplits(org.apache.flink.api.connector.source.SplitsAssignment<SplitT> newSplitAssignments) - Specified by:
assignSplitsin interfaceorg.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
-
signalNoMoreSplits
public void signalNoMoreSplits(int subtask) - Specified by:
signalNoMoreSplitsin interfaceorg.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
-
callAsync
Records the call instead of running it, so a test decides when the enumerator's planning step completes. MirrorsExecutorNotifier: the callable runs off the coordinator thread and the handler then runs on it with exactly one of (result, error) set.- Specified by:
callAsyncin interfaceorg.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
-
runAsyncCalls
public void runAsyncCalls()Runs every async call recorded so far, including any a handler enqueues. -
callAsync
public <T> void callAsync(Callable<T> callable, BiConsumer<T, Throwable> handler, long initialDelayMillis, long periodMillis) - Specified by:
callAsyncin interfaceorg.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
-
runPeriodicAsyncCalls
public void runPeriodicAsyncCalls()Runs each registered periodic async callback once, without waiting for wall-clock time. -
runInCoordinatorThread
- Specified by:
runInCoordinatorThreadin interfaceorg.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
-
counter
Returns a counter the enumerator registered. The extra path element is Flink's own:InternalSplitEnumeratorMetricGroupregisters under an"enumerator"subgroup. -
gauge
Returns the value of a gauge the enumerator registered.
-