[hotfix][tests] fix ineffective file existence check and remove duplicate code


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/ca5573b2
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/ca5573b2
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/ca5573b2

Branch: refs/heads/master
Commit: ca5573b21867930709f094306733bf854d82fda7
Parents: 57b3ce8
Author: Nico Kruber <n...@data-artisans.com>
Authored: Tue Apr 3 14:13:41 2018 +0200
Committer: Nico Kruber <n...@data-artisans.com>
Committed: Thu Apr 12 10:40:15 2018 -0700

----------------------------------------------------------------------
 .../YARNSessionCapacitySchedulerITCase.java     | 18 ++++------
 .../flink/yarn/YarnConfigurationITCase.java     |  5 ++-
 .../apache/flink/yarn/util/YarnTestUtils.java   | 36 ++++++++++++++++++++
 3 files changed, 44 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/ca5573b2/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YARNSessionCapacitySchedulerITCase.java
----------------------------------------------------------------------
diff --git 
a/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YARNSessionCapacitySchedulerITCase.java
 
b/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YARNSessionCapacitySchedulerITCase.java
index 3767629..ac8eaa0 100644
--- 
a/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YARNSessionCapacitySchedulerITCase.java
+++ 
b/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YARNSessionCapacitySchedulerITCase.java
@@ -78,6 +78,7 @@ import java.util.regex.Pattern;
 import static junit.framework.TestCase.assertTrue;
 import static org.apache.flink.yarn.UtilsTest.addTestAppender;
 import static org.apache.flink.yarn.UtilsTest.checkForLogString;
+import static org.apache.flink.yarn.util.YarnTestUtils.getTestJarPath;
 import static org.junit.Assume.assumeTrue;
 
 /**
@@ -123,8 +124,7 @@ public class YARNSessionCapacitySchedulerITCase extends 
YarnTestBase {
        public void perJobYarnCluster() throws IOException {
                LOG.info("Starting perJobYarnCluster()");
                addTestAppender(JobClient.class, Level.INFO);
-               File exampleJarLocation = new 
File("target/programs/BatchWordCount.jar");
-               Assert.assertNotNull("Could not find wordcount jar", 
exampleJarLocation);
+               File exampleJarLocation = getTestJarPath("BatchWordCount.jar");
                runWithArgs(new String[]{"run", "-m", "yarn-cluster",
                                "-yj", flinkUberjar.getAbsolutePath(), "-yt", 
flinkLibFolder.getAbsolutePath(),
                                "-yn", "1",
@@ -152,8 +152,7 @@ public class YARNSessionCapacitySchedulerITCase extends 
YarnTestBase {
        public void perJobYarnClusterOffHeap() throws IOException {
                LOG.info("Starting perJobYarnCluster()");
                addTestAppender(JobClient.class, Level.INFO);
-               File exampleJarLocation = new 
File("target/programs/BatchWordCount.jar");
-               Assert.assertNotNull("Could not find wordcount jar", 
exampleJarLocation);
+               File exampleJarLocation = getTestJarPath("BatchWordCount.jar");
 
                // set memory constraints (otherwise this is the same test as 
perJobYarnCluster() above)
                final long taskManagerMemoryMB = 1024;
@@ -394,8 +393,7 @@ public class YARNSessionCapacitySchedulerITCase extends 
YarnTestBase {
                // write log messages to stdout as well, so that the 
runWithArgs() method
                // is catching the log output
                addTestAppender(JobClient.class, Level.INFO);
-               File exampleJarLocation = new 
File("target/programs/BatchWordCount.jar");
-               Assert.assertNotNull("Could not find wordcount jar", 
exampleJarLocation);
+               File exampleJarLocation = getTestJarPath("BatchWordCount.jar");
                runWithArgs(new String[]{"run",
                                "-p", "2", //test that the job is executed with 
a DOP of 2
                                "-m", "yarn-cluster",
@@ -419,9 +417,7 @@ public class YARNSessionCapacitySchedulerITCase extends 
YarnTestBase {
        public void testDetachedPerJobYarnCluster() throws Exception {
                LOG.info("Starting testDetachedPerJobYarnCluster()");
 
-               File exampleJarLocation = new 
File("target/programs/BatchWordCount.jar");
-
-               Assert.assertNotNull("Could not find batch wordcount jar", 
exampleJarLocation);
+               File exampleJarLocation = getTestJarPath("BatchWordCount.jar");
 
                
testDetachedPerJobYarnClusterInternal(exampleJarLocation.getAbsolutePath());
 
@@ -435,9 +431,7 @@ public class YARNSessionCapacitySchedulerITCase extends 
YarnTestBase {
        public void testDetachedPerJobYarnClusterWithStreamingJob() throws 
Exception {
                LOG.info("Starting 
testDetachedPerJobYarnClusterWithStreamingJob()");
 
-               File exampleJarLocation = new 
File("target/programs/StreamingWordCount.jar");
-
-               Assert.assertNotNull("Could not find streaming wordcount jar", 
exampleJarLocation);
+               File exampleJarLocation = 
getTestJarPath("StreamingWordCount.jar");
 
                
testDetachedPerJobYarnClusterInternal(exampleJarLocation.getAbsolutePath());
 

http://git-wip-us.apache.org/repos/asf/flink/blob/ca5573b2/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YarnConfigurationITCase.java
----------------------------------------------------------------------
diff --git 
a/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YarnConfigurationITCase.java
 
b/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YarnConfigurationITCase.java
index c5d683e..3a2f957 100644
--- 
a/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YarnConfigurationITCase.java
+++ 
b/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YarnConfigurationITCase.java
@@ -56,6 +56,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.CompletableFuture;
 
+import static org.apache.flink.yarn.util.YarnTestUtils.getTestJarPath;
 import static org.hamcrest.Matchers.closeTo;
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
@@ -100,9 +101,7 @@ public class YarnConfigurationITCase extends YarnTestBase {
                clusterDescriptor.setLocalJarPath(new 
Path(flinkUberjar.getAbsolutePath()));
                
clusterDescriptor.addShipFiles(Arrays.asList(flinkLibFolder.listFiles()));
 
-               final File streamingWordCountFile = new 
File("target/programs/WindowJoin.jar");
-
-               assertThat(streamingWordCountFile.exists(), is(true));
+               final File streamingWordCountFile = 
getTestJarPath("WindowJoin.jar");
 
                final PackagedProgram packagedProgram = new 
PackagedProgram(streamingWordCountFile);
                final JobGraph jobGraph = 
PackagedProgramUtils.createJobGraph(packagedProgram, configuration, 1);

http://git-wip-us.apache.org/repos/asf/flink/blob/ca5573b2/flink-yarn-tests/src/test/java/org/apache/flink/yarn/util/YarnTestUtils.java
----------------------------------------------------------------------
diff --git 
a/flink-yarn-tests/src/test/java/org/apache/flink/yarn/util/YarnTestUtils.java 
b/flink-yarn-tests/src/test/java/org/apache/flink/yarn/util/YarnTestUtils.java
new file mode 100644
index 0000000..25d833b
--- /dev/null
+++ 
b/flink-yarn-tests/src/test/java/org/apache/flink/yarn/util/YarnTestUtils.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.yarn.util;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+
+/**
+ * Utility methods for YARN tests.
+ */
+public class YarnTestUtils {
+       public static File getTestJarPath(String fileName) throws 
FileNotFoundException {
+               File f = new File("target/programs/" + fileName);
+               if (!f.exists()) {
+                       throw new FileNotFoundException("Test jar " + 
f.getPath() + " not present. Invoke tests using maven "
+                               + "or build the jar using 'mvn 
process-test-classes' in flink-yarn-tests");
+               }
+               return f;
+       }
+}

Reply via email to