logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1172052 [2/2] - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core: ./ src/main/java/org/apache/logging/log4j/core/ src/main/java/org/apache/logging/log4j/core/config/ src/main/java/org/apache/logging/log4j/core/filter/ ...
Date Sat, 17 Sep 2011 19:15:58 GMT
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/ReflectionComparison.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/ReflectionComparison.java?rev=1172052&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/ReflectionComparison.java
(added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/ReflectionComparison.java
Sat Sep 17 19:15:56 2011
@@ -0,0 +1,98 @@
+/*
+ * 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;
+
+import org.apache.logging.log4j.core.Timer;
+import org.apache.logging.log4j.core.helpers.Loader;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import sun.reflect.Reflection;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests the cost of invoking Reflection.getCallerClass via reflection vs calling it directly.
+ */
+public class ReflectionComparison {
+
+    private static Method getCallerClass;
+
+    private static final int COUNT = 1000000;
+
+    @BeforeClass
+    public static void setupCallerCheck() {
+        try {
+            ClassLoader loader = Loader.getClassLoader();
+            Class clazz = loader.loadClass("sun.reflect.Reflection");
+            Method[] methods = clazz.getMethods();
+            for (Method method : methods) {
+                int modifier = method.getModifiers();
+                if (method.getName().equals("getCallerClass") && Modifier.isStatic(modifier))
{
+                    getCallerClass = method;
+                    break;
+                }
+            }
+        } catch (ClassNotFoundException cnfe) {
+            cnfe.printStackTrace();
+            throw  new RuntimeException(cnfe);
+        }
+    }
+
+    @Test
+    public void test1() {
+        Timer timer = new Timer("Reflection", COUNT);
+        timer.start();
+        Object[] arr = new Object[1];
+        arr[0] = 3;
+        for (int i= 0; i < COUNT; ++i) {
+            getCallerClass(arr);
+        }
+        timer.stop();
+        System.out.println(timer.toString());
+    }
+
+
+    @Test
+    public void test2() {
+        Timer timer = new Timer("Reflection", COUNT);
+        timer.start();
+        for (int i= 0; i < COUNT; ++i) {
+
+            Reflection.getCallerClass(3);
+        }
+        timer.stop();
+        System.out.println(timer.toString());
+    }
+
+    private Class getCallerClass(Object[] array) {
+        if (getCallerClass != null) {
+            try {
+                /*Object[] params = new Object[]{index}; */
+                return (Class) getCallerClass.invoke(null, array);
+            } catch (Exception ex) {
+                fail(ex.getMessage());
+                // logger.debug("Unable to determine caller class via Sun Reflection", ex);
+            }
+        }
+        return null;
+    }
+
+}

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java?rev=1172052&r1=1172051&r2=1172052&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java
Sat Sep 17 19:15:56 2011
@@ -17,9 +17,8 @@
 package org.apache.logging.log4j.core.appender;
 
 import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.ThreadContext;
 import org.apache.logging.log4j.core.Layout;
-import org.apache.logging.log4j.core.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.layout.PatternLayout;
 import org.apache.logging.log4j.message.SimpleMessage;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java?rev=1172052&r1=1172051&r2=1172052&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java
Sat Sep 17 19:15:56 2011
@@ -18,7 +18,7 @@ package org.apache.logging.log4j.core.ap
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Layout;
-import org.apache.logging.log4j.core.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.layout.PatternLayout;
 import org.apache.logging.log4j.message.SimpleMessage;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilterTest.java?rev=1172052&r1=1172051&r2=1172052&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilterTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilterTest.java
Sat Sep 17 19:15:56 2011
@@ -19,7 +19,7 @@ package org.apache.logging.log4j.core.fi
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.ThreadContext;
 import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.junit.Test;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/MarkerFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/MarkerFilterTest.java?rev=1172052&r1=1172051&r2=1172052&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/MarkerFilterTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/MarkerFilterTest.java
Sat Sep 17 19:15:56 2011
@@ -20,7 +20,7 @@ import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.MarkerManager;
 import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.junit.Test;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java?rev=1172052&r1=1172051&r2=1172052&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java
Sat Sep 17 19:15:56 2011
@@ -18,7 +18,7 @@ package org.apache.logging.log4j.core.fi
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.junit.Test;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThresholdFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThresholdFilterTest.java?rev=1172052&r1=1172051&r2=1172052&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThresholdFilterTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThresholdFilterTest.java
Sat Sep 17 19:15:56 2011
@@ -18,7 +18,7 @@ package org.apache.logging.log4j.core.fi
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.junit.Test;
@@ -41,7 +41,7 @@ public class ThresholdFilterTest {
         assertTrue(filter.filter(null, Level.ERROR, null, null, (Throwable)null) == Filter.Result.NEUTRAL);
         LogEvent event = new Log4jLogEvent(null, null, null, Level.DEBUG, new SimpleMessage("Test"),
null);
         assertTrue(filter.filter(event) == Filter.Result.DENY);
-        event = new Log4jLogEvent(null, null, null, Level.ERROR, new SimpleMessage("Test"),
null);        
+        event = new Log4jLogEvent(null, null, null, Level.ERROR, new SimpleMessage("Test"),
null);
         assertTrue(filter.filter(event) == Filter.Result.NEUTRAL);
     }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/TimeFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/TimeFilterTest.java?rev=1172052&r1=1172051&r2=1172052&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/TimeFilterTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/TimeFilterTest.java
Sat Sep 17 19:15:56 2011
@@ -18,9 +18,8 @@ package org.apache.logging.log4j.core.fi
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.message.SimpleMessage;
 import org.junit.Test;
 
 import java.util.Calendar;

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverterTest.java
(from r1147720, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverterTest.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverterTest.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java&r1=1147720&r2=1172052&rev=1172052&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverterTest.java
Sat Sep 17 19:15:56 2011
@@ -16,63 +16,51 @@
  */
 package org.apache.logging.log4j.core.pattern;
 
+import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.Logger;
-
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.message.SimpleMessage;
 import org.junit.Before;
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.util.List;
 
+import static org.junit.Assert.*;
+
 /**
  *
  */
-public class PatternParserTest {
+public class ExtendedThrowablePatternConverterTest {
 
-    static String OUTPUT_FILE   = "output/PatternParser";
-    static String WITNESS_FILE  = "witness/PatternParser";
-    LoggerContext ctx = (LoggerContext) LogManager.getContext();
-    Logger root = ctx.getLogger("");
-
-    private static String msgPattern = "%m%n";
-    private String mdcMsgPattern1 = "%m : %X%n";
-    private String mdcMsgPattern2 = "%m : %X{key1}%n";
-    private String mdcMsgPattern3 = "%m : %X{key2}%n";
-    private String mdcMsgPattern4 = "%m : %X{key3}%n";
-    private String mdcMsgPattern5 = "%m : %X{key1},%X{key2},%X{key3}%n";
 
 
-    private static final String KEY = "Converter";
-    private PatternParser parser;
-
     @Before
     public void setup() {
-        parser = new PatternParser(KEY);
-    }
 
-    private void validateConverter(List<PatternConverter> converters, int index, String
name) {
-        PatternConverter pc = converters.get(index);
-        assertEquals("Incorrect converter " + pc.getName() + " at index " + index + " expected
" + name,
-            pc.getName(), name);
     }
 
-    /**
-     * Test the default pattern
-     */
     @Test
-    public void defaultPattern() {
-        List<PatternConverter> converters = parser.parse(msgPattern);
-        assertNotNull(converters);
-        assertTrue(converters.size() == 2);
-        validateConverter(converters, 0, "Message");
-        validateConverter(converters, 1, "Line Sep");
+    public void testFull() {
+        ExtendedThrowablePatternConverter converter = ExtendedThrowablePatternConverter.newInstance(null);
+        Throwable cause = new NullPointerException("null pointer");
+        Throwable parent = new IllegalArgumentException("IllegalArgument", cause);
+        LogEvent event = new Log4jLogEvent("testLogger", null, this.getClass().getName(),
Level.DEBUG,
+            new SimpleMessage("test exception"), parent);
+        StringBuilder sb = new StringBuilder();
+        converter.format(event, sb);
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+        parent.printStackTrace(pw);
+        String result = sb.toString();
+        //System.out.print(result);
+        result = result.replaceAll(" ~?\\[.*\\]", "");
+        assertEquals(sw.toString(), result);
     }
-
-
 }



Mime
View raw message