16 #include <gtest/gtest.h>
25 TEST(MemTestTest, SingleTrackerNoLimit) {
37 TEST(MemTestTest, SingleTrackerWithLimit) {
51 TEST(MemTestTest, ConsumptionMetric) {
52 UIntGauge metric(
"test", TUnit::BYTES, 0);
53 EXPECT_EQ(metric.value(), 0);
56 EXPECT_TRUE(t.has_limit());
57 EXPECT_EQ(t.consumption(), 0);
61 EXPECT_EQ(t.consumption(), 0);
62 EXPECT_EQ(t.peak_consumption(), 0);
63 EXPECT_FALSE(t.LimitExceeded());
65 EXPECT_EQ(t.consumption(), 0);
66 EXPECT_EQ(t.peak_consumption(), 0);
67 EXPECT_FALSE(t.LimitExceeded());
73 EXPECT_EQ(t.consumption(), 10);
74 EXPECT_EQ(t.peak_consumption(), 10);
77 EXPECT_EQ(t.consumption(), 5);
78 EXPECT_EQ(t.peak_consumption(), 10);
79 EXPECT_FALSE(t.LimitExceeded());
80 metric.Increment(150);
82 EXPECT_EQ(t.consumption(), 155);
83 EXPECT_EQ(t.peak_consumption(), 155);
84 EXPECT_TRUE(t.LimitExceeded());
85 metric.Increment(-150);
87 EXPECT_EQ(t.consumption(), 5);
88 EXPECT_EQ(t.peak_consumption(), 155);
89 EXPECT_FALSE(t.LimitExceeded());
92 TEST(MemTestTest, TrackerHierarchy) {
145 TEST(MemTestTest, GcFunctions) {
194 int main(
int argc,
char **argv) {
195 ::testing::InitGoogleTest(&argc, argv);
196 return RUN_ALL_TESTS();
GcFunctionHelper(MemTracker *tracker)
int64_t consumption() const
Returns the memory consumed in bytes.
bool TryConsume(int64_t bytes)
void AddGcFunction(GcFunction f)
static const int NUM_RELEASE_BYTES
This class is thread-safe.
void Release(int64_t bytes)
Decreases consumption of this tracker and its ancestors by 'bytes'.
void Consume(int64_t bytes)
Increases consumption of this tracker and its ancestors by 'bytes'.
int main(int argc, char **argv)