Commit 0f00cc10 authored by Geoff Oakham's avatar Geoff Oakham Committed by Facebook GitHub Bot

TokenBucketStorage primitive extracted from BasicDynamicTokenBucket

Summary:
Extract the underlying primitive that powers BasicDynamicTokenBucket, as TokenBucketStroage. This abstraction speaks to "tokens" (instead of time) and allows for arbitrary borrowing.  It also handles thread safety.

This allows other bucket token based libraries to be created (eg. a Cooperative Scheduler) using the same primitive.

API compatibility has been maintained with the existing classes.

Reviewed By: yfeldblum, rohithmenon

Differential Revision: D29522354

fbshipit-source-id: 010bd9caf3f9c3726621e87d23e5c564773424b7
parent 7a18d182
This diff is collapsed.
...@@ -35,6 +35,20 @@ TEST(TokenBucket, ReverseTime) { ...@@ -35,6 +35,20 @@ TEST(TokenBucket, ReverseTime) {
EXPECT_EQ(tokensBefore, tokenBucket.available()); EXPECT_EQ(tokensBefore, tokenBucket.available());
} }
TEST(TokenBucketTest, CtorAssign) {
BasicDynamicTokenBucket bucketA(100.0);
EXPECT_EQ(0, bucketA.available(10, 10, 90));
BasicDynamicTokenBucket bucketB(bucketA);
EXPECT_EQ(0, bucketB.available(10, 10, 90));
bucketA.reset(0.0);
EXPECT_EQ(10, bucketA.available(10, 10, 90));
bucketB = bucketA;
EXPECT_EQ(10, bucketB.available(10, 10, 90));
}
TEST_P(TokenBucketTest, sanity) { TEST_P(TokenBucketTest, sanity) {
std::pair<double, double> params = GetParam(); std::pair<double, double> params = GetParam();
double rate = params.first; double rate = params.first;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment