public class FlinkContainers extends Object implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback
This containerized Flink cluster is based on Testcontainers, which simulates a truly distributed
environment for E2E tests. This class can also be used as an Extension of JUnit 5 so that
the lifecycle of the cluster can be easily managed by JUnit Jupiter engine.
{@code
public class E2ETest {
// Create a Flink cluster using default configurations.
// Remember to declare it as "static" as required by
// JUnit 5.| Modifier and Type | Class and Description |
|---|---|
static class |
FlinkContainers.Builder
The
FlinkContainers builder. |
| Modifier and Type | Field and Description |
|---|---|
static java.time.Duration |
DEFAULT_TIMEOUT |
| Modifier and Type | Method and Description |
|---|---|
void |
afterAll(org.junit.jupiter.api.extension.ExtensionContext context) |
void |
beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) |
static FlinkContainers.Builder |
builder()
Creates a builder for
FlinkContainers. |
org.testcontainers.containers.GenericContainer<?> |
getJobManager()
Gets JobManager container.
|
String |
getJobManagerHost()
Gets JobManager's hostname on the host machine.
|
int |
getJobManagerPort()
Gets JobManager's port on the host machine.
|
org.apache.flink.client.program.rest.RestClusterClient<org.apache.flink.client.deployment.StandaloneClusterId> |
getRestClusterClient()
Gets REST client connected to JobManager.
|
List<org.testcontainers.containers.GenericContainer<?>> |
getTaskManagers()
Gets TaskManager containers.
|
boolean |
isStarted()
Gets the running state of the cluster.
|
void |
restartJobManager(org.apache.flink.util.function.RunnableWithException afterFailAction)
Restarts JobManager container.
|
void |
restartTaskManager(org.apache.flink.util.function.RunnableWithException afterFailAction)
Restarts all TaskManager containers.
|
void |
start()
Starts all containers.
|
void |
stop()
Stops all containers.
|
org.apache.flink.api.common.JobID |
submitJob(org.apache.flink.test.util.JobSubmission job)
Submits the given job to the cluster.
|
void |
submitSQLJob(org.apache.flink.test.util.SQLJobSubmission job)
Submits an SQL job to the running cluster.
|
public static FlinkContainers.Builder builder()
FlinkContainers.public void stop()
public boolean isStarted()
public org.testcontainers.containers.GenericContainer<?> getJobManager()
public List<org.testcontainers.containers.GenericContainer<?>> getTaskManagers()
public String getJobManagerHost()
public int getJobManagerPort()
@Nullable public org.apache.flink.client.program.rest.RestClusterClient<org.apache.flink.client.deployment.StandaloneClusterId> getRestClusterClient()
public void restartJobManager(org.apache.flink.util.function.RunnableWithException afterFailAction)
throws Exception
Note that the REST port will be changed because the new JM container will be mapped to another random port. Please make sure to get the REST cluster client again after this method is invoked.
Exceptionpublic void restartTaskManager(org.apache.flink.util.function.RunnableWithException afterFailAction)
throws Exception
Exceptionpublic void submitSQLJob(org.apache.flink.test.util.SQLJobSubmission job)
throws IOException,
InterruptedException
NOTE: You should not use '\t'.
IOExceptionInterruptedExceptionpublic org.apache.flink.api.common.JobID submitJob(org.apache.flink.test.util.JobSubmission job)
throws IOException,
InterruptedException
job - job to submitIOExceptionInterruptedExceptionpublic void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
throws Exception
beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallbackExceptionpublic void afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
afterAll in interface org.junit.jupiter.api.extension.AfterAllCallbackCopyright © 2014–2024 The Apache Software Foundation. All rights reserved.