NIFI-1165: Fix for tests TestRouteText and PutHDFS which did not succeed on Windows
Reviewed by Tony Kurc ([email protected]) Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/fb335ea2 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/fb335ea2 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/fb335ea2 Branch: refs/heads/NIFI-655 Commit: fb335ea282961a236381f78fe18939c15afb66a0 Parents: e862f7f Author: Joe Percivall <[email protected]> Authored: Tue Nov 17 11:41:49 2015 -0500 Committer: Tony Kurc <[email protected]> Committed: Thu Nov 19 01:01:34 2015 -0500 ---------------------------------------------------------------------- .../nifi/processors/hadoop/PutHDFSTest.java | 24 ++++++++++++++++++++ .../nifi/processors/standard/TestRouteText.java | 15 +++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/fb335ea2/nifi-nar-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/test/java/org/apache/nifi/processors/hadoop/PutHDFSTest.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/test/java/org/apache/nifi/processors/hadoop/PutHDFSTest.java b/nifi-nar-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/test/java/org/apache/nifi/processors/hadoop/PutHDFSTest.java index d159336..fe3b5b8 100644 --- a/nifi-nar-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/test/java/org/apache/nifi/processors/hadoop/PutHDFSTest.java +++ b/nifi-nar-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/test/java/org/apache/nifi/processors/hadoop/PutHDFSTest.java @@ -19,6 +19,7 @@ package org.apache.nifi.processors.hadoop; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.FileInputStream; @@ -44,10 +45,23 @@ import org.apache.nifi.util.MockProcessContext; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; public class PutHDFSTest { + @BeforeClass + public static void setUp() throws Exception{ + /* + * Running Hadoop on Windows requires a special build which will produce required binaries and native modules [1]. Since functionality + * provided by this module and validated by these test does not have any native implication we do not distribute required binaries and native modules + * to support running these tests in Windows environment, therefore they are ignored. You can also get more info from this StackOverflow thread [2] + * + * [1] https://wiki.apache.org/hadoop/Hadoop2OnWindows + * [2] http://stackoverflow.com/questions/19620642/failed-to-locate-the-winutils-binary-in-the-hadoop-binary-path + */ + } + @Test public void testValidators() { TestRunner runner = TestRunners.newTestRunner(PutHDFS.class); @@ -159,6 +173,9 @@ public class PutHDFSTest { @Test public void testPutFile() throws IOException { + // Refer to comment in the BeforeClass method for an explanation + assumeTrue(isNotWindows()); + TestRunner runner = TestRunners.newTestRunner(PutHDFS.class); runner.setProperty(PutHDFS.DIRECTORY, "target/test-classes"); runner.setProperty(PutHDFS.CONFLICT_RESOLUTION, "replace"); @@ -182,6 +199,9 @@ public class PutHDFSTest { @Test public void testPutFileWithException() throws IOException { + // Refer to comment in the BeforeClass method for an explanation + assumeTrue(isNotWindows()); + String dirName = "target/testPutFileWrongPermissions"; File file = new File(dirName); file.mkdirs(); @@ -213,4 +233,8 @@ public class PutHDFSTest { fs.setPermission(p, new FsPermission(FsAction.EXECUTE, FsAction.EXECUTE, FsAction.EXECUTE)); fs.delete(p, true); } + + private boolean isNotWindows() { + return !System.getProperty("os.name").startsWith("Windows"); + } } http://git-wip-us.apache.org/repos/asf/nifi/blob/fb335ea2/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteText.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteText.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteText.java index 0cd0034..760986d 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteText.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteText.java @@ -707,9 +707,22 @@ public class TestRouteText { if (str == null || str.isEmpty()) { return 0; } + + String lineSeparator; + + if(str.contains("\r\n")){ + lineSeparator = "\r\n"; + } else if(str.contains("\n")){ + lineSeparator = "\n"; + } else if(str.contains("\r")){ + lineSeparator = "\r"; + } else { + return 1; + } + int lines = 0; int pos = 0; - while ((pos = str.indexOf(System.lineSeparator(), pos) + 1) != 0) { + while ((pos = str.indexOf(lineSeparator, pos) + 1) != 0) { lines++; } return lines;
