Search in sources :

Example 11 with Delay

use of com.ibm.streamsx.kafka.test.utils.Delay in project streamsx.kafka by IBMStreams.

the class KafkaProducerFanOutTest method kafkaFanOutTest.

@Test
public void kafkaFanOutTest() throws Exception {
    Topology topo = getTopology();
    // create the producers (produces tuples after a short delay)
    TStream<String> stringSrcStream = topo.strings(Constants.STRING_DATA).modify(new Delay<>(5000)).lowLatency();
    SPL.invokeSink(Constants.KafkaProducerOp, KafkaSPLStreamsUtils.convertStreamToKafkaTuple(stringSrcStream), getKafkaParams());
    SPL.invokeSink(Constants.KafkaProducerOp, KafkaSPLStreamsUtils.convertStreamToKafkaTuple(stringSrcStream), getKafkaParams());
    // create the consumer
    SPLStream consumerStream = SPL.invokeSource(topo, Constants.KafkaConsumerOp, getKafkaParams(), KafkaSPLStreamsUtils.STRING_SCHEMA);
    SPLStream msgStream = SPLStreams.stringToSPLStream(consumerStream.convert(t -> t.getString("message")));
    // test the output of the consumer
    StreamsContext<?> context = StreamsContextFactory.getStreamsContext(Type.DISTRIBUTED_TESTER);
    Tester tester = topo.getTester();
    // both producers are sending the same data, so each result is duplicated
    String[] expectedArr = KafkaSPLStreamsUtils.duplicateArrayEntries(Constants.STRING_DATA, 2);
    Condition<List<String>> condition = KafkaSPLStreamsUtils.stringContentsUnordered(tester, msgStream, expectedArr);
    tester.complete(context, new HashMap<>(), condition, 30, TimeUnit.SECONDS);
    // check the results
    Assert.assertTrue(condition.getResult().size() > 0);
    Assert.assertTrue(condition.getResult().toString(), condition.valid());
}
Also used : TStream(com.ibm.streamsx.topology.TStream) Tester(com.ibm.streamsx.topology.tester.Tester) Delay(com.ibm.streamsx.kafka.test.utils.Delay) StreamsContextFactory(com.ibm.streamsx.topology.context.StreamsContextFactory) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) HashMap(java.util.HashMap) Test(org.junit.Test) KafkaSPLStreamsUtils(com.ibm.streamsx.kafka.test.utils.KafkaSPLStreamsUtils) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) StreamsContext(com.ibm.streamsx.topology.context.StreamsContext) Constants(com.ibm.streamsx.kafka.test.utils.Constants) Map(java.util.Map) SPL(com.ibm.streamsx.topology.spl.SPL) Condition(com.ibm.streamsx.topology.tester.Condition) Type(com.ibm.streamsx.topology.context.StreamsContext.Type) SPLStreams(com.ibm.streamsx.topology.spl.SPLStreams) Assert(org.junit.Assert) Tester(com.ibm.streamsx.topology.tester.Tester) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) Delay(com.ibm.streamsx.kafka.test.utils.Delay) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Test(org.junit.Test)

Aggregations

Constants (com.ibm.streamsx.kafka.test.utils.Constants)11 Delay (com.ibm.streamsx.kafka.test.utils.Delay)11 KafkaSPLStreamsUtils (com.ibm.streamsx.kafka.test.utils.KafkaSPLStreamsUtils)11 TStream (com.ibm.streamsx.topology.TStream)11 Topology (com.ibm.streamsx.topology.Topology)11 StreamsContext (com.ibm.streamsx.topology.context.StreamsContext)11 Type (com.ibm.streamsx.topology.context.StreamsContext.Type)11 StreamsContextFactory (com.ibm.streamsx.topology.context.StreamsContextFactory)11 SPL (com.ibm.streamsx.topology.spl.SPL)11 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)11 SPLStreams (com.ibm.streamsx.topology.spl.SPLStreams)11 Condition (com.ibm.streamsx.topology.tester.Condition)11 Tester (com.ibm.streamsx.topology.tester.Tester)11 HashMap (java.util.HashMap)11 List (java.util.List)11 Map (java.util.Map)11 TimeUnit (java.util.concurrent.TimeUnit)11 Assert (org.junit.Assert)11 Test (org.junit.Test)11 OutputTuple (com.ibm.streams.operator.OutputTuple)6