use of kafka.javaapi.message.ByteBufferMessageSet in project storm by apache.
the class KafkaUtilsTest method generateTuplesWithValueAndStringMultiSchemeWithTopic.
@Test
public void generateTuplesWithValueAndStringMultiSchemeWithTopic() {
config.scheme = new StringMultiSchemeWithTopic();
String value = "value";
createTopicAndSendMessage(value);
ByteBufferMessageSet messageAndOffsets = getLastMessage();
for (MessageAndOffset msg : messageAndOffsets) {
Iterable<List<Object>> lists = KafkaUtils.generateTuples(config, msg.message(), config.topic);
List<Object> list = lists.iterator().next();
assertEquals(value, list.get(0));
assertEquals(config.topic, list.get(1));
}
}
use of kafka.javaapi.message.ByteBufferMessageSet in project storm by apache.
the class KafkaUtilsTest method generateTuplesWithValueSchemeAndKeyValueMessage.
@Test
public void generateTuplesWithValueSchemeAndKeyValueMessage() {
config.scheme = new SchemeAsMultiScheme(new StringScheme());
String value = "value";
String key = "key";
createTopicAndSendMessage(key, value);
ByteBufferMessageSet messageAndOffsets = getLastMessage();
for (MessageAndOffset msg : messageAndOffsets) {
Iterable<List<Object>> lists = KafkaUtils.generateTuples(config, msg.message(), config.topic);
assertEquals(value, lists.iterator().next().get(0));
}
}
use of kafka.javaapi.message.ByteBufferMessageSet in project storm by apache.
the class KafkaUtilsTest method generateTuplesWithMessageAndMetadataScheme.
@Test
public void generateTuplesWithMessageAndMetadataScheme() {
String value = "value";
Partition mockPartition = Mockito.mock(Partition.class);
mockPartition.partition = 0;
long offset = 0L;
MessageMetadataSchemeAsMultiScheme scheme = new MessageMetadataSchemeAsMultiScheme(new StringMessageAndMetadataScheme());
createTopicAndSendMessage(null, value);
ByteBufferMessageSet messageAndOffsets = getLastMessage();
for (MessageAndOffset msg : messageAndOffsets) {
Iterable<List<Object>> lists = KafkaUtils.generateTuples(scheme, msg.message(), mockPartition, offset);
List<Object> values = lists.iterator().next();
assertEquals("Message is incorrect", value, values.get(0));
assertEquals("Partition is incorrect", mockPartition.partition, values.get(1));
assertEquals("Offset is incorrect", offset, values.get(2));
}
}
use of kafka.javaapi.message.ByteBufferMessageSet in project storm by apache.
the class KafkaUtilsTest method runGetValueOnlyTuplesTest.
private void runGetValueOnlyTuplesTest() {
String value = "value";
createTopicAndSendMessage(null, value);
ByteBufferMessageSet messageAndOffsets = getLastMessage();
for (MessageAndOffset msg : messageAndOffsets) {
Iterable<List<Object>> lists = KafkaUtils.generateTuples(config, msg.message(), config.topic);
assertEquals(value, lists.iterator().next().get(0));
}
}
use of kafka.javaapi.message.ByteBufferMessageSet in project storm by apache.
the class KafkaBoltTest method mockSingleMessage.
private static ByteBufferMessageSet mockSingleMessage(byte[] key, byte[] message) {
ByteBufferMessageSet sets = mock(ByteBufferMessageSet.class);
MessageAndOffset msg = mock(MessageAndOffset.class);
final List<MessageAndOffset> msgs = ImmutableList.of(msg);
doReturn(msgs.iterator()).when(sets).iterator();
Message kafkaMessage = mock(Message.class);
doReturn(ByteBuffer.wrap(key)).when(kafkaMessage).key();
doReturn(ByteBuffer.wrap(message)).when(kafkaMessage).payload();
doReturn(kafkaMessage).when(msg).message();
return sets;
}
Aggregations