Skip to content

Commit

Permalink
test-utils-stress: sorted StressResult output
Browse files Browse the repository at this point in the history
Signed-off-by: Ketoth Xupack <ketoth.xupack@gmail.com>
  • Loading branch information
KetothXupack committed Mar 17, 2014
1 parent 6e0091e commit 76ff71e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.nohope.test.stress.TimeUtils.throughputTo;
Expand Down Expand Up @@ -74,9 +76,13 @@ public String toString() {
.append('\n')
.append(separator)
.append('\n');
for (final Result stats : results.values()) {
builder.append(stats.toString());

// sorted output
final Set<String> keys = new TreeSet<>(results.keySet());
for (final String key : keys) {
builder.append(results.get(key).toString());
}

return builder.append(separator)
.append('\n')
.append(pad("Total error count:"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,42 @@ public Long get() throws Exception {
}
}


@Test
public void sortedOutput() throws InterruptedException {
final StressResult result =
StressScenario.of(TimerResolution.MILLISECONDS).measure(10, 1, new Action() {
@Override
protected void doAction(final MeasureProvider p) throws Exception {
p.invoke("action4", new Invoke() {
@Override
public void invoke() throws Exception {
}
});
p.invoke("action1", new Invoke() {
@Override
public void invoke() throws Exception {
}
});
p.invoke("action2", new Invoke() {
@Override
public void invoke() throws Exception {
}
});
p.invoke("action3", new Invoke() {
@Override
public void invoke() throws Exception {
}
});
}
});

final int action1 = result.toString().indexOf("action1");
final int action2 = result.toString().indexOf("action2");
final int action3 = result.toString().indexOf("action3");
final int action4 = result.toString().indexOf("action4");
assertTrue(action4 > action3);
assertTrue(action3 > action2);
assertTrue(action2 > action1);
}
}

0 comments on commit 76ff71e

Please sign in to comment.