Class FakeSourceReaderContext

java.lang.Object
io.github.flink.gcp.connector.testutils.FakeSourceReaderContext
All Implemented Interfaces:
org.apache.flink.api.connector.source.SourceReaderContext

@Internal public final class FakeSourceReaderContext extends Object implements org.apache.flink.api.connector.source.SourceReaderContext
In-memory SourceReaderContext for the tests of a pull-assignment source reader.

sendSplitRequest() is counted rather than refused, because asking for the next split is how such a reader gets work and a test has to be able to count the asks. A push-assigned source wants its own fake, in which that method throws — the Pub/Sub source keeps one for exactly that reason, so a test fails if it ever starts requesting splits ( docs/adr/0050).

The metric group is a constructor parameter rather than something built here: a caller already holds one that its assertions read through, and taking it keeps InternalSourceReaderMetricGroup — an unannotated flink-runtime type — out of this module's main sources and therefore out of the Flink API tier audit.

Everything else answers what a reader reads, and sendSourceEventToCoordinator records: sourceEvents() returns what the reader sent, in order, which is how a test of a reader that reports to its coordinator asserts the report was made.

  • Constructor Summary

    Constructors
    Constructor
    Description
    FakeSourceReaderContext(org.apache.flink.metrics.groups.SourceReaderMetricGroup metricGroup)
     
    FakeSourceReaderContext(org.apache.flink.metrics.groups.SourceReaderMetricGroup metricGroup, org.apache.flink.configuration.Configuration configuration)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    org.apache.flink.configuration.Configuration
     
    int
     
     
    org.apache.flink.util.UserCodeClassLoader
    Implemented here rather than through SimpleUserCodeClassLoader.create(...): that factory is unannotated, and the interface it satisfies is @PublicEvolving with two methods, so writing them costs less than carrying an allowlist entry for a helper.
    org.apache.flink.metrics.groups.SourceReaderMetricGroup
     
    void
    sendSourceEventToCoordinator(org.apache.flink.api.connector.source.SourceEvent sourceEvent)
     
    void
     
    List<org.apache.flink.api.connector.source.SourceEvent>
    Returns the source events sent to the coordinator, in order.
    int
    Returns how many splits this reader has asked the enumerator for.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.apache.flink.api.connector.source.SourceReaderContext

    emitWatermark
  • Constructor Details

    • FakeSourceReaderContext

      public FakeSourceReaderContext(org.apache.flink.metrics.groups.SourceReaderMetricGroup metricGroup)
    • FakeSourceReaderContext

      public FakeSourceReaderContext(org.apache.flink.metrics.groups.SourceReaderMetricGroup metricGroup, org.apache.flink.configuration.Configuration configuration)
  • Method Details

    • splitRequests

      public int splitRequests()
      Returns how many splits this reader has asked the enumerator for.
    • sourceEvents

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

      public org.apache.flink.metrics.groups.SourceReaderMetricGroup metricGroup()
      Specified by:
      metricGroup in interface org.apache.flink.api.connector.source.SourceReaderContext
    • getConfiguration

      public org.apache.flink.configuration.Configuration getConfiguration()
      Specified by:
      getConfiguration in interface org.apache.flink.api.connector.source.SourceReaderContext
    • getLocalHostName

      public String getLocalHostName()
      Specified by:
      getLocalHostName in interface org.apache.flink.api.connector.source.SourceReaderContext
    • getIndexOfSubtask

      public int getIndexOfSubtask()
      Specified by:
      getIndexOfSubtask in interface org.apache.flink.api.connector.source.SourceReaderContext
    • sendSplitRequest

      public void sendSplitRequest()
      Specified by:
      sendSplitRequest in interface org.apache.flink.api.connector.source.SourceReaderContext
    • sendSourceEventToCoordinator

      public void sendSourceEventToCoordinator(org.apache.flink.api.connector.source.SourceEvent sourceEvent)
      Specified by:
      sendSourceEventToCoordinator in interface org.apache.flink.api.connector.source.SourceReaderContext
    • getUserCodeClassLoader

      public org.apache.flink.util.UserCodeClassLoader getUserCodeClassLoader()
      Implemented here rather than through SimpleUserCodeClassLoader.create(...): that factory is unannotated, and the interface it satisfies is @PublicEvolving with two methods, so writing them costs less than carrying an allowlist entry for a helper.
      Specified by:
      getUserCodeClassLoader in interface org.apache.flink.api.connector.source.SourceReaderContext
    • currentParallelism

      public int currentParallelism()
      Specified by:
      currentParallelism in interface org.apache.flink.api.connector.source.SourceReaderContext