1 /** 2 * Copyright (c) 2004-2016 QOS.ch 3 * All rights reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining 6 * a copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sublicense, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be 14 * included in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 * 24 */ 25 package org.slf4j.simple; 26 27 import java.io.PrintStream; 28 29 import org.junit.After; 30 import org.junit.Before; 31 import org.slf4j.LoggerFactoryFriend; 32 import org.slf4j.helpers.StringPrintStream; 33 import org.slf4j.testHarness.MultithreadedInitializationTest; 34 35 public class SimpleLoggerMultithreadedInitializationTest extends MultithreadedInitializationTest { 36 // final static int THREAD_COUNT = 4 + Runtime.getRuntime().availableProcessors() * 2; 37 // private final List<Logger> createdLoggers = Collections.synchronizedList(new ArrayList<Logger>()); 38 // private final AtomicLong eventCount = new AtomicLong(0); 39 // 40 // private final CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT + 1); 41 // 42 // final int diff = new Random().nextInt(10000); 43 static int NUM_LINES_IN_SLF4J_REPLAY_WARNING = 3; 44 private final PrintStream oldErr = System.err; 45 final String loggerName = this.getClass().getName(); 46 StringPrintStream sps = new StringPrintStream(oldErr, false); 47 48 @Before 49 public void setup() { 50 System.out.println("THREAD_COUNT=" + THREAD_COUNT); 51 System.setErr(sps); 52 System.setProperty(SimpleLogger.LOG_FILE_KEY, "System.err"); 53 LoggerFactoryFriend.reset(); 54 } 55 56 @After 57 public void tearDown() throws Exception { 58 LoggerFactoryFriend.reset(); 59 System.clearProperty(SimpleLogger.LOG_FILE_KEY); 60 System.setErr(oldErr); 61 } 62 63 @Override 64 protected long getRecordedEventCount() { 65 return sps.stringList.size(); 66 }; 67 68 @Override 69 protected int extraLogEvents() { 70 return NUM_LINES_IN_SLF4J_REPLAY_WARNING; 71 } 72 73 }