Tsuyoshi Ozawa, are these tests failing ? Maybe there is some other problem.
Because dispatcher.await() would only make sense if we are verifying an event which we expect to be sent to dispatcher or verifying something which happens upon processing of such an event.
In the instances pointed above, I think it should be fine even without dispatcher.await()
1. In testRecovery, the statements pointed out above, we are first checking for whether localization has started or not for a resource and then posting ResourceLocallizedEvent to localizer tracker. We are not verifying what happens due to handling of that event. If you notice we do have a dispatcher.await() right after these set of statements. And after that only we check the state of resource. So this single dispatcher.await() should be enough here.
2. In testResourceRelease also, the statement being verified is that whether cleanupPrivLocalizers has been called. This method is called when we call ResourceLocalizationService#handle with ContainerLocalizationCleanupEvent directly. Because handle() will call handleCleanupContainerResources() where this method is called. We do not need to wait here as we will be able to verify this method invocation as soon as call to handle() finishes. And we do have dispatcher.await() for later verifications.
spyService.handle(new ContainerLocalizationCleanupEvent(c, req)); verify(mockLocallilzerTracker)
3. For testFailedDirsResourceRelease too, same explanation holds true. Even the delete statements being verified below the code snippet pointed out by you will be called in handleCleanupContainerResources(). So we do not need to wait. And we have dispatcher.await() after these verifications.