diff options
author | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-01-17 16:02:56 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-01-17 16:02:56 +0000 |
commit | 28a3fb6be2904d94848b3ffe51772b2ab3ed07de (patch) | |
tree | b9098d4b0ccdc3786b3448335b9b11ba20e6a742 /messagebus/src/tests | |
parent | af0de1790ddcec36d90821fa2fa15d8364ac312e (diff) |
Update C++ DynamicThrottlePolicy to match Java impl semantics
This is an attempt at making the C++ implementation 1-1 with the
Java implementation, the latter considered the source of truth for
this matter. Unit tests have been updated to match their Java
equivalents as well.
This task was approached much in the same way a novice wizard would
transcribe arcane runes that may possible blow their hands off;
carefully and with more pragmatic respect than understanding.
Diffstat (limited to 'messagebus/src/tests')
-rw-r--r-- | messagebus/src/tests/throttling/throttling.cpp | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/messagebus/src/tests/throttling/throttling.cpp b/messagebus/src/tests/throttling/throttling.cpp index 07db548be48..a601845a5fc 100644 --- a/messagebus/src/tests/throttling/throttling.cpp +++ b/messagebus/src/tests/throttling/throttling.cpp @@ -252,36 +252,39 @@ Test::testMinOne() void Test::testDynamicWindowSize() { - std::unique_ptr<DynamicTimer> ptr(new DynamicTimer()); - DynamicTimer *timer = ptr.get(); + auto ptr = std::make_unique<DynamicTimer>(); + auto* timer = ptr.get(); DynamicThrottlePolicy policy(std::move(ptr)); - policy.setWindowSizeIncrement(5); + policy.setWindowSizeIncrement(5) + .setResizeRate(1); double windowSize = getWindowSize(policy, *timer, 100); - ASSERT_TRUE(windowSize >= 90 && windowSize <= 110); + ASSERT_TRUE(windowSize >= 90 && windowSize <= 105); windowSize = getWindowSize(policy, *timer, 200); - ASSERT_TRUE(windowSize >= 90 && windowSize <= 210); + ASSERT_TRUE(windowSize >= 180 && windowSize <= 205); windowSize = getWindowSize(policy, *timer, 50); - ASSERT_TRUE(windowSize >= 9 && windowSize <= 55); + ASSERT_TRUE(windowSize >= 45 && windowSize <= 55); windowSize = getWindowSize(policy, *timer, 500); - ASSERT_TRUE(windowSize >= 90 && windowSize <= 505); + ASSERT_TRUE(windowSize >= 450 && windowSize <= 505); windowSize = getWindowSize(policy, *timer, 100); - ASSERT_TRUE(windowSize >= 90 && windowSize <= 110); + ASSERT_TRUE(windowSize >= 90 && windowSize <= 115); } void Test::testIdleTimePeriod() { - ITimer::UP ptr(new DynamicTimer()); - DynamicTimer *timer = static_cast<DynamicTimer*>(ptr.get()); + auto ptr = std::make_unique<DynamicTimer>(); + auto* timer = ptr.get(); DynamicThrottlePolicy policy(std::move(ptr)); - policy.setWindowSizeIncrement(5); + policy.setWindowSizeIncrement(5) + .setMinWindowSize(1) + .setResizeRate(1); double windowSize = getWindowSize(policy, *timer, 100); ASSERT_TRUE(windowSize >= 90 && windowSize <= 110); @@ -303,12 +306,13 @@ Test::testIdleTimePeriod() void Test::testMinWindowSize() { - ITimer::UP ptr(new DynamicTimer()); - DynamicTimer *timer = static_cast<DynamicTimer*>(ptr.get()); + auto ptr = std::make_unique<DynamicTimer>(); + auto* timer = ptr.get(); DynamicThrottlePolicy policy(std::move(ptr)); - policy.setWindowSizeIncrement(5); - policy.setMinWindowSize(150); + policy.setWindowSizeIncrement(5) + .setResizeRate(1) + .setMinWindowSize(150); double windowSize = getWindowSize(policy, *timer, 200); ASSERT_TRUE(windowSize >= 150 && windowSize <= 210); @@ -317,12 +321,13 @@ Test::testMinWindowSize() void Test::testMaxWindowSize() { - ITimer::UP ptr(new DynamicTimer()); - DynamicTimer *timer = static_cast<DynamicTimer*>(ptr.get()); + auto ptr = std::make_unique<DynamicTimer>(); + auto* timer = ptr.get(); DynamicThrottlePolicy policy(std::move(ptr)); - policy.setWindowSizeIncrement(5); - policy.setMaxWindowSize(50); + policy.setWindowSizeIncrement(5) + .setResizeRate(1) + .setMaxWindowSize(50); double windowSize = getWindowSize(policy, *timer, 100); ASSERT_TRUE(windowSize >= 40 && windowSize <= 50); @@ -338,6 +343,7 @@ Test::getWindowSize(DynamicThrottlePolicy &policy, DynamicTimer &timer, uint32_t { SimpleMessage msg("foo"); SimpleReply reply("bar"); + reply.setContext(mbus::Context(uint64_t(1))); // To offset pending size bump in static policy for (uint32_t i = 0; i < 999; ++i) { uint32_t numPending = 0; @@ -354,6 +360,6 @@ Test::getWindowSize(DynamicThrottlePolicy &policy, DynamicTimer &timer, uint32_t } } uint32_t ret = policy.getMaxPendingCount(); - printf("getWindowSize() = %d\n", ret); + fprintf(stderr, "getWindowSize() = %u\n", ret); return ret; } |