Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-6397

MultipleProgramsTestBase does not reset ContextEnvironment

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.3.0, 1.4.0
    • Fix Version/s: 1.3.0, 1.4.0
    • Component/s: Tests
    • Labels:
      None

      Description

      The MultipleProgramsTestBase sets a new TestEnvironment as a context environment but never explicitly unsets it, which can result subsequent tests categorically failing.

      The CustomDistributionITCase doesn't unset the context either; and some streaming test that i haven't quite nailed down yet.

        Issue Links

          Activity

          Hide
          SleePy Biao Liu added a comment -

          I would like to fix this problem.
          But I didn't find the ClusterDistributionITCase in master branch Chesnay Schepler

          Show
          SleePy Biao Liu added a comment - I would like to fix this problem. But I didn't find the ClusterDistributionITCase in master branch Chesnay Schepler
          Hide
          Zentol Chesnay Schepler added a comment -

          It's called

          {CustomDistributionITCase}

          , fixing the description now.

          Show
          Zentol Chesnay Schepler added a comment - It's called {CustomDistributionITCase} , fixing the description now.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user ifndef-SleePy commented on a diff in the pull request:

          https://github.com/apache/flink/pull/3810#discussion_r115133175

          — Diff: flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/MultipleProgramsTestBase.java —
          @@ -80,29 +80,36 @@

          protected final TestExecutionMode mode;

          • + private TestEnvironment testEnvironment;
            +
            + private CollectionTestEnvironment collectionTestEnvironment;
            +
            public MultipleProgramsTestBase(TestExecutionMode mode) {
            this.mode = mode;

          • +
            switch(mode){
            case CLUSTER:

          • new TestEnvironment(cluster, 4).setAsContext();
            + testEnvironment = new TestEnvironment(cluster, 4);
              • End diff –

          @zentol I just found that I can not move these codes into @Before method, because it will not work with JUnit Parameterized. I proposal to keep these codes in constructor. What do you think?

          Show
          githubbot ASF GitHub Bot added a comment - Github user ifndef-SleePy commented on a diff in the pull request: https://github.com/apache/flink/pull/3810#discussion_r115133175 — Diff: flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/MultipleProgramsTestBase.java — @@ -80,29 +80,36 @@ protected final TestExecutionMode mode; + private TestEnvironment testEnvironment; + + private CollectionTestEnvironment collectionTestEnvironment; + public MultipleProgramsTestBase(TestExecutionMode mode) { this.mode = mode; + switch(mode){ case CLUSTER: new TestEnvironment(cluster, 4).setAsContext(); + testEnvironment = new TestEnvironment(cluster, 4); End diff – @zentol I just found that I can not move these codes into @Before method, because it will not work with JUnit Parameterized. I proposal to keep these codes in constructor. What do you think?
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user ifndef-SleePy commented on the issue:

          https://github.com/apache/flink/pull/3810

          I think Till has implemented a static unsetAsContext method in TestEnvironment recently. I rebased the implementation from master, and recommit the pull request.

          Show
          githubbot ASF GitHub Bot added a comment - Github user ifndef-SleePy commented on the issue: https://github.com/apache/flink/pull/3810 I think Till has implemented a static unsetAsContext method in TestEnvironment recently. I rebased the implementation from master, and recommit the pull request.
          Hide
          SleePy Biao Liu added a comment -

          Somehow the pull request did not been connected with jira. Maybe because I did not write the right title at beginning.

          Show
          SleePy Biao Liu added a comment - Somehow the pull request did not been connected with jira. Maybe because I did not write the right title at beginning.
          Hide
          githubbot ASF GitHub Bot added a comment -

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

          https://github.com/apache/flink/pull/3810#discussion_r115137365

          — Diff: flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/MultipleProgramsTestBase.java —
          @@ -80,29 +80,36 @@

          protected final TestExecutionMode mode;

          • + private TestEnvironment testEnvironment;
            +
            + private CollectionTestEnvironment collectionTestEnvironment;
            +
            public MultipleProgramsTestBase(TestExecutionMode mode) {
            this.mode = mode;

          • +
            switch(mode){
            case CLUSTER:

          • new TestEnvironment(cluster, 4).setAsContext();
            + testEnvironment = new TestEnvironment(cluster, 4);
              • End diff –

          Could you try this instead: https://github.com/junit-team/junit4/issues/45#issuecomment-6422143

          Show
          githubbot ASF GitHub Bot added a comment - Github user zentol commented on a diff in the pull request: https://github.com/apache/flink/pull/3810#discussion_r115137365 — Diff: flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/MultipleProgramsTestBase.java — @@ -80,29 +80,36 @@ protected final TestExecutionMode mode; + private TestEnvironment testEnvironment; + + private CollectionTestEnvironment collectionTestEnvironment; + public MultipleProgramsTestBase(TestExecutionMode mode) { this.mode = mode; + switch(mode){ case CLUSTER: new TestEnvironment(cluster, 4).setAsContext(); + testEnvironment = new TestEnvironment(cluster, 4); End diff – Could you try this instead: https://github.com/junit-team/junit4/issues/45#issuecomment-6422143
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user ifndef-SleePy commented on a diff in the pull request:

          https://github.com/apache/flink/pull/3810#discussion_r115170542

          — Diff: flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/MultipleProgramsTestBase.java —
          @@ -80,29 +80,36 @@

          protected final TestExecutionMode mode;

          • + private TestEnvironment testEnvironment;
            +
            + private CollectionTestEnvironment collectionTestEnvironment;
            +
            public MultipleProgramsTestBase(TestExecutionMode mode) {
            this.mode = mode;

          • +
            switch(mode){
            case CLUSTER:

          • new TestEnvironment(cluster, 4).setAsContext();
            + testEnvironment = new TestEnvironment(cluster, 4);
              • End diff –

          Thank you for responding. Last my comment is not correct. Actually what I want to say is that we can not move these code to @BeforeClass and @AfterClass. But we can move them to @Before and @After, however it will bring a little overhead since @Before and @After will be called for each test method. I pushed a new commit using @Before and @After.

          Show
          githubbot ASF GitHub Bot added a comment - Github user ifndef-SleePy commented on a diff in the pull request: https://github.com/apache/flink/pull/3810#discussion_r115170542 — Diff: flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/MultipleProgramsTestBase.java — @@ -80,29 +80,36 @@ protected final TestExecutionMode mode; + private TestEnvironment testEnvironment; + + private CollectionTestEnvironment collectionTestEnvironment; + public MultipleProgramsTestBase(TestExecutionMode mode) { this.mode = mode; + switch(mode){ case CLUSTER: new TestEnvironment(cluster, 4).setAsContext(); + testEnvironment = new TestEnvironment(cluster, 4); End diff – Thank you for responding. Last my comment is not correct. Actually what I want to say is that we can not move these code to @BeforeClass and @AfterClass. But we can move them to @Before and @After, however it will bring a little overhead since @Before and @After will be called for each test method. I pushed a new commit using @Before and @After.
          Hide
          githubbot ASF GitHub Bot added a comment -

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

          https://github.com/apache/flink/pull/3810#discussion_r115274563

          — Diff: flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/MultipleProgramsTestBase.java —
          @@ -97,6 +105,12 @@ public MultipleProgramsTestBase(TestExecutionMode mode) {
          }
          }

          + @After
          + public void teardownEnvironment() {
          + TestEnvironment.unsetAsContext();
          — End diff –

          you could add another switch here, instead of calling both methods every time.

          Show
          githubbot ASF GitHub Bot added a comment - Github user zentol commented on a diff in the pull request: https://github.com/apache/flink/pull/3810#discussion_r115274563 — Diff: flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/MultipleProgramsTestBase.java — @@ -97,6 +105,12 @@ public MultipleProgramsTestBase(TestExecutionMode mode) { } } + @After + public void teardownEnvironment() { + TestEnvironment.unsetAsContext(); — End diff – you could add another switch here, instead of calling both methods every time.
          Hide
          githubbot ASF GitHub Bot added a comment -

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

          https://github.com/apache/flink/pull/3810#discussion_r115274387

          — Diff: flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/CollectionTestEnvironment.java —
          @@ -49,7 +49,7 @@ public JobExecutionResult execute(String jobName) throws Exception

          { return result; }
          • protected void setAsContext() {
            + public void setAsContext() {
              • End diff –

          do we still need this change?

          Show
          githubbot ASF GitHub Bot added a comment - Github user zentol commented on a diff in the pull request: https://github.com/apache/flink/pull/3810#discussion_r115274387 — Diff: flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/CollectionTestEnvironment.java — @@ -49,7 +49,7 @@ public JobExecutionResult execute(String jobName) throws Exception { return result; } protected void setAsContext() { + public void setAsContext() { End diff – do we still need this change?
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user ifndef-SleePy commented on the issue:

          https://github.com/apache/flink/pull/3810

          Hi, I updated this review. I don't know why there is no reminding in jira and email.

          Show
          githubbot ASF GitHub Bot added a comment - Github user ifndef-SleePy commented on the issue: https://github.com/apache/flink/pull/3810 Hi, I updated this review. I don't know why there is no reminding in jira and email.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user zentol commented on the issue:

          https://github.com/apache/flink/pull/3810

          We don't get notifications about pushed commits in general, only for comments and created/closed pull requests.

          Show
          githubbot ASF GitHub Bot added a comment - Github user zentol commented on the issue: https://github.com/apache/flink/pull/3810 We don't get notifications about pushed commits in general, only for comments and created/closed pull requests.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user ifndef-SleePy commented on the issue:

          https://github.com/apache/flink/pull/3810

          OK, got it. Thank you for explanation. Is there any more problems with this pull request?

          Show
          githubbot ASF GitHub Bot added a comment - Github user ifndef-SleePy commented on the issue: https://github.com/apache/flink/pull/3810 OK, got it. Thank you for explanation. Is there any more problems with this pull request?
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user zentol commented on the issue:

          https://github.com/apache/flink/pull/3810

          Not quite; the `CassandraConnectorITCase` was broken in the process. This test contains both batch and streaming jobs that rely on different TestEnvironments. When the batch `TestEnvironment` is set as the context the streaming tests will fail.

          `StreamExecutionEnvironment#getExecutionEnvironment()` doesn't account for this case, and tries to create a `LocalStreamEnvironment` which however fails since no explicit environment may be create when a context environment was set.

          This is more or less a problem of the cassandra test; it shouldn't actually run any streaming jobs. Let me fix that, then we'll get back to this PR.

          Besides that i don't see any problems right now.

          Show
          githubbot ASF GitHub Bot added a comment - Github user zentol commented on the issue: https://github.com/apache/flink/pull/3810 Not quite; the `CassandraConnectorITCase` was broken in the process. This test contains both batch and streaming jobs that rely on different TestEnvironments. When the batch `TestEnvironment` is set as the context the streaming tests will fail. `StreamExecutionEnvironment#getExecutionEnvironment()` doesn't account for this case, and tries to create a `LocalStreamEnvironment` which however fails since no explicit environment may be create when a context environment was set. This is more or less a problem of the cassandra test; it shouldn't actually run any streaming jobs. Let me fix that, then we'll get back to this PR. Besides that i don't see any problems right now.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user zentol commented on the issue:

          https://github.com/apache/flink/pull/3810

          I've fixed the cassandra tests, would be great if you could rebase this PR. You should be able to discard all changes to the cassandra tests in this PR.

          Show
          githubbot ASF GitHub Bot added a comment - Github user zentol commented on the issue: https://github.com/apache/flink/pull/3810 I've fixed the cassandra tests, would be great if you could rebase this PR. You should be able to discard all changes to the cassandra tests in this PR.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user ifndef-SleePy commented on the issue:

          https://github.com/apache/flink/pull/3810

          Nice work!
          I have rebased master.

          Show
          githubbot ASF GitHub Bot added a comment - Github user ifndef-SleePy commented on the issue: https://github.com/apache/flink/pull/3810 Nice work! I have rebased master.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user zentol commented on the issue:

          https://github.com/apache/flink/pull/3810

          merging.

          Show
          githubbot ASF GitHub Bot added a comment - Github user zentol commented on the issue: https://github.com/apache/flink/pull/3810 merging.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

          https://github.com/apache/flink/pull/3810

          Show
          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/flink/pull/3810
          Hide
          Zentol Chesnay Schepler added a comment -

          1.3: 36edac4b16993459dedf9f76d05f9e96b918c783
          1.4: 707f25fdf9800e4113661c8d774bfcdc5d9c51d1

          Show
          Zentol Chesnay Schepler added a comment - 1.3: 36edac4b16993459dedf9f76d05f9e96b918c783 1.4: 707f25fdf9800e4113661c8d774bfcdc5d9c51d1

            People

            • Assignee:
              SleePy Biao Liu
              Reporter:
              Zentol Chesnay Schepler
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development