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


##########
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:
   Resolvin as I think the cleanup path is covered by this assertion 
https://github.com/apache/flink/pull/25813/files#diff-79c3e62c398bfa7a3009353c53d75657092a55405ace973682afd6f017aa5404R40



##########
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:
   Resolving as I think the cleanup path is covered by this assertion 
https://github.com/apache/flink/pull/25813/files#diff-79c3e62c398bfa7a3009353c53d75657092a55405ace973682afd6f017aa5404R40



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