text
stringlengths
0
2.2M
Ti d_expPeakWnd;
bool d_exact;
} DATA[] = {
// LINE S_RATE S_WND P_RATE P_WND EXP_S_WND EXP_P_WND EXACT
// ---- --------- --------- -------- ---------- --------- --------- -----
{L_, 100, Ti( 1), 1000, Ti(0.001), Ti( 1), Ti(0.001), true},
{L_, 10, Ti( 0.5), 150, Ti( 0.1), Ti( 0.5), Ti( 0.1), true},
{L_, BIG_VAL, Ti(1000), MAX_RT, Ti( 50), Ti(1000), Ti( 50), true},
{L_, MAX_RT/2, Ti( 100), MAX_RT, Ti( 90), Ti( 100), Ti( 90), true},
// C-4
{L_, 5, Ti( 0.3), 1000, Ti( 0.1), Ti( 0.2), Ti( 0.1), false},
// C-5
{L_, 1, Ti( 10), 10, Ti( 1.55), Ti( 10), Ti( 1.5), false},
// C-6
{L_, 1, Ti( 0.1), 100, Ti( 0.05), Ti( 1), Ti( 0.05), false},
};
const int NUM_DATA = sizeof(DATA)/sizeof(*DATA);
Obj x(1, Ti(10), 1, Ti(10), Ti(0));
for (int ti = 0; ti < NUM_DATA; ++ti) {
const Uint64 LINE = DATA[ti].d_line;
const Uint64 S_RATE = DATA[ti].d_sustRate;
const Ti S_WND = DATA[ti].d_sustWindow;
const Uint64 P_RATE = DATA[ti].d_peakRate;
const Ti P_WND = DATA[ti].d_peakWindow;
const Ti EXP_S_WND = DATA[ti].d_expSustWnd;
const Ti EXP_P_WND = DATA[ti].d_expPeakWnd;
const bool EXACT = DATA[ti].d_exact;
// A rate/window pair can be exactly supported when their product
// is an integer number of seconds. Compute that by counting
// powers of 2 and 5 to avoid overflow.
int s2 = 0, s5 = 0, p2 = 0, p5 = 0;
for (Uint64 i = S_WND.totalNanoseconds(); i % 2 == 0; i /= 2) ++s2;
for (Uint64 i = S_WND.totalNanoseconds(); i % 5 == 0; i /= 5) ++s5;
for (Uint64 i = S_RATE; i % 2 == 0; i /= 2) ++s2;
for (Uint64 i = S_RATE; i % 5 == 0; i /= 5) ++s5;
for (Uint64 i = P_WND.totalNanoseconds(); i % 2 == 0; i /= 2) ++p2;
for (Uint64 i = P_WND.totalNanoseconds(); i % 5 == 0; i /= 5) ++p5;
for (Uint64 i = P_RATE; i % 2 == 0; i /= 2) ++p2;
for (Uint64 i = P_RATE; i % 5 == 0; i /= 5) ++p5;
LOOP_ASSERT(LINE,
EXACT == (p2 >= 9 && p5 >= 9 && s2 >= 9 && s5 >= 9));
LOOP_ASSERT(LINE, EXACT == x.supportsRateLimitsExactly(
S_RATE, S_WND, P_RATE, P_WND));
x.setRateLimits(S_RATE, S_WND, P_RATE, P_WND);
const Obj& X = x;
// C-1, C-2
LOOP_ASSERT(LINE, S_RATE == X.sustainedRateLimit());
LOOP_ASSERT(LINE, EXP_S_WND == X.sustainedRateWindow());
LOOP_ASSERT(LINE, P_RATE == X.peakRateLimit());
LOOP_ASSERT(LINE, EXP_P_WND == X.peakRateWindow());
LOOP_ASSERT(LINE, CREATION_TIME == X.lastUpdateTime());
LOOP_ASSERT(LINE,
CREATION_TIME == X.statisticsCollectionStartTime());
}
// C-3
if (verbose) cout << endl << "Negative Testing" << endl;
{
bsls::AssertTestHandlerGuard hG;
// Zero rate or zero window.
ASSERT(!x.supportsRateLimitsExactly(0, Ti(15), 10, Ti(10)));
ASSERT_FAIL( x.setRateLimits(0, Ti(15), 10, Ti(10)));
ASSERT(!x.supportsRateLimitsExactly(1, Ti( 0), 10, Ti(10)));
ASSERT_FAIL( x.setRateLimits(1, Ti( 0), 10, Ti(10)));
ASSERT(!x.supportsRateLimitsExactly(1, Ti(15), 0, Ti(10)));
ASSERT_FAIL( x.setRateLimits(1, Ti(15), 0, Ti(10)));
ASSERT(!x.supportsRateLimitsExactly(1, Ti(15), 10, Ti( 0)));
ASSERT_FAIL( x.setRateLimits(1, Ti(15), 10, Ti( 0)));
// Negative window.
ASSERT(!x.supportsRateLimitsExactly(1, Ti(-15), 10, Ti(10)));
ASSERT_FAIL( x.setRateLimits(1, Ti(-15), 10, Ti(10)));
ASSERT(!x.supportsRateLimitsExactly(1, Ti(15), 10, Ti(-10)));
ASSERT_FAIL( x.setRateLimits(1, Ti(15), 10, Ti(-10)));
}
} break;
case 5: {
// --------------------------------------------------------------------
// CLASS METHOD 'reserve', 'unitsReserved', 'submitReserved'
//
// Concerns:
//: 1 'reserve' increments 'unitsReserved'.
//:
//: 2 'unitsReserved' returns number of units currently reserved.
//:
//: 3 'submitReserved' decrements 'unitsReserved' and submits units.
//:
//: 4 'submitReserved' may submit more units, than there are actually
//: reserved.
//:
//: 5 Specifying wrong parameters to 'reserve' causes certain behavior
//: in special build configuration.