001package org.slf4j.simple;
002
003import static org.junit.Assert.fail;
004
005import org.junit.Test;
006import org.slf4j.ILoggerFactory;
007import org.slf4j.LoggerFactory;
008import org.slf4j.MDC;
009import org.slf4j.MarkerFactory;
010
011// See https://jira.qos.ch/browse/SLF4J-463
012public class DoubleInitializationPitfallTest {
013
014    // See https://jira.qos.ch/browse/SLF4J-463
015    @Test
016    public void verifyImpactOfMarkerFactory() {
017        ILoggerFactory firstFactory = LoggerFactory.getILoggerFactory();
018        MarkerFactory.getMarker("DOUBLE_INIT");
019        ILoggerFactory secondFactory = LoggerFactory.getILoggerFactory();
020
021        if (firstFactory != secondFactory) {
022            fail("MarkerFactory.getMarker causes multiple provider initialization");
023        }
024    }
025
026    @Test
027    public void verifyImpactOfMDC() {
028        ILoggerFactory firstFactory = LoggerFactory.getILoggerFactory();
029        MDC.put("DoubleInitializationPitfallTest", "a");
030        ILoggerFactory secondFactory = LoggerFactory.getILoggerFactory();
031
032        if (firstFactory != secondFactory) {
033            fail("MarkerFactory.getMarker causes multiple provider initialization");
034        }
035    }
036
037}