use of com.ibm.streamsx.topology.messaging.mqtt.MqttStreams in project streamsx.topology by IBMStreams.
the class MqttStreamsTest method testSubtypeExplicitTopicProducer.
@Test
public void testSubtypeExplicitTopicProducer() throws Exception {
checkAssumes();
setupDebug();
Topology top = new Topology("testSubtypeExplicitTopicProducer");
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<MyMsgSubtype> msgs = new ArrayList<>();
for (Message m : createMsgs(mgen, null)) {
msgs.add(new MyMsgSubtype(m.getMessage()));
}
List<String> expectedAsString = mapList(msgs, subtypeMsgToJSONStringFunc(topicVal));
// Test producer that takes a TStream<MyMsgSubtype>
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, 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);
}
use of com.ibm.streamsx.topology.messaging.mqtt.MqttStreams in project streamsx.topology by IBMStreams.
the class MqttStreamsTest method testMultiTopicProducer.
@Test
public void testMultiTopicProducer() throws Exception {
checkAssumes();
setupDebug();
Topology top = new Topology("testMultiTopicProducer");
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());
// Test producer that publishes to multiple topics (implies implicit 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);
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(sink != null);
}
use of com.ibm.streamsx.topology.messaging.mqtt.MqttStreams in project streamsx.topology by IBMStreams.
the class MqttStreamsTest method testImplicitTopicProducer.
@Test
public void testImplicitTopicProducer() throws Exception {
checkAssumes();
setupDebug();
Topology top = new Topology("testImplicitTopicProducer");
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, topic);
List<String> expectedAsString = mapList(msgs, msgToJSONStringFunc());
// Test producer that takes an arbitrary TStream<T> and implicit 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);
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);
}
Aggregations