ProfileLevel.MIN);
final ProfileOperation op1 =
cons1.createOperation(op1Name,
ProfileDataType.TASK_AND_AGGREGATE,
ProfileLevel.MIN);
final AggregateProfileOperation opAgg = (AggregateProfileOperation) op;
final AggregateProfileOperation op1Agg =
(AggregateProfileOperation) op1;
// Because the listener is running in a different thread, JUnit
// is not able to report the assertions and failures.
// Use an exchanger to synchronize between the threads and communicate
// any problems.
final Exchanger<AssertionError> errorExchanger =
new Exchanger<AssertionError>();
final Identity myOwner = new DummyIdentity("me");
SimpleTestListener test = new SimpleTestListener(
new Runnable() {
public void run() {
AssertionError error = null;
ProfileReport report = SimpleTestListener.report;
if (report.getTaskOwner().equals(myOwner)) {
try {
List<String> ops =
report.getReportedOperations();
System.err.println("+++");
for (String name : ops) {
assertTrue(name.contains(opName)
|| name.contains(op1Name));
System.err.println("+ " + name);
}
System.err.println("+++");
// Our aggregate counter knows that it was updated
assertEquals(4, opAgg.getCount());
assertEquals(2, op1Agg.getCount());
} catch (AssertionError e) {
error = e;
}
}
// Signal that we're done, and return the exception
try {
errorExchanger.exchange(error);
} catch (InterruptedException ignored) {
// do nothing
}
}
});
profileCollector.addListener(test, true);
op.report();
op1.report();
assertEquals(1, opAgg.getCount());
assertEquals(1, op1Agg.getCount());
op.report();
assertEquals(2, opAgg.getCount());
txnScheduler.runTask(
new TestAbstractKernelRunnable() {
public void run() {
// We expect to see the operations in the profile report
op.report();
op1.report();
op.report();
}
}, myOwner);
AssertionError error =
errorExchanger.exchange(null, 100, TimeUnit.MILLISECONDS);
if (error != null) {
throw new AssertionError(error);
}
assertEquals(4, opAgg.getCount());
assertEquals(2, op1Agg.getCount());
}