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