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