Search in sources :

Example 11 with Message

use of com.ibm.streamsx.topology.tuple.Message 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 12 with Message

use of com.ibm.streamsx.topology.tuple.Message in project streamsx.topology by IBMStreams.

the class KafkaStreamsTest method testSubtypeImplicitTopicProducer.

@Test
public void testSubtypeImplicitTopicProducer() throws Exception {
    checkAssumes();
    Topology top = new Topology("testSubtypeImplicitTopicProducer");
    MsgGenerator mgen = new MsgGenerator(top.getName());
    String groupId = newGroupId(top.getName());
    String topicVal = getKafkaTopics()[0];
    Supplier<String> topic = new Value<String>(topicVal);
    KafkaProducer producer = new KafkaProducer(top, createProducerConfig());
    KafkaConsumer consumer = new KafkaConsumer(top, createConsumerConfig(groupId));
    // Test producer that takes a TStream<MyMsgSubtype> implicit topic
    List<MyMsgSubtype> msgs = new ArrayList<>();
    msgs.add(new MyMsgSubtype(mgen.create(topicVal, "Hello"), null, topicVal));
    msgs.add(new MyMsgSubtype(mgen.create(topicVal, "key1", "Are you there?"), "key1", topicVal));
    TStream<MyMsgSubtype> msgsToPublish = top.constants(msgs).asType(MyMsgSubtype.class);
    msgsToPublish = msgsToPublish.modify(new InitialDelay<MyMsgSubtype>(PUB_DELAY_MSEC));
    producer.publish(msgsToPublish);
    TStream<Message> rcvdMsgs = consumer.subscribe(topic);
    // for validation...
    rcvdMsgs.print();
    // just our msgs
    rcvdMsgs = selectMsgs(rcvdMsgs, mgen.pattern());
    TStream<String> rcvdAsString = rcvdMsgs.transform(msgToJSONStringFunc());
    List<String> expectedAsString = mapList(msgs, subtypeMsgToJSONStringFunc(null));
    setupDebug();
    if (testBuildOnly(top))
        return;
    completeAndValidate(groupId, top, rcvdAsString, SEC_TIMEOUT, expectedAsString.toArray(new String[0]));
}
Also used : KafkaProducer(com.ibm.streamsx.topology.messaging.kafka.KafkaProducer) InitialDelay(com.ibm.streamsx.topology.test.InitialDelay) SimpleMessage(com.ibm.streamsx.topology.tuple.SimpleMessage) Message(com.ibm.streamsx.topology.tuple.Message) ArrayList(java.util.ArrayList) KafkaConsumer(com.ibm.streamsx.topology.messaging.kafka.KafkaConsumer) 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 13 with Message

use of com.ibm.streamsx.topology.tuple.Message in project streamsx.topology by IBMStreams.

the class KafkaStreamsTest method testExplicitTopicProducer.

@Test
public void testExplicitTopicProducer() throws Exception {
    checkAssumes();
    Topology top = new Topology("testNewExplicitTopicProducer");
    MsgGenerator mgen = new MsgGenerator(top.getName());
    String groupId = newGroupId(top.getName());
    String topicVal = getKafkaTopics()[0];
    Supplier<String> topic = new Value<String>(topicVal);
    KafkaProducer producer = new KafkaProducer(top, createProducerConfig());
    KafkaConsumer consumer = new KafkaConsumer(top, createConsumerConfig(groupId));
    // Test producer that takes an arbitrary TStream<T> and explicit topic
    List<Vals> msgs = new ArrayList<>();
    msgs.add(new Vals(mgen.create(topicVal, "Hello"), null, null));
    msgs.add(new Vals(mgen.create(topicVal, "key1", "Are you there?"), "key1", null));
    msgs.add(new Vals(mgen.create(topicVal, "Msg with an empty key"), "", null));
    msgs.add(new Vals("", mgen.create(topicVal, null, "Msg with an empty msg (this is the key)"), null));
    TStream<Vals> valsToPublish = top.constants(msgs).asType(Vals.class);
    TStream<Message> msgsToPublish = valsToPublish.transform(msgFromValsFunc(null));
    msgsToPublish = msgsToPublish.modify(new InitialDelay<Message>(PUB_DELAY_MSEC));
    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());
    List<Message> expectedAsMessage = mapList(msgs, msgFromValsFunc(topicVal));
    expectedAsMessage = modifyList(expectedAsMessage, adjustKey());
    List<String> expectedAsString = mapList(expectedAsMessage, msgToJSONStringFunc());
    setupDebug();
    if (testBuildOnly(top))
        return;
    completeAndValidate(groupId, top, rcvdAsString, SEC_TIMEOUT, expectedAsString.toArray(new String[0]));
}
Also used : KafkaProducer(com.ibm.streamsx.topology.messaging.kafka.KafkaProducer) InitialDelay(com.ibm.streamsx.topology.test.InitialDelay) SimpleMessage(com.ibm.streamsx.topology.tuple.SimpleMessage) Message(com.ibm.streamsx.topology.tuple.Message) ArrayList(java.util.ArrayList) KafkaConsumer(com.ibm.streamsx.topology.messaging.kafka.KafkaConsumer) 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 14 with Message

use of com.ibm.streamsx.topology.tuple.Message 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)

Example 15 with Message

use of com.ibm.streamsx.topology.tuple.Message in project streamsx.topology by IBMStreams.

the class MqttStreamsTest method createMsgs.

private List<Message> createMsgs(MsgGenerator mgen, String topic) {
    List<Message> msgs = new ArrayList<>();
    msgs.add(new SimpleMessage(mgen.create(topic, "Hello"), null, topic));
    msgs.add(new SimpleMessage(mgen.create(topic, "Are you there?"), null, topic));
    return msgs;
}
Also used : SimpleMessage(com.ibm.streamsx.topology.tuple.SimpleMessage) Message(com.ibm.streamsx.topology.tuple.Message) SimpleMessage(com.ibm.streamsx.topology.tuple.SimpleMessage) ArrayList(java.util.ArrayList)

Aggregations

Message (com.ibm.streamsx.topology.tuple.Message)26 SimpleMessage (com.ibm.streamsx.topology.tuple.SimpleMessage)25 Topology (com.ibm.streamsx.topology.Topology)20 Test (org.junit.Test)19 TestTopology (com.ibm.streamsx.topology.test.TestTopology)18 Value (com.ibm.streamsx.topology.logic.Value)15 TSink (com.ibm.streamsx.topology.TSink)13 MqttStreams (com.ibm.streamsx.topology.messaging.mqtt.MqttStreams)12 ArrayList (java.util.ArrayList)12 KafkaConsumer (com.ibm.streamsx.topology.messaging.kafka.KafkaConsumer)8 KafkaProducer (com.ibm.streamsx.topology.messaging.kafka.KafkaProducer)8 InitialDelay (com.ibm.streamsx.topology.test.InitialDelay)7 HashMap (java.util.HashMap)6 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)4 JSONObject (com.ibm.json.java.JSONObject)3 File (java.io.File)2