davidradl commented on code in PR #25813:
URL: https://github.com/apache/flink/pull/25813#discussion_r1894005895


##########
flink-core/src/test/java/org/apache/flink/util/MdcUtilsTest.java:
##########
@@ -50,6 +56,19 @@ class MdcUtilsTest {
     public final LoggerAuditingExtension loggerExtension =
             new LoggerAuditingExtension(MdcUtilsTest.class, DEBUG);
 
+    @Test
+    void testContextRestorationWorksWithNullContext() {
+        try (MockedStatic<MDC> mockStatic = Mockito.mockStatic(MDC.class, new 
CallsRealMethods())) {
+            mockStatic.when(MDC::getCopyOfContextMap).thenReturn(null);
+            mockStatic.when(() -> MDC.setContextMap(isNull()))
+                    .thenThrow(NullPointerException.class);
+
+            MdcCloseable restoreContext = 
MdcUtils.withContext(Collections.singletonMap("k", "v"));
+            assertThat(MDC.get("k")).isEqualTo("v");
+            assertDoesNotThrow(restoreContext::close);

Review Comment:
   could we have a test for .clear() also please



-- 
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]

Reply via email to