Repository: incubator-edgent Updated Branches: refs/heads/master e47ba5417 -> cc405cc6c
[Edgent-319] fix CommandStreamTest on MSWin Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent/commit/88f3a535 Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent/tree/88f3a535 Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent/diff/88f3a535 Branch: refs/heads/master Commit: 88f3a5353c100ae61acccb505abcbe7173ee6eae Parents: c7cbe49 Author: Dale LaBossiere <[email protected]> Authored: Wed Dec 28 10:40:26 2016 -0500 Committer: Dale LaBossiere <[email protected]> Committed: Wed Dec 28 10:40:26 2016 -0500 ---------------------------------------------------------------------- .../connectors/command/CommandStreamsTest.java | 36 +++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/88f3a535/connectors/command/src/test/java/org/apache/edgent/test/connectors/command/CommandStreamsTest.java ---------------------------------------------------------------------- diff --git a/connectors/command/src/test/java/org/apache/edgent/test/connectors/command/CommandStreamsTest.java b/connectors/command/src/test/java/org/apache/edgent/test/connectors/command/CommandStreamsTest.java index a24bec8..3959dda 100644 --- a/connectors/command/src/test/java/org/apache/edgent/test/connectors/command/CommandStreamsTest.java +++ b/connectors/command/src/test/java/org/apache/edgent/test/connectors/command/CommandStreamsTest.java @@ -20,6 +20,7 @@ package org.apache.edgent.test.connectors.command; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assume.assumeTrue; import java.io.File; import java.lang.ProcessBuilder.Redirect; @@ -50,6 +51,28 @@ public class CommandStreamsTest extends TopologyAbstractTest implements DirectTe "Line 2", "Line 3", }; + + private boolean isWindows() { + return System.getProperty("os.name").contains("Windows"); + } + + private String[] mkCatFileCmd(String path) { + if (isWindows()) { + return new String[] {"cmd", "/c", "type", path}; + } + else { + return new String[] {"cat", path}; + } + } + + private String[] mkCatStdInOutCmd() { + if (isWindows()) { + return new String[] {"cmd", "/c", "findstr", "^"}; + } + else { + return new String[] {"cat"}; + } + } public String[] getLines() { return stdLines; @@ -77,7 +100,7 @@ public class CommandStreamsTest extends TopologyAbstractTest implements DirectTe Path tempFile1 = FileUtil.createTempFile("test1", ".txt", getLines()); System.out.println("Test: "+t.getName()+" "+tempFile1); - ProcessBuilder cmd = new ProcessBuilder("cat", tempFile1.toString()); + ProcessBuilder cmd = new ProcessBuilder(mkCatFileCmd(tempFile1.toString())); int NUM_POLLS = 3; List<String> expLines = new ArrayList<>(); @@ -103,7 +126,7 @@ public class CommandStreamsTest extends TopologyAbstractTest implements DirectTe Path tempFile1 = FileUtil.createTempFile("test1", ".txt", getLines()); System.out.println("Test: "+t.getName()+" "+tempFile1); - ProcessBuilder cmd = new ProcessBuilder("cat", tempFile1.toString()); + ProcessBuilder cmd = new ProcessBuilder(mkCatFileCmd(tempFile1.toString())); // N.B. if looking at trace: EDGENT-224 generate() continues running after job is closed TStream<String> s = CommandStreams.generate(t, cmd); @@ -123,7 +146,7 @@ public class CommandStreamsTest extends TopologyAbstractTest implements DirectTe Path tempFile1 = FileUtil.createTempFile("test1", ".txt", getLines()); System.out.println("Test: "+t.getName()+" "+tempFile1); - ProcessBuilder cmd = new ProcessBuilder("cat", tempFile1.toString()); + ProcessBuilder cmd = new ProcessBuilder(mkCatFileCmd(tempFile1.toString())); int NUM_RUNS = 3; List<String> expLines = new ArrayList<>(); @@ -144,7 +167,7 @@ public class CommandStreamsTest extends TopologyAbstractTest implements DirectTe Path tempFile1 = FileUtil.createTempFile("test1", ".txt", new String[0]); System.out.println("Test: "+t.getName()+" "+tempFile1); - ProcessBuilder cmd = new ProcessBuilder("cat") + ProcessBuilder cmd = new ProcessBuilder(mkCatStdInOutCmd()) .redirectOutput(Redirect.appendTo(tempFile1.toFile())); TStream<String> s = t.strings(getLines()); @@ -169,6 +192,11 @@ public class CommandStreamsTest extends TopologyAbstractTest implements DirectTe public void testSinkRestart() throws Exception { Topology t = newTopology("testSinkRestart"); + // until someone cares enough to create Win version of sinkcmd + if (isWindows()) { + assumeTrue("need sinkcmd for Windows", false); + } + Path tempFile1 = FileUtil.createTempFile("test1", ".txt", new String[0]); System.out.println("Test: "+t.getName()+" "+tempFile1);
