zentol commented on a change in pull request #7653: [FLINK-11367][tests] Port
TaskManagerProcessReapingTestBase to new codebase
URL: https://github.com/apache/flink/pull/7653#discussion_r254226281
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunnerTest.java
##########
@@ -37,44 +43,57 @@
*/
public class TaskManagerRunnerTest extends TestLogger {
- @Test
- public void testTaskManagerRunnerShutdown() throws Exception {
- final Configuration configuration = new Configuration();
- final ResourceID taskManagerResourceId = ResourceID.generate();
-
- final ServerSocket localhost = new ServerSocket(0);
-
- configuration.setString(JobManagerOptions.ADDRESS,
localhost.getInetAddress().getHostName());
- configuration.setInteger(JobManagerOptions.PORT,
localhost.getLocalPort());
-
configuration.setString(TaskManagerOptions.REGISTRATION_TIMEOUT, "10 ms");
- final CompletableFuture<Void> jvmTerminationFuture = new
CompletableFuture<>();
- final TestingTaskManagerRunner taskManagerRunner = new
TestingTaskManagerRunner(configuration, taskManagerResourceId,
jvmTerminationFuture);
+ @Rule
+ public final Timeout timeout = Timeout.seconds(30);
- taskManagerRunner.start();
+ private Configuration configuration;
- try {
- // wait until we trigger the jvm termination
- jvmTerminationFuture.get();
+ @Before
+ public void setUp() {
+ configuration = new Configuration();
+ configuration.setString(JobManagerOptions.ADDRESS, "localhost");
+ configuration.setString(TaskManagerOptions.HOST, "localhost");
+ }
-
assertThat(taskManagerRunner.getTerminationFuture().isDone(), is(true));
- } finally {
- localhost.close();
- taskManagerRunner.close();
+ @Test
+ public void testShouldShutdownOnFatalError() throws Exception {
+ try (TaskManagerRunner taskManagerRunner =
createTaskManagerRunner(configuration)) {
+ taskManagerRunner.start();
+
+ final SystemExitTrackingSecurityManager
systemExitTrackingSecurityManager =
+ runWithSystemExitTracking(() -> {
+ taskManagerRunner.onFatalError(new
RuntimeException());
+
taskManagerRunner.getTerminationFuture().get(30, TimeUnit.SECONDS);
+ });
+
+
assertThat(systemExitTrackingSecurityManager.getCount(), is(equalTo(1)));
+
assertThat(systemExitTrackingSecurityManager.getStatus(),
is(equalTo(TaskManagerRunner.RUNTIME_FAILURE_RETURN_CODE)));
}
}
- private static class TestingTaskManagerRunner extends TaskManagerRunner
{
+ @Test
+ public void testShouldShutdownIfRegistrationWithJobManagerFails()
throws Exception {
+
configuration.setString(TaskManagerOptions.REGISTRATION_TIMEOUT, "10 ms");
- private final CompletableFuture<Void> jvmTerminationFuture;
+ try (TaskManagerRunner taskManagerRunner =
createTaskManagerRunner(configuration)) {
+ taskManagerRunner.start();
- public TestingTaskManagerRunner(Configuration configuration,
ResourceID resourceId, CompletableFuture<Void> jvmTerminationFuture) throws
Exception {
- super(configuration, resourceId);
- this.jvmTerminationFuture = jvmTerminationFuture;
- }
+ final SystemExitTrackingSecurityManager
systemExitTrackingSecurityManager =
+ runWithSystemExitTracking(() ->
+
taskManagerRunner.getTerminationFuture().get());
Review comment:
shouldn't we call `taskManagerRunner.start();` inside this runnable as well?
If the runnable exits before `runWithSystemExitTracking` is called, will it
still track `exit` calls?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services