vy commented on code in PR #2072:
URL: https://github.com/apache/logging-log4j2/pull/2072#discussion_r1418771714
##########
log4j-jndi-test/src/main/java/org/apache/logging/log4j/jndi/test/junit/JndiRule.java:
##########
@@ -16,42 +16,113 @@
*/
package org.apache.logging.log4j.jndi.test.junit;
+import static java.util.Objects.requireNonNull;
+import static org.junit.Assert.assertNotNull;
+
import java.util.Collections;
+import java.util.Hashtable;
import java.util.Map;
+import java.util.Set;
+import java.util.Spliterators;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import javax.annotation.Nullable;
import javax.naming.Context;
+import javax.naming.NameClassPair;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactoryBuilder;
+import javax.naming.spi.NamingManager;
+import org.apache.logging.log4j.jndi.JndiManager;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
-import org.springframework.mock.jndi.SimpleNamingContextBuilder;
+import org.osjava.sj.jndi.MemoryContext;
/**
* JUnit rule to create a mock {@link Context} and bind an object to a name.
*
* @since 2.8
*/
+@SuppressWarnings("BanJNDI")
public class JndiRule implements TestRule {
- private final Map<String, Object> initialBindings;
+ static {
+ final InitialContextFactoryBuilder factoryBuilder =
+ factoryBuilderEnv -> factoryEnv -> new MemoryContext(new
Hashtable<>()) {};
Review Comment:
`Context` is closeable, and if the underlying implementation doesn't support
re-use after close (as a matter of fact `MemoryContext` indeed doesn't support
reuse), you need a new context at every request.
As a side note, I actually tried reusing it, though bumped into several
blockers.
--
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]