@Test public void shouldDispatchEventSuccessfully() throws InterruptedException, ExecutionException, TimeoutException { whenEventHandlerDispatchReturning(CompletableFuture.completedFuture(null)); eventDispatcher.dispatch(de).get(1, TimeUnit.SECONDS); verify(eventHandler).dispatch(de); verifyZeroInteractions(exceptionHandlerManager); }
public CompletableFuture<?> dispatch(DispatchedEvent<Event> de) { EventHandler eventHandler = eventTypesAndHandlers.get(de.getEventType()); if (eventHandler != null) { CompletableFuture<Object> result = new CompletableFuture<>(); dispatchEvent(de, eventHandler, result, Optional.empty()); return result; } else { RuntimeException ex = new RuntimeException("No handler for event - subscriberId: " + subscriberId + ", " + de.getEventType()); logger.error("dispatching failure", ex); CompletableFuture completableFuture = new CompletableFuture(); completableFuture.completeExceptionally(ex); return completableFuture; } }
EventDispatcher { public CompletableFuture<?> dispatch(DispatchedEvent<Event> de) { EventHandler eventHandler = eventTypesAndHandlers.get(de.getEventType()); if (eventHandler != null) { CompletableFuture<Object> result = new CompletableFuture<>(); dispatchEvent(de, eventHandler, result, Optional.empty()); return result; } else { RuntimeException ex = new RuntimeException("No handler for event - subscriberId: " + subscriberId + ", " + de.getEventType()); logger.error("dispatching failure", ex); CompletableFuture completableFuture = new CompletableFuture(); completableFuture.completeExceptionally(ex); return completableFuture; } } }
EventDispatcher { public CompletableFuture<?> dispatch(DispatchedEvent<Event> de) { EventHandler eventHandler = eventTypesAndHandlers.get(de.getEventType()); if (eventHandler != null) { CompletableFuture<Object> result = new CompletableFuture<>(); dispatchEvent(de, eventHandler, result, Optional.empty()); return result; } else { RuntimeException ex = new RuntimeException("No handler for event - subscriberId: " + subscriberId + ", " + de.getEventType()); logger.error("dispatching failure", ex); CompletableFuture completableFuture = new CompletableFuture(); completableFuture.completeExceptionally(ex); return completableFuture; } } EventDispatcher(String subscriberId, Map<Class<?>, EventHandler> eventTypesAndHandlers, EventDeliveryExceptionHandlerManager eventDeliveryExceptionHandlerManager); }
EventDispatcher { public CompletableFuture<?> dispatch(DispatchedEvent<Event> de) { EventHandler eventHandler = eventTypesAndHandlers.get(de.getEventType()); if (eventHandler != null) { CompletableFuture<Object> result = new CompletableFuture<>(); dispatchEvent(de, eventHandler, result, Optional.empty()); return result; } else { RuntimeException ex = new RuntimeException("No handler for event - subscriberId: " + subscriberId + ", " + de.getEventType()); logger.error("dispatching failure", ex); CompletableFuture completableFuture = new CompletableFuture(); completableFuture.completeExceptionally(ex); return completableFuture; } } EventDispatcher(String subscriberId, Map<Class<?>, EventHandler> eventTypesAndHandlers, EventDeliveryExceptionHandlerManager eventDeliveryExceptionHandlerManager); CompletableFuture<?> dispatch(DispatchedEvent<Event> de); }
EventDispatcher { public CompletableFuture<?> dispatch(DispatchedEvent<Event> de) { EventHandler eventHandler = eventTypesAndHandlers.get(de.getEventType()); if (eventHandler != null) { CompletableFuture<Object> result = new CompletableFuture<>(); dispatchEvent(de, eventHandler, result, Optional.empty()); return result; } else { RuntimeException ex = new RuntimeException("No handler for event - subscriberId: " + subscriberId + ", " + de.getEventType()); logger.error("dispatching failure", ex); CompletableFuture completableFuture = new CompletableFuture(); completableFuture.completeExceptionally(ex); return completableFuture; } } EventDispatcher(String subscriberId, Map<Class<?>, EventHandler> eventTypesAndHandlers, EventDeliveryExceptionHandlerManager eventDeliveryExceptionHandlerManager); CompletableFuture<?> dispatch(DispatchedEvent<Event> de);  }