* Create rate limiter using factory function in the test.

* Convert function local statics in option helper to a C array
  that does not perform dynamic memory allocation. This is helpful
  when you try to memory isolate different DB instances.
main
Dmitri Smirnov 8 years ago committed by Islam AbdelRahman
parent 2a2ebb6f5e
commit 3981345be1
  1. 27
      util/options_helper.cc
  2. 4
      util/rate_limiter_test.cc

@ -34,23 +34,34 @@ bool isSpecialChar(const char c) {
return false;
}
namespace {
using
CharMap = std::pair<char, char>;
}
char UnescapeChar(const char c) {
static const std::unordered_map<char, char> convert_map = {{'r', '\r'},
{'n', '\n'}};
static const CharMap convert_map[] = {{'r', '\r'},
{'n', '\n'}};
auto iter = convert_map.find(c);
if (iter == convert_map.end()) {
auto iter = std::find_if(std::begin(convert_map),
std::end(convert_map),
[c](const CharMap& p) { return p.first == c; });
if (iter == std::end(convert_map)) {
return c;
}
return iter->second;
}
char EscapeChar(const char c) {
static const std::unordered_map<char, char> convert_map = {{'\n', 'n'},
{'\r', 'r'}};
static const CharMap convert_map[] = {{'\n', 'n'},
{'\r', 'r'}};
auto iter = std::find_if(std::begin(convert_map),
std::end(convert_map),
[c](const CharMap& p) { return p.first == c; });
auto iter = convert_map.find(c);
if (iter == convert_map.end()) {
if (iter == std::end(convert_map)) {
return c;
}
return iter->second;

@ -29,14 +29,14 @@ TEST_F(RateLimiterTest, OverflowRate) {
}
TEST_F(RateLimiterTest, StartStop) {
std::unique_ptr<RateLimiter> limiter(new GenericRateLimiter(100, 100, 10));
std::unique_ptr<RateLimiter> limiter(NewGenericRateLimiter(100, 100, 10));
}
TEST_F(RateLimiterTest, Rate) {
auto* env = Env::Default();
struct Arg {
Arg(int32_t _target_rate, int _burst)
: limiter(new GenericRateLimiter(_target_rate, 100 * 1000, 10)),
: limiter(NewGenericRateLimiter(_target_rate, 100 * 1000, 10)),
request_size(_target_rate / 10),
burst(_burst) {}
std::unique_ptr<RateLimiter> limiter;

Loading…
Cancel
Save