9 #include <gmock/gmock.h> 10 #include <gtest/gtest.h> 16 #include <unordered_set> 18 using namespace folly;
26 auto randchar = []() ->
char {
27 const char kCharset[] =
29 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 30 "abcdefghijklmnopqrstuvwxyz";
34 std::generate_n(str.begin(), length, randchar);
42 TEST(SlidingBloomReplayCacheTest, TestSimpleGetSet) {
43 const int numTries = 1 << 14;
45 std::vector<std::string> history(numTries);
46 for (
size_t i = 0;
i < numTries;
i++) {
50 for (
size_t i = 0;
i < numTries;
i++) {
56 TEST(SlidingBloomReplayCacheTest, TestSimpleTestAndSet) {
57 const int numTries = 1 << 14;
59 std::vector<std::string> history(numTries);
60 size_t falsePositives = 0;
61 for (
size_t i = 0;
i < numTries;
i++) {
68 for (
size_t i = 0;
i < numTries;
i++) {
72 double actualErrorRate =
static_cast<double>(falsePositives) / numTries;
76 TEST(SlidingBloomReplayCacheTest, TestCacheErrorRate) {
77 const int numTries = 1 << 14;
79 std::vector<std::string> history(numTries);
80 for (
size_t i = 0;
i < numTries;
i++) {
85 size_t falsePositives = 0;
86 std::unordered_set<std::string>
seen(history.begin(), history.end());
88 for (
size_t i = 0;
i < numTries;
i++) {
92 }
while (
seen.count(needle) == 1);
99 double actualErrorRate =
static_cast<double>(falsePositives) / numTries;
103 TEST(SlidingBloomReplayCacheTest, TestTimeBucketing) {
104 const int numTries = 1 << 14;
109 std::vector<std::string> history(numTries);
110 for (
size_t i = 0;
i < numTries;
i++) {
118 for (
int i = 0;
i < numTries; ++
i) {
122 evb.
now() + std::chrono::seconds(6));
127 for (
int i = 0;
i < numTries; ++
i) {
132 evb.
now() + std::chrono::seconds(13));
static std::string generateRandomString(size_t minimum, size_t maximum)
bool testAndSet(folly::ByteRange query)
bool test(folly::ByteRange query) const
—— Concurrent Priority Queue Implementation ——
void scheduleAt(Func &&fn, TimePoint const &timeout) override
std::unordered_set< std::pair< const IValidator *, const dynamic * > > seen
void set(folly::ByteRange query)
virtual TimePoint now()
Get this executor's notion of time. Must be threadsafe.
#define EXPECT_TRUE(condition)
Range< const unsigned char * > ByteRange
#define EXPECT_FALSE(condition)
#define EXPECT_LT(val1, val2)
TEST(SequencedExecutor, CPUThreadPoolExecutor)
static folly::ByteRange toRange(const std::string &str)