EmbeddedChannel extends AbstractChannel { public long runScheduledPendingTasks() { try { return loop.runScheduledTasks(); } catch (Exception e) { recordException(e); return loop.nextScheduledTask(); } } EmbeddedChannel(ChannelHandler... handlers); @Override ChannelMetadata metadata(); @Override ChannelConfig config(); @Override boolean isOpen(); @Override boolean isActive(); Queue<Object> inboundMessages(); @Deprecated Queue<Object> lastInboundBuffer(); Queue<Object> outboundMessages(); @Deprecated Queue<Object> lastOutboundBuffer(); Object readInbound(); Object readOutbound(); boolean writeInbound(Object... msgs); boolean writeOutbound(Object... msgs); boolean finish(); void runPendingTasks(); long runScheduledPendingTasks(); void checkException();  }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testScheduling() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter()); final CountDownLatch latch = new CountDownLatch(2); ScheduledFuture future = ch.eventLoop().schedule(new Runnable() { @Override public void run() { latch.countDown(); } }, 1, TimeUnit.SECONDS); future.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { latch.countDown(); } }); long next = ch.runScheduledPendingTasks(); Assert.assertTrue(next > 0); Thread.sleep(TimeUnit.NANOSECONDS.toMillis(next) + 50); Assert.assertEquals(-1, ch.runScheduledPendingTasks()); latch.await(); }