Skip to content

Commit b8b3f60

Browse files
committed
Hide toSymbols() fn from public API
Signed-off-by: James Buckland <[email protected]>
1 parent 0ded3e5 commit b8b3f60

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

include/envoy/stats/symbol_table.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class StatName {
2020
StatName() {}
2121
virtual ~StatName(){};
2222
virtual std::string toString() const PURE;
23-
virtual SymbolVec toSymbols() const PURE;
2423
};
2524

2625
using StatNamePtr = std::unique_ptr<StatName>;

source/common/stats/symbol_table_impl.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
namespace Envoy {
1818
namespace Stats {
1919

20+
class StatNameTest;
21+
2022
class SymbolTableImpl : public SymbolTable {
2123
public:
2224
StatNamePtr encode(const std::string& name) override;
@@ -44,14 +46,15 @@ class SymbolTableImpl : public SymbolTable {
4446
* StatName) must manually call free(symbol_vec) when it is freeing the stat it represents. This
4547
* way, the symbol table will grow and shrink dynamically, instead of being write-only.
4648
*
49+
* @param SymbolVec& the vector of symbols to be freed.
4750
* @return bool whether or not the total free operation was successful. Expected to be true.
4851
*/
4952
void free(const SymbolVec& symbol_vec);
5053

5154
Symbol toSymbol(const std::string& str);
5255
std::string fromSymbol(const Symbol symbol) const;
5356

54-
Symbol curr_counter_ = 0;
57+
Symbol curr_counter_{};
5558

5659
// Bimap implementation.
5760
// The encode map stores both the symbol and the ref count of that symbol.
@@ -69,9 +72,9 @@ class StatNameImpl : public StatName {
6972
: symbol_vec_(symbol_vec), symbol_table_(symbol_table) {}
7073
~StatNameImpl() override { symbol_table_->free(symbol_vec_); }
7174
std::string toString() const override { return symbol_table_->decode(symbol_vec_); }
72-
SymbolVec toSymbols() const override { return symbol_vec_; }
7375

7476
private:
77+
friend class StatNameTest;
7578
SymbolVec symbol_vec_;
7679
SymbolTableImpl* symbol_table_;
7780
};

test/common/stats/symbol_table_test.cc

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class StatNameTest : public testing::Test {
1414
public:
1515
StatNameTest() {}
1616
SymbolTableImpl table_;
17+
18+
SymbolVec getSymbols(StatNamePtr stat_name_ptr) {
19+
StatNameImpl& impl = dynamic_cast<StatNameImpl&>(*stat_name_ptr.get());
20+
return impl.symbol_vec_;
21+
}
1722
};
1823

1924
TEST_F(StatNameTest, TestArbitrarySymbolRoundtrip) {
@@ -32,9 +37,9 @@ TEST_F(StatNameTest, TestUnusualDelimitersRoundtrip) {
3237
}
3338

3439
TEST_F(StatNameTest, TestSuccessfulDoubleLookup) {
35-
auto stat_name_1 = table_.encode("foo.bar.baz");
36-
auto stat_name_2 = table_.encode("foo.bar.baz");
37-
EXPECT_EQ(stat_name_1->toSymbols(), stat_name_2->toSymbols());
40+
StatNamePtr stat_name_1 = table_.encode("foo.bar.baz");
41+
StatNamePtr stat_name_2 = table_.encode("foo.bar.baz");
42+
EXPECT_EQ(getSymbols(std::move(stat_name_1)), getSymbols(std::move(stat_name_2)));
3843
}
3944

4045
TEST_F(StatNameTest, TestSuccessfulDecode) {
@@ -48,39 +53,33 @@ TEST_F(StatNameTest, TestSuccessfulDecode) {
4853
TEST_F(StatNameTest, TestDifferentStats) {
4954
auto stat_name_1 = table_.encode("foo.bar");
5055
auto stat_name_2 = table_.encode("bar.foo");
51-
EXPECT_NE(stat_name_1->toSymbols(), stat_name_2->toSymbols());
5256
EXPECT_NE(stat_name_1->toString(), stat_name_2->toString());
57+
EXPECT_NE(getSymbols(std::move(stat_name_1)), getSymbols(std::move(stat_name_2)));
5358
}
5459

5560
TEST_F(StatNameTest, TestSymbolConsistency) {
5661
auto stat_name_1 = table_.encode("foo.bar");
5762
auto stat_name_2 = table_.encode("bar.foo");
5863
// We expect the encoding of "foo" in one context to be the same as another.
59-
EXPECT_EQ(stat_name_1->toSymbols()[0], stat_name_2->toSymbols()[1]);
60-
EXPECT_EQ(stat_name_2->toSymbols()[0], stat_name_1->toSymbols()[1]);
64+
SymbolVec vec_1 = getSymbols(std::move(stat_name_1));
65+
SymbolVec vec_2 = getSymbols(std::move(stat_name_2));
66+
EXPECT_EQ(vec_1[0], vec_2[1]);
67+
EXPECT_EQ(vec_2[0], vec_1[1]);
6168
}
6269

63-
// We also wish to test the internals of what gets called inside a SymbolTable, even though these
64-
// functions are not user-facing.
65-
class SymbolTableTest : public testing::Test {
66-
public:
67-
SymbolTableTest() {}
68-
SymbolTableImpl table_;
69-
};
70-
7170
// TODO(ambuc): Test decoding an invalid symbol vector. This will probably need a test which
7271
// implements a mock StatNameImpl, so that it can get access to .decode(), which is protected.
7372

7473
// Even though the symbol table does manual reference counting, curr_counter_ is monotonically
7574
// increasing. So encoding "foo", freeing the sole stat containing "foo", and then re-encoding
7675
// "foo" will produce a different symbol each time.
77-
TEST_F(SymbolTableTest, TestNewValueAfterFree) {
76+
TEST_F(StatNameTest, TestNewValueAfterFree) {
7877
{
7978
StatNamePtr stat_name_1 = table_.encode("foo");
80-
SymbolVec stat_name_1_symbols = stat_name_1->toSymbols();
79+
SymbolVec stat_name_1_symbols = getSymbols(std::move(stat_name_1));
8180
stat_name_1.reset();
8281
StatNamePtr stat_name_2 = table_.encode("foo");
83-
SymbolVec stat_name_2_symbols = stat_name_2->toSymbols();
82+
SymbolVec stat_name_2_symbols = getSymbols(std::move(stat_name_2));
8483
EXPECT_NE(stat_name_1_symbols, stat_name_2_symbols);
8584
}
8685

@@ -90,11 +89,11 @@ TEST_F(SymbolTableTest, TestNewValueAfterFree) {
9089
// "bar" to have a different symbol.
9190
StatNamePtr stat_foo = table_.encode("foo");
9291
StatNamePtr stat_foobar_1 = table_.encode("foo.bar");
93-
SymbolVec stat_foobar_1_symbols = stat_foobar_1->toSymbols();
92+
SymbolVec stat_foobar_1_symbols = getSymbols(std::move(stat_foobar_1));
9493
stat_foobar_1.reset();
9594

9695
StatNamePtr stat_foobar_2 = table_.encode("foo.bar");
97-
SymbolVec stat_foobar_2_symbols = stat_foobar_2->toSymbols();
96+
SymbolVec stat_foobar_2_symbols = getSymbols(std::move(stat_foobar_2));
9897

9998
EXPECT_EQ(stat_foobar_1_symbols[0],
10099
stat_foobar_2_symbols[0]); // Both "foo" components have the same symbol,
@@ -103,7 +102,7 @@ TEST_F(SymbolTableTest, TestNewValueAfterFree) {
103102
}
104103
}
105104

106-
TEST_F(SymbolTableTest, TestShrinkingExpectation) {
105+
TEST_F(StatNameTest, TestShrinkingExpectation) {
107106
// We expect that as we free stat names, the memory used to store those underlying symbols will
108107
// be freed.
109108
// ::size() is a public function, but should only be used for testing.

0 commit comments

Comments
 (0)