Class StubWriterInitContext

java.lang.Object
io.github.flink.gcp.connector.testutils.StubWriterInitContext
All Implemented Interfaces:
org.apache.flink.api.connector.sink2.InitContext, org.apache.flink.api.connector.sink2.WriterInitContext

@Internal public class StubWriterInitContext extends Object implements org.apache.flink.api.connector.sink2.WriterInitContext
The parts of WriterInitContext a sink reads when creating a writer; everything a sink has no reason to touch is unsupported, so a new dependency on the context shows up as a failing test rather than as a silent null.

Subclassable on purpose: a test that needs one accessor to misbehave — a sink that reads the context after a point of no return, say — overrides that method and inherits the rest, rather than reimplementing every method of the interface to change one.

The metric group is a real TestSinkWriterMetricGroup held in a field, so repeated calls return the same instance: a test can still assert by identity that the group reached whatever it was handed to, and — unlike the no-op Proxy this replaced — a writer that captures counters in its constructor gets counters rather than nulls. Every sink writer here does since #208, so the proxy would fail each of them with a NullPointerException. getSinkWriterMetricGroup() reads back what the writer registered.

  • Constructor Details

    • StubWriterInitContext

      public StubWriterInitContext(int subtaskIndex)
      Creates a context for a single-subtask writer.
      Parameters:
      subtaskIndex - the subtask index the context reports
    • StubWriterInitContext

      public StubWriterInitContext(int subtaskIndex, int parallelism)
      Creates a context.
      Parameters:
      subtaskIndex - the subtask index the context reports
      parallelism - the parallelism the context reports
  • Method Details

    • getTaskInfo

      public org.apache.flink.api.common.TaskInfo getTaskInfo()
      Specified by:
      getTaskInfo in interface org.apache.flink.api.connector.sink2.InitContext
    • getJobInfo

      public org.apache.flink.api.common.JobInfo getJobInfo()
      Specified by:
      getJobInfo in interface org.apache.flink.api.connector.sink2.InitContext
    • metricGroup

      public org.apache.flink.metrics.groups.SinkWriterMetricGroup metricGroup()
      Specified by:
      metricGroup in interface org.apache.flink.api.connector.sink2.WriterInitContext
    • getSinkWriterMetricGroup

      public TestSinkWriterMetricGroup getSinkWriterMetricGroup()
      Returns the same group as metricGroup(), typed so its metrics can be read back.
    • getRestoredCheckpointId

      public OptionalLong getRestoredCheckpointId()
      Specified by:
      getRestoredCheckpointId in interface org.apache.flink.api.connector.sink2.InitContext
    • getProcessingTimeService

      public org.apache.flink.api.common.operators.ProcessingTimeService getProcessingTimeService()
      Specified by:
      getProcessingTimeService in interface org.apache.flink.api.connector.sink2.WriterInitContext
    • isObjectReuseEnabled

      public boolean isObjectReuseEnabled()
      Specified by:
      isObjectReuseEnabled in interface org.apache.flink.api.connector.sink2.WriterInitContext
    • getUserCodeClassLoader

      public org.apache.flink.util.UserCodeClassLoader getUserCodeClassLoader()
      Specified by:
      getUserCodeClassLoader in interface org.apache.flink.api.connector.sink2.WriterInitContext
    • getMailboxExecutor

      public org.apache.flink.api.common.operators.MailboxExecutor getMailboxExecutor()
      Specified by:
      getMailboxExecutor in interface org.apache.flink.api.connector.sink2.WriterInitContext
    • asSerializationSchemaInitializationContext

      public org.apache.flink.api.common.serialization.SerializationSchema.InitializationContext asSerializationSchemaInitializationContext()
      Specified by:
      asSerializationSchemaInitializationContext in interface org.apache.flink.api.connector.sink2.WriterInitContext
    • createInputSerializer

      public <IN> org.apache.flink.api.common.typeutils.TypeSerializer<IN> createInputSerializer()
      Specified by:
      createInputSerializer in interface org.apache.flink.api.connector.sink2.WriterInitContext