You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by dl...@apache.org on 2017/11/02 03:21:27 UTC
[16/50] [abbrv] incubator-edgent git commit: fix command test
completion to not be TMO based
fix command test completion to not be TMO based
Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent/commit/719fe6d8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent/tree/719fe6d8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent/diff/719fe6d8
Branch: refs/heads/develop
Commit: 719fe6d8bf787e16cff01c49d86b2ae281437cc5
Parents: b7897e5
Author: Dale LaBossiere <dl...@us.ibm.com>
Authored: Wed Oct 25 15:29:27 2017 -0400
Committer: Dale LaBossiere <dl...@us.ibm.com>
Committed: Wed Oct 25 15:29:27 2017 -0400
----------------------------------------------------------------------
.../connectors/command/CommandStreamsTest.java | 47 +++++++++++++++-----
.../edgent/test/connectors/common/FileUtil.java | 27 +++++++++--
2 files changed, 61 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/719fe6d8/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 344650e..bc96ad2 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
@@ -41,8 +41,6 @@ import org.apache.edgent.topology.Topology;
import org.apache.edgent.topology.tester.Condition;
import org.junit.Test;
-import com.google.gson.JsonObject;
-
public class CommandStreamsTest extends DirectTopologyTestBase {
private String[] stdLines = new String[] {
@@ -176,9 +174,24 @@ public class CommandStreamsTest extends DirectTopologyTestBase {
assertNotNull(sink);
try {
- // start the job, sleep for a bit (await the timeout) then validate sink output
- Condition<?> never = t.getTester().tupleCount(s, Long.MAX_VALUE);
- t.getTester().complete(getSubmitter(), new JsonObject(), never, 3, TimeUnit.SECONDS);
+ // complete when the sink has generated the expected results
+ Condition<Object> tc = new Condition<Object>() {
+ public boolean valid() {
+ try {
+ return FileUtil.validateFile(tempFile1, getLines(), true);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+ public Object getResult() { return "todo-files-lines"; }
+ };
+
+ // If we time out, still validate content to see what we did get
+ try {
+ complete(t, tc, 3, TimeUnit.SECONDS);
+ } catch (Exception e) {
+ System.out.println("test time out");
+ }
FileUtil.validateFile(tempFile1, getLines());
}
@@ -229,11 +242,25 @@ public class CommandStreamsTest extends DirectTopologyTestBase {
assertNotNull(sink);
try {
- // start the job, sleep for a bit (await the timeout) then validate sink output
- Condition<?> never = t.getTester().tupleCount(s, Long.MAX_VALUE);
- t.getTester().complete(getSubmitter(), new JsonObject(), never,
- 6 + ((NUM_RUNS-1) * 1/*restart delay*/), TimeUnit.SECONDS);
-
+ // complete when the sink has generated the expected results
+ Condition<Object> tc = new Condition<Object>() {
+ public boolean valid() {
+ try {
+ return FileUtil.validateFile(tempFile1, expLines.toArray(new String[0]), true);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+ public Object getResult() { return "todo-files-lines"; }
+ };
+
+ // If we time out, still validate content to see what we did get
+ try {
+ complete(t, tc, 6 + ((NUM_RUNS-1) * 1/*restart delay*/), TimeUnit.SECONDS);
+ } catch (Exception e) {
+ System.out.println("test time out");
+ }
+
FileUtil.validateFile(tempFile1, expLines.toArray(new String[0]));
}
finally {
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/719fe6d8/connectors/common/src/test/java/org/apache/edgent/test/connectors/common/FileUtil.java
----------------------------------------------------------------------
diff --git a/connectors/common/src/test/java/org/apache/edgent/test/connectors/common/FileUtil.java b/connectors/common/src/test/java/org/apache/edgent/test/connectors/common/FileUtil.java
index 8032f55..4902544 100644
--- a/connectors/common/src/test/java/org/apache/edgent/test/connectors/common/FileUtil.java
+++ b/connectors/common/src/test/java/org/apache/edgent/test/connectors/common/FileUtil.java
@@ -30,6 +30,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
@@ -69,9 +70,11 @@ public class FileUtil {
* Validate that the file contains the specified content.
* @param path file to validate
* @param lines the expected content
- * @throws Exception on failure
+ * @param silent control return vs throw
+ * @return false on failure - only applicable when silent==true
+ * @throws Exception on failure when silent==false
*/
- public static void validateFile(Path path, String[] lines) throws Exception {
+ public static boolean validateFile(Path path, String[] lines, boolean silent) throws Exception {
List<String> actLines = new ArrayList<>();
try (BufferedReader reader =
new BufferedReader(new InputStreamReader(
@@ -81,8 +84,26 @@ public class FileUtil {
while ((line = reader.readLine()) != null) {
actLines.add(line);
}
- assertArrayEquals(lines, actLines.toArray(new String[actLines.size()]));
+ if (!silent)
+ assertArrayEquals(lines, actLines.toArray(new String[actLines.size()]));
+ else if (!Arrays.equals(lines, actLines.toArray(new String[actLines.size()])))
+ return false;
+ return true;
+ }
+ catch (Exception e) {
+ if (!silent) throw e;
+ return false;
}
}
+
+ /**
+ * Validate that the file contains the specified content.
+ * @param path file to validate
+ * @param lines the expected content
+ * @throws Exception on failure
+ */
+ public static void validateFile(Path path, String[] lines) throws Exception {
+ validateFile(path, lines, false);
+ }
}