1
2
3
4
5
6
7
8
9
10 package ch.qos.logback.classic.control;
11
12 import java.util.LinkedList;
13
14 import ch.qos.logback.classic.ClassicGlobal;
15 import ch.qos.logback.classic.Level;
16
17 public class ScenarioMaker {
18
19 private final static int AVERAGE_LOGGER_DEPTH = 4;
20 private final static int LOGGER_DEPT_DEV = 2;
21
22 private final static int CREATE_LOGGER_TO_SET_LEVEL_FREQUENCY = 5;
23 private final static int SECOND_SET_LEVEL_FREQUENCY = 3;
24
25 private static long count = 0;
26
27
28
29
30
31
32
33
34
35
36 static public Scenario makeTypeAScenario(int len) {
37 Scenario scenario = new Scenario();
38 ;
39 for (int i = 0; i < len; i++) {
40 String loggerName = ScenarioRandomUtil.randomLoggerName(
41 AVERAGE_LOGGER_DEPTH, LOGGER_DEPT_DEV);
42 scenario.add(new CreateLogger(loggerName));
43 }
44 return scenario;
45 }
46
47 static public Scenario makeRealisticCreationScenario(int len) {
48 Scenario scenario = new Scenario();
49 LinkedList<String> queue = new LinkedList<String>();
50 int loggerCreationCount = 0;
51
52
53 queue.add("");
54
55 while (loggerCreationCount < len) {
56 if ((count % 100) == 0) {
57 System.out.println("count=" + count);
58 }
59
60 String loggerName = (String) queue.removeFirst();
61 int randomChildrenCount = ScenarioRandomUtil
62 .randomChildrenCount(loggerName);
63
64 if (randomChildrenCount == 0) {
65 scenario.add(new CreateLogger(loggerName));
66 addSetLevelSubScenario(scenario, loggerName);
67 loggerCreationCount++;
68 } else {
69 for (int i = 0; i < randomChildrenCount; i++) {
70 String childName;
71 if (loggerName.equals("")) {
72 childName = ScenarioRandomUtil.randomId();
73 count += childName.length();
74 } else {
75 childName = loggerName + ClassicGlobal.LOGGER_SEPARATOR
76 + ScenarioRandomUtil.randomId();
77 count += childName.length();
78 }
79 queue.add(childName);
80 addSetLevelSubScenario(scenario, loggerName);
81 loggerCreationCount++;
82 }
83 }
84 }
85 return scenario;
86 }
87
88 static void addSetLevelSubScenario(Scenario scenario, String loggerName) {
89 if (ScenarioRandomUtil.oneInFreq(CREATE_LOGGER_TO_SET_LEVEL_FREQUENCY)) {
90 Level l = ScenarioRandomUtil.randomLevel();
91 scenario.add(new SetLevel(l, loggerName));
92 if (ScenarioRandomUtil.oneInFreq(SECOND_SET_LEVEL_FREQUENCY)) {
93 l = ScenarioRandomUtil.randomLevel();
94 scenario.add(new SetLevel(l, loggerName));
95 }
96 }
97 }
98
99 }