testThrottler(100, 100, 50, 5000);
}
public void testThrottler(int readSize, int numReads, long readTime, long throttledRate) {
long startTime = 1000;
MockTime time = new MockTime(startTime);
EventThrottler throttler = new EventThrottler(time, throttledRate, 50);
for(int i = 0; i < numReads; i++) {
time.addMilliseconds(readTime);
throttler.maybeThrottle(readSize);
}
long doneTime = time.getMilliseconds();
long bytesRead = numReads * (long) readSize;
double unthrottledSecs = readTime * numReads / (double) Time.MS_PER_SECOND;
double ellapsedSecs = (double) (doneTime - startTime) / Time.MS_PER_SECOND;
double observedRate = bytesRead / ellapsedSecs;
double unthrottledRate = bytesRead / unthrottledSecs;