use of org.apache.storm.testing.MkTupleParam in project storm by apache.
the class KafkaBoltTest method testSimple.
@SuppressWarnings({ "unchecked", "serial" })
@Test
public void testSimple() {
final KafkaProducer<String, String> producer = mock(KafkaProducer.class);
when(producer.send(any(), any())).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Callback c = (Callback) invocation.getArguments()[1];
c.onCompletion(null, null);
return null;
}
});
KafkaBolt<String, String> bolt = new KafkaBolt<String, String>() {
@Override
protected KafkaProducer<String, String> mkProducer(Properties props) {
return producer;
}
};
bolt.withTopicSelector("MY_TOPIC");
OutputCollector collector = mock(OutputCollector.class);
TopologyContext context = mock(TopologyContext.class);
Map<String, Object> conf = new HashMap<>();
bolt.prepare(conf, context, collector);
MkTupleParam param = new MkTupleParam();
param.setFields("key", "message");
Tuple testTuple = Testing.testTuple(Arrays.asList("KEY", "VALUE"), param);
bolt.execute(testTuple);
verify(producer).send(argThat(new ArgumentMatcher<ProducerRecord<String, String>>() {
@Override
public boolean matches(Object argument) {
LOG.info("GOT {} ->", argument);
ProducerRecord<String, String> arg = (ProducerRecord<String, String>) argument;
LOG.info(" {} {} {}", arg.topic(), arg.key(), arg.value());
return "MY_TOPIC".equals(arg.topic()) && "KEY".equals(arg.key()) && "VALUE".equals(arg.value());
}
}), any(Callback.class));
verify(collector).ack(testTuple);
}
Aggregations