mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2025-11-01 19:18:04 +00:00
Print offset when dumping partition object (#55)
This commit is contained in:

committed by
Matias Fontanini

parent
83a963c1db
commit
8fc6a0f02d
@@ -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
|
||||
|
@@ -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());
|
||||
}
|
||||
EXPECT_EQ("[ foo[-1:#], bar[2:#], foobar[3:4] ]", output.str());
|
||||
}
|
||||
|
Reference in New Issue
Block a user