From 8fc6a0f02d92b20aff4f168686af5f63042873d1 Mon Sep 17 00:00:00 2001 From: Alex Damian Date: Mon, 23 Apr 2018 21:32:14 -0400 Subject: [PATCH] Print offset when dumping partition object (#55) --- src/topic_partition.cpp | 6 +++++- tests/topic_partition_list_test.cpp | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/topic_partition.cpp b/src/topic_partition.cpp index e6dfbfc..8ded9ee 100644 --- a/src/topic_partition.cpp +++ b/src/topic_partition.cpp @@ -33,6 +33,7 @@ #include "topic_partition.h" using std::string; +using std::to_string; using std::ostream; using std::tie; @@ -92,7 +93,10 @@ bool TopicPartition::operator!=(const TopicPartition& rhs) const { } ostream& operator<<(ostream& output, const TopicPartition& rhs) { - return output << rhs.get_topic() << "[" << rhs.get_partition() << "]"; + return output << rhs.get_topic() << "[" + << rhs.get_partition() << ":" + << (rhs.get_offset() == RD_KAFKA_OFFSET_INVALID ? "#" : to_string(rhs.get_offset())) + << "]"; } } // cppkafka diff --git a/tests/topic_partition_list_test.cpp b/tests/topic_partition_list_test.cpp index 661aaaf..ce325ff 100644 --- a/tests/topic_partition_list_test.cpp +++ b/tests/topic_partition_list_test.cpp @@ -34,7 +34,7 @@ TEST_F(TopicPartitionListTest, AsString) { ostringstream output; TopicPartition topic_partition("foo", 5); output << topic_partition; - EXPECT_EQ("foo[5]", output.str()); + EXPECT_EQ("foo[5:#]", output.str()); } TEST_F(TopicPartitionListTest, ListAsString) { @@ -42,7 +42,8 @@ TEST_F(TopicPartitionListTest, ListAsString) { TopicPartitionList list; list.push_back("foo"); list.push_back({ "bar", 2 }); + list.push_back({ "foobar", 3, 4 }); output << list; - EXPECT_EQ("[ foo[-1], bar[2] ]", output.str()); -} \ No newline at end of file + EXPECT_EQ("[ foo[-1:#], bar[2:#], foobar[3:4] ]", output.str()); +}