MessageUtils.makeMessageBuffer(msgId,
new PutCommand(topic, partition.getPartition(), "hello".getBytes(), null, 0, 0)).array();
final FetchRequest request =
new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset), maxSize);
final FetchRequestRunner runner = this.fetchManager.new FetchRequestRunner();
EasyMock.expect(this.consumer.fetch(request, -1, null)).andReturn(new MessageIterator(topic, data));
final AtomicReference<Message> msg = new AtomicReference<Message>();
EasyMock.expect(this.consumer.getMessageListener(topic)).andReturn(new MessageListener() {
@Override
public void recieveMessages(final Message message) {
msg.set(message);
}
@Override
public Executor getExecutor() {
return null;
}
});
EasyMock.expect(this.consumer.getMessageFilter(topic)).andReturn(new ConsumerMessageFilter() {
@Override
public boolean accept(String group, Message message) {
return true;
}
});
EasyMock.expect(this.consumer.getConsumerConfig()).andReturn(new ConsumerConfig("test"));
final FetchRequest newRequest =
new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset + data.length, msgId),
maxSize);
EasyMock.replay(this.consumer);
runner.processRequest(request);
EasyMock.verify(this.consumer);
assertEquals("hello", new String(msg.get().getData()));
assertEquals(msgId, msg.get().getId());
assertEquals(topic, msg.get().getTopic());
assertEquals(newRequest, this.fetchManager.takeFetchRequest());