zentol commented on code in PR #21304: URL: https://github.com/apache/flink/pull/21304#discussion_r1021186465
########## flink-rpc/flink-rpc-akka/src/test/java/org/apache/flink/runtime/rpc/akka/ContextClassLoadingSettingTest.java: ########## @@ -150,21 +154,28 @@ void testAkkaRpcService_ScheduleRunnableSetsFlinkContextClassLoader() void testAkkaRpcService_ScheduleRunnableWithFixedRateSetsFlinkContextClassLoader() { final int numberOfScheduledRuns = 2; final List<ClassLoader> contextClassLoaders = new ArrayList<>(numberOfScheduledRuns); - akkaRpcService - .getScheduledExecutor() - .scheduleAtFixedRate( - () -> { - if (contextClassLoaders.size() < numberOfScheduledRuns) { - contextClassLoaders.add( - Thread.currentThread().getContextClassLoader()); - } else { - throw new RuntimeException("cancel task"); - } - }, - 0, - 1, - TimeUnit.MILLISECONDS); - + ScheduledFuture<?> future = + akkaRpcService + .getScheduledExecutor() + .scheduleAtFixedRate( + () -> { + if (contextClassLoaders.size() < numberOfScheduledRuns) { + contextClassLoaders.add( + Thread.currentThread().getContextClassLoader()); + } else { + throw new RuntimeException("cancel task"); + } + }, + 0, + 1, + TimeUnit.MILLISECONDS); + try { + future.get(); Review Comment: use assertThatThrownBy ########## flink-rpc/flink-rpc-akka/src/test/java/org/apache/flink/runtime/rpc/akka/ContextClassLoadingSettingTest.java: ########## @@ -150,21 +154,28 @@ void testAkkaRpcService_ScheduleRunnableSetsFlinkContextClassLoader() void testAkkaRpcService_ScheduleRunnableWithFixedRateSetsFlinkContextClassLoader() { final int numberOfScheduledRuns = 2; final List<ClassLoader> contextClassLoaders = new ArrayList<>(numberOfScheduledRuns); - akkaRpcService - .getScheduledExecutor() - .scheduleAtFixedRate( - () -> { - if (contextClassLoaders.size() < numberOfScheduledRuns) { - contextClassLoaders.add( - Thread.currentThread().getContextClassLoader()); - } else { - throw new RuntimeException("cancel task"); - } - }, - 0, - 1, - TimeUnit.MILLISECONDS); - + ScheduledFuture<?> future = + akkaRpcService + .getScheduledExecutor() + .scheduleAtFixedRate( + () -> { + if (contextClassLoaders.size() < numberOfScheduledRuns) { + contextClassLoaders.add( + Thread.currentThread().getContextClassLoader()); + } else { + throw new RuntimeException("cancel task"); + } + }, + 0, + 1, + TimeUnit.MILLISECONDS); + try { + future.get(); + fail("The future should fail."); Review Comment: It could be more straight-forward to complete a future within `scheduleAtFixedRate` (before the throw the exception) that we wait for outside the executor. ########## flink-rpc/flink-rpc-akka/src/test/java/org/apache/flink/runtime/rpc/akka/ContextClassLoadingSettingTest.java: ########## @@ -173,21 +184,30 @@ void testAkkaRpcService_ScheduleRunnableWithFixedRateSetsFlinkContextClassLoader @Test void testAkkaRpcService_ScheduleRunnableWithFixedDelaySetsFlinkContextClassLoader() { final int numberOfScheduledRuns = 2; + final List<ClassLoader> contextClassLoaders = new ArrayList<>(numberOfScheduledRuns); - akkaRpcService - .getScheduledExecutor() - .scheduleWithFixedDelay( - () -> { - if (contextClassLoaders.size() < numberOfScheduledRuns) { - contextClassLoaders.add( - Thread.currentThread().getContextClassLoader()); - } else { - throw new RuntimeException("cancel task"); - } - }, - 0, - 1, - TimeUnit.MILLISECONDS); + ScheduledFuture<?> future = + akkaRpcService + .getScheduledExecutor() + .scheduleWithFixedDelay( + () -> { + if (contextClassLoaders.size() < numberOfScheduledRuns) { + contextClassLoaders.add( + Thread.currentThread().getContextClassLoader()); + } else { + throw new RuntimeException("cancel task"); + } + }, + 0, + 1, + TimeUnit.MILLISECONDS); + try { + future.get(); Review Comment: use assertThatThrownBy -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org