@Test public void testAllExchangeEventsReceived() throws Exception { EventCounter counter = new EventCounter(); _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); }
@Test public void testExchangeCompletedEvent() { EventCounter counter = new EventCounter(); _domain.addEventObserver(counter, ExchangeCompletionEvent.class); // send in-only and check the count ServiceReference inOnlyService = _domain.createInOnlyService(new QName("ExchangeCompleteEvent-1")); Exchange inOnly = inOnlyService.createExchange(); inOnly.send(inOnly.createMessage()); Assert.assertEquals(1, counter.completedCount); // reset count counter.completedCount = 0; // send in-out and check the count ServiceReference inOutService = _domain.createInOutService( new QName("ExchangeCompleteEvent-2"), new MockHandler().forwardInToOut()); Exchange inOut = inOutService.createExchange(new MockHandler()); inOut.send(inOut.createMessage()); Assert.assertEquals(1, counter.completedCount); }