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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.flink.connector.testframe.environment.TestEnvironment
TestEnvironment.Endpoint
-
-
Constructor Summary
Constructors Constructor Description MiniClusterTestEnvironment()
MiniClusterTestEnvironment(MiniClusterResourceConfiguration conf)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StreamExecutionEnvironment
createExecutionEnvironment(TestEnvironmentSettings envOptions)
Get an instance ofStreamExecutionEnvironment
for building and executing Flink jobs based on the provided configuration.String
getCheckpointUri()
Get a path in string for storing checkpoint and savepoint in the test environment.TestEnvironment.Endpoint
getRestEndpoint()
Get endpoint of the test environment for connecting via REST API.void
isolateNetwork(JobClient jobClient, Runnable afterFailAction)
Disconnect network between Flink cluster and external system.void
startUp()
Start up the test resource.void
tearDown()
Tear down the test resource.String
toString()
void
triggerJobManagerFailover(JobClient jobClient, Runnable afterFailAction)
Triggers a JobManager failover.void
triggerTaskManagerFailover(JobClient jobClient, Runnable afterFailAction)
Triggers TaskManager failover.
-
-
-
Method Detail
-
createExecutionEnvironment
public StreamExecutionEnvironment createExecutionEnvironment(TestEnvironmentSettings envOptions)
Description copied from interface:TestEnvironment
Get an instance ofStreamExecutionEnvironment
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 interfaceTestEnvironment
- 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 interfaceTestEnvironment
-
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 interfaceTestEnvironment
-
triggerJobManagerFailover
public void triggerJobManagerFailover(JobClient jobClient, Runnable afterFailAction) throws ExecutionException, InterruptedException
Description copied from interface:ClusterControllable
Triggers a JobManager failover.- Specified by:
triggerJobManagerFailover
in interfaceClusterControllable
- Parameters:
jobClient
- client of the running jobafterFailAction
- action to take before restarting the JobManager- Throws:
ExecutionException
InterruptedException
-
triggerTaskManagerFailover
public void triggerTaskManagerFailover(JobClient jobClient, Runnable afterFailAction) throws Exception
Description copied from interface:ClusterControllable
Triggers TaskManager failover.- Specified by:
triggerTaskManagerFailover
in interfaceClusterControllable
- Parameters:
jobClient
- client of the running jobafterFailAction
- action to take before restarting TaskManager(s)- Throws:
Exception
-
isolateNetwork
public void isolateNetwork(JobClient jobClient, Runnable afterFailAction)
Description copied from interface:ClusterControllable
Disconnect network between Flink cluster and external system.- Specified by:
isolateNetwork
in interfaceClusterControllable
- Parameters:
jobClient
- client of the running jobafterFailAction
- 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 interfaceTestResource
- 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 interfaceTestResource
- Throws:
Exception
- if anything wrong when tearing the resource down
-
-