}
public void testThreads() throws Exception {
double targetMBPerSec = 10.0 + 20 * random().nextDouble();
final SimpleRateLimiter limiter = new SimpleRateLimiter(targetMBPerSec);
final CountDownLatch startingGun = new CountDownLatch(1);
Thread[] threads = new Thread[TestUtil.nextInt(random(), 3, 6)];
final AtomicLong totBytes = new AtomicLong();
for(int i=0;i<threads.length;i++) {
threads[i] = new Thread() {
@Override
public void run() {
try {
startingGun.await();
} catch (InterruptedException ie) {
throw new ThreadInterruptedException(ie);
}
long bytesSinceLastPause = 0;
for(int i=0;i<500;i++) {
long numBytes = TestUtil.nextInt(random(), 1000, 10000);
totBytes.addAndGet(numBytes);
bytesSinceLastPause += numBytes;
if (bytesSinceLastPause > limiter.getMinPauseCheckBytes()) {
limiter.pause(bytesSinceLastPause);
bytesSinceLastPause = 0;
}
}
}
};