logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1334558 - in /logging/log4j/log4j2/trunk/core/src/test: java/org/apache/logging/log4j/core/ThreadedTest.java resources/log4j-threaded.xml
Date Sun, 06 May 2012 05:35:47 GMT
Author: rgoers
Date: Sun May  6 05:35:47 2012
New Revision: 1334558

URL: http://svn.apache.org/viewvc?rev=1334558&view=rev
Log:
Add test for log4j 1.2 bug 24159

Added:
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/ThreadedTest.java
      - copied, changed from r1332056, logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/ThreadedPerfTest.java
    logging/log4j/log4j2/trunk/core/src/test/resources/log4j-threaded.xml

Copied: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/ThreadedTest.java
(from r1332056, logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/ThreadedPerfTest.java)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/ThreadedTest.java?p2=logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/ThreadedTest.java&p1=logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/ThreadedPerfTest.java&r1=1332056&r2=1334558&rev=1334558&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/ThreadedPerfTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/ThreadedTest.java
Sun May  6 05:35:47 2012
@@ -16,9 +16,14 @@
  */
 package org.apache.logging.log4j.core;
 
-import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.XMLConfigurationFactory;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import java.util.concurrent.ExecutorService;
@@ -27,54 +32,82 @@ import java.util.concurrent.Executors;
 /**
  *
  */
-public class ThreadedPerfTest {
-
-    private static org.apache.logging.log4j.Logger logger = LogManager.getLogger(ThreadedPerfTest.class.getName());
+public class ThreadedTest {
+    private static final String CONFIG = "log4j-threaded.xml";
+    private Logger logger = LogManager.getLogger(ThreadedTest.class.getName());
     private volatile Level lvl = Level.DEBUG;
-    private static final int LOOP_CNT = 10000000;
-    private static final int THREADS = 10;     
+    private static final int LOOP_CNT = 25;
+    private static final int THREADS = 4;
+    private static int counter = 0;
+
+    @BeforeClass
+    public static void setupClass() {
+        System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+        LoggerContext ctx = (LoggerContext) LogManager.getContext();
+        Configuration config = ctx.getConfiguration();
+    }
 
-    @Test
-    public void debugDisabled() {
-        Timer timer = new Timer("DebugDisabled", LOOP_CNT * THREADS);
-        Runnable runnable = new DebugDisabledRunnable();
-        ExecutorService pool = Executors.newFixedThreadPool(THREADS);
-        timer.start();
-        for (int i=0; i < THREADS; ++i) {
-            pool.execute(runnable);
-        }
-        pool.shutdown();
-        timer.stop();
-        System.out.println(timer.toString());
+    @AfterClass
+    public static void cleanupClass() {
+        System.clearProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+        LoggerContext ctx = (LoggerContext) LogManager.getContext();
+        ctx.reconfigure();
+        StatusLogger.getLogger().reset();
     }
 
     @Test
-    public void debugLogger() {
-        Timer timer = new Timer("DebugLogger", LOOP_CNT * THREADS);
-        Runnable runnable = new DebugLoggerRunnable();
-        ExecutorService pool = Executors.newFixedThreadPool(THREADS);
-        timer.start();
-        for (int i=0; i < THREADS; ++i) {
-            pool.execute(runnable);
+    public void testDeadlock() throws Exception {
+        ExecutorService pool = Executors.newFixedThreadPool(THREADS * 2);
+        State state = new State();
+        for (int count=0; count < THREADS; ++count) {
+            pool.execute(new LoggingRunnable(state));
+            pool.execute(new StateSettingRunnable(state));
         }
+        Thread.sleep(250);
         pool.shutdown();
-        timer.stop();
-        System.out.println(timer.toString());
+        System.out.println("Counter = " + counter);
     }
 
-    public class DebugDisabledRunnable implements Runnable {
+    public class LoggingRunnable implements Runnable {
+        private State state;
+
+        public LoggingRunnable(State state) {
+            this.state = state;
+        }
         public void run() {
             for (int i=0; i < LOOP_CNT; ++i) {
-                logger.isDebugEnabled();
+                logger.debug(state);
             }
         }
     }
+    public class StateSettingRunnable implements Runnable {
+        private State state;
 
-     public class DebugLoggerRunnable implements Runnable {
+        public StateSettingRunnable(State state) {
+            this.state = state;
+        }
         public void run() {
-            for (int i=0; i < LOOP_CNT; ++i) {
-                logger.debug("This is a test");
+            for (int i=0; i < LOOP_CNT*4; ++i) {
+                Thread.yield();
+                state.setState();
             }
         }
     }
+
+    class State {
+
+        synchronized void setState() {
+            // Something takes a long time here
+            logger.debug("hello world");
+        }
+
+        synchronized Object getState() {
+            ++counter;
+            return counter;
+        }
+
+        public String toString() {
+            return "state=" + getState();
+        }
+    }
 }
\ No newline at end of file

Added: logging/log4j/log4j2/trunk/core/src/test/resources/log4j-threaded.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j-threaded.xml?rev=1334558&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/log4j-threaded.xml (added)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j-threaded.xml Sun May  6 05:35:47
2012
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<configuration status="warn" name="XMLConfigTest" packages="org.apache.logging.log4j.test">
+
+  <appenders>
+    <Console name="STDOUT">
+      <PatternLayout pattern="%d %p %C{1.} [%t] %m%n"/>
+    </Console>
+    <List name="List">
+      <filters>
+        <ThresholdFilter level="error"/>
+      </filters>
+    </List>
+  </appenders>
+
+  <loggers>
+    <root level="debug">
+      <appender-ref ref="STDOUT"/>
+    </root>
+  </loggers>
+
+</configuration>
\ No newline at end of file



Mime
View raw message