Search in sources :

Example 76 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class MqttStreamsTest method testConfigParams.

@Test
public void testConfigParams() throws Exception {
    checkAssumes();
    setupDebug();
    Topology top = new Topology("testConfigParams");
    MsgGenerator mgen = new MsgGenerator(top.getName());
    String clientId = newPubClientId(top.getName());
    String topicVal = getMqttTopics()[0];
    Supplier<String> topic = new Value<String>(topicVal);
    List<Message> msgs = createMsgs(mgen, null);
    // Test more config properties to be sure we don't blow up
    Map<String, Object> config = createConfig(clientId);
    config.put("defaultQOS", 1);
    config.put("keepAliveInterval", 20);
    config.put("commandTimeoutMsec", 30000L);
    config.put("reconnectDelayMsec", 5000L);
    config.put("receiveBufferSize", 10);
    config.put("reconnectionBound", 20);
    config.put("retain", false);
    config.put("userID", System.getProperty("user.name"));
    config.put("password", "foobar");
    config.put("trustStore", "/tmp/no-such-trustStore");
    config.put("trustStorePassword", "woohoo");
    config.put("keyStore", "/tmp/no-such-keyStore");
    config.put("keyStorePassword", "woohoo");
    MqttStreams mqtt = new MqttStreams(top, config);
    Map<String, Object> pcfg = mqtt.getConfig();
    for (String s : config.keySet()) assertEquals("property " + s, config.get(s), pcfg.get(s));
    TStream<Message> msgsToPublish = top.constants(msgs).modify(new InitialDelay<Message>(PUB_DELAY_MSEC));
    TSink sink = mqtt.publish(msgsToPublish, topic);
    TStream<Message> rcvdMsgs = mqtt.subscribe(topic);
    // for validation...
    rcvdMsgs.print();
    // bundle construction fails for unrecognized or incorrectly typed SPL op params
    File actBundle = (File) StreamsContextFactory.getStreamsContext(StreamsContext.Type.BUNDLE).submit(top, getConfig()).get(15, TimeUnit.SECONDS);
    System.out.println("bundle " + actBundle.getAbsolutePath());
    assertTrue(actBundle != null);
    actBundle.delete();
    assertTrue(sink != null);
}
Also used : TSink(com.ibm.streamsx.topology.TSink) MqttStreams(com.ibm.streamsx.topology.messaging.mqtt.MqttStreams) SimpleMessage(com.ibm.streamsx.topology.tuple.SimpleMessage) Message(com.ibm.streamsx.topology.tuple.Message) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Value(com.ibm.streamsx.topology.logic.Value) JSONObject(com.ibm.json.java.JSONObject) File(java.io.File) Test(org.junit.Test)

Example 77 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class MqttStreamsTest method testMsgImplProducer.

@Test
public void testMsgImplProducer() throws Exception {
    checkAssumes();
    setupDebug();
    Topology top = new Topology("testMsgImplProducer");
    MsgGenerator mgen = new MsgGenerator(top.getName());
    String subClientId = newSubClientId(top.getName());
    String pubClientId = newPubClientId(top.getName());
    String topicVal = getMqttTopics()[0];
    Supplier<String> topic = new Value<String>(topicVal);
    List<Message> msgs = createMsgs(mgen, null);
    List<String> expectedAsString = mapList(modifyList(msgs, setTopic(topicVal)), msgToJSONStringFunc());
    // Test producer that takes TStream<SimpleMessage> and an explicit topic.
    MqttStreams producer = new MqttStreams(top, createConfig(pubClientId));
    MqttStreams consumer = new MqttStreams(top, createConfig(subClientId));
    TStream<Message> msgsToPublish = top.constants(msgs).modify(new InitialDelay<Message>(PUB_DELAY_MSEC));
    TSink sink = producer.publish(msgsToPublish, topic);
    TStream<Message> rcvdMsgs = consumer.subscribe(topic);
    // for validation...
    rcvdMsgs.print();
    // just our msgs
    rcvdMsgs = selectMsgs(rcvdMsgs, mgen.pattern());
    TStream<String> rcvdAsString = rcvdMsgs.transform(msgToJSONStringFunc());
    if (testBuildOnly(top))
        return;
    completeAndValidate(subClientId, top, rcvdAsString, SEC_TIMEOUT, expectedAsString.toArray(new String[0]));
    assertTrue(sink != null);
}
Also used : TSink(com.ibm.streamsx.topology.TSink) MqttStreams(com.ibm.streamsx.topology.messaging.mqtt.MqttStreams) SimpleMessage(com.ibm.streamsx.topology.tuple.SimpleMessage) Message(com.ibm.streamsx.topology.tuple.Message) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Value(com.ibm.streamsx.topology.logic.Value) Test(org.junit.Test)

Example 78 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class PublishSubscribeJsonPythonTest method testPublishJsonFlatMap.

/**
 * Json Subscribe feeding a flat map
 */
@Test
public void testPublishJsonFlatMap() throws Exception {
    Random r = new Random();
    final Topology t = new Topology();
    JSONObject j1 = new JSONObject();
    j1.put("a", r.nextLong());
    j1.put("b", "Hello:" + r.nextInt(200));
    JSONObject j2 = new JSONObject();
    j2.put("a", r.nextLong());
    j2.put("b", "Goodbye:" + r.nextInt(200));
    JSONObject j3 = new JSONObject();
    j3.put("a", r.nextLong());
    j3.put("b", "So long:" + r.nextInt(200));
    String s1a = j1.get("a").toString();
    String s1b = j1.get("b").toString();
    String s2a = j2.get("a").toString();
    String s2b = j2.get("b").toString();
    String s3a = j3.get("a").toString();
    String s3b = j3.get("b").toString();
    includePythonApp(t, "json_flatmap_string.py", "json_flatmap_string::json_flatmap_str");
    TStream<JSONObject> source = t.constants(Arrays.asList(j1, j2, j3));
    source = addStartupDelay(source).asType(JSONObject.class);
    source.publish("pytest/json/flatmap");
    TStream<String> subscribe = t.subscribe("pytest/json/flatmap/result", String.class);
    completeAndValidate(subscribe, 60, s1a, s1b, s2a, s2b, s3a, s3b);
}
Also used : Random(java.util.Random) JSONObject(com.ibm.json.java.JSONObject) Topology(com.ibm.streamsx.topology.Topology) Test(org.junit.Test)

Example 79 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class PublishSubscribeJsonPythonTest method testPublishJsonMap.

/**
 * Json Subscribe feeding a map
 */
@Test
public void testPublishJsonMap() throws Exception {
    Random r = new Random();
    final Topology t = new Topology();
    JSONObject j1 = new JSONObject();
    j1.put("a", r.nextLong());
    j1.put("b", "Hello:" + r.nextInt(200));
    JSONObject j2 = new JSONObject();
    j2.put("a", r.nextLong());
    j2.put("b", "Goodbye:" + r.nextInt(200));
    JSONObject j3 = new JSONObject();
    j3.put("a", r.nextLong());
    j3.put("b", "So long:" + r.nextInt(200));
    String s1 = "R" + j1.get("a") + "X" + j1.get("b") + "X" + (((Long) j1.get("a")) + 235L);
    String s2 = "R" + j2.get("a") + "X" + j2.get("b") + "X" + (((Long) j2.get("a")) + 235L);
    String s3 = "R" + j3.get("a") + "X" + j3.get("b") + "X" + (((Long) j3.get("a")) + 235L);
    includePythonApp(t, "json_map_json.py", "json_map_json::json_map_json");
    TStream<JSONObject> source = t.constants(Arrays.asList(j1, j2, j3));
    source = addStartupDelay(source).asType(JSONObject.class);
    source.publish("pytest/json/map");
    TStream<JSONObject> subscribe = t.subscribe("pytest/json/map/result", JSONObject.class);
    TStream<String> asString = subscribe.transform(j -> "R" + j.get("a") + "X" + j.get("b") + "X" + j.get("c"));
    completeAndValidate(asString, 30, s1, s2, s3);
}
Also used : Random(java.util.Random) JSONObject(com.ibm.json.java.JSONObject) Topology(com.ibm.streamsx.topology.Topology) Test(org.junit.Test)

Example 80 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class PublishSubscribeTopicNames method testWildcardHash2TopicName.

@Test(expected = IllegalArgumentException.class)
public void testWildcardHash2TopicName() throws Exception {
    final Topology t = new Topology();
    t.strings().publish("#", true);
}
Also used : Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Aggregations

Topology (com.ibm.streamsx.topology.Topology)372 TestTopology (com.ibm.streamsx.topology.test.TestTopology)315 Test (org.junit.Test)301 List (java.util.List)116 Tester (com.ibm.streamsx.topology.tester.Tester)115 ArrayList (java.util.ArrayList)70 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)68 HashMap (java.util.HashMap)49 TStream (com.ibm.streamsx.topology.TStream)42 Condition (com.ibm.streamsx.topology.tester.Condition)28 File (java.io.File)27 TimeUnit (java.util.concurrent.TimeUnit)27 StreamSchema (com.ibm.streams.operator.StreamSchema)26 Random (java.util.Random)26 JSONObject (com.ibm.json.java.JSONObject)23 HashSet (java.util.HashSet)23 RString (com.ibm.streams.operator.types.RString)21 StreamsContext (com.ibm.streamsx.topology.context.StreamsContext)21 Message (com.ibm.streamsx.topology.tuple.Message)20 SimpleMessage (com.ibm.streamsx.topology.tuple.SimpleMessage)20