TheNeuralBit commented on a change in pull request #13345:
URL: https://github.com/apache/beam/pull/13345#discussion_r524431127
##########
File path:
sdks/java/harness/src/test/java/org/apache/beam/fn/harness/logging/BeamFnLoggingClientTest.java
##########
@@ -146,20 +147,25 @@ public void testLogging() throws Exception {
apiServiceDescriptor,
(Endpoints.ApiServiceDescriptor descriptor) -> channel);
+ // Keep a strong reference to the loggers in this block. Otherwise the
call to client.close()
+ // removes the only reference and the logger may get GC'd (BEAM-4136).
+ Logger rootLogger = LogManager.getLogManager().getLogger("");
+ Logger configuredLogger =
LogManager.getLogManager().getLogger("ConfiguredLogger");
+
// Ensure that log levels were correctly set.
- assertEquals(Level.OFF,
LogManager.getLogManager().getLogger("").getLevel());
- assertEquals(Level.FINE,
LogManager.getLogManager().getLogger("ConfiguredLogger").getLevel());
+ assertEquals(Level.OFF, rootLogger.getLevel());
+ assertEquals(Level.FINE, configuredLogger.getLevel());
// Should be filtered because the default log level override is OFF
- LogManager.getLogManager().getLogger("").log(FILTERED_RECORD);
+ rootLogger.log(FILTERED_RECORD);
// Should not be filtered because the default log level override for
ConfiguredLogger is DEBUG
-
LogManager.getLogManager().getLogger("ConfiguredLogger").log(TEST_RECORD);
-
LogManager.getLogManager().getLogger("ConfiguredLogger").log(TEST_RECORD_WITH_EXCEPTION);
+ configuredLogger.log(TEST_RECORD);
+ configuredLogger.log(TEST_RECORD_WITH_EXCEPTION);
client.close();
// Verify that after close, log levels are reset.
- assertEquals(Level.INFO,
LogManager.getLogManager().getLogger("").getLevel());
-
assertNull(LogManager.getLogManager().getLogger("ConfiguredLogger").getLevel());
+ assertEquals(Level.INFO, rootLogger.getLevel());
+ assertNull(configuredLogger.getLevel());
assertTrue(clientClosedStream.get());
assertTrue(channel.isShutdown());
Review comment:
ok I fixed the other tests as well, PTAL
----------------------------------------------------------------
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]