Search in sources :

Example 71 with Topology

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

the class PublishSubscribeStringPythonTest method testPublishStringFilter.

/**
 * String Subscribe feeding a filter
 */
@Test
public void testPublishStringFilter() throws Exception {
    final Topology t = new Topology();
    includePythonApp(t, "string_filter_string.py", "string_filter_string::str_filter_str");
    TStream<String> source = t.strings("ABC", "DEF", "4372", "34", "24234XXX");
    source = addStartupDelay(source);
    source.publish("pytest/string/filter");
    TStream<String> subscribe = t.subscribe("pytest/string/filter/result", String.class);
    completeAndValidate(subscribe, 30, "ABC", "DEF", "34");
}
Also used : Topology(com.ibm.streamsx.topology.Topology) Test(org.junit.Test)

Example 72 with Topology

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

the class MqttStreamsTest method testMultiPubSub.

@Test
public void testMultiPubSub() throws Exception {
    checkAssumes();
    setupDebug();
    Topology top = new Topology("testMultiPubSub");
    MsgGenerator mgen = new MsgGenerator(top.getName());
    String subClientId = newSubClientId(top.getName());
    String pubClientId = newPubClientId(top.getName());
    String[] topics = getMqttTopics();
    String topic1 = topics[0];
    String topic2 = topics[1];
    List<Message> topic1Msgs = createMsgs(mgen, topic1);
    List<Message> topic2Msgs = createMsgs(mgen, topic2);
    List<Message> msgs = new ArrayList<>(topic1Msgs);
    msgs.addAll(topic2Msgs);
    List<String> expectedAsString = mapList(msgs, msgToJSONStringFunc());
    // Multi pub / sub on a single connector
    MqttStreams producer = new MqttStreams(top, createConfig(pubClientId));
    MqttStreams consumer = new MqttStreams(top, createConfig(subClientId));
    TStream<Message> topic1MsgsToPublish = top.constants(topic1Msgs).modify(new InitialDelay<Message>(PUB_DELAY_MSEC));
    TStream<Message> topic2MsgsToPublish = top.constants(topic2Msgs).modify(new InitialDelay<Message>(PUB_DELAY_MSEC));
    TSink sink1 = producer.publish(topic1MsgsToPublish, new Value<String>(topic1));
    TSink sink2 = producer.publish(topic2MsgsToPublish, new Value<String>(topic2));
    TStream<Message> rcvdTopic1Msgs = consumer.subscribe(new Value<String>(topic1));
    TStream<Message> rcvdTopic2Msgs = consumer.subscribe(new Value<String>(topic2));
    // for validation...
    TStream<Message> rcvdMsgs = rcvdTopic1Msgs.union(rcvdTopic2Msgs);
    rcvdMsgs.print();
    // just our msgs
    rcvdMsgs = selectMsgs(rcvdMsgs, mgen.pattern());
    TStream<String> rcvdAsString = rcvdMsgs.transform(msgToJSONStringFunc());
    if (testBuildOnly(top))
        return;
    completeAndValidateUnordered(subClientId, top, rcvdAsString, SEC_TIMEOUT, expectedAsString.toArray(new String[0]));
    assertTrue(sink1 != null);
    assertTrue(sink2 != 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) ArrayList(java.util.ArrayList) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 73 with Topology

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

the class MqttStreamsTest method testExplicitTopicProducer.

@Test
public void testExplicitTopicProducer() throws Exception {
    checkAssumes();
    setupDebug();
    Topology top = new Topology("testNewExplicitTopicProducer");
    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 an explicit topic and implicit config qos
    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 74 with Topology

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

the class MqttStreamsTest method testReusableApp.

@Test
public void testReusableApp() throws Exception {
    checkAssumes();
    setupDebug();
    Topology top = new Topology("testReusableApp");
    MsgGenerator mgen = new MsgGenerator(top.getName());
    String subClientId = newSubClientId(top.getName());
    String pubClientId = newPubClientId(top.getName());
    String topic = getMqttTopics()[0];
    List<Message> msgs = createMsgs(mgen, null);
    // Test an app structured more as a "reusable asset" - i.e.,
    // where the mqtt connection info (URI, authInfo) and
    // topic are defined at submission time.
    // define/create the app's submission parameters
    ParameterHelper params = new ParameterHelper(top);
    params.definitions().put("mqtt.serverURI", String.class);
    params.definitions().put("mqtt.userID", System.getProperty("user.name"));
    params.definitions().put("mqtt.password", String.class);
    params.definitions().put("mqtt.pub.topic", String.class);
    params.definitions().put("mqtt.sub.topic", String.class);
    params.createAll();
    // add the actual param values for our call to submit()
    Map<String, Object> submitParams = new HashMap<>();
    submitParams.put("mqtt.serverURI", "tcp://localhost:1883");
    // submitParams.put("mqtt.userID", System.getProperty("user.name"));
    submitParams.put("mqtt.password", "myMosquittoPw");
    submitParams.put("mqtt.pub.topic", topic);
    submitParams.put("mqtt.sub.topic", topic);
    getConfig().put(ContextProperties.SUBMISSION_PARAMS, submitParams);
    // Produce and consume the msgs
    Map<String, Object> pconfig = createConfig(pubClientId);
    addMqttParams(pconfig, false, params);
    Map<String, Object> cconfig = createConfig(subClientId);
    addMqttParams(cconfig, true, params);
    MqttStreams producer = new MqttStreams(top, pconfig);
    MqttStreams consumer = new MqttStreams(top, cconfig);
    TStream<Message> msgsToPublish = top.constants(msgs).modify(new InitialDelay<Message>(PUB_DELAY_MSEC));
    TSink sink = producer.publish(msgsToPublish, params.getString("mqtt.pub.topic"));
    TStream<Message> rcvdMsgs = consumer.subscribe(params.getString("mqtt.sub.topic"));
    // for validation...
    rcvdMsgs.print();
    // just our msgs
    rcvdMsgs = selectMsgs(rcvdMsgs, mgen.pattern());
    TStream<String> rcvdAsString = rcvdMsgs.transform(msgToJSONStringFunc());
    msgs = modifyList(msgs, setTopic(topic));
    List<String> expectedAsString = mapList(msgs, 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) HashMap(java.util.HashMap) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) JSONObject(com.ibm.json.java.JSONObject) Test(org.junit.Test)

Example 75 with Topology

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

the class MqttStreamsTest method testSubtypeImplicitTopicProducer.

@Test
public void testSubtypeImplicitTopicProducer() throws Exception {
    checkAssumes();
    setupDebug();
    Topology top = new Topology("testSubtypeImplicitTopicProducer");
    MsgGenerator mgen = new MsgGenerator(top.getName());
    String subClientId = newSubClientId(top.getName());
    String pubClientId = newPubClientId(top.getName());
    String topic = getMqttTopics()[0];
    List<MyMsgSubtype> msgs = new ArrayList<>();
    for (Message m : createMsgs(mgen, topic)) {
        msgs.add(new MyMsgSubtype(m.getMessage(), m.getTopic()));
    }
    List<String> expectedAsString = mapList(msgs, subtypeMsgToJSONStringFunc(null));
    // Test producer that takes a TStream<MyMsgSubtype> implicit topic
    MqttStreams producer = new MqttStreams(top, createConfig(pubClientId));
    MqttStreams consumer = new MqttStreams(top, createConfig(subClientId));
    TStream<MyMsgSubtype> msgsToPublish = top.constants(msgs).asType(MyMsgSubtype.class).modify(new InitialDelay<MyMsgSubtype>(PUB_DELAY_MSEC));
    TSink sink = producer.publish(msgsToPublish);
    TStream<Message> rcvdMsgs = consumer.subscribe(new Value<String>(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) ArrayList(java.util.ArrayList) 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