Author: bpoussin Date: 2010-10-20 16:16:17 +0200 (Wed, 20 Oct 2010) New Revision: 436 Url: http://nuiton.org/repositories/revision/wikitty/436 Log: modification pour que le test fonctionne "toujours". Il y a un petit probleme de synchro de thread mais le probleme ne peut apparaitre que dans les tests (fonctionnalite de synchro non utilise dans un vrai developpement). Donc pour l'instant un petit sleep suffira :) Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java =================================================================== --- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-20 14:14:33 UTC (rev 435) +++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-20 14:16:17 UTC (rev 436) @@ -638,16 +638,21 @@ /** * thread that want wait for particulare event to be processed, can be - * call this method with event time in argument. + * call this method with event time in argument. Used only in unit test + * but this is necessary for test. */ public void waitFor(long eventTime) throws InterruptedException { - if (eventTime <= lastEventTime) { - // le thread demande a attendre un event deja passe - // on le met donc pas en attente - return; - } Object mutex = null; + sleep(1); // sleep 1 millis to prevent problem with 2 events in same millis synchronized (waiter) { + if (eventTime <= lastEventTime) { + // le thread demande a attendre un event deja passe + // on le met donc pas en attente + if (log.isDebugEnabled()) { + log.debug("event deja passe " + eventTime + " <= " + lastEventTime); + } + return; + } mutex = waiter.get(eventTime); if (mutex == null) { mutex = new Object(); @@ -700,6 +705,9 @@ log.error("Can't notify listener", eee); } synchronized (waiter) { + // on met a jour l'heure du dernier event envoye + lastEventTime = event.getTime(); + // on previent les threads en attente si besoin // dans un premier temps on ne recupere que ceux @@ -734,7 +742,6 @@ } } } - lastEventTime = event.getTime(); } } catch (InterruptedException eee) { log.error("Notification thread error", eee); Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java =================================================================== --- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java 2010-10-20 14:14:33 UTC (rev 435) +++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java 2010-10-20 14:16:17 UTC (rev 436) @@ -103,8 +103,8 @@ wsn.processRemoteEvent(event); wsn.getEventThread().waitFor(event.getTime()); if (hasListener) { - Assert.assertEquals(WikittyServiceEvent.WikittyEventType.PUT_EXTENSION, - lastEvent); + Assert.assertEquals(WikittyServiceEvent.WikittyEventType.PUT_EXTENSION, + lastEvent); } else { Assert.assertEquals(null, lastEvent); }