Search in sources :

Example 6 with InitialDelay

use of com.ibm.streamsx.topology.test.InitialDelay in project streamsx.topology by IBMStreams.

the class KafkaStreamsTest method testSubtypeExplicitTopicProducer.

@Test
public void testSubtypeExplicitTopicProducer() throws Exception {
    checkAssumes();
    Topology top = new Topology("testSubtypeExplicitTopicProducer");
    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>
    List<MyMsgSubtype> msgs = new ArrayList<>();
    msgs.add(new MyMsgSubtype(mgen.create(topicVal, "Hello")));
    msgs.add(new MyMsgSubtype(mgen.create(topicVal, "key1", "Are you there?"), "key1"));
    TStream<MyMsgSubtype> msgsToPublish = top.constants(msgs).asType(MyMsgSubtype.class);
    msgsToPublish = msgsToPublish.modify(new InitialDelay<MyMsgSubtype>(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<String> expectedAsString = mapList(msgs, subtypeMsgToJSONStringFunc(topicVal));
    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 7 with InitialDelay

use of com.ibm.streamsx.topology.test.InitialDelay in project streamsx.topology by IBMStreams.

the class KafkaStreamsTest method testMsgImplProducer.

@Test
public void testMsgImplProducer() throws Exception {
    checkAssumes();
    Topology top = new Topology("testMsgImplProducer");
    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 TStream<SimpleMessage> and an explicit topic.
    List<Message> msgs = new ArrayList<>();
    msgs.add(new SimpleMessage(mgen.create(topicVal, "Hello")));
    msgs.add(new SimpleMessage(mgen.create(topicVal, "key1", "Are you there?"), "key1"));
    TStream<Message> msgsToPublish = top.constants(msgs);
    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());
    msgs = modifyList(msgs, setTopic(topicVal));
    List<String> expectedAsString = mapList(msgs, 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) SimpleMessage(com.ibm.streamsx.topology.tuple.SimpleMessage) 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)

Aggregations

Topology (com.ibm.streamsx.topology.Topology)7 KafkaConsumer (com.ibm.streamsx.topology.messaging.kafka.KafkaConsumer)7 KafkaProducer (com.ibm.streamsx.topology.messaging.kafka.KafkaProducer)7 InitialDelay (com.ibm.streamsx.topology.test.InitialDelay)7 TestTopology (com.ibm.streamsx.topology.test.TestTopology)7 Message (com.ibm.streamsx.topology.tuple.Message)7 SimpleMessage (com.ibm.streamsx.topology.tuple.SimpleMessage)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Value (com.ibm.streamsx.topology.logic.Value)6