use of com.ibm.streamsx.topology.tuple.Message 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);
}
use of com.ibm.streamsx.topology.tuple.Message 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);
}
use of com.ibm.streamsx.topology.tuple.Message in project streamsx.topology by IBMStreams.
the class KafkaStreamsTest method testMultiTopicProducer.
@Test
public void testMultiTopicProducer() throws Exception {
checkAssumes();
// streamsx.messaging issue#118 prevents successful execution
// For standalone it seems to consistently get 0 topic1 msgs.
assumeTrue(getTesterType() != StreamsContext.Type.STANDALONE_TESTER);
Topology top = new Topology("testMultiTopicProducer");
MsgGenerator mgen = new MsgGenerator(top.getName());
String groupId = newGroupId(top.getName());
String[] topics = getKafkaTopics();
String topic1Val = topics[0];
String topic2Val = topics[1];
Supplier<String> topic1 = new Value<String>(topic1Val);
Supplier<String> topic2 = new Value<String>(topic2Val);
KafkaProducer producer = new KafkaProducer(top, createProducerConfig());
KafkaConsumer consumer = new KafkaConsumer(top, createConsumerConfig(groupId));
// Test producer that publishes to multiple topics (implies implicit topic)
List<Message> topic1Msgs = new ArrayList<>();
topic1Msgs.add(new SimpleMessage(mgen.create(topic1Val, "Hello"), null, topic1Val));
topic1Msgs.add(new SimpleMessage(mgen.create(topic1Val, "Are you there?"), null, topic1Val));
List<Message> topic2Msgs = new ArrayList<>();
topic2Msgs.add(new SimpleMessage(mgen.create(topic2Val, "Hello"), null, topic2Val));
topic2Msgs.add(new SimpleMessage(mgen.create(topic2Val, "Are you there?"), null, topic2Val));
List<Message> msgs = new ArrayList<>(topic1Msgs);
msgs.addAll(topic2Msgs);
TStream<Message> msgsToPublish = top.constants(msgs);
msgsToPublish = msgsToPublish.modify(new InitialDelay<Message>(PUB_DELAY_MSEC));
producer.publish(msgsToPublish);
TStream<Message> rcvdTopic1Msgs = consumer.subscribe(topic1);
TStream<Message> rcvdTopic2Msgs = consumer.subscribe(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());
List<String> expectedAsString = mapList(msgs, msgToJSONStringFunc());
setupDebug();
if (testBuildOnly(top))
return;
completeAndValidateUnordered(groupId, top, rcvdAsString, SEC_TIMEOUT, expectedAsString.toArray(new String[0]));
}
use of com.ibm.streamsx.topology.tuple.Message in project streamsx.topology by IBMStreams.
the class KafkaStreamsTest method testSimpleMessage.
@Test
public void testSimpleMessage() throws Exception {
// test ctors
for (Vals vals : testMsgVals) {
SimpleMessage t = !vals.hasTopic() ? new SimpleMessage(vals.msg, vals.key) : new SimpleMessage(vals.msg, vals.key, vals.topic);
assertEquals("ctor " + vals.toString(), vals.key, t.getKey());
assertEquals("ctor " + vals.toString(), vals.msg, t.getMessage());
assertEquals("ctor " + vals.toString(), vals.topic, t.getTopic());
if (!vals.hasKey() && !vals.hasTopic()) {
t = new SimpleMessage(vals.msg);
assertEquals("ctor " + vals.toString(), vals.key, t.getKey());
assertEquals("ctor " + vals.toString(), vals.msg, t.getMessage());
assertEquals("ctor " + vals.toString(), vals.topic, t.getTopic());
}
Exception exc = null;
try {
// throw IAE
new SimpleMessage(null, "key", "topic");
} catch (Exception e) {
exc = e;
}
assertNotNull(exc);
assertTrue(exc.getClass().toString(), exc instanceof IllegalArgumentException);
}
// test equals()
for (Vals vals : testMsgVals) {
Message t = !vals.hasTopic() ? new SimpleMessage(vals.msg, vals.key) : new SimpleMessage(vals.msg, vals.key, vals.topic);
Message t2 = !vals.hasTopic() ? new SimpleMessage(vals.msg, vals.key) : new SimpleMessage(vals.msg, vals.key, vals.topic);
assertTrue("same equals() - " + t.toString(), t.equals(t));
assertTrue("equals() - " + t.toString(), t.equals(t2));
}
// test equals() negative
for (Vals vals : testMsgVals) {
Message t = !vals.hasTopic() ? new SimpleMessage(vals.msg, vals.key) : new SimpleMessage(vals.msg, vals.key, vals.topic);
Message t2 = !vals.hasTopic() ? new SimpleMessage("someOtherValue", "someOtherKey") : new SimpleMessage("someOtherValue", "someOtherKey", "someOtherTopic");
assertFalse("neg equals() - " + t.toString(), t.equals(t2));
t2 = new SimpleMessage(vals.msg, vals.key, "someOtherTopic");
assertFalse("neg equals() - " + t.toString(), t.equals(t2));
t2 = new SimpleMessage("someOtherValue", vals.key);
assertFalse("neg equals() - " + t.toString(), t.equals(t2));
t2 = new SimpleMessage(vals.msg, "someOtherKey");
assertFalse("neg equals() - " + t.toString(), t.equals(t2));
assertFalse("neg equals() - " + t.toString(), t.equals(null));
assertFalse("neg equals() - " + t.toString(), t.equals("notAMessageObject"));
}
// test hashCode()
{
SimpleMessage t = new SimpleMessage("x", "y", "z");
assertTrue(t.hashCode() != 0);
t = new SimpleMessage("x", null, null);
assertTrue(t.hashCode() != 0);
}
}
use of com.ibm.streamsx.topology.tuple.Message 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);
}
Aggregations