1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic;
15
16 import java.io.ByteArrayInputStream;
17 import java.util.concurrent.TimeUnit;
18
19 import org.junit.jupiter.api.AfterEach;
20 import org.junit.jupiter.api.BeforeEach;
21 import org.junit.jupiter.api.Test;
22
23 import ch.qos.logback.classic.joran.JoranConfigurator;
24 import ch.qos.logback.core.joran.spi.JoranException;
25 import org.junit.jupiter.api.Timeout;
26
27 public class LoggerContextDeadlockTest {
28
29 LoggerContext loggerContext = new LoggerContext();
30
31 GetLoggerThread getLoggerThread = new GetLoggerThread(loggerContext);
32
33 @BeforeEach
34 public void setUp() throws Exception {
35
36 }
37
38 @AfterEach
39 public void tearDown() throws Exception {
40 }
41
42
43
44 @Test
45 @Timeout(value = 20, unit= TimeUnit.SECONDS)
46 public void test_LOGBACK_394() throws JoranException {
47
48 getLoggerThread.start();
49 for (int i = 0; i < 500; i++) {
50 JoranConfigurator jc = new JoranConfigurator();
51 jc.setContext(loggerContext);
52 ByteArrayInputStream baos = new ByteArrayInputStream(
53 "<configuration><root level=\"DEBUG\"/></configuration>".getBytes());
54 jc.doConfigure(baos);
55 }
56 }
57
58 class GetLoggerThread extends Thread {
59
60 final LoggerContext loggerContext;
61
62 GetLoggerThread(LoggerContext loggerContext) {
63 this.loggerContext = loggerContext;
64 }
65
66 @Override
67 public void run() {
68 for (int i = 0; i < 10000; i++) {
69 if (i % 100 == 0) {
70 try {
71 Thread.sleep(1);
72 } catch (InterruptedException e) {
73 }
74 }
75 loggerContext.getLogger("a" + i);
76 }
77 }
78 }
79
80 }