text
stringlengths
0
2.2M
if (verbose) cout << endl << "Negative Testing" << endl;
{
bsls::AssertTestHandlerGuard hG;
// Units reserved, trying to submit & reserve.
Obj y1(100, Ti(10), 1000, Ti(1), Ti(0));
// C-5
y1.reserve(ULLONG_MAX);
ASSERT_SAFE_FAIL(y1.submit(1));
ASSERT_SAFE_FAIL(y1.reserve(1));
Obj y2(100, Ti(10), 1000, Ti(1), Ti(0));
y2.reserve(ULLONG_MAX/2);
ASSERT_SAFE_FAIL(y2.submit((ULLONG_MAX>>2)*3));
ASSERT_SAFE_FAIL(y2.reserve((ULLONG_MAX>>2)*3));
// C-6
Obj y3(100, Ti(10), 1000, Ti(1), Ti(0));
y3.submit(1);
y3.reserve(1);
ASSERT_FAIL(y3.submitReserved(ULLONG_MAX));
ASSERT_FAIL(y3.submitReserved(ULLONG_MAX/2+1));
}
} break;
case 4: {
// --------------------------------------------------------------------
// 'submit', 'wouldExceedBandwidth', 'calculateTimeToSubmit'
//
// Concerns:
//: 1 'wouldExceedBandwidth' has the same behavior, when compared to
//: the pair of 'balb::LeakyBucket' objects.
//:
//: 2 Specifying wrong parameters to 'submit' causes certain behavior
//: in special build configuration.
//
// Testing:
// void submit(unsigned int numOfUnits);
// bool wouldExceedBandwidth(bsls::TimeInterval currentTime);
// --------------------------------------------------------------------
if (verbose)
cout << endl
<< "'submit', 'wouldExceedBandwidth', calculateTimeToSubmit'"
<< endl
<< "========================================================"
<< endl;
struct {
int d_line;
Uint64 d_sustRate;
Ti d_sustWindow;
Uint64 d_peakRate;
Ti d_peakWindow;
Ti d_creationTime;
Uint64 d_nSubmits;
Uint64 d_units;
Ti d_submitInterval;
} DATA[] = {
// LINE S_RATE S_WND P_RATE P_WND TCREATE NSUBMITS UNITS INTERVAL
// ---- ------- ------- ------- --------- -------- -------- ------ --------
{L_, 100, Ti(10), 1000, Ti( 1), Ti(0), 500, 10, Ti( 0.1)},
{L_, 100, Ti(10), 1000, Ti( 1), Ti(0), 50, 100, Ti( 0.1)},
{L_, 100, Ti(10), 1000, Ti(0.5), Ti(0), 10, 100, Ti( 1)},
{L_, 100, Ti(10), 1000, Ti(0.1), Ti(0), 10, 100, Ti(0.01)}
};
const int NUM_DATA = sizeof(DATA)/sizeof(*DATA);
if (verbose) cout << endl << "Testing: 'wouldExceedBandwidth'"
<< endl;
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 CREATION_TIME = DATA[ti].d_creationTime;
const Uint64 N_SUBMITS = DATA[ti].d_nSubmits;
const Uint64 UNITS = DATA[ti].d_units;
const Ti SUBMIT_INTERVAL = DATA[ti].d_submitInterval;
const Uint64 S_CAP = balb::LeakyBucket::calculateCapacity(S_RATE,
S_WND);
const Uint64 P_CAP = balb::LeakyBucket::calculateCapacity(P_RATE,
P_WND);
balb::LeakyBucket peakLB(P_RATE, P_CAP, CREATION_TIME);
balb::LeakyBucket sustLB(S_RATE, S_CAP, CREATION_TIME);