Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/protocol/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,9 @@ function decodeOffsetResponse (resp) {
function decodeOffsets (end, vars) {
if (--vars.offsetNum <= 0) end();
topics[vars.topic][vars.partition] = topics[vars.topic][vars.partition] || [];
if (vars.offsetNum < 0) {
return;
}
this.word64bs('offset').tap(function (vars) {
if (vars.offset != null) topics[vars.topic][vars.partition].push(vars.offset);
});
Expand Down
16 changes: 15 additions & 1 deletion test/test.offset.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Offset', function () {
client = new Client();
producer = new Producer(client);
producer.on('ready', function () {
producer.createTopics(['_exist_topic_3_test'], true, function (err) {
producer.createTopics(['_exist_topic_3_test', '_exist_topic_4_test'], true, function (err) {
done(err);
});
});
Expand All @@ -38,6 +38,20 @@ describe('Offset', function () {
});
});

it('should return empty offsets list by old timestamp', function (done) {
var firstTopic = '_exist_topic_3_test';
var secondTopic = '_exist_topic_4_test';
var fakeTime = new Date('2019-05-16').getTime();
var topics = [{ topic: firstTopic, time: fakeTime }, { topic: secondTopic, time: fakeTime }];
offset.fetch(topics, function (err, data) {
var firstOffsets = data[firstTopic][0];
var secondOffsets = data[secondTopic][0];
firstOffsets.should.be.an.instanceOf(Array);
secondOffsets.should.be.an.instanceOf(Array);
done(err);
});
});

it('should return earliest offset of the topics', function (done) {
var topic = '_exist_topic_3_test';
var topics = [{ topic: topic, time: -2 }];
Expand Down