@Test
public void testTimeOut() throws Exception {
//set the default waiting time greater than time out time to produce a time out
EventRegistry theEventRegistry = EventRegistryFactory.getInstance().getEventRegistry();
EventServiceConfiguration theEventServiceConfiguration = theEventRegistry.getConfiguration();
final int theTimeoutTime = 400;
final int theNewMaxWaitingTime = theTimeoutTime + 1700;
EventServiceConfiguration theNewEventServiceConfiguration = createConfiguration(
theEventServiceConfiguration.getMinWaitingTime(),
theNewMaxWaitingTime,
theTimeoutTime);
tearDownEventServiceConfiguration();
setUp(theNewEventServiceConfiguration);
theEventRegistry = EventRegistryFactory.getInstance().getEventRegistry();
theEventRegistry.registerUser(TEST_DOMAIN, TEST_USER_ID, null);
theEventRegistry.addEvent(TEST_DOMAIN, new DummyEvent());
assertTrue(theEventRegistry.isUserRegistered(TEST_USER_ID));
theEventRegistry.registerUnlistenEvent(TEST_USER_ID, UnlistenEventListener.Scope.UNLISTEN, null);
List<DomainEvent> theEvents = theEventRegistry.listen(getLongPollingListener(), TEST_USER_ID);
assertNotNull(theEvents);
assertEquals(1, theEvents.size());
assertFalse(theEvents.get(0).getEvent() instanceof UnlistenEvent);
assertTrue(theEventRegistry.isUserRegistered(TEST_USER_ID));
//It is waiting for events and will cause a timeout, because the max. waiting time is configured longer than the timeout time.
//The result is a UnlistenEvent, because the timeout doesn't effect that method, but the next call.
theEvents = theEventRegistry.listen(getLongPollingListener(), TEST_USER_ID);
//wait for the UserActivityScheduler-Thread
Thread.yield();
Thread.sleep(theNewEventServiceConfiguration.getTimeoutTime() + 100);
assertNotNull(theEvents);
assertEquals(1, theEvents.size());
assertTrue(theEvents.get(0).getEvent() instanceof UnlistenEvent);
assertFalse(theEventRegistry.isUserRegistered(TEST_USER_ID));