Skip to content

Commit

Permalink
Cleanup IntelliJ warnings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cberner committed Feb 16, 2016
1 parent 640da4e commit 7ae7180
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public static void main(String[] args)
}
}

private ListeningExecutorService executor;
private TaskExecutor taskExecutor;
private final ListeningExecutorService executor;
private final TaskExecutor taskExecutor;

public TaskExecutorSimulator()
{
Expand Down Expand Up @@ -121,14 +121,14 @@ public void run()

// warm up
for (int i = 0; i < 30; i++) {
TimeUnit.MILLISECONDS.sleep(1000);
MILLISECONDS.sleep(1000);
System.out.println(taskExecutor);
}
tasks.clear();

// run
for (int i = 0; i < 60; i++) {
TimeUnit.MILLISECONDS.sleep(1000);
MILLISECONDS.sleep(1000);
System.out.println(taskExecutor);
}

Expand Down Expand Up @@ -160,10 +160,10 @@ public void run()
for (SimulationSplit split : task.getSplits()) {
taskStart = Math.min(taskStart, split.getStartNanos());
taskEnd = Math.max(taskEnd, split.getDoneNanos());
totalCpuTime += TimeUnit.MILLISECONDS.toNanos(split.getRequiredProcessMillis());
totalCpuTime += MILLISECONDS.toNanos(split.getRequiredProcessMillis());
}

Duration taskDuration = new Duration(taskEnd - taskStart, NANOSECONDS).convertTo(TimeUnit.MILLISECONDS);
Duration taskDuration = new Duration(taskEnd - taskStart, NANOSECONDS).convertTo(MILLISECONDS);
durationDistribution.add(taskDuration.toMillis());

double taskParallelism = 1.0 * totalCpuTime / (taskEnd - taskStart);
Expand Down Expand Up @@ -200,30 +200,24 @@ public void run()
Thread.sleep(10);
}

private ListenableFuture<?> createUser(final String userId,
final int splitsPerTask,
final TaskExecutor taskExecutor,
final AtomicBoolean done,
final Multimap<Integer, SimulationTask> tasks)
private ListenableFuture<?> createUser(String userId,
int splitsPerTask,
TaskExecutor taskExecutor,
AtomicBoolean done,
Multimap<Integer, SimulationTask> tasks)
{
return executor.submit(new Callable<Void>()
{
@Override
public Void call()
throws Exception
{
long taskId = 0;
while (!done.get()) {
SimulationTask task = new SimulationTask(taskExecutor, new TaskId(userId, "0", String.valueOf(taskId++)));
task.schedule(splitsPerTask, executor, new Duration(0, MILLISECONDS)).get();
task.destroy();
return executor.submit((Callable<Void>) () -> {
long taskId = 0;
while (!done.get()) {
SimulationTask task = new SimulationTask(taskExecutor, new TaskId(userId, "0", String.valueOf(taskId++)));
task.schedule(splitsPerTask, executor, new Duration(0, MILLISECONDS)).get();
task.destroy();

printTaskCompletion(task);
printTaskCompletion(task);

tasks.put(splitsPerTask, task);
}
return null;
tasks.put(splitsPerTask, task);
}
return null;
});
}

Expand All @@ -242,22 +236,22 @@ private synchronized void printTaskCompletion(SimulationTask task)
taskStart = Math.min(taskStart, split.getStartNanos());
taskEnd = Math.max(taskEnd, split.getDoneNanos());
taskQueuedTime += split.getQueuedNanos();
totalCpuTime += TimeUnit.MILLISECONDS.toNanos(split.getRequiredProcessMillis());
totalCpuTime += MILLISECONDS.toNanos(split.getRequiredProcessMillis());
}

System.out.printf("%-12s %8s %8s %.2f\n",
task.getTaskId() + ":",
new Duration(taskQueuedTime, NANOSECONDS).convertTo(TimeUnit.MILLISECONDS),
new Duration(taskEnd - taskStart, NANOSECONDS).convertTo(TimeUnit.MILLISECONDS),
new Duration(taskQueuedTime, NANOSECONDS).convertTo(MILLISECONDS),
new Duration(taskEnd - taskStart, NANOSECONDS).convertTo(MILLISECONDS),
1.0 * totalCpuTime / (taskEnd - taskStart)
);

// print split info
if (PRINT_SPLIT_COMPLETION) {
for (SimulationSplit split : task.getSplits()) {
Duration totalQueueTime = new Duration(split.getQueuedNanos(), NANOSECONDS).convertTo(TimeUnit.MILLISECONDS);
Duration executionWallTime = new Duration(split.getDoneNanos() - split.getStartNanos(), NANOSECONDS).convertTo(TimeUnit.MILLISECONDS);
Duration totalWallTime = new Duration(split.getDoneNanos() - split.getCreatedNanos(), NANOSECONDS).convertTo(TimeUnit.MILLISECONDS);
Duration totalQueueTime = new Duration(split.getQueuedNanos(), NANOSECONDS).convertTo(MILLISECONDS);
Duration executionWallTime = new Duration(split.getDoneNanos() - split.getStartNanos(), NANOSECONDS).convertTo(MILLISECONDS);
Duration totalWallTime = new Duration(split.getDoneNanos() - split.getCreatedNanos(), NANOSECONDS).convertTo(MILLISECONDS);
System.out.printf(" %8s %8s %8s\n", totalQueueTime, executionWallTime, totalWallTime);
}

Expand Down Expand Up @@ -288,30 +282,25 @@ public void destroy()
taskExecutor.removeTask(taskHandle);
}

public ListenableFuture<?> schedule(final int splits, ExecutorService executor, final Duration entryDelay)
public ListenableFuture<?> schedule(int splits, ExecutorService executor, Duration entryDelay)
{
final SettableFuture<Void> future = SettableFuture.create();

executor.submit(new Runnable()
{
@Override
public void run()
{
try {
for (int splitId = 0; splitId < splits; splitId++) {
SimulationSplit split = new SimulationSplit(new Duration(80, TimeUnit.MILLISECONDS), new Duration(1, TimeUnit.MILLISECONDS));
SimulationTask.this.splits.add(split);
splitFutures.addAll(taskExecutor.enqueueSplits(taskHandle, false, ImmutableList.of(split)));
Thread.sleep(entryDelay.toMillis());
}

Futures.allAsList(splitFutures).get();
future.set(null);
}
catch (Throwable e) {
future.setException(e);
throw Throwables.propagate(e);
SettableFuture<Void> future = SettableFuture.create();

executor.submit((Runnable) () -> {
try {
for (int splitId = 0; splitId < splits; splitId++) {
SimulationSplit split = new SimulationSplit(new Duration(80, MILLISECONDS), new Duration(1, MILLISECONDS));
SimulationTask.this.splits.add(split);
splitFutures.addAll(taskExecutor.enqueueSplits(taskHandle, false, ImmutableList.of(split)));
Thread.sleep(entryDelay.toMillis());
}

Futures.allAsList(splitFutures).get();
future.set(null);
}
catch (Throwable e) {
future.setException(e);
throw Throwables.propagate(e);
}
});

Expand Down Expand Up @@ -402,7 +391,7 @@ public ListenableFuture<?> processFor(Duration duration)
queuedNanos.addAndGet(callStart - lastCallNanos);

long processMillis = Math.min(requiredProcessMillis - completedProcessMillis.get(), processMillisPerCall);
TimeUnit.MILLISECONDS.sleep(processMillis);
MILLISECONDS.sleep(processMillis);
long completedMillis = completedProcessMillis.addAndGet(processMillis);

boolean isFinished = completedMillis >= requiredProcessMillis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public void test()
try {
TaskHandle taskHandle = taskExecutor.addTask(new TaskId("test", "test", "test"));

final Phaser beginPhase = new Phaser();
Phaser beginPhase = new Phaser();
beginPhase.register();
final Phaser verificationComplete = new Phaser();
Phaser verificationComplete = new Phaser();
verificationComplete.register();

// add two jobs
Expand Down

0 comments on commit 7ae7180

Please sign in to comment.