From fb335ea282961a236381f78fe18939c15afb66a0 Mon Sep 17 00:00:00 2001 From: Joe Percivall Date: Tue, 17 Nov 2015 11:41:49 -0500 Subject: [PATCH] NIFI-1165: Fix for tests TestRouteText and PutHDFS which did not succeed on Windows Reviewed by Tony Kurc (tkurc@apache.org) --- .../nifi/processors/hadoop/PutHDFSTest.java | 24 +++++++++++++++++++ .../processors/standard/TestRouteText.java | 15 +++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) 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 d159336874..fe3b5b8a5c 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"); + } } 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 0cd0034772..760986df5a 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;