1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.turbo;
15
16 import java.io.File;
17 import java.io.IOException;
18
19 import ch.qos.logback.core.testUtil.EnvUtilForTests;
20 import org.junit.jupiter.api.BeforeEach;
21 import org.junit.jupiter.api.Disabled;
22 import org.junit.jupiter.api.Test;
23
24 import ch.qos.logback.classic.ClassicTestConstants;
25 import ch.qos.logback.classic.Logger;
26 import ch.qos.logback.classic.LoggerContext;
27 import ch.qos.logback.classic.issue.lbclassic135.LoggingRunnable;
28 import ch.qos.logback.classic.joran.JoranConfigurator;
29 import ch.qos.logback.core.contention.MultiThreadedHarness;
30 import ch.qos.logback.core.contention.RunnableWithCounterAndDone;
31 import ch.qos.logback.core.joran.spi.JoranException;
32
33 @Disabled
34 public class ReconfigurePerf {
35 final static int THREAD_COUNT = 500;
36
37
38
39
40 final static String CONF_FILE_AS_STR = ClassicTestConstants.INPUT_PREFIX + "turbo/scan_perf.xml";
41
42
43
44
45 final static int DEFAULT_SLEEP_BETWEEN_UPDATES = 110;
46
47 int sleepBetweenUpdates = DEFAULT_SLEEP_BETWEEN_UPDATES;
48
49 static int numberOfCycles = 100;
50 static int totalTestDuration;
51
52 LoggerContext loggerContext = new LoggerContext();
53 Logger logger = loggerContext.getLogger(this.getClass());
54 MultiThreadedHarness harness;
55
56 @BeforeEach
57 public void setUp() {
58
59 if (EnvUtilForTests.isLinux()) {
60 sleepBetweenUpdates = 850;
61 totalTestDuration = sleepBetweenUpdates * numberOfCycles;
62 } else {
63 totalTestDuration = sleepBetweenUpdates * numberOfCycles * 2;
64 }
65 harness = new MultiThreadedHarness(totalTestDuration);
66 }
67
68 void configure(File file) throws JoranException {
69 JoranConfigurator jc = new JoranConfigurator();
70 jc.setContext(loggerContext);
71 jc.doConfigure(file);
72 }
73
74 RunnableWithCounterAndDone[] buildRunnableArray() {
75 RunnableWithCounterAndDone[] rArray = new RunnableWithCounterAndDone[THREAD_COUNT];
76 for (int i = 0; i < THREAD_COUNT; i++) {
77 rArray[i] = new LoggingRunnable(logger);
78 }
79 return rArray;
80 }
81
82
83 @Test
84 public void scan1() throws JoranException, IOException, InterruptedException {
85 File file = new File(CONF_FILE_AS_STR);
86 configure(file);
87 System.out.println("Running scan1()");
88 doRun();
89 }
90
91 void doRun() throws InterruptedException {
92 RunnableWithCounterAndDone[] runnableArray = buildRunnableArray();
93 harness.execute(runnableArray);
94 }
95 }