use of kafka.message.Message in project heron by twitter.
the class TestUtils method verifyMessage.
public static boolean verifyMessage(String key, String message, KafkaTestBroker broker, SimpleConsumer simpleConsumer) {
long lastMessageOffset = KafkaUtils.getOffset(simpleConsumer, TestUtils.TOPIC, 0, OffsetRequest.LatestTime()) - 1;
ByteBufferMessageSet messageAndOffsets = KafkaUtils.fetchMessages(TestUtils.getKafkaConfig(broker), simpleConsumer, new Partition(Broker.fromString(broker.getBrokerConnectionString()), TestUtils.TOPIC, 0), lastMessageOffset);
MessageAndOffset messageAndOffset = messageAndOffsets.iterator().next();
Message kafkaMessage = messageAndOffset.message();
ByteBuffer messageKeyBuffer = kafkaMessage.key();
String keyString = null;
String messageString = new String(Utils.toByteArray(kafkaMessage.payload()));
if (messageKeyBuffer != null) {
keyString = new String(Utils.toByteArray(messageKeyBuffer));
}
assertEquals(key, keyString);
assertEquals(message, messageString);
return true;
}
use of kafka.message.Message 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;
}
use of kafka.message.Message in project storm by apache.
the class KafkaBoltTest method verifyMessage.
private boolean verifyMessage(String key, String message) {
long lastMessageOffset = KafkaUtils.getOffset(simpleConsumer, kafkaConfig.topic, 0, OffsetRequest.LatestTime()) - 1;
ByteBufferMessageSet messageAndOffsets = KafkaUtils.fetchMessages(kafkaConfig, simpleConsumer, new Partition(Broker.fromString(broker.getBrokerConnectionString()), kafkaConfig.topic, 0), lastMessageOffset);
MessageAndOffset messageAndOffset = messageAndOffsets.iterator().next();
Message kafkaMessage = messageAndOffset.message();
ByteBuffer messageKeyBuffer = kafkaMessage.key();
String keyString = null;
String messageString = new String(Utils.toByteArray(kafkaMessage.payload()));
if (messageKeyBuffer != null) {
keyString = new String(Utils.toByteArray(messageKeyBuffer));
}
assertEquals(key, keyString);
assertEquals(message, messageString);
return true;
}
use of kafka.message.Message in project elasticsearch-river-kafka by endgameinc.
the class JsonMessageHandlerTest method testReadMessage.
public void testReadMessage() throws Exception {
JsonMessageHandler h = new JsonMessageHandler(null);
byte[] json = toJson(rec).getBytes();
Message message = createMock(Message.class);
expect(message.payload()).andReturn(ByteBuffer.wrap(json));
replay(message);
try {
h.readMessage(message);
} catch (Exception e) {
fail("This should not fail");
}
verify(message);
}
use of kafka.message.Message in project elasticsearch-river-kafka by endgameinc.
the class RawMessageHandlerTest method testIt.
public void testIt() throws Exception {
byte[] data = "somedata".getBytes();
List<String> l = new ArrayList<>();
MessageHandler m = new RawMessageHandler();
Message message = createMock(Message.class);
expect(message.payload()).andReturn(ByteBuffer.wrap(data));
BulkRequestBuilder bulkRequestBuilder = createMock(BulkRequestBuilder.class);
expect(bulkRequestBuilder.add(aryEq(data), eq(0), eq(data.length), eq(false))).andReturn(null);
replay(message, bulkRequestBuilder);
m.handle(bulkRequestBuilder, message);
verify(bulkRequestBuilder, message);
}
Aggregations