startup();
}
private void doTest() throws Exception {
TaskRunner exec = new TaskRunner(NUM_THREADS);
log.warn("Starting test");
int i;
long print = NUM_OPERATIONS / 10;
AtomicLong durationPuts = new AtomicLong();
AtomicLong durationGets = new AtomicLong();
AtomicLong durationRemoves = new AtomicLong();
long stElapsed = System.nanoTime();
for (i = 0; i < NUM_OPERATIONS; i++) {
MyRunnable r = null;
switch (i % 3) {
case 0:
r = new Putter(i, durationPuts);
break;
case 1:
r = new Getter(i, durationGets);
break;
case 2:
r = new Remover(i, durationRemoves);
break;
}
if (i % print == 0)
log.warn("processing iteration " + i);
exec.execute(r);
// if (USE_SLEEP) TestingUtil.sleepRandom(MAX_RANDOM_SLEEP_MILLIS);
if (USE_SLEEP) TestingUtil.sleepThread(MAX_RANDOM_SLEEP_MILLIS);
}
log.warn("Finished generating runnables; awaiting executor completion");
// wait for executors to complete!
exec.stop();
// wait up to 1 sec for each call?
long elapsedTimeNanos = System.nanoTime() - stElapsed;
log.warn("Finished test. " + printDuration((long) toMillis(elapsedTimeNanos)));