public class TestFetcher {
@Test
public void testThrottling() throws InterruptedException {
double bytesPerSec = 1000;
Throttler throttler = new Throttler(bytesPerSec);
long startTime = System.currentTimeMillis();
int bytesConsumed = 0;
for(int i = 0; i < 10; i++) {
int bytes = (int)(Math.random() * 1000);
bytesConsumed += bytes;
throttler.incrementAndThrottle(bytes);
}
long endTime = System.currentTimeMillis();
double secs = (endTime - startTime) / (double)1000;
double avgBytesPerSec = bytesConsumed / secs;