Class FakeSplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>

java.lang.Object
io.github.flink.gcp.connector.testutils.FakeSplitEnumeratorContext<SplitT>
Type Parameters:
SplitT - the split type the enumerator assigns
All Implemented Interfaces:
org.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT>

@Internal public final class FakeSplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit> extends Object implements org.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT>
In-memory 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 Details

    • FakeSplitEnumeratorContext

      public FakeSplitEnumeratorContext(int parallelism)
  • Method Details

    • registerReader

      public void registerReader(int subtaskId)
      Registers a reader, as the coordinator does before calling addReader.
    • unregisterReader

      public void unregisterReader(int subtaskId)
      Drops a reader, as the coordinator does when its last attempt goes away.
    • assignedSplits

      public List<SplitT> assignedSplits(int subtaskId)
      Returns a copy: a caller that fed this straight back in would otherwise mutate it.
    • readersToldNoMoreSplits

      public Set<Integer> readersToldNoMoreSplits()
    • events

      public List<String> 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:
      metricGroup in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
    • putMetricVariable

      public void putMetricVariable(String key, String value)
      Puts a variable into what the metric group's getAllVariables() 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:
      sendEventToSourceReader in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
    • sourceEvents

      public List<org.apache.flink.api.connector.source.SourceEvent> sourceEvents(int subtaskId)
      Returns the coordinator events sent to one source reader, in order.
    • currentParallelism

      public int currentParallelism()
      Specified by:
      currentParallelism in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
    • registeredReaders

      public Map<Integer,org.apache.flink.api.connector.source.ReaderInfo> registeredReaders()
      Specified by:
      registeredReaders in interface org.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:
      assignSplits in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
    • signalNoMoreSplits

      public void signalNoMoreSplits(int subtask)
      Specified by:
      signalNoMoreSplits in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
    • callAsync

      public <T> void callAsync(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. Mirrors ExecutorNotifier: the callable runs off the coordinator thread and the handler then runs on it with exactly one of (result, error) set.
      Specified by:
      callAsync in interface org.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:
      callAsync in interface org.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

      public void runInCoordinatorThread(Runnable runnable)
      Specified by:
      runInCoordinatorThread in interface org.apache.flink.api.connector.source.SplitEnumeratorContext<SplitT extends org.apache.flink.api.connector.source.SourceSplit>
    • counter

      public long counter(String name)
      Returns a counter the enumerator registered. The extra path element is Flink's own: InternalSplitEnumeratorMetricGroup registers under an "enumerator" subgroup.
    • gauge

      public <T> T gauge(String name)
      Returns the value of a gauge the enumerator registered.