zentol commented on a change in pull request #15108:
URL: https://github.com/apache/flink/pull/15108#discussion_r594337000



##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/util/FlinkSecurityManagerITCase.java
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.util;
+
+import org.apache.flink.configuration.ClusterOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.security.FlinkSecurityManager;
+import org.apache.flink.runtime.testutils.TestJvmProcess;
+import org.apache.flink.util.OperatingSystem;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeTrue;
+
+/** Integration tests for the {@link 
org.apache.flink.runtime.security.FlinkSecurityManager}. */
+public class FlinkSecurityManagerITCase extends TestLogger {
+
+    @Before
+    public void ensureSupportedOS() {
+        // based on the assumption in JvmExitOnFatalErrorTest, and manual 
testing on Mac, we do not
+        // support all platforms (in particular not Windows)
+        assumeTrue(OperatingSystem.isLinux() || OperatingSystem.isMac());
+    }
+
+    // Test will run forever if JVM exit failed

Review comment:
       ```suggestion
   ```

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/util/FlinkSecurityManagerITCase.java
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.util;
+
+import org.apache.flink.configuration.ClusterOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.security.FlinkSecurityManager;
+import org.apache.flink.runtime.testutils.TestJvmProcess;
+import org.apache.flink.util.OperatingSystem;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeTrue;
+
+/** Integration tests for the {@link 
org.apache.flink.runtime.security.FlinkSecurityManager}. */
+public class FlinkSecurityManagerITCase extends TestLogger {
+
+    @Before
+    public void ensureSupportedOS() {
+        // based on the assumption in JvmExitOnFatalErrorTest, and manual 
testing on Mac, we do not
+        // support all platforms (in particular not Windows)
+        assumeTrue(OperatingSystem.isLinux() || OperatingSystem.isMac());
+    }
+
+    // Test will run forever if JVM exit failed
+    @Test
+    public void testForcedJVMExit() throws Exception {
+        final ForcedJVMExitProcess testProcess =
+                new ForcedJVMExitProcess(ForcedExitEntryPoint.class);
+
+        try {
+            testProcess.startProcess();
+            testProcess.waitFor();
+            assertThat(testProcess.exitCode(), is(222));
+        } finally {
+            testProcess.destroy();
+        }
+    }
+
+    @Test
+    public void testIgnoredJVMExit() throws Exception {
+        final ForcedJVMExitProcess testProcess =
+                new ForcedJVMExitProcess(IgnoredExitEntryPoint.class);
+
+        try {
+            testProcess.startProcess();
+            testProcess.waitFor();
+            assertThat(testProcess.exitCode(), is(0));
+
+        } finally {
+            testProcess.destroy();
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    //  Blocking Process Implementation
+    // ------------------------------------------------------------------------
+
+    private static final class ForcedJVMExitProcess extends TestJvmProcess {
+
+        private final Class<?> entryPointName;
+
+        private ForcedJVMExitProcess(Class<?> entryPointName) throws Exception 
{
+            this.entryPointName = entryPointName;
+        }
+
+        @Override
+        public String getName() {
+            return getEntryPointClassName();
+        }
+
+        @Override
+        public String[] getJvmArgs() {
+            return new String[0];
+        }
+
+        @Override
+        public String getEntryPointClassName() {
+            return entryPointName.getName();
+        }
+    }
+
+    // ------------------------------------------------------------------------
+
+    public static final class ForcedExitEntryPoint {
+
+        public static void main(String[] args) throws Exception {
+            Configuration configuration = new Configuration();
+            // configure FlinkSecurityManager to intercept calls to 
System.exit().
+            configuration.set(
+                    ClusterOptions.INTERCEPT_USER_SYSTEM_EXIT,
+                    ClusterOptions.UserSystemExitMode.THROW);
+            FlinkSecurityManager.setFromConfiguration(configuration);
+
+            FlinkSecurityManager.forceProcessExit(222);
+
+            System.exit(0);
+        }
+    }
+
+    public static final class IgnoredExitEntryPoint {
+
+        public static void main(String[] args) throws Exception {
+            Configuration configuration = new Configuration();
+            // configure FlinkSecurityManager to intercept calls to 
System.exit().
+            configuration.set(
+                    ClusterOptions.INTERCEPT_USER_SYSTEM_EXIT,
+                    ClusterOptions.UserSystemExitMode.THROW);
+            FlinkSecurityManager.setFromConfiguration(configuration);
+
+            FlinkSecurityManager.monitorUserSystemExitForCurrentThread();
+            // expect this call to be ignored
+            try {
+                System.exit(123);
+            } catch (Throwable t) {
+                System.err.println(
+                        "Caught exception during system exit with message: " + 
t.getMessage());
+            }
+
+            System.err.println("Test has passed");

Review comment:
       this can be misleading because it is also printed if System.exit threw 
an exception

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/util/FlinkSecurityManagerITCase.java
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.util;
+
+import org.apache.flink.configuration.ClusterOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.security.FlinkSecurityManager;
+import org.apache.flink.runtime.testutils.TestJvmProcess;
+import org.apache.flink.util.OperatingSystem;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeTrue;
+
+/** Integration tests for the {@link 
org.apache.flink.runtime.security.FlinkSecurityManager}. */
+public class FlinkSecurityManagerITCase extends TestLogger {
+
+    @Before
+    public void ensureSupportedOS() {
+        // based on the assumption in JvmExitOnFatalErrorTest, and manual 
testing on Mac, we do not
+        // support all platforms (in particular not Windows)
+        assumeTrue(OperatingSystem.isLinux() || OperatingSystem.isMac());
+    }
+
+    // Test will run forever if JVM exit failed
+    @Test
+    public void testForcedJVMExit() throws Exception {
+        final ForcedJVMExitProcess testProcess =
+                new ForcedJVMExitProcess(ForcedExitEntryPoint.class);
+
+        try {
+            testProcess.startProcess();
+            testProcess.waitFor();
+            assertThat(testProcess.exitCode(), is(222));
+        } finally {
+            testProcess.destroy();
+        }
+    }
+
+    @Test
+    public void testIgnoredJVMExit() throws Exception {
+        final ForcedJVMExitProcess testProcess =
+                new ForcedJVMExitProcess(IgnoredExitEntryPoint.class);
+
+        try {
+            testProcess.startProcess();
+            testProcess.waitFor();
+            assertThat(testProcess.exitCode(), is(0));
+

Review comment:
       ```suggestion
   ```

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/util/FlinkSecurityManagerITCase.java
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.util;
+
+import org.apache.flink.configuration.ClusterOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.security.FlinkSecurityManager;
+import org.apache.flink.runtime.testutils.TestJvmProcess;
+import org.apache.flink.util.OperatingSystem;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeTrue;
+
+/** Integration tests for the {@link 
org.apache.flink.runtime.security.FlinkSecurityManager}. */
+public class FlinkSecurityManagerITCase extends TestLogger {
+
+    @Before
+    public void ensureSupportedOS() {
+        // based on the assumption in JvmExitOnFatalErrorTest, and manual 
testing on Mac, we do not
+        // support all platforms (in particular not Windows)
+        assumeTrue(OperatingSystem.isLinux() || OperatingSystem.isMac());
+    }
+
+    // Test will run forever if JVM exit failed
+    @Test
+    public void testForcedJVMExit() throws Exception {
+        final ForcedJVMExitProcess testProcess =
+                new ForcedJVMExitProcess(ForcedExitEntryPoint.class);
+
+        try {
+            testProcess.startProcess();
+            testProcess.waitFor();
+            assertThat(testProcess.exitCode(), is(222));
+        } finally {
+            testProcess.destroy();
+        }
+    }
+
+    @Test
+    public void testIgnoredJVMExit() throws Exception {
+        final ForcedJVMExitProcess testProcess =
+                new ForcedJVMExitProcess(IgnoredExitEntryPoint.class);
+
+        try {
+            testProcess.startProcess();
+            testProcess.waitFor();
+            assertThat(testProcess.exitCode(), is(0));
+
+        } finally {
+            testProcess.destroy();
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    //  Blocking Process Implementation

Review comment:
       Outdated since nothing is blocking anymore

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/util/FlinkSecurityManagerITCase.java
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.util;
+
+import org.apache.flink.configuration.ClusterOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.security.FlinkSecurityManager;
+import org.apache.flink.runtime.testutils.TestJvmProcess;
+import org.apache.flink.util.OperatingSystem;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeTrue;
+
+/** Integration tests for the {@link 
org.apache.flink.runtime.security.FlinkSecurityManager}. */
+public class FlinkSecurityManagerITCase extends TestLogger {
+
+    @Before
+    public void ensureSupportedOS() {
+        // based on the assumption in JvmExitOnFatalErrorTest, and manual 
testing on Mac, we do not
+        // support all platforms (in particular not Windows)
+        assumeTrue(OperatingSystem.isLinux() || OperatingSystem.isMac());
+    }
+
+    // Test will run forever if JVM exit failed
+    @Test
+    public void testForcedJVMExit() throws Exception {
+        final ForcedJVMExitProcess testProcess =
+                new ForcedJVMExitProcess(ForcedExitEntryPoint.class);
+
+        try {
+            testProcess.startProcess();
+            testProcess.waitFor();
+            assertThat(testProcess.exitCode(), is(222));
+        } finally {
+            testProcess.destroy();
+        }
+    }
+
+    @Test
+    public void testIgnoredJVMExit() throws Exception {
+        final ForcedJVMExitProcess testProcess =
+                new ForcedJVMExitProcess(IgnoredExitEntryPoint.class);
+
+        try {
+            testProcess.startProcess();

Review comment:
       if this fails then destroy will fail with an IllegalStateException.

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/util/FlinkSecurityManagerITCase.java
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.util;
+
+import org.apache.flink.configuration.ClusterOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.security.FlinkSecurityManager;
+import org.apache.flink.runtime.testutils.TestJvmProcess;
+import org.apache.flink.util.OperatingSystem;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeTrue;
+
+/** Integration tests for the {@link 
org.apache.flink.runtime.security.FlinkSecurityManager}. */

Review comment:
       ```suggestion
   /** Integration tests for the {@link FlinkSecurityManager}. */
   ```




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to