use of com.ibm.streamsx.topology.tester.Tester 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());
}
use of com.ibm.streamsx.topology.tester.Tester in project streamsx.kafka by IBMStreams.
the class KafkaProducerPartitionAttrTest method kafkaProducerPartitionAttrTest.
@Test
public void kafkaProducerPartitionAttrTest() throws Exception {
Topology topo = getTopology();
topo.addFileDependency("etc/custom_partitioner.properties", "etc");
topo.addFileDependency("etc/custompartitioner.jar", "etc");
// create producer
TStream<Message<Integer, String>> src = topo.limitedSource(new MySupplier(), 9).modify(new Delay<>(Constants.PRODUCER_DELAY));
SPLStream outStream = SPLStreams.convertStream(src, new MessageConverter(), PRODUCER_SCHEMA);
SPL.invokeSink(Constants.KafkaProducerOp, outStream, getKafkaProducerParams());
// create the consumers
SPLStream msgStream1 = createConsumer(topo, PARTITION_NUM);
TStream<String> unionStream = msgStream1.transform(t -> t.getString("message"));
SPLStream msgStream = SPLStreams.stringToSPLStream(unionStream);
StreamsContext<?> context = StreamsContextFactory.getStreamsContext(Type.DISTRIBUTED_TESTER);
Tester tester = topo.getTester();
String[] expectedArr = { "A0", "B1", "C2", "A3", "B4", "C5", "A6", "B7", "C8" };
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());
}
Aggregations