@Test
public void testIncrementEventCount() throws Exception
{

  RateControl rc = new RateControl(2,1);
  MockRateMonitor mrm = new MockRateMonitor("mock");
  mrm.setNanoTime(0L);
  mrm.start();
  Field field = rc.getClass().getDeclaredField("_ra");
  field.setAccessible(true);
  field.set(rc, mrm);
  // #events=1, #time=2ns. Event accepted, rate exceeded
  long expWakeupTime = DbusConstants.NUM_NSECS_IN_SEC /2;
  long tc = rc.incrementEventCount();
  Assert.assertEquals(tc, 1L);
  Assert.assertEquals(rc.getNumSleeps(),1);
  Assert.assertEquals(mrm.getNanoTime(),expWakeupTime);
  // #events=1, #time=0.5s + 1. Event accepted, rate not exceeded
  long curTime = expWakeupTime + 1;
  mrm.setNanoTime(curTime);
  tc = rc.incrementEventCount();
  Assert.assertEquals(tc, 2L);
  Assert.assertEquals(rc.getNumSleeps(),2);
  
  // it is DbusConstants.NUM_NSECS_IN_SEC+1, instead of DbusConstants.NUM_NSECS_IN_SEC because of approximating sleeps to a ms
  Assert.assertEquals(DbusConstants.NUM_NSECS_IN_SEC+1, mrm.getNanoTime());
}