Class FlinkContainers

  • All Implemented Interfaces:
    org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.Extension

    public class FlinkContainers
    extends Object
    implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback
    A Flink cluster running JM and TMs on containers.

    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.

    Example usage

    {@code
     public class E2ETest {
         // Create a Flink cluster using default configurations.
         // Remember to declare it as "static" as required by
         // JUnit 5.
    • Field Detail

      • DEFAULT_TIMEOUT

        public static final Duration DEFAULT_TIMEOUT
    • Method Detail

      • stop

        public void stop()
        Stops all containers.
      • isStarted

        public boolean isStarted()
        Gets the running state of the cluster.
      • getJobManager

        public org.testcontainers.containers.GenericContainer<?> getJobManager()
        Gets JobManager container.
      • getTaskManagers

        public List<org.testcontainers.containers.GenericContainer<?>> getTaskManagers()
        Gets TaskManager containers.
      • getJobManagerHost

        public String getJobManagerHost()
        Gets JobManager's hostname on the host machine.
      • getJobManagerPort

        public int getJobManagerPort()
        Gets JobManager's port on the host machine.
      • restartJobManager

        public void restartJobManager​(RunnableWithException afterFailAction)
                               throws Exception
        Restarts JobManager container.

        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.

        Throws:
        Exception
      • beforeAll

        public void beforeAll​(org.junit.jupiter.api.extension.ExtensionContext context)
                       throws Exception
        Specified by:
        beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
        Throws:
        Exception
      • afterAll

        public void afterAll​(org.junit.jupiter.api.extension.ExtensionContext context)
        Specified by:
        afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback