Skip to content

Commit 8fc6a0f

Browse files
acceleratedmfontanini
authored andcommitted
Print offset when dumping partition object (#55)
1 parent 83a963c commit 8fc6a0f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/topic_partition.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "topic_partition.h"
3434

3535
using std::string;
36+
using std::to_string;
3637
using std::ostream;
3738
using std::tie;
3839

@@ -92,7 +93,10 @@ bool TopicPartition::operator!=(const TopicPartition& rhs) const {
9293
}
9394

9495
ostream& operator<<(ostream& output, const TopicPartition& rhs) {
95-
return output << rhs.get_topic() << "[" << rhs.get_partition() << "]";
96+
return output << rhs.get_topic() << "["
97+
<< rhs.get_partition() << ":"
98+
<< (rhs.get_offset() == RD_KAFKA_OFFSET_INVALID ? "#" : to_string(rhs.get_offset()))
99+
<< "]";
96100
}
97101

98102
} // cppkafka

tests/topic_partition_list_test.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ TEST_F(TopicPartitionListTest, AsString) {
3434
ostringstream output;
3535
TopicPartition topic_partition("foo", 5);
3636
output << topic_partition;
37-
EXPECT_EQ("foo[5]", output.str());
37+
EXPECT_EQ("foo[5:#]", output.str());
3838
}
3939

4040
TEST_F(TopicPartitionListTest, ListAsString) {
4141
ostringstream output;
4242
TopicPartitionList list;
4343
list.push_back("foo");
4444
list.push_back({ "bar", 2 });
45+
list.push_back({ "foobar", 3, 4 });
4546

4647
output << list;
47-
EXPECT_EQ("[ foo[-1], bar[2] ]", output.str());
48-
}
48+
EXPECT_EQ("[ foo[-1:#], bar[2:#], foobar[3:4] ]", output.str());
49+
}

0 commit comments

Comments
 (0)