proxygen
BufferedStatTest.cpp File Reference

Go to the source code of this file.

Classes

struct  MockClock
 
class  SimpleDigest< MergeSize >
 
class  BufferedDigestTest
 
class  BufferedSlidingWindowTest
 

Functions

 TEST_F (BufferedDigestTest, Buffering)
 
 TEST_F (BufferedDigestTest, PartiallyPassedExpiry)
 
 TEST_F (BufferedDigestTest, ForceUpdate)
 
 TEST_F (BufferedSlidingWindowTest, Buffering)
 
 TEST_F (BufferedSlidingWindowTest, PartiallyPassedExpiry)
 
 TEST_F (BufferedSlidingWindowTest, ForceUpdate)
 
 TEST_F (BufferedSlidingWindowTest, BufferingAfterSlide)
 
 TEST_F (BufferedSlidingWindowTest, TwoSlides)
 
 TEST_F (BufferedSlidingWindowTest, MultiWindowDurationSlide)
 
 TEST_F (BufferedSlidingWindowTest, SlidePastWindow)
 

Variables

const size_t kDigestSize = 100
 

Function Documentation

TEST_F ( BufferedDigestTest  ,
Buffering   
)

Definition at line 93 of file BufferedStatTest.cpp.

References EXPECT_TRUE.

93  {
94  bd->append(0);
95  bd->append(1);
96  bd->append(2);
97 
98  auto digest = bd->get();
99  EXPECT_TRUE(digest.empty());
100 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
TEST_F ( BufferedDigestTest  ,
PartiallyPassedExpiry   
)

Definition at line 102 of file BufferedStatTest.cpp.

References EXPECT_EQ, MockClock::Now, and values().

102  {
103  bd->append(0);
104  bd->append(1);
105  bd->append(2);
106 
107  MockClock::Now += bufferDuration / 10;
108 
109  auto digest = bd->get();
110 
111  auto values = digest.getValues();
112  EXPECT_EQ(0, values[0]);
113  EXPECT_EQ(1, values[1]);
114  EXPECT_EQ(2, values[2]);
115 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static time_point Now
std::vector< int > values(1'000)
TEST_F ( BufferedDigestTest  ,
ForceUpdate   
)

Definition at line 117 of file BufferedStatTest.cpp.

References EXPECT_EQ, EXPECT_TRUE, MockClock::Now, and values().

117  {
118  bd->append(0);
119  bd->append(1);
120  bd->append(2);
121 
122  // empty since we haven't passed expiry
123  auto digest = bd->get();
124  EXPECT_TRUE(digest.empty());
125 
126  // force update
127  bd->flush();
128  digest = bd->get();
129  auto values = digest.getValues();
130  EXPECT_EQ(0, values[0]);
131  EXPECT_EQ(1, values[1]);
132  EXPECT_EQ(2, values[2]);
133 
134  // append 3 and do a normal get; only the previously
135  // flushed values should show up and not 3 since we
136  // haven't passed expiry
137  bd->append(3);
138  digest = bd->get();
139  values = digest.getValues();
140  EXPECT_EQ(0, values[0]);
141  EXPECT_EQ(1, values[1]);
142  EXPECT_EQ(2, values[2]);
143 
144  // pass expiry; 3 should now be visible
145  MockClock::Now += bufferDuration;
146  digest = bd->get();
147  values = digest.getValues();
148  EXPECT_EQ(0, values[0]);
149  EXPECT_EQ(1, values[1]);
150  EXPECT_EQ(2, values[2]);
151  EXPECT_EQ(3, values[3]);
152 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static time_point Now
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::vector< int > values(1'000)
TEST_F ( BufferedSlidingWindowTest  ,
Buffering   
)

Definition at line 168 of file BufferedStatTest.cpp.

References EXPECT_EQ.

168  {
169  bsw->append(0);
170  bsw->append(1);
171  bsw->append(2);
172 
173  auto digests = bsw->get();
174  EXPECT_EQ(0, digests.size());
175 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST_F ( BufferedSlidingWindowTest  ,
PartiallyPassedExpiry   
)

Definition at line 177 of file BufferedStatTest.cpp.

References EXPECT_EQ, i, MockClock::Now, and folly::size().

177  {
178  bsw->append(0);
179  bsw->append(1);
180  bsw->append(2);
181 
182  MockClock::Now += windowDuration / 10;
183 
184  auto digests = bsw->get();
185 
186  EXPECT_EQ(1, digests.size());
187  EXPECT_EQ(3, digests[0].getValues().size());
188 
189  for (double i = 0; i < 3; ++i) {
190  EXPECT_EQ(i, digests[0].getValues()[i]);
191  }
192 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static time_point Now
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
TEST_F ( BufferedSlidingWindowTest  ,
ForceUpdate   
)

Definition at line 194 of file BufferedStatTest.cpp.

References EXPECT_EQ, i, MockClock::Now, and folly::size().

194  {
195  bsw->append(0);
196  bsw->append(1);
197  bsw->append(2);
198 
199  // empty since we haven't passed expiry
200  auto digests = bsw->get();
201  EXPECT_EQ(0, digests.size());
202 
203  // flush
204  bsw->flush();
205  digests = bsw->get();
206  EXPECT_EQ(1, digests.size());
207  EXPECT_EQ(3, digests[0].getValues().size());
208  for (double i = 0; i < 3; ++i) {
209  EXPECT_EQ(i, digests[0].getValues()[i]);
210  }
211 
212  // append 3 and flush again; 3 will be merged with
213  // current window
214  bsw->append(3);
215  bsw->flush();
216  digests = bsw->get();
217  EXPECT_EQ(1, digests.size());
218  EXPECT_EQ(4, digests[0].getValues().size());
219  for (double i = 0; i < 4; ++i) {
220  EXPECT_EQ(i, digests[0].getValues()[i]);
221  }
222 
223  // append 4 and do a regular get. previous values
224  // show up but not 4
225  bsw->append(4);
226  digests = bsw->get();
227  EXPECT_EQ(1, digests.size());
228  EXPECT_EQ(4, digests[0].getValues().size());
229  for (double i = 0; i < 4; ++i) {
230  EXPECT_EQ(i, digests[0].getValues()[i]);
231  }
232 
233  // pass expiry
234  MockClock::Now += windowDuration;
235  digests = bsw->get();
236  EXPECT_EQ(2, digests.size());
237 
238  EXPECT_EQ(1, digests[0].getValues().size());
239  EXPECT_EQ(4, digests[0].getValues().front());
240 
241  EXPECT_EQ(4, digests[1].getValues().size());
242  for (double i = 0; i < 4; ++i) {
243  EXPECT_EQ(i, digests[1].getValues()[i]);
244  }
245 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static time_point Now
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
TEST_F ( BufferedSlidingWindowTest  ,
BufferingAfterSlide   
)

Definition at line 247 of file BufferedStatTest.cpp.

References EXPECT_EQ, and MockClock::Now.

247  {
248  MockClock::Now += std::chrono::milliseconds{1};
249 
250  bsw->append(1);
251 
252  auto digests = bsw->get();
253  EXPECT_EQ(0, digests.size());
254 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static time_point Now
TEST_F ( BufferedSlidingWindowTest  ,
TwoSlides   
)

Definition at line 256 of file BufferedStatTest.cpp.

References EXPECT_EQ, MockClock::Now, and folly::size().

256  {
257  bsw->append(0);
258 
259  MockClock::Now += windowDuration;
260 
261  bsw->append(1);
262 
263  MockClock::Now += windowDuration;
264 
265  auto digests = bsw->get();
266 
267  EXPECT_EQ(2, digests.size());
268  EXPECT_EQ(1, digests[0].getValues().size());
269  EXPECT_EQ(1, digests[0].getValues()[0]);
270  EXPECT_EQ(1, digests[1].getValues().size());
271  EXPECT_EQ(0, digests[1].getValues()[0]);
272 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static time_point Now
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
TEST_F ( BufferedSlidingWindowTest  ,
MultiWindowDurationSlide   
)

Definition at line 274 of file BufferedStatTest.cpp.

References EXPECT_EQ, and MockClock::Now.

274  {
275  bsw->append(0);
276 
277  MockClock::Now += windowDuration * 2;
278 
279  auto digests = bsw->get();
280  EXPECT_EQ(1, digests.size());
281 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static time_point Now
TEST_F ( BufferedSlidingWindowTest  ,
SlidePastWindow   
)

Definition at line 283 of file BufferedStatTest.cpp.

References EXPECT_EQ, and MockClock::Now.

283  {
284  bsw->append(0);
285 
286  MockClock::Now += windowDuration * (nBuckets + 1);
287 
288  auto digests = bsw->get();
289 
290  EXPECT_EQ(0, digests.size());
291 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static time_point Now

Variable Documentation

const size_t kDigestSize = 100