DefaultFuture extends CompletableFuture<Object> { private DefaultFuture(Channel channel, Request request, int timeout) { this.channel = channel; this.request = request; this.id = request.getId(); this.timeout = timeout > 0 ? timeout : channel.getUrl().getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT); FUTURES.put(id, this); CHANNELS.put(id, channel); } private  DefaultFuture(Channel channel, Request request, int timeout); ExecutorService getExecutor(); void setExecutor(ExecutorService executor); static DefaultFuture newFuture(Channel channel, Request request, int timeout, ExecutorService executor); static DefaultFuture getFuture(long id); static boolean hasFuture(Channel channel); static void sent(Channel channel, Request request); static void closeChannel(Channel channel); static void received(Channel channel, Response response); static void received(Channel channel, Response response, boolean timeout); @Override boolean cancel(boolean mayInterruptIfRunning); void cancel(); Request getRequest(); static final Timer TIME_OUT_TIMER; }
@Test @Disabled public void timeoutNotSend() throws Exception { final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); System.out.println("before a future is create , time is : " + LocalDateTime.now().format(formatter)); DefaultFuture f = defaultFuture(5000); while (!f.isDone()) { Thread.sleep(100); } System.out.println("after a future is timeout , time is : " + LocalDateTime.now().format(formatter)); try { f.get(); } catch (Exception e) { Assertions.assertTrue(e.getCause() instanceof TimeoutException, "catch exception is not timeout exception!"); System.out.println(e.getMessage()); } }