### Question:
AkkaRpcService implements RpcService { @Override public ScheduledExecutor getScheduledExecutor() { return internalScheduledExecutor; } AkkaRpcService(final ActorSystem actorSystem, final AkkaRpcServiceConfiguration configuration); ActorSystem getActorSystem(); @Override String getAddress(); @Override int getPort(); @Override CompletableFuture<C> connect(
			final String address,
			final Class<C> clazz); @Override CompletableFuture<C> connect(String address, F fencingToken, Class<C> clazz); @Override RpcServer startServer(C rpcEndpoint); @Override RpcServer fenceRpcServer(RpcServer rpcServer, F fencingToken); @Override void stopServer(RpcServer selfGateway); @Override CompletableFuture<Void> stopService(); @Override CompletableFuture<Void> getTerminationFuture(); @Override Executor getExecutor(); @Override ScheduledExecutor getScheduledExecutor(); @Override ScheduledFuture<?> scheduleRunnable(Runnable runnable, long delay, TimeUnit unit); @Override void execute(Runnable runnable); @Override CompletableFuture<T> execute(Callable<T> callable);  }### Answer:
@Test(timeout = 60000) public void testScheduledExecutorServiceSimpleSchedule() throws Exception { ScheduledExecutor scheduledExecutor = akkaRpcService.getScheduledExecutor(); final OneShotLatch latch = new OneShotLatch(); ScheduledFuture<?> future = scheduledExecutor.schedule( latch::trigger, 10L, TimeUnit.MILLISECONDS); future.get(); assertTrue(latch.isTriggered()); }
@Test(timeout = 60000) public void testScheduledExecutorServicePeriodicSchedule() throws Exception { ScheduledExecutor scheduledExecutor = akkaRpcService.getScheduledExecutor(); final int tries = 4; final long delay = 10L; final CountDownLatch countDownLatch = new CountDownLatch(tries); long currentTime = System.nanoTime(); ScheduledFuture<?> future = scheduledExecutor.scheduleAtFixedRate( countDownLatch::countDown, delay, delay, TimeUnit.MILLISECONDS); assertTrue(!future.isDone()); countDownLatch.await(); assertTrue(!future.isDone()); long finalTime = System.nanoTime() - currentTime; assertTrue(finalTime >= tries * delay); future.cancel(true); }
@Test(timeout = 60000) public void testScheduledExecutorServiceWithFixedDelaySchedule() throws Exception { ScheduledExecutor scheduledExecutor = akkaRpcService.getScheduledExecutor(); final int tries = 4; final long delay = 10L; final CountDownLatch countDownLatch = new CountDownLatch(tries); long currentTime = System.nanoTime(); ScheduledFuture<?> future = scheduledExecutor.scheduleWithFixedDelay( countDownLatch::countDown, delay, delay, TimeUnit.MILLISECONDS); assertTrue(!future.isDone()); countDownLatch.await(); assertTrue(!future.isDone()); long finalTime = System.nanoTime() - currentTime; assertTrue(finalTime >= tries * delay); future.cancel(true); }
@Test public void testScheduledExecutorServiceCancelWithFixedDelay() throws InterruptedException { ScheduledExecutor scheduledExecutor = akkaRpcService.getScheduledExecutor(); long delay = 10L; final OneShotLatch futureTask = new OneShotLatch(); final OneShotLatch latch = new OneShotLatch(); final OneShotLatch shouldNotBeTriggeredLatch = new OneShotLatch(); ScheduledFuture<?> future = scheduledExecutor.scheduleWithFixedDelay( () -> { try { if (futureTask.isTriggered()) { shouldNotBeTriggeredLatch.trigger(); } else { futureTask.trigger(); latch.await(); } } catch (InterruptedException ignored) { } }, delay, delay, TimeUnit.MILLISECONDS); futureTask.await(); future.cancel(false); latch.trigger(); try { shouldNotBeTriggeredLatch.await(5 * delay, TimeUnit.MILLISECONDS); fail("The shouldNotBeTriggeredLatch should never be triggered."); } catch (TimeoutException e) { } }