Skip to content

Commit

Permalink
[FLINK-6397] [tests] Reset context environments after test execution
Browse files Browse the repository at this point in the history
This closes apache#3810.
  • Loading branch information
biao.liub authored and zentol committed May 13, 2017
1 parent 947c44e commit 707f25f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ trait FlinkTestBase extends BeforeAndAfter {

after {
cluster.foreach(c => TestBaseUtils.stopCluster(c, TestBaseUtils.DEFAULT_TIMEOUT))

TestEnvironment.unsetAsContext()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ public ExecutionEnvironment createExecutionEnvironment() {

initializeContextEnvironment(factory);
}

protected static void unsetAsContext() {
resetContextEnvironment();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ protected boolean skipCollectionExecution() {
@Test
public void testJobWithObjectReuse() throws Exception {
isCollectionExecution = false;

startCluster();

try {
// pre-submit
try {
Expand All @@ -109,7 +110,7 @@ public void testJobWithObjectReuse() throws Exception {
e.printStackTrace();
Assert.fail("Pre-submit work caused an error: " + e.getMessage());
}

// prepare the test environment
TestEnvironment env = new TestEnvironment(this.executor, this.parallelism, false);
env.getConfig().enableObjectReuse();
Expand Down Expand Up @@ -143,6 +144,7 @@ public void testJobWithObjectReuse() throws Exception {
}
} finally {
stopCluster();
TestEnvironment.unsetAsContext();
}
}

Expand Down Expand Up @@ -195,6 +197,7 @@ public void testJobWithoutObjectReuse() throws Exception {
}
} finally {
stopCluster();
TestEnvironment.unsetAsContext();
}
}

Expand Down Expand Up @@ -231,6 +234,8 @@ public void testJobCollectionExecution() throws Exception {
System.err.println(e.getMessage());
e.printStackTrace();
Assert.fail("Error while calling the test program: " + e.getMessage());
} finally {
CollectionTestEnvironment.unsetAsContext();
}

Assert.assertNotNull("The test program never triggered an execution.", this.latestExecutionResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
package org.apache.flink.test.util;

import org.apache.flink.runtime.minicluster.LocalFlinkMiniCluster;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runners.Parameterized;

Expand Down Expand Up @@ -80,10 +82,16 @@ public enum TestExecutionMode {

protected final TestExecutionMode mode;


public MultipleProgramsTestBase(TestExecutionMode mode) {
this.mode = mode;

}

// ------------------------------------------------------------------------
// Environment setup & teardown
// ------------------------------------------------------------------------

@Before
public void setupEnvironment() {
switch(mode){
case CLUSTER:
new TestEnvironment(cluster, 4, false).setAsContext();
Expand All @@ -97,6 +105,19 @@ public MultipleProgramsTestBase(TestExecutionMode mode) {
}
}

@After
public void teardownEnvironment() {
switch(mode) {
case CLUSTER:
case CLUSTER_OBJECT_REUSE:
TestEnvironment.unsetAsContext();
break;
case COLLECTION:
CollectionTestEnvironment.unsetAsContext();
break;
}
}

// ------------------------------------------------------------------------
// Cluster setup & teardown
// ------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.flink.util.Collector;
import org.apache.flink.util.TestLogger;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -70,6 +71,11 @@ public void prepare() {
clusterEnv.setAsContext();
}

@After
public void cleanup() {
TestEnvironment.unsetAsContext();
}

// ------------------------------------------------------------------------

/**
Expand Down

0 comments on commit 707f25f

Please sign in to comment.