001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic;
015
016import java.io.ByteArrayInputStream;
017
018import org.junit.After;
019import org.junit.Before;
020import org.junit.Test;
021
022import ch.qos.logback.classic.joran.JoranConfigurator;
023import ch.qos.logback.core.joran.spi.JoranException;
024
025public class LoggerContextDeadlockTest {
026
027    LoggerContext loggerContext = new LoggerContext();
028    JoranConfigurator jc = new JoranConfigurator();
029    GetLoggerThread getLoggerThread = new GetLoggerThread(loggerContext);
030
031    @Before
032    public void setUp() throws Exception {
033        jc.setContext(loggerContext);
034    }
035
036    @After
037    public void tearDown() throws Exception {
038    }
039
040    @Test(timeout = 20000)
041    public void testLBCLASSIC_81() throws JoranException {
042
043        getLoggerThread.start();
044        for (int i = 0; i < 500; i++) {
045            ByteArrayInputStream baos = new ByteArrayInputStream("<configuration><root level=\"DEBUG\"/></configuration>".getBytes());
046            jc.doConfigure(baos);
047        }
048    }
049
050    class GetLoggerThread extends Thread {
051
052        final LoggerContext loggerContext;
053
054        GetLoggerThread(LoggerContext loggerContext) {
055            this.loggerContext = loggerContext;
056        }
057
058        @Override
059        public void run() {
060            for (int i = 0; i < 10000; i++) {
061                if (i % 100 == 0) {
062                    try {
063                        Thread.sleep(1);
064                    } catch (InterruptedException e) {
065                    }
066                }
067                loggerContext.getLogger("a" + i);
068            }
069        }
070    }
071
072}