@Test
public void testOperationMediumToMaxLevel() throws Exception {
ProfileCollector collector = getCollector(serverNode);
ProfileConsumer cons1 = collector.getConsumer("c1");
final ProfileOperation op =
cons1.createOperation("something", testType,ProfileLevel.MEDIUM);
// 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>();
// The owner for our positive test. The listener uses this owner
// to find the ProfileReport for the task in this test.
final Identity positiveOwner = new DummyIdentity("opmedtomax");
final Identity negativeOwner = new DummyIdentity("opmedtomaxneg");
SimpleTestListener test = new SimpleTestListener(
new OperationReportRunnable(op.getName(),
negativeOwner, positiveOwner,
errorExchanger));
profileCollector.addListener(test, true);
txnScheduler.runTask(
new TestAbstractKernelRunnable() {
public void run() {
// We do not expect to see this reported.
op.report();
}
}, negativeOwner);
AssertionError error =
errorExchanger.exchange(null, TIMEOUT, TimeUnit.MILLISECONDS);
if (error != null) {
throw new AssertionError(error);
}
cons1.setProfileLevel(ProfileLevel.MAX);
txnScheduler.runTask(
new TestAbstractKernelRunnable() {
public void run() {
op.report();
}
}, positiveOwner);
error = errorExchanger.exchange(null, TIMEOUT, TimeUnit.MILLISECONDS);
if (error != null) {