tisonkun commented on PR #16884:
URL: https://github.com/apache/pulsar/pull/16884#issuecomment-1201512995
Well. I fixed this issue locally. Here is a patch you can make use of:
```patch
diff --git a/pom.xml b/pom.xml
index a6ce94fe734..2d093f1f1eb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -95,7 +95,8 @@ flexible messaging model and an intuitive client
API.</description>
<test.additional.args>
--add-opens java.base/jdk.internal.loader=ALL-UNNAMED
--add-opens java.base/java.lang=ALL-UNNAMED <!--Mockito-->
- --add-opens java.base/java.io=ALL-UNNAMED <!--Bookkeeper NativeIO -->
+ --add-opens java.base/java.io=ALL-UNNAMED <!--Bookkeeper NativeIO-->
+ --add-opens java.base/java.util=ALL-UNNAMED <!--System Lambda-->
--add-opens java.base/sun.net=ALL-UNNAMED <!--netty.DnsResolverUtil-->
--add-opens java.management/sun.management=ALL-UNNAMED
<!--JvmDefaultGCMetricsLogger-->
</test.additional.args>
@@ -1294,6 +1295,13 @@ flexible messaging model and an intuitive client
API.</description>
</dependencyManagement>
<dependencies>
+ <dependency>
+ <groupId>com.github.stefanbirkner</groupId>
+ <artifactId>system-lambda</artifactId>
+ <version>1.2.1</version>
+ <scope>test</scope>
+ </dependency>
+
<!-- These dependencies are common to all the submodules -->
<dependency>
<groupId>org.apache.pulsar</groupId>
diff --git
a/pulsar-functions/secrets/src/test/java/org/apache/pulsar/functions/secretsprovider/EnvironmentBasedSecretsProviderTest.java
b/pulsar-functions/secrets/src/test/java/org/apache/pulsar/functions/secretsprovider/EnvironmentBasedSecretsProviderTest.java
index 8dbc880fa16..22ef2dd9e60 100644
---
a/pulsar-functions/secrets/src/test/java/org/apache/pulsar/functions/secretsprovider/EnvironmentBasedSecretsProviderTest.java
+++
b/pulsar-functions/secrets/src/test/java/org/apache/pulsar/functions/secretsprovider/EnvironmentBasedSecretsProviderTest.java
@@ -21,11 +21,7 @@ package org.apache.pulsar.functions.secretsprovider;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.powermock.reflect.Whitebox;
+import com.github.stefanbirkner.systemlambda.SystemLambda;
import org.testng.annotations.Test;
public class EnvironmentBasedSecretsProviderTest {
@@ -33,22 +29,8 @@ public class EnvironmentBasedSecretsProviderTest {
public void testConfigValidation() throws Exception {
EnvironmentBasedSecretsProvider provider = new
EnvironmentBasedSecretsProvider();
assertNull(provider.provideSecret("mySecretName", "Ignored"));
- injectEnvironmentVariable("mySecretName", "SecretValue");
- assertEquals(provider.provideSecret("mySecretName", "Ignored"),
"SecretValue");
- }
-
- private static void injectEnvironmentVariable(String key, String value)
- throws Exception {
-
- Class<?> processEnvironment =
Class.forName("java.lang.ProcessEnvironment");
- Map<String,String> unmodifiableMap = new HashMap<>(Whitebox
- .getInternalState(processEnvironment,
"theUnmodifiableEnvironment"));
- unmodifiableMap.put(key, value);
- Whitebox.setInternalState(processEnvironment,
"theUnmodifiableEnvironment", unmodifiableMap);
-
- Map<String,String> envMap = new HashMap<>(Whitebox
- .getInternalState(processEnvironment, "theEnvironment"));
- envMap.put(key, value);
- Whitebox.setInternalState(processEnvironment, "theEnvironment",
envMap);
+ SystemLambda.withEnvironmentVariable("mySecretName",
"SecretValue").execute(() -> {
+ assertEquals(provider.provideSecret("mySecretName", "Ignored"),
"SecretValue");
+ });
}
}
```
I guess the reason is that `Whitebox` failed to set the unmodifiableMap with
log4j2 2.18.0 while I don't have an idea how it happens.
I don't like powermock as it's lack of maintenance. It seems all usage of
powermock is `Whitebox`. We can get rid of it with simple reflections. This can
be a separated issue, though.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]