### Question:
EventWatcher { public void start(EventQueue queue) { queue.addHandler(startEvent, this::handleStartEvent); queue.addHandler(completionEvent, (completionPayload, publisher) -> { try { handleCompletion(completionPayload, publisher); } catch (LeaseNotFoundException e) { LOG.warn("Completion event without active lease. Id={}", completionPayload.getId()); } }); MetricsSystem ms = DefaultMetricsSystem.instance(); ms.register(name, "EventWatcher metrics", metrics); } EventWatcher(String name, Event<TIMEOUT_PAYLOAD> startEvent,
      Event<COMPLETION_PAYLOAD> completionEvent,
      LeaseManager<Long> leaseManager);  EventWatcher(Event<TIMEOUT_PAYLOAD> startEvent,
      Event<COMPLETION_PAYLOAD> completionEvent,
      LeaseManager<Long> leaseManager); void start(EventQueue queue); synchronized boolean contains(TIMEOUT_PAYLOAD payload); synchronized boolean remove(TIMEOUT_PAYLOAD payload); List<TIMEOUT_PAYLOAD> getTimeoutEvents(
      Predicate<? super TIMEOUT_PAYLOAD> predicate);  }### Answer:
@Test public void testEventHandling() throws InterruptedException { EventQueue queue = new EventQueue(); EventWatcher<UnderreplicatedEvent, ReplicationCompletedEvent> replicationWatcher = createEventWatcher(); EventHandlerStub<UnderreplicatedEvent> underReplicatedEvents = new EventHandlerStub<>(); queue.addHandler(UNDER_REPLICATED, underReplicatedEvents); replicationWatcher.start(queue); long id1 = HddsIdFactory.getLongId(); long id2 = HddsIdFactory.getLongId(); queue.fireEvent(WATCH_UNDER_REPLICATED, new UnderreplicatedEvent(id1, "C1")); queue.fireEvent(WATCH_UNDER_REPLICATED, new UnderreplicatedEvent(id2, "C2")); Assert.assertEquals(0, underReplicatedEvents.getReceivedEvents().size()); Thread.sleep(1000); queue.fireEvent(REPLICATION_COMPLETED, new ReplicationCompletedEvent(id1, "C2", "D1")); Assert.assertEquals(0, underReplicatedEvents.getReceivedEvents().size()); Thread.sleep(1500); queue.processAll(1000L); Assert.assertEquals(1, underReplicatedEvents.getReceivedEvents().size()); Assert.assertEquals(id2, underReplicatedEvents.getReceivedEvents().get(0).id); }