View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
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.Before;
21  import org.junit.Ignore;
22  import org.junit.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  @Ignore
34  public class ReconfigurePerf {
35      final static int THREAD_COUNT = 500;
36      // final static int LOOP_LEN = 1000 * 1000;
37  
38      // the space in the file name mandated by
39      // http://jira.qos.ch/browse/LBCORE-119
40      final static String CONF_FILE_AS_STR = ClassicTestConstants.INPUT_PREFIX + "turbo/scan_perf.xml";
41  
42      // it actually takes time for Windows to propagate file modification changes
43      // values below 100 milliseconds can be problematic the same propagation
44      // latency occurs in Linux but is even larger (>600 ms)
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      @Before
57      public void setUp() {
58          // take into account propagation latency occurs on Linux
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      // Tests whether ConfigurationAction is installing ReconfigureOnChangeFilter
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  }