chesnokoff commented on code in PR #11615:
URL: https://github.com/apache/ignite/pull/11615#discussion_r1840892701


##########
modules/core/src/test/java/org/apache/ignite/logger/java/JavaLoggerTest.java:
##########
@@ -17,39 +17,110 @@
 
 package org.apache.ignite.logger.java;
 
+import java.io.File;
 import java.util.UUID;
+import java.util.logging.LogManager;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.logger.IgniteLoggerEx;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.LogListener;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.apache.ignite.testframework.junits.common.GridCommonTest;
 import org.junit.Test;
 
-import static org.junit.Assert.assertTrue;
+import static org.apache.ignite.logger.java.JavaLogger.DFLT_CONFIG_PATH;
 
 /**
  * Java logger test.
  */
 @GridCommonTest(group = "Logger")
-public class JavaLoggerTest {
-    /** */
-    @SuppressWarnings({"FieldCanBeLocal"})
-    private IgniteLogger log;
+public class JavaLoggerTest extends GridCommonAbstractTest {
+    /**
+     * Path to jul configuration with DEBUG enabled.
+     */
+    private static final String LOG_CONFIG_DEBUG = 
"modules/core/src/test/config/jul-debug.properties";
+
+    /**
+     * Reset JavaLogger.
+     */
+    @Override protected void afterTest() throws Exception {
+        GridTestUtils.setFieldValue(JavaLogger.class, JavaLogger.class, 
"inited", false);
+    }
+
+
+    /**
+     * Check JavaLogger default constructor.
+     */
+    @Test
+    public void testDefaultConstructorWithDefaultConfig() {
+        IgniteLogger log1 = new JavaLogger();
+        IgniteLogger log2 = log1.getLogger(getClass());
+
+        assertTrue(log1.toString().contains("JavaLogger"));
+        assertTrue(log1.toString().contains(DFLT_CONFIG_PATH));
+
+        assertTrue(log2.toString().contains("JavaLogger"));
+        assertTrue(log2.toString().contains(DFLT_CONFIG_PATH));
+    }
+
+    /**
+     * Check JavaLogger constructor from java.util.logging.config.file 
property.
+     */
+    @Test
+    public void testDefaultConstructorWithProperty() throws Exception {
+        File file = new File(U.getIgniteHome(), LOG_CONFIG_DEBUG);
+        System.setProperty("java.util.logging.config.file", file.getPath());
+        // Call readConfiguration explicitly because Logger.getLogger was 
already called during IgniteUtils initialization
+        LogManager.getLogManager().readConfiguration();
+
+        IgniteLogger log1 = new JavaLogger();
+        assertTrue(log1.toString().contains("JavaLogger"));
+        assertTrue(log1.toString().contains(LOG_CONFIG_DEBUG));
+        assertTrue(log1.isDebugEnabled());
+
+        IgniteLogger log2 = log1.getLogger(getClass());
+        assertTrue(log2.toString().contains("JavaLogger"));
+        assertTrue(log2.toString().contains(LOG_CONFIG_DEBUG));
+        assertTrue(log1.isDebugEnabled());
+
+        System.clearProperty("java.util.logging.config.file");
+    }
+
+    /**
+     * Check Grid logging.
+     */
+    @Test
+    public void testGridLoggingWithDefaultLogger() throws Exception {
+        LogListener lsn = LogListener.matches("JavaLogger [quiet=true,")
+            .andMatches(DFLT_CONFIG_PATH)
+            .build();
+        ListeningTestLogger log = new ListeningTestLogger(new JavaLogger(), 
lsn);
+
+        IgniteConfiguration cfg = 
getConfiguration(getTestIgniteInstanceName());
+        cfg.setGridLogger(log);
+        startGrid(cfg);
+
+        assertTrue(GridTestUtils.waitForCondition(lsn::check, 2_000));

Review Comment:
   I thought the program would log after the execution of `startGrid`. However, 
I've checked it, and the message is actually logged before the execution of 
`startGrid` completes.



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to