internalTestGetPktInRate(CounterType.DOUBLE);
}
protected void internalTestGetPktInRate(CounterType type) {
Date currentTime = new Date();
SimpleCounter newCnt = (SimpleCounter)SimpleCounter.createCounter(
currentTime, type);
newCnt.increment(currentTime, 1);
// Set the lastCounter time in the future of the current time
Date lastCounterTime = new Date(currentTime.getTime() + 1000);
flowReconcileMgr.lastPacketInCounter =
(SimpleCounter)SimpleCounter.createCounter(
lastCounterTime, type);
flowReconcileMgr.lastPacketInCounter.increment(lastCounterTime, 1);
assertEquals(FlowReconcileManager.MAX_SYSTEM_LOAD_PER_SECOND,
flowReconcileMgr.getPktInRate(newCnt, new Date()));
// Verify the rate == 0 time difference is zero.
lastCounterTime = new Date(currentTime.getTime() - 1000);
flowReconcileMgr.lastPacketInCounter.increment(lastCounterTime, 1);
assertEquals(0, flowReconcileMgr.getPktInRate(newCnt, lastCounterTime));
/** verify the computation is correct.
* new = 2000, old = 1000, Tdiff = 1 second.
* rate should be 1000/second
*/
newCnt = (SimpleCounter)SimpleCounter.createCounter(
currentTime, type);
newCnt.increment(currentTime, 2000);
lastCounterTime = new Date(currentTime.getTime() - 1000);
flowReconcileMgr.lastPacketInCounter =
(SimpleCounter)SimpleCounter.createCounter(
lastCounterTime, type);
flowReconcileMgr.lastPacketInCounter.increment(lastCounterTime, 1000);
assertEquals(1000, flowReconcileMgr.getPktInRate(newCnt, currentTime));
/** verify the computation is correct.
* new = 2,000,000, old = 1,000,000, Tdiff = 2 second.
* rate should be 1000/second
*/
newCnt = (SimpleCounter)SimpleCounter.createCounter(
currentTime, type);
newCnt.increment(currentTime, 2000000);
lastCounterTime = new Date(currentTime.getTime() - 2000);
flowReconcileMgr.lastPacketInCounter =
(SimpleCounter)SimpleCounter.createCounter(
lastCounterTime, type);