public void testTaskCounterMultConsumer() throws Exception {
final String name = "sharedName";
ProfileCollector collector = getCollector(serverNode);
ProfileConsumer cons1 = collector.getConsumer("c1");
ProfileConsumer cons2 = collector.getConsumer("c2");
final ProfileCounter counter1 =
cons1.createCounter(name, testType, ProfileLevel.MIN);
final ProfileCounter counter2 =
cons2.createCounter(name, testType, ProfileLevel.MIN);
// 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 {
Map<String, Long> counts =
SimpleTestListener.report.
getUpdatedTaskCounters();
System.err.println("+++");
for (Map.Entry<String, Long> entry :
counts.entrySet())
{
System.err.println("+ " + entry.getKey() +
", " + entry.getValue());
}
} 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);
txnScheduler.runTask(
new TestAbstractKernelRunnable() {
public void run() {
counter1.incrementCount();
counter2.incrementCount();
counter1.incrementCount();
}
}, myOwner);
AssertionError error =