You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/04/18 15:40:40 UTC

[1/2] logging-log4j2 git commit: LOG4J2-1334 MutableLogEvent unit tests

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 23b1395a2 -> ea6e1808b


LOG4J2-1334 MutableLogEvent unit tests


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d557c8ee
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d557c8ee
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d557c8ee

Branch: refs/heads/master
Commit: d557c8ee4bae4f501fa558238fc0e693f007a203
Parents: 3c37ca3
Author: rpopma <rp...@apache.org>
Authored: Mon Apr 18 22:37:00 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Mon Apr 18 22:37:00 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/impl/MutableLogEvent.java        |  16 ++
 .../log4j/core/impl/MutableLogEventTest.java    | 198 ++++++++++++++++++-
 2 files changed, 211 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d557c8ee/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
index 9edb6f2..b619615 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
@@ -1,3 +1,19 @@
+/*
+ * 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.logging.log4j.core.impl;
 
 import java.io.InvalidObjectException;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d557c8ee/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
index 23a49f4..40e13e8 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
@@ -1,4 +1,4 @@
-package org.apache.logging.log4j.core.impl;/*
+/*
  * 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.
@@ -15,17 +15,24 @@ package org.apache.logging.log4j.core.impl;/*
  * limitations under the license.
  */
 
+package org.apache.logging.log4j.core.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.MarkerManager;
 import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.message.ParameterizedMessage;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.spi.MutableThreadContextStack;
+import org.apache.logging.log4j.util.Strings;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
@@ -83,4 +90,189 @@ public class MutableLogEventTest {
         assertEquals("proxy", source.getThrownProxy(), mutable.getThrownProxy());
         assertEquals("millis", source.getTimeMillis(), mutable.getTimeMillis());
     }
+
+    @Test
+    public void testClear() {
+        MutableLogEvent mutable = new MutableLogEvent();
+        assertNull("context map", mutable.getContextMap());
+        assertNull("context stack", mutable.getContextStack());
+        assertFalse("end of batch", mutable.isEndOfBatch());
+        assertFalse("incl loc", mutable.isIncludeLocation());
+        assertNull("level", mutable.getLevel());
+        assertNull("fqcn", mutable.getLoggerFqcn());
+        assertNull("logger", mutable.getLoggerName());
+        assertNull("marker", mutable.getMarker());
+        assertEquals("msg", new SimpleMessage(Strings.EMPTY), mutable.getMessage());
+        assertEquals("nanoTm", 0, mutable.getNanoTime());
+        assertEquals("tid", 0, mutable.getThreadId());
+        assertNull("tname", mutable.getThreadName());
+        assertEquals("tpriority", 0, mutable.getThreadPriority());
+        assertNull("thrwn", mutable.getThrown());
+        assertEquals("timeMs", 0, mutable.getTimeMillis());
+
+        assertNull("source", mutable.getSource());
+        assertNull("thrownProxy", mutable.getThrownProxy());
+
+        mutable.setContextMap(CONTEXTMAP);
+        mutable.setContextStack(STACK);
+        mutable.setEndOfBatch(true);
+        mutable.setIncludeLocation(true);
+        mutable.setLevel(Level.WARN);
+        mutable.setLoggerFqcn(getClass().getName());
+        mutable.setLoggerName("loggername");
+        mutable.setMarker(MarkerManager.getMarker("marked man"));
+        mutable.setMessage(new ParameterizedMessage("message in a {}", "bottle"));
+        mutable.setNanoTime(1234);
+        mutable.setThreadId(987);
+        mutable.setThreadName("ito");
+        mutable.setThreadPriority(9);
+        mutable.setThrown(new Exception());
+        mutable.setTimeMillis(56789);
+
+        assertNotNull("context map", mutable.getContextMap());
+        assertNotNull("context stack", mutable.getContextStack());
+        assertTrue("end of batch", mutable.isEndOfBatch());
+        assertTrue("incl loc", mutable.isIncludeLocation());
+        assertNotNull("level", mutable.getLevel());
+        assertNotNull("fqcn", mutable.getLoggerFqcn());
+        assertNotNull("logger", mutable.getLoggerName());
+        assertNotNull("marker", mutable.getMarker());
+        assertEquals("msg", new ParameterizedMessage("message in a {}", "bottle"), mutable.getMessage());
+        assertNotEquals("nanoTm", 0, mutable.getNanoTime());
+        assertNotEquals("tid", 0, mutable.getThreadId());
+        assertNotNull("tname", mutable.getThreadName());
+        assertNotEquals("tpriority", 0, mutable.getThreadPriority());
+        assertNotNull("thrwn", mutable.getThrown());
+        assertNotEquals("timeMs", 0, mutable.getTimeMillis());
+
+        assertNotNull("source", mutable.getSource());
+        assertNotNull("thrownProxy", mutable.getThrownProxy());
+
+        mutable.clear();
+        assertNull("context map", mutable.getContextMap());
+        assertNull("context stack", mutable.getContextStack());
+        assertNull("level", mutable.getLevel());
+        assertNull("fqcn", mutable.getLoggerFqcn());
+        assertNull("logger", mutable.getLoggerName());
+        assertNull("marker", mutable.getMarker());
+        assertEquals("msg", new SimpleMessage(Strings.EMPTY), mutable.getMessage());
+        assertNull("thrwn", mutable.getThrown());
+
+        assertNull("source", mutable.getSource());
+        assertNull("thrownProxy", mutable.getThrownProxy());
+
+        // primitive fields are NOT reset:
+        assertTrue("end of batch", mutable.isEndOfBatch());
+        assertTrue("incl loc", mutable.isIncludeLocation());
+        assertNotEquals("nanoTm", 0, mutable.getNanoTime());
+        assertNotEquals("timeMs", 0, mutable.getTimeMillis());
+
+        // thread-local fields are NOT reset:
+        assertNotEquals("tid", 0, mutable.getThreadId());
+        assertNotNull("tname", mutable.getThreadName());
+        assertNotEquals("tpriority", 0, mutable.getThreadPriority());
+    }
+
+    @Test
+    public void testJavaIoSerializable() throws Exception {
+        MutableLogEvent evt = new MutableLogEvent();
+        evt.setContextMap(CONTEXTMAP);
+        evt.setContextStack(STACK);
+        evt.setEndOfBatch(true);
+        evt.setIncludeLocation(true);
+        evt.setLevel(Level.WARN);
+        evt.setLoggerFqcn(getClass().getName());
+        evt.setLoggerName("loggername");
+        evt.setMarker(MarkerManager.getMarker("marked man"));
+        //evt.setMessage(new ParameterizedMessage("message in a {}", "bottle")); // TODO ParameterizedMessage serialization
+        evt.setMessage(new SimpleMessage("peace for all"));
+        evt.setNanoTime(1234);
+        evt.setThreadId(987);
+        evt.setThreadName("ito");
+        evt.setThreadPriority(9);
+        evt.setTimeMillis(56789);
+
+        final byte[] binary = serialize(evt);
+        final Log4jLogEvent evt2 = deserialize(binary);
+
+        assertEquals(evt.getTimeMillis(), evt2.getTimeMillis());
+        assertEquals(evt.getLoggerFqcn(), evt2.getLoggerFqcn());
+        assertEquals(evt.getLevel(), evt2.getLevel());
+        assertEquals(evt.getLoggerName(), evt2.getLoggerName());
+        assertEquals(evt.getMarker(), evt2.getMarker());
+        assertEquals(evt.getContextMap(), evt2.getContextMap());
+        assertEquals(evt.getContextStack(), evt2.getContextStack());
+        assertEquals(evt.getMessage(), evt2.getMessage());
+        assertNotNull(evt2.getSource());
+        assertEquals(evt.getSource(), evt2.getSource());
+        assertEquals(evt.getThreadName(), evt2.getThreadName());
+        assertNull(evt2.getThrown());
+        assertNull(evt2.getThrownProxy());
+        assertEquals(evt.isEndOfBatch(), evt2.isEndOfBatch());
+        assertEquals(evt.isIncludeLocation(), evt2.isIncludeLocation());
+
+        assertNotEquals(evt.getNanoTime(), evt2.getNanoTime()); // nano time is transient in log4j log event
+        assertEquals(0, evt2.getNanoTime());
+    }
+
+    @Test
+    public void testJavaIoSerializableWithThrown() throws Exception {
+        final Error thrown = new InternalError("test error");
+        MutableLogEvent evt = new MutableLogEvent();
+        evt.setContextMap(CONTEXTMAP);
+        evt.setContextStack(STACK);
+        evt.setEndOfBatch(true);
+        evt.setIncludeLocation(true);
+        evt.setLevel(Level.WARN);
+        evt.setLoggerFqcn(getClass().getName());
+        evt.setLoggerName("loggername");
+        evt.setMarker(MarkerManager.getMarker("marked man"));
+        //evt.setMessage(new ParameterizedMessage("message in a {}", "bottle")); // TODO ParameterizedMessage serialization
+        evt.setMessage(new SimpleMessage("peace for all"));
+        evt.setNanoTime(1234);
+        evt.setThreadId(987);
+        evt.setThreadName("ito");
+        evt.setThreadPriority(9);
+        evt.setThrown(new Exception());
+        evt.setTimeMillis(56789);
+
+        final byte[] binary = serialize(evt);
+        final Log4jLogEvent evt2 = deserialize(binary);
+
+        assertEquals(evt.getTimeMillis(), evt2.getTimeMillis());
+        assertEquals(evt.getLoggerFqcn(), evt2.getLoggerFqcn());
+        assertEquals(evt.getLevel(), evt2.getLevel());
+        assertEquals(evt.getLoggerName(), evt2.getLoggerName());
+        assertEquals(evt.getMarker(), evt2.getMarker());
+        assertEquals(evt.getContextMap(), evt2.getContextMap());
+        assertEquals(evt.getContextStack(), evt2.getContextStack());
+        assertEquals(evt.getMessage(), evt2.getMessage());
+        assertNotNull(evt2.getSource());
+        assertEquals(evt.getSource(), evt2.getSource());
+        assertEquals(evt.getThreadName(), evt2.getThreadName());
+        assertNull(evt2.getThrown());
+        assertNotNull(evt2.getThrownProxy());
+        assertEquals(evt.getThrownProxy(), evt2.getThrownProxy());
+        assertEquals(evt.isEndOfBatch(), evt2.isEndOfBatch());
+        assertEquals(evt.isIncludeLocation(), evt2.isIncludeLocation());
+
+        assertNotEquals(evt.getNanoTime(), evt2.getNanoTime()); // nano time is transient in log4j log event
+        assertEquals(0, evt2.getNanoTime());
+    }
+
+    private byte[] serialize(final MutableLogEvent event) throws IOException {
+        final ByteArrayOutputStream arr = new ByteArrayOutputStream();
+        final ObjectOutputStream out = new ObjectOutputStream(arr);
+        out.writeObject(event);
+        return arr.toByteArray();
+    }
+
+    private Log4jLogEvent deserialize(final byte[] binary) throws IOException, ClassNotFoundException {
+        final ByteArrayInputStream inArr = new ByteArrayInputStream(binary);
+        final ObjectInputStream in = new ObjectInputStream(inArr);
+        final Log4jLogEvent result = (Log4jLogEvent) in.readObject();
+        return result;
+    }
+
+
 }
\ No newline at end of file


[2/2] logging-log4j2 git commit: Merge remote-tracking branch 'origin/master'

Posted by rp...@apache.org.
Merge remote-tracking branch 'origin/master'

Conflicts:
	log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/ea6e1808
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ea6e1808
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ea6e1808

Branch: refs/heads/master
Commit: ea6e1808b57a133a7fd802522769bacd169c5a3f
Parents: d557c8e 23b1395
Author: rpopma <rp...@apache.org>
Authored: Mon Apr 18 22:39:47 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Mon Apr 18 22:39:47 2016 +0900

----------------------------------------------------------------------
 .../message/ReusableParameterizedMessage.java   |   2 +-
 .../log4j/message/ReusableSimpleMessage.java    |  20 +-
 .../logging/log4j/message/SimpleMessage.java    |  23 +-
 .../org/apache/logging/log4j/util/Strings.java  |  12 +
 .../org/apache/logging/log4j/util/Unbox.java    |   2 -
 .../logging/log4j/AbstractLoggerTest.java       |   6 +-
 .../log4j/message/ParameterFormatterTest.java   |   2 -
 .../apache/logging/log4j/util/UnboxTest.java    |   2 +
 .../core/appender/MemoryMappedFileManager.java  |   3 +-
 .../core/appender/RandomAccessFileManager.java  |   3 +-
 .../RollingRandomAccessFileAppender.java        |   2 +-
 .../core/appender/rolling/PatternProcessor.java |   1 +
 .../rolling/RollingRandomAccessFileManager.java |   3 +-
 .../appender/rolling/action/DeleteAction.java   | 432 +++++-----
 .../core/async/AsyncEventRouterFactory.java     |   2 -
 .../log4j/core/async/RingBufferLogEvent.java    |  30 +-
 .../logging/log4j/core/impl/Log4jLogEvent.java  |   3 +-
 .../log4j/core/jackson/Log4jYamlModule.java     |  48 ++
 .../core/jackson/Log4jYamlObjectMapper.java     |  41 +
 .../log4j/core/layout/CsvLogEventLayout.java    | 213 +++--
 .../log4j/core/layout/CsvParameterLayout.java   | 207 +++--
 .../logging/log4j/core/layout/GelfLayout.java   |  13 +-
 .../log4j/core/layout/JacksonFactory.java       |  34 +
 .../logging/log4j/core/layout/YamlLayout.java   | 824 +++++++++++++++++++
 .../log4j/core/net/server/TcpSocketServer.java  |  19 +-
 .../core/pattern/DatePatternConverter.java      |   3 +-
 .../ExtendedThrowablePatternConverter.java      |   1 -
 .../pattern/RootThrowablePatternConverter.java  |   1 -
 .../logging/log4j/MarkerMixInYamlTest.java      |  31 +
 .../log4j/core/AppenderRefLevelJsonTest.java    |  12 +-
 .../log4j/core/AppenderRefLevelTest.java        |  12 +-
 .../log4j/core/GcFreeLoggingTestUtil.java       |   1 +
 .../core/GcFreeMixedSyncAyncLoggingTest.java    |  15 -
 .../core/GcFreeSynchronousLoggingTest.java      |  16 -
 .../apache/logging/log4j/core/LoggerTest.java   |  12 +-
 .../logging/log4j/core/LoggerUpdateTest.java    |   4 +-
 .../logging/log4j/core/PatternSelectorTest.java |  12 +-
 .../logging/log4j/core/StrictXmlConfigTest.java |  13 +-
 .../log4j/core/TimestampMessageTest.java        |   3 +-
 .../appender/JsonCompleteFileAppenderTest.java  |   2 +-
 .../log4j/core/appender/SocketAppenderTest.java |   2 +-
 .../async/AsyncLoggerTimestampMessageTest.java  |   3 +-
 .../core/async/perftest/SimpleLatencyTest.java  |   1 +
 .../core/filter/AbstractScriptFilterTest.java   |   4 +-
 .../log4j/core/jackson/LevelMixInJsonTest.java  |   1 +
 .../log4j/core/jackson/LevelMixInYamlTest.java  |  29 +
 .../jackson/StackTraceElementMixInTest.java     |   5 +
 .../log4j/core/layout/YamlLayoutTest.java       | 287 +++++++
 .../resources/JsonCompleteFileAppenderTest.xml  |   4 +-
 .../appender/NoSqlDatabaseManagerTest.java      |  26 +-
 .../message/ParameterFormatterBenchmark.java    |   2 -
 .../log4j/perf/jmh/CollectionsBenchmark.java    |  12 +-
 .../log4j/perf/jmh/LoggerConfigBenchmark.java   |   2 +-
 .../logging/log4j/perf/jmh/SimpleBenchmark.java |   5 +-
 .../perf/jmh/TextEncoderHelperBenchmark.java    |   2 +-
 ...ThreadLocalVsConcurrentHashMapBenchmark.java | 186 ++---
 .../logging/log4j/perf/nogc/NoGcLayout.java     |   1 -
 .../logging/log4j/lookup/CustomLookup.java      |   3 +-
 .../logging/log4j/lookup/MapMessageLookup.java  |   6 +-
 .../org/apache/logging/slf4j/LoggerTest.java    | 360 ++++----
 .../log4j/web/ServletRequestThreadContext.java  |  29 +
 src/changes/changes.xml                         |   6 +
 src/site/site.xml                               |   1 +
 src/site/xdoc/manual/layouts.xml.vm             | 151 ++++
 64 files changed, 2381 insertions(+), 832 deletions(-)
----------------------------------------------------------------------