// 2 events/sec, with duration for 1 sec
RateControl rc = new RateControl(4,5);
Assert.assertEquals(true, rc.isEnabled());
long curTime = 0L;
MockRateMonitor mrm = new MockRateMonitor("mock");
mrm.setNanoTime(curTime);
mrm.start();
Field field = rc.getClass().getDeclaredField("_ra");
field.setAccessible(true);
field.set(rc, mrm);
// Current time = 10ns. No event is in so far.
curTime = 10L;
mrm.setNanoTime(curTime);
Assert.assertEquals(false, rc.checkExpired());
Assert.assertEquals(false, rc.checkRateExceeded());
// Event #1. Accept the event, but sleep until 0.25secs
long tc = rc.incrementEventCount();
Assert.assertEquals(tc, 1);
Assert.assertEquals(false, rc.checkExpired());
Assert.assertEquals(false, rc.checkRateExceeded());
// Set Current time as ( 0.5s - 10ns ). Rate has been met
curTime = (DbusConstants.NUM_NSECS_IN_SEC/2) - 10L;
mrm.setNanoTime(curTime);
Assert.assertEquals(false, rc.checkExpired());
Assert.assertEquals(false, rc.checkRateExceeded());
tc = rc.incrementEventCount();
Assert.assertEquals(tc, 2);
// Set Current time as ( 0.5s ). Rate has been met
curTime = (DbusConstants.NUM_NSECS_IN_SEC/2);
mrm.setNanoTime(curTime);
Assert.assertEquals(false, rc.checkExpired());
Assert.assertEquals(false, rc.checkRateExceeded());
// Rate has fallen below accepted threshold
curTime = (DbusConstants.NUM_NSECS_IN_SEC/2) + 10L;
mrm.setNanoTime(curTime);
Assert.assertEquals(false, rc.checkExpired());
Assert.assertEquals(false, rc.checkRateExceeded());
// Event #3
tc = rc.incrementEventCount();