RequestTracker implements Closeable { @VisibleForTesting void reap() { outstanding.stream() .filter(OngoingRequest::isExpired) .forEach( request -> { LOG.warn("Dropping expired request: {}", request); request.drop(); }); } RequestTracker(); void register(OngoingRequest request); boolean remove(OngoingRequest request); @Override void close();  }
@Test public void droppedAfterExpiration() { Request requestMessage = Request.forUri("http: OngoingRequest ongoingRequest = mock(OngoingRequest.class); when(ongoingRequest.request()).thenReturn(requestMessage); when(ongoingRequest.isExpired()).thenReturn(true); new TrackedOngoingRequestImpl(ongoingRequest, tracker); tracker.reap(); verify(ongoingRequest).drop(); }