Github user GJL commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4896#discussion_r158254745
  
    --- Diff: 
flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/AbstractTestBase.java
 ---
    @@ -19,81 +19,61 @@
     package org.apache.flink.test.util;
     
     import org.apache.flink.configuration.Configuration;
    -import org.apache.flink.runtime.akka.AkkaUtils;
    -import org.apache.flink.runtime.minicluster.LocalFlinkMiniCluster;
     import org.apache.flink.util.FileUtils;
     
     import org.junit.ClassRule;
     import org.junit.rules.TemporaryFolder;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
     
     import java.io.File;
     import java.io.IOException;
    -import java.util.Objects;
    -
    -import scala.concurrent.duration.FiniteDuration;
     
     /**
    - * A base class for tests that run test programs in a Flink mini cluster.
    + * Base class for unit tests that run multiple tests and want to reuse the 
same
    + * Flink cluster. This saves a significant amount of time, since the 
startup and
    + * shutdown of the Flink clusters (including actor systems, etc) usually 
dominates
    + * the execution of the actual tests.
    + *
    + * <p>To write a unit test against this test base, simply extend it and add
    + * one or more regular test methods and retrieve the 
StreamExecutionEnvironment from
    + * the context:
    + *
    + * <pre>
    + *   {@literal @}Test
    + *   public void someTest() {
    + *       ExecutionEnvironment env = 
ExecutionEnvironment.getExecutionEnvironment();
    + *       // test code
    + *       env.execute();
    + *   }
    + *
    + *   {@literal @}Test
    + *   public void anotherTest() {
    + *       StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
    + *       // test code
    + *       env.execute();
    + *   }
    + *
    + * </pre>
      */
     public abstract class AbstractTestBase extends TestBaseUtils {
     
    -   /** Configuration to start the testing cluster with. */
    -   protected final Configuration config;
    +   protected static final Logger LOG = 
LoggerFactory.getLogger(AbstractTestBase.class);
     
    -   private final FiniteDuration timeout;
    +   private static final int DEFAULT_PARALLELISM = 4;
     
    -   protected int taskManagerNumSlots = 1;
    +   protected static final Configuration MINICLUSTER_CONFIGURATION = new 
Configuration();
    --- End diff --
    
    I think it's dangerous to have mutable global state. 
    
    For example if I have the following two tests:
    ```
    public class TestTest extends AbstractTestBase {
    
        @BeforeClass
        public static void setUp() throws Exception {
                MINICLUSTER_CONFIGURATION.setString("foo", "bar");
        }
    
        @Test
        public void name() throws Exception {
                System.out.println(MINICLUSTER_CONFIGURATION);
        }
    
    }
    ```
    
    ```
    public class TestTest2 extends AbstractTestBase {
    
        @Test
        public void name() throws Exception {
                System.out.println(MINICLUSTER_CONFIGURATION);
        }
    
    }
    ```
    and run them both from IntelliJ, `{foo=bar}` is printed twice.
    
    `MINICLUSTER_CONFIGURATION` is never cleaned up.


---

Reply via email to