diff --git a/distribution/server/src/assemble/LICENSE.bin.txt b/distribution/server/src/assemble/LICENSE.bin.txt index 936528ad8b7e2..d4c8f0a9b2ff4 100644 --- a/distribution/server/src/assemble/LICENSE.bin.txt +++ b/distribution/server/src/assemble/LICENSE.bin.txt @@ -388,11 +388,11 @@ The Apache Software License, Version 2.0 - jakarta.validation-jakarta.validation-api-2.0.2.jar - javax.validation-validation-api-1.1.0.Final.jar * Log4J - - org.apache.logging.log4j-log4j-api-2.17.1.jar - - org.apache.logging.log4j-log4j-core-2.17.1.jar - - org.apache.logging.log4j-log4j-slf4j-impl-2.17.1.jar - - org.apache.logging.log4j-log4j-web-2.17.1.jar - - org.apache.logging.log4j-log4j-1.2-api-2.17.1.jar + - org.apache.logging.log4j-log4j-api-2.18.0.jar + - org.apache.logging.log4j-log4j-core-2.18.0.jar + - org.apache.logging.log4j-log4j-slf4j-impl-2.18.0.jar + - org.apache.logging.log4j-log4j-web-2.18.0.jar + - org.apache.logging.log4j-log4j-1.2-api-2.18.0.jar * Java Native Access JNA -- net.java.dev.jna-jna-4.2.0.jar * BookKeeper - org.apache.bookkeeper-bookkeeper-common-4.12.1.jar diff --git a/pom.xml b/pom.xml index e793d8998b7bf..867afadbf673d 100644 --- a/pom.xml +++ b/pom.xml @@ -111,7 +111,7 @@ flexible messaging model and an intuitive client API. 6.10.2 1.7.25 3.2.2 - 2.17.1 + 2.18.0 1.68 1.0.2 2.11.1 @@ -127,6 +127,7 @@ flexible messaging model and an intuitive client API. 1.18.0 ${grpc.version} 2.8.9 + 1.2.1 0.8.3 2.2.0 3.6.0 @@ -996,6 +997,13 @@ flexible messaging model and an intuitive client API. test + + com.github.stefanbirkner + system-lambda + ${system-lambda.version} + test + + org.powermock powermock-module-testng 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 1fc76b337a5fd..ef4d41ee80cad 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,10 +21,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; - -import java.lang.reflect.Field; -import java.util.Map; - +import com.github.stefanbirkner.systemlambda.SystemLambda; import org.testng.annotations.Test; public class EnvironmentBasedSecretsProviderTest { @@ -32,38 +29,9 @@ 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"); - - Field unmodifiableMapField = getAccessibleField(processEnvironment, "theUnmodifiableEnvironment"); - Object unmodifiableMap = unmodifiableMapField.get(null); - injectIntoUnmodifiableMap(key, value, unmodifiableMap); - - Field mapField = getAccessibleField(processEnvironment, "theEnvironment"); - Map map = (Map) mapField.get(null); - map.put(key, value); - } - - private static Field getAccessibleField(Class clazz, String fieldName) - throws NoSuchFieldException { - - Field field = clazz.getDeclaredField(fieldName); - field.setAccessible(true); - return field; + SystemLambda.withEnvironmentVariable("mySecretName", "SecretValue").execute(() -> { + assertEquals(provider.provideSecret("mySecretName", "Ignored"), "SecretValue"); + }); } - private static void injectIntoUnmodifiableMap(String key, String value, Object map) - throws ReflectiveOperationException { - - Class unmodifiableMap = Class.forName("java.util.Collections$UnmodifiableMap"); - Field field = getAccessibleField(unmodifiableMap, "m"); - Object obj = field.get(map); - ((Map) obj).put(key, value); - } } diff --git a/pulsar-io/flume/src/test/java/org/apache/pulsar/io/flume/node/TestEnvVarResolverProperties.java b/pulsar-io/flume/src/test/java/org/apache/pulsar/io/flume/node/TestEnvVarResolverProperties.java index dc62c2bef70ad..f826da92d801f 100644 --- a/pulsar-io/flume/src/test/java/org/apache/pulsar/io/flume/node/TestEnvVarResolverProperties.java +++ b/pulsar-io/flume/src/test/java/org/apache/pulsar/io/flume/node/TestEnvVarResolverProperties.java @@ -18,16 +18,16 @@ */ package org.apache.pulsar.io.flume.node; -import junit.framework.Assert; +import static org.testng.Assert.assertEquals; +import com.github.stefanbirkner.systemlambda.SystemLambda; +import java.io.File; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.EnvironmentVariables; -import java.io.File; - -public class TestEnvVarResolverProperties { - private static final File TESTFILE = new File( +public final class TestEnvVarResolverProperties { + private static final File TEST_FILE = new File( TestEnvVarResolverProperties.class.getClassLoader() .getResource("flume-conf-with-envvars.properties").getFile()); @@ -36,35 +36,38 @@ public class TestEnvVarResolverProperties { private PropertiesFileConfigurationProvider provider; @Before - public void setUp() throws Exception { - provider = new PropertiesFileConfigurationProvider("a1", TESTFILE); + public void setUp() { + provider = new PropertiesFileConfigurationProvider("a1", TEST_FILE); } @Test public void resolveEnvVar() throws Exception { - environmentVariables.set("VARNAME", "varvalue"); - String resolved = EnvVarResolverProperties.resolveEnvVars("padding ${VARNAME} padding"); - Assert.assertEquals("padding varvalue padding", resolved); + SystemLambda.withEnvironmentVariable("VARNAME", "varvalue").execute(() -> { + String resolved = EnvVarResolverProperties.resolveEnvVars("padding ${VARNAME} padding"); + assertEquals(resolved, "padding varvalue padding"); + }); } @Test public void resolveEnvVars() throws Exception { - environmentVariables.set("VARNAME1", "varvalue1"); - environmentVariables.set("VARNAME2", "varvalue2"); - String resolved = EnvVarResolverProperties - .resolveEnvVars("padding ${VARNAME1} ${VARNAME2} padding"); - Assert.assertEquals("padding varvalue1 varvalue2 padding", resolved); + SystemLambda.withEnvironmentVariable("VARNAME1", "varvalue1") + .and("VARNAME2", "varvalue2") + .execute(() -> { + String resolved = EnvVarResolverProperties.resolveEnvVars( + "padding ${VARNAME1} ${VARNAME2} padding"); + assertEquals(resolved, "padding varvalue1 varvalue2 padding"); + }); } @Test public void getProperty() throws Exception { - String NC_PORT = "6667"; - environmentVariables.set("NC_PORT", NC_PORT); - System.setProperty("propertiesImplementation", - "org.apache.pulsar.io.flume.node.EnvVarResolverProperties"); + SystemLambda.withEnvironmentVariable("NC_PORT", "6667").execute(() -> { + System.setProperty("propertiesImplementation", + "org.apache.pulsar.io.flume.node.EnvVarResolverProperties"); - Assert.assertEquals(NC_PORT, provider.getFlumeConfiguration() - .getConfigurationFor("a1") - .getSourceContext().get("r1").getParameters().get("port")); + assertEquals(provider.getFlumeConfiguration() + .getConfigurationFor("a1") + .getSourceContext().get("r1").getParameters().get("port"), "6667"); + }); } -} +} \ No newline at end of file