use of org.apache.kafka.clients.producer.MockProducer in project storm by apache.
the class KafkaBoltTest method testSimple.
@Test
public void testSimple() {
MockProducer<String, String> producer = new MockProducer<>(Cluster.empty(), false, null, null, null);
KafkaBolt<String, String> bolt = makeBolt(producer);
OutputCollector collector = mock(OutputCollector.class);
TopologyContext context = mock(TopologyContext.class);
Map<String, Object> conf = new HashMap<>();
bolt.prepare(conf, context, collector);
String key = "KEY";
String value = "VALUE";
Tuple testTuple = createTestTuple(key, value);
bolt.execute(testTuple);
assertThat(producer.history().size(), is(1));
ProducerRecord<String, String> arg = producer.history().get(0);
LOG.info("GOT {} ->", arg);
LOG.info("{}, {}, {}", arg.topic(), arg.key(), arg.value());
assertThat(arg.topic(), is("MY_TOPIC"));
assertThat(arg.key(), is(key));
assertThat(arg.value(), is(value));
// Complete the send
producer.completeNext();
verify(collector).ack(testTuple);
}
use of org.apache.kafka.clients.producer.MockProducer in project kafka by apache.
the class MockClientSupplier method getProducer.
@Override
public Producer<byte[], byte[]> getProducer(final Map<String, Object> config) {
if (applicationId != null) {
assertThat((String) config.get(ProducerConfig.TRANSACTIONAL_ID_CONFIG), startsWith(applicationId + "-"));
} else {
assertFalse(config.containsKey(ProducerConfig.TRANSACTIONAL_ID_CONFIG));
}
final MockProducer<byte[], byte[]> producer = new MockProducer<>(cluster, true, new DefaultPartitioner(), BYTE_ARRAY_SERIALIZER, BYTE_ARRAY_SERIALIZER);
producers.add(producer);
return producer;
}
Aggregations