Class MiniClusterTestEnvironment

java.lang.Object
org.apache.flink.connector.testframe.environment.MiniClusterTestEnvironment
All Implemented Interfaces:
ClusterControllable, TestEnvironment, TestResource

@Experimental public class MiniClusterTestEnvironment extends Object implements TestEnvironment, ClusterControllable
Test environment for running jobs on Flink mini-cluster.
  • Constructor Details

    • MiniClusterTestEnvironment

      public MiniClusterTestEnvironment()
    • MiniClusterTestEnvironment

      public MiniClusterTestEnvironment(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration conf)
  • Method Details

    • createExecutionEnvironment

      public org.apache.flink.streaming.api.environment.StreamExecutionEnvironment createExecutionEnvironment(TestEnvironmentSettings envOptions)
      Description copied from interface: TestEnvironment
      Get an instance of StreamExecutionEnvironment for building and executing Flink jobs based on the provided configuration.

      Note that this environment should be bound with the Flink cluster, because this will be the entrypoint to submit Flink jobs (via StreamExecutionEnvironment.execute()) in test cases.

      Specified by:
      createExecutionEnvironment in interface TestEnvironment
      Parameters:
      envOptions - options for the environment to satisfy
    • getRestEndpoint

      public TestEnvironment.Endpoint getRestEndpoint()
      Description copied from interface: TestEnvironment
      Get endpoint of the test environment for connecting via REST API.
      Specified by:
      getRestEndpoint in interface TestEnvironment
    • getCheckpointUri

      public String getCheckpointUri()
      Description copied from interface: TestEnvironment
      Get a path in string for storing checkpoint and savepoint in the test environment.

      Note that testing framework may have no access to this storage (e.g. Flink cluster is on some cloud service and testing framework is executed locally). In test cases for testing failover scenario, this path will be passed to cluster client directly for triggering checkpoint / savepoint in this path and recovering from checkpoint / savepoint stored under this path.

      Specified by:
      getCheckpointUri in interface TestEnvironment
    • triggerJobManagerFailover

      public void triggerJobManagerFailover(org.apache.flink.core.execution.JobClient jobClient, Runnable afterFailAction) throws ExecutionException, InterruptedException
      Description copied from interface: ClusterControllable
      Triggers a JobManager failover.
      Specified by:
      triggerJobManagerFailover in interface ClusterControllable
      Parameters:
      jobClient - client of the running job
      afterFailAction - action to take before restarting the JobManager
      Throws:
      ExecutionException
      InterruptedException
    • triggerTaskManagerFailover

      public void triggerTaskManagerFailover(org.apache.flink.core.execution.JobClient jobClient, Runnable afterFailAction) throws Exception
      Description copied from interface: ClusterControllable
      Triggers TaskManager failover.
      Specified by:
      triggerTaskManagerFailover in interface ClusterControllable
      Parameters:
      jobClient - client of the running job
      afterFailAction - action to take before restarting TaskManager(s)
      Throws:
      Exception
    • isolateNetwork

      public void isolateNetwork(org.apache.flink.core.execution.JobClient jobClient, Runnable afterFailAction)
      Description copied from interface: ClusterControllable
      Disconnect network between Flink cluster and external system.
      Specified by:
      isolateNetwork in interface ClusterControllable
      Parameters:
      jobClient - client of the running job
      afterFailAction - action to take before recovering the network connection
    • startUp

      public void startUp() throws Exception
      Description copied from interface: TestResource
      Start up the test resource.

      The implementation of this method should be idempotent.

      Specified by:
      startUp in interface TestResource
      Throws:
      Exception - if anything wrong when starting the resource
    • tearDown

      public void tearDown() throws Exception
      Description copied from interface: TestResource
      Tear down the test resource.

      The test resource should be able to tear down even without a startup (could be a no-op).

      Specified by:
      tearDown in interface TestResource
      Throws:
      Exception - if anything wrong when tearing the resource down
    • toString

      public String toString()
      Overrides:
      toString in class Object