_domain.addEventObserver(counter, ExchangeInitiatedEvent.class);
_domain.addEventObserver(counter, ExchangeCompletionEvent.class);
// send 10 in-only messages and check the counters
for (int i = 0; i < 10; i++) {
ServiceReference inOnlyService = _domain.createInOnlyService(new QName("ExchangeEvent-0" + i));
Exchange inOnly = inOnlyService.createExchange();
inOnly.send(inOnly.createMessage());
}
Assert.assertEquals(10, counter.initiatedCount);
Assert.assertEquals(10, counter.completedCount);
// initialize counters
counter.initiatedCount = 0;
counter.completedCount = 0;
// send 10 in-out and check the count
for (int i = 0; i < 10; i++) {
ServiceReference inOutService = _domain.createInOutService(
new QName("ExchangeEvent-1" + i), new MockHandler().forwardInToOut());
Exchange inOut = inOutService.createExchange(new MockHandler());
inOut.send(inOut.createMessage());
}
Assert.assertEquals(10, counter.initiatedCount);
Assert.assertEquals(10, counter.completedCount);