You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/07/20 16:55:13 UTC

[10/24] incubator-ignite git commit: # ignite-788: copy tests

# ignite-788: copy tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/86b47a04
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/86b47a04
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/86b47a04

Branch: refs/heads/ignite-788-last-review
Commit: 86b47a041d47080d70b3ab2f7fa0a8469b986001
Parents: 6932017
Author: ashutak <as...@gridgain.com>
Authored: Wed Jul 15 19:37:40 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Wed Jul 15 19:37:40 2015 +0300

----------------------------------------------------------------------
 .../log4j2/GridLog4j2CorrectFileNameTest.java   | 134 +++++++++++++++++++
 .../log4j2/GridLog4j2InitializedTest.java       |  54 ++++++++
 .../log4j2/GridLog4j2LoggingFileTest.java       |  59 ++++++++
 .../log4j2/GridLog4j2LoggingPathTest.java       |  52 +++++++
 .../logger/log4j2/GridLog4j2LoggingUrlTest.java |  59 ++++++++
 .../log4j2/GridLog4j2NotInitializedTest.java    |  46 +++++++
 6 files changed, 404 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86b47a04/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2CorrectFileNameTest.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2CorrectFileNameTest.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2CorrectFileNameTest.java
new file mode 100644
index 0000000..4699ab8
--- /dev/null
+++ b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2CorrectFileNameTest.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.logger.log4j2;
+
+import junit.framework.*;
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Tests that several grids log to files with correct names.
+ */
+@GridCommonTest(group = "Logger")
+public class GridLog4j2CorrectFileNameTest extends TestCase {
+    /** Appender */
+    private Log4jRollingFileAppender appender;
+
+    /** {@inheritDoc} */
+    @Override protected void setUp() throws Exception {
+        Logger root = Logger.getRootLogger();
+
+        for (Enumeration appenders = root.getAllAppenders(); appenders.hasMoreElements(); ) {
+            if (appenders.nextElement() instanceof Log4jRollingFileAppender)
+                return;
+        }
+
+        appender = createAppender();
+
+        root.addAppender(appender);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void tearDown() {
+        if (appender != null) {
+            Logger.getRootLogger().removeAppender(Log4jRollingFileAppender.class.getSimpleName());
+
+            Log4JLogger.removeAppender(appender);
+        }
+    }
+
+    /**
+     * Tests correct behaviour in case 2 local nodes are started.
+     *
+     * @throws Exception If error occurs.
+     */
+    public void testLogFilesTwoNodes() throws Exception {
+        checkOneNode(0);
+        checkOneNode(1);
+    }
+
+    /**
+     * Starts the local node and checks for presence of log file.
+     * Also checks that this is really a log of a started node.
+     *
+     * @param id Test-local node ID.
+     * @throws Exception If error occurred.
+     */
+    private void checkOneNode(int id) throws Exception {
+        try (Ignite ignite = G.start(getConfiguration("grid" + id))) {
+            String id8 = U.id8(ignite.cluster().localNode().id());
+            String logPath = "work/log/ignite-" + id8 + ".log";
+            File logFile = U.resolveIgnitePath(logPath);
+
+            assertNotNull("Failed to resolve path: " + logPath, logFile);
+            assertTrue("Log file does not exist: " + logFile, logFile.exists());
+
+            String logContent = U.readFileToString(logFile.getAbsolutePath(), "UTF-8");
+
+            assertTrue("Log file does not contain it's node ID: " + logFile,
+                logContent.contains(">>> Local node [ID=" + id8.toUpperCase()));
+        }
+    }
+
+    /**
+     * Creates grid configuration.
+     *
+     * @param gridName Grid name.
+     * @return Grid configuration.
+     * @throws Exception If error occurred.
+     */
+    private static IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = new IgniteConfiguration();
+
+        cfg.setGridName(gridName);
+        cfg.setGridLogger(new Log4JLogger());
+        cfg.setConnectorConfiguration(null);
+
+        return cfg;
+    }
+
+    /**
+     * Creates new GridLog4jRollingFileAppender.
+     *
+     * @return GridLog4jRollingFileAppender.
+     * @throws Exception If error occurred.
+     */
+    private static Log4jRollingFileAppender createAppender() throws Exception {
+        Log4jRollingFileAppender appender = new Log4jRollingFileAppender();
+
+        appender.setLayout(new PatternLayout("[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"));
+        appender.setFile("work/log/ignite.log");
+        appender.setName(Log4jRollingFileAppender.class.getSimpleName());
+
+        LevelRangeFilter lvlFilter = new LevelRangeFilter();
+
+        lvlFilter.setLevelMin(Level.DEBUG);
+        lvlFilter.setLevelMax(Level.INFO);
+
+        appender.addFilter(lvlFilter);
+
+        return appender;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86b47a04/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2InitializedTest.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2InitializedTest.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2InitializedTest.java
new file mode 100644
index 0000000..107ec38
--- /dev/null
+++ b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2InitializedTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.logger.log4j2;
+
+import junit.framework.*;
+import org.apache.ignite.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+/**
+ * Log4j initialized test.
+ */
+@GridCommonTest(group = "Logger")
+public class GridLog4j2InitializedTest extends TestCase {
+
+    /**
+     * @throws Exception If failed.
+     */
+    @Override protected void setUp() throws Exception {
+        BasicConfigurator.configure();
+    }
+
+    /** */
+    public void testLogInitialize() {
+        IgniteLogger log = new Log4JLogger();
+
+        assert log.isInfoEnabled() == true;
+
+        if (log.isDebugEnabled())
+            log.debug("This is 'debug' message.");
+
+        log.info("This is 'info' message.");
+        log.warning("This is 'warning' message.");
+        log.warning("This is 'warning' message.", new Exception("It's a test warning exception"));
+        log.error("This is 'error' message.");
+        log.error("This is 'error' message.", new Exception("It's a test error exception"));
+
+        assert log.getLogger(GridLog4j2InitializedTest.class.getName()) instanceof Log4JLogger;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86b47a04/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2LoggingFileTest.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2LoggingFileTest.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2LoggingFileTest.java
new file mode 100644
index 0000000..e52e58f
--- /dev/null
+++ b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2LoggingFileTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.logger.log4j2;
+
+import junit.framework.*;
+import org.apache.ignite.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.io.*;
+
+/**
+ * Grid Log4j SPI test.
+ */
+@GridCommonTest(group = "Logger")
+public class GridLog4j2LoggingFileTest extends TestCase {
+    /** */
+    private IgniteLogger log;
+
+    /** {@inheritDoc} */
+    @Override protected void setUp() throws Exception {
+        File xml = GridTestUtils.resolveIgnitePath("modules/core/src/test/config/log4j-test.xml");
+
+        assert xml != null;
+        assert xml.exists() == true;
+
+        log = new Log4JLogger(xml).getLogger(getClass());
+    }
+
+    /**
+     * Tests log4j logging SPI.
+     */
+    public void testLog() {
+        assert log.isDebugEnabled() == true;
+        assert log.isInfoEnabled() == true;
+
+        log.debug("This is 'debug' message.");
+        log.info("This is 'info' message.");
+        log.warning("This is 'warning' message.");
+        log.warning("This is 'warning' message.", new Exception("It's a test warning exception"));
+        log.error("This is 'error' message.");
+        log.error("This is 'error' message.", new Exception("It's a test error exception"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86b47a04/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2LoggingPathTest.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2LoggingPathTest.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2LoggingPathTest.java
new file mode 100644
index 0000000..7477528
--- /dev/null
+++ b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2LoggingPathTest.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.logger.log4j2;
+
+import junit.framework.*;
+import org.apache.ignite.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+/**
+ * Grid Log4j SPI test.
+ */
+@GridCommonTest(group = "Logger")
+public class GridLog4j2LoggingPathTest extends TestCase {
+    /** */
+    private IgniteLogger log;
+
+    /** {@inheritDoc} */
+    @Override protected void setUp() throws Exception {
+        log = new Log4JLogger("modules/core/src/test/config/log4j-test.xml").getLogger(getClass());
+    }
+
+    /**
+     * Tests log4j logging SPI.
+     */
+    public void testLog() {
+        assert log.isInfoEnabled() == true;
+
+        if (log.isDebugEnabled())
+            log.debug("This is 'debug' message.");
+
+        log.info("This is 'info' message.");
+        log.warning("This is 'warning' message.");
+        log.warning("This is 'warning' message.", new Exception("It's a test warning exception"));
+        log.error("This is 'error' message.");
+        log.error("This is 'error' message.", new Exception("It's a test error exception"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86b47a04/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2LoggingUrlTest.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2LoggingUrlTest.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2LoggingUrlTest.java
new file mode 100644
index 0000000..03ff4ba
--- /dev/null
+++ b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2LoggingUrlTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.logger.log4j2;
+
+import junit.framework.*;
+import org.apache.ignite.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.io.*;
+
+/**
+ * Grid Log4j SPI test.
+ */
+@GridCommonTest(group = "Logger")
+public class GridLog4j2LoggingUrlTest extends TestCase {
+    /** */
+    private IgniteLogger log;
+
+    /** {@inheritDoc} */
+    @Override protected void setUp() throws Exception {
+        File xml = GridTestUtils.resolveIgnitePath("modules/core/src/test/config/log4j-test.xml");
+
+        assert xml != null;
+        assert xml.exists();
+
+        log = new Log4JLogger(xml.toURI().toURL()).getLogger(getClass());
+    }
+
+    /**
+     * Tests log4j logging SPI.
+     */
+    public void testLog() {
+        assert log.isDebugEnabled();
+        assert log.isInfoEnabled();
+
+        log.debug("This is 'debug' message.");
+        log.info("This is 'info' message.");
+        log.warning("This is 'warning' message.");
+        log.warning("This is 'warning' message.", new Exception("It's a test warning exception"));
+        log.error("This is 'error' message.");
+        log.error("This is 'error' message.", new Exception("It's a test error exception"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86b47a04/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2NotInitializedTest.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2NotInitializedTest.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2NotInitializedTest.java
new file mode 100644
index 0000000..10bf0a1
--- /dev/null
+++ b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2NotInitializedTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.logger.log4j2;
+
+import junit.framework.*;
+import org.apache.ignite.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+/**
+ * Log4j not initialized test.
+ */
+@GridCommonTest(group = "Logger")
+public class GridLog4j2NotInitializedTest extends TestCase {
+    /** */
+    public void testLogInitialize() {
+        IgniteLogger log = new Log4JLogger().getLogger(GridLog4j2NotInitializedTest.class);
+
+        if (log.isDebugEnabled())
+            log.debug("This is 'debug' message.");
+        else
+            System.out.println("DEBUG level is not enabled.");
+
+        if (log.isInfoEnabled())
+            log.info("This is 'info' message.");
+        else
+            System.out.println("INFO level is not enabled.");
+
+        log.warning("This is 'warning' message.");
+        log.error("This is 'error' message.");
+    }
+}