RequestFilter extends AbstractIoFilter { @SuppressWarnings({ "rawtypes", "unchecked" }) public IoFuture<RESPONSE> request(IoSession session, REQUEST request, long timeoutInMs) { Map inFlight = session.getAttribute(IN_FLIGHT_REQUESTS); RequestFuture<REQUEST, RESPONSE> future = new RequestFuture<REQUEST, RESPONSE>(session, request.requestId()); future.setTimeoutFuture(schedExec.schedule(future.timeout, timeoutInMs, TimeUnit.MILLISECONDS)); inFlight.put(request.requestId(), future); session.write(request); return future; }  @SuppressWarnings({ "rawtypes", "unchecked" }) IoFuture<RESPONSE> request(IoSession session, REQUEST request, long timeoutInMs); @SuppressWarnings("rawtypes") @Override void sessionOpened(IoSession session); @SuppressWarnings("unchecked") @Override void messageReceived(IoSession session, Object message, ReadFilterChainController controller); @Override void sessionClosed(IoSession session);  }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void request_and_produce_a_future() { IoSession session = mock(IoSession.class); Request r = mock(Request.class); when(r.requestId()).thenReturn("ID"); Map m = mock(Map.class); when(session.getAttribute(RequestFilter.IN_FLIGHT_REQUESTS)).thenReturn(m); IoFuture f = rq.request(session, r, 12345); Assert.assertFalse(f.isDone()); Assert.assertFalse(f.isCancelled()); verify(r, times(2)).requestId(); verify(session).write(r); verify(m).put("ID", f); verify(session).getAttribute(RequestFilter.IN_FLIGHT_REQUESTS); verifyNoMoreInteractions(session, m); }