private static final int READ_TIME = 2000;
@Test()
public void testThrottleSemaphore() throws Exception {
int bytesPerSecond = 30000;
final ThrottleSemaphore semaphore = new ThrottleSemaphore(bytesPerSecond);
Thread[] threads = new Thread[3];
final AtomicInteger totalAquiredBytes = new AtomicInteger();
final List<String> errors = new ArrayList<String>();
long time = System.currentTimeMillis();
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread() {
public void run() {
try {
int mbPerThread = 1;
for (int i = 0; i < mbPerThread * 256; i++) {
int acquireBytes;
acquireBytes = semaphore.aquireBytes(4096);
totalAquiredBytes.addAndGet(acquireBytes);
// System.out.println(getName() + "[" + i + "]: " + acquireBytes);
if (acquireBytes <= 0) {
errors.add("acquired bytes incorrect " + acquireBytes);
}