Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/trigger_files/beam_PreCommit_Java.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"comment": "Modify this file in a trivial way to cause this test suite to run.",
"modification": 1
"modification": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.security.Permission;
Expand Down Expand Up @@ -211,20 +210,28 @@ private static void restoreEnvironment() throws Exception {
* because Flink's CliFrontend requires a Flink configuration file for which the location can only
* be set using the {@code ConfigConstants.ENV_FLINK_CONF_DIR} environment variable.
*/
@SuppressWarnings("unchecked")
private static void modifyEnv(Map<String, String> env) throws Exception {
Class processEnv = Class.forName("java.lang.ProcessEnvironment");
Field envField = processEnv.getDeclaredField("theUnmodifiableEnvironment");
Class<?> processEnvironment = Class.forName("java.lang.ProcessEnvironment");
Field theEnvironmentField = processEnvironment.getDeclaredField("theEnvironment");
theEnvironmentField.setAccessible(true);
Map<String, String> envMap = (Map<String, String>) theEnvironmentField.get(null);
envMap.clear();
envMap.putAll(env);

Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(envField, envField.getModifiers() & ~Modifier.FINAL);

envField.setAccessible(true);
envField.set(null, env);
envField.setAccessible(false);

modifiersField.setInt(envField, envField.getModifiers() & Modifier.FINAL);
modifiersField.setAccessible(false);
try {
Field theCaseInsensitiveEnvironmentField =
processEnvironment.getDeclaredField("theCaseInsensitiveEnvironment");
theCaseInsensitiveEnvironmentField.setAccessible(true);
Map<String, String> ciEnvMap =
(Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
if (ciEnvMap != null) {
ciEnvMap.clear();
ciEnvMap.putAll(env);
}
} catch (NoSuchFieldException e) {
// theCaseInsensitiveEnvironment is not present on all JDK platforms (e.g. Linux).
}
}

/** Prevents the CliFrontend from calling System.exit. */
Expand Down
16 changes: 16 additions & 0 deletions runners/flink/flink_runner.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,29 @@ if (use_override) {
}
}

def flinkTestJvmArgs() {
def testJavaVer = project.findProperty('testJavaVersion') ? (project.property('testJavaVersion') as int) : JavaVersion.current().majorVersion.toInteger()
if (testJavaVer >= 17) {
return [
"--add-opens=java.base/sun.nio.ch=ALL-UNNAMED",
"--add-opens=java.base/java.nio=ALL-UNNAMED",
"--add-opens=java.base/java.util=ALL-UNNAMED",
"--add-opens=java.base/java.lang.invoke=ALL-UNNAMED",
"--add-opens=java.base/java.lang=ALL-UNNAMED",
]
} else {
return []
}
}

test {
systemProperty "log4j.configuration", "log4j-test.properties"
// Change log level to debug:
// systemProperty "org.slf4j.simpleLogger.defaultLogLevel", "debug"
// Change log level to debug only for the package and nested packages:
// systemProperty "org.slf4j.simpleLogger.log.org.apache.beam.runners.flink.translation.wrappers.streaming", "debug"
jvmArgs "-XX:-UseGCOverheadLimit"
jvmArgs += flinkTestJvmArgs()
if (System.getProperty("beamSurefireArgline")) {
jvmArgs System.getProperty("beamSurefireArgline")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.security.Permission;
Expand Down Expand Up @@ -231,20 +230,28 @@ private static void restoreEnvironment() throws Exception {
* because Flink's CliFrontend requires a Flink configuration file for which the location can only
* be set using the {@code ConfigConstants.ENV_FLINK_CONF_DIR} environment variable.
*/
@SuppressWarnings("unchecked")
private static void modifyEnv(Map<String, String> env) throws Exception {
Class processEnv = Class.forName("java.lang.ProcessEnvironment");
Field envField = processEnv.getDeclaredField("theUnmodifiableEnvironment");
Class<?> processEnvironment = Class.forName("java.lang.ProcessEnvironment");
Field theEnvironmentField = processEnvironment.getDeclaredField("theEnvironment");
theEnvironmentField.setAccessible(true);
Map<String, String> envMap = (Map<String, String>) theEnvironmentField.get(null);
envMap.clear();
envMap.putAll(env);

Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(envField, envField.getModifiers() & ~Modifier.FINAL);

envField.setAccessible(true);
envField.set(null, env);
envField.setAccessible(false);

modifiersField.setInt(envField, envField.getModifiers() & Modifier.FINAL);
modifiersField.setAccessible(false);
try {
Field theCaseInsensitiveEnvironmentField =
processEnvironment.getDeclaredField("theCaseInsensitiveEnvironment");
theCaseInsensitiveEnvironmentField.setAccessible(true);
Map<String, String> ciEnvMap =
(Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
if (ciEnvMap != null) {
ciEnvMap.clear();
ciEnvMap.putAll(env);
}
} catch (NoSuchFieldException e) {
// theCaseInsensitiveEnvironment is not present on all JDK platforms (e.g. Linux).
}
}

/** Prevents the CliFrontend from calling System.exit. */
Expand Down
Loading