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:29 UTC
[18/50] [abbrv] incubator-edgent git commit: fix MQTT test to not use
complete() TMO upon success
fix MQTT test to not use complete() TMO upon success
Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent/commit/786d934f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent/tree/786d934f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent/diff/786d934f
Branch: refs/heads/develop
Commit: 786d934f0837d387e2b97043a68cc56cc793608e
Parents: a6db4b8
Author: Dale LaBossiere <dl...@us.ibm.com>
Authored: Wed Oct 25 16:10:54 2017 -0400
Committer: Dale LaBossiere <dl...@us.ibm.com>
Committed: Wed Oct 25 16:10:54 2017 -0400
----------------------------------------------------------------------
.../connectors/common/ConnectorTestBase.java | 20 ++++++++++++++++++++
.../connectors/mqtt/MqttStreamsTestManual.java | 19 +++++++++++++------
.../javax/websocket/WebSocketClientTest.java | 19 -------------------
3 files changed, 33 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/786d934f/connectors/common/src/test/java/org/apache/edgent/test/connectors/common/ConnectorTestBase.java
----------------------------------------------------------------------
diff --git a/connectors/common/src/test/java/org/apache/edgent/test/connectors/common/ConnectorTestBase.java b/connectors/common/src/test/java/org/apache/edgent/test/connectors/common/ConnectorTestBase.java
index f5230a9..82a70c0 100644
--- a/connectors/common/src/test/java/org/apache/edgent/test/connectors/common/ConnectorTestBase.java
+++ b/connectors/common/src/test/java/org/apache/edgent/test/connectors/common/ConnectorTestBase.java
@@ -23,10 +23,12 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import org.apache.edgent.test.providers.direct.DirectTopologyTestBase;
import org.apache.edgent.topology.TStream;
import org.apache.edgent.topology.Topology;
+import org.apache.edgent.topology.tester.Condition;
public class ConnectorTestBase extends DirectTopologyTestBase {
@@ -102,5 +104,23 @@ public class ConnectorTestBase extends DirectTopologyTestBase {
super.completeAndValidate(ordered, msg, t, s, secTimeout, expected);
}
+
+ public static Condition<Object> newWaitTimeCondition(int seconds) {
+ return new Condition<Object>() {
+ private long startTime = 0;
+ private long endTime = 0;
+ private volatile boolean done = false;
+ public boolean valid() {
+ if (startTime==0) {
+ startTime = System.currentTimeMillis();
+ endTime = startTime + TimeUnit.SECONDS.toMillis(seconds);
+ }
+ long now = System.currentTimeMillis();
+ done = now >= endTime;
+ return done;
+ }
+ public Object getResult() { return done; }
+ };
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/786d934f/connectors/mqtt/src/test/java/org/apache/edgent/test/connectors/mqtt/MqttStreamsTestManual.java
----------------------------------------------------------------------
diff --git a/connectors/mqtt/src/test/java/org/apache/edgent/test/connectors/mqtt/MqttStreamsTestManual.java b/connectors/mqtt/src/test/java/org/apache/edgent/test/connectors/mqtt/MqttStreamsTestManual.java
index 018c1c6..4eae1f1 100644
--- a/connectors/mqtt/src/test/java/org/apache/edgent/test/connectors/mqtt/MqttStreamsTestManual.java
+++ b/connectors/mqtt/src/test/java/org/apache/edgent/test/connectors/mqtt/MqttStreamsTestManual.java
@@ -495,17 +495,24 @@ public class MqttStreamsTestManual extends ConnectorTestBase {
top.collection(msgs), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS);
// Code coverage test: induce connection failure
- //
- // At this point the only thing we can check is an expected
- // result of 0 msgs received.
MqttConfig config = newConfig("tcp://localhost:31999", clientId);
MqttStreams mqtt = new MqttStreams(top, () -> config);
mqtt.publish(s, topic, qos, retain);
- TStream<String> rcvd = mqtt.subscribe(topic, qos);
-
- completeAndValidate(clientId, top, rcvd, mgen, SEC_TIMEOUT, new String[0]);
+ TStream<String> rcvd = mqtt.subscribe(topic, qos); // rcv nothing
+
+ // in this case there's no useful condition that we can check for
+ // to validate this is behaving properly other than the connector doesn't
+ // blow up and that nothing is rcvd, so just wait a short time
+ // before verifying nothing was rcvd.
+ // Don't use the complete() TMO for successful termination.
+
+ Condition<List<String>> rcvdContent = top.getTester().streamContents(rcvd, new String[0]);
+ Condition<Object> tc = newWaitTimeCondition(3);
+
+ complete(top, tc, SEC_TIMEOUT, TimeUnit.SECONDS);
+ assertTrue("rcvd: "+rcvdContent.getResult(), rcvdContent.valid());
}
private String retainTestSetup(boolean isRetained, MsgGenerator mgen) throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/786d934f/connectors/websocket/src/test/java/org/apache/edgent/test/connectors/wsclient/javax/websocket/WebSocketClientTest.java
----------------------------------------------------------------------
diff --git a/connectors/websocket/src/test/java/org/apache/edgent/test/connectors/wsclient/javax/websocket/WebSocketClientTest.java b/connectors/websocket/src/test/java/org/apache/edgent/test/connectors/wsclient/javax/websocket/WebSocketClientTest.java
index fd16084..4ef65c9 100644
--- a/connectors/websocket/src/test/java/org/apache/edgent/test/connectors/wsclient/javax/websocket/WebSocketClientTest.java
+++ b/connectors/websocket/src/test/java/org/apache/edgent/test/connectors/wsclient/javax/websocket/WebSocketClientTest.java
@@ -614,25 +614,6 @@ public class WebSocketClientTest extends ConnectorTestBase {
assertTrue("rcvd: "+rcvdContent.getResult(), rcvdContent.valid());
}
- private Condition<Object> newWaitTimeCondition(int seconds) {
- return new Condition<Object>() {
- private long startTime = 0;
- private long endTime = 0;
- private volatile boolean done = false;
- public boolean valid() {
- if (startTime==0) {
- startTime = System.currentTimeMillis();
- endTime = startTime + TimeUnit.SECONDS.toMillis(seconds);
- }
- long now = System.currentTimeMillis();
- done = now >= endTime;
- return done;
- }
- public Object getResult() { return done; }
- };
-
- }
-
@Test
public void testSslClientAuth() throws Exception {