Commit | Line | Data |
---|---|---|
fe6a3925 AM |
1 | /* |
2 | * Copyright (C) 2016, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along | |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 | */ | |
18 | ||
19 | package org.lttng.ust.agent.integration.events; | |
20 | ||
7a4f0255 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; |
fe6a3925 AM |
22 | |
23 | import java.io.IOException; | |
24 | import java.util.ArrayList; | |
fe6a3925 AM |
25 | import java.util.Collections; |
26 | import java.util.List; | |
7a4f0255 MJ |
27 | import java.util.stream.Stream; |
28 | ||
29 | import org.junit.jupiter.api.AfterEach; | |
30 | import org.junit.jupiter.api.BeforeEach; | |
31 | import org.junit.jupiter.api.extension.ExtendWith; | |
32 | import org.junit.jupiter.params.ParameterizedTest; | |
33 | import org.junit.jupiter.params.provider.Arguments; | |
34 | import org.junit.jupiter.params.provider.MethodSource; | |
fe6a3925 | 35 | import org.lttng.tools.ILttngSession; |
7a4f0255 | 36 | import org.lttng.ust.agent.utils.TestPrintExtension; |
fe6a3925 AM |
37 | |
38 | /** | |
39 | * Base class testing the "lttng list" command when using loggers organized as a | |
40 | * hierarchy. | |
41 | * | |
42 | * For example, if a "org.myapp" logger exists and has a LTTng handler attached, | |
43 | * a "org.myapp.mycomponent" logger should show up in "lttng list", even if | |
44 | * itself does not have a handler, because its parent's handler can catch the | |
45 | * log events as UST tracepoints. | |
46 | * | |
47 | * @author Alexandre Montplaisir | |
48 | */ | |
7a4f0255 | 49 | @ExtendWith(TestPrintExtension.class) |
fe6a3925 AM |
50 | public abstract class LoggerHierachyListITBase { |
51 | ||
52 | protected static final String PARENT_LOGGER = "org.lttng"; | |
53 | protected static final String CHILD_LOGGER = "org.lttng.mycomponent"; | |
54 | ||
fe6a3925 AM |
55 | private ILttngSession session; |
56 | ||
57 | // ------------------------------------------------------------------------ | |
58 | // Test parameter definition | |
59 | // ------------------------------------------------------------------------ | |
60 | ||
61 | /** | |
62 | * Generator for the test parameters. | |
63 | * | |
64 | * Generates all possible combinations of the 4 constructor parameters, | |
65 | * except "parentActive" is necessarily true when "hasHandler" is true for a | |
66 | * given logger. | |
67 | * | |
fe6a3925 AM |
68 | * @param parentLoggerActive |
69 | * Parent logger has been instantiated | |
70 | * @param parentLoggerHasHandler | |
71 | * Parent logger has a LTTng handler attached to it | |
72 | * @param childLoggerActive | |
73 | * Child logger has been instantiated | |
74 | * @param childLoggerHasHandler | |
75 | * Child logger has a LTTng handler attached to it | |
7a4f0255 MJ |
76 | * |
77 | * @return The test parameters | |
fe6a3925 | 78 | */ |
7a4f0255 MJ |
79 | protected static Stream<Arguments> provideArguments() { |
80 | ||
81 | /* | |
82 | * Kept the whole array for clarity, but some cases are commented out: | |
83 | * it is impossible to attach an handler if the logger itself is not | |
84 | * defined! | |
85 | */ | |
86 | return Stream.of( | |
87 | Arguments.of( Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE ), | |
88 | Arguments.of( Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE ), | |
89 | // Arguments.of( Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, Boolean.TRUE ), | |
90 | Arguments.of( Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE ), | |
91 | ||
92 | Arguments.of( Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.TRUE ), | |
93 | Arguments.of( Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE ), | |
94 | // Arguments.of( Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE ), | |
95 | Arguments.of( Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE ), | |
96 | ||
97 | // Arguments.of( Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE ), | |
98 | // Arguments.of( Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE ), | |
99 | // Arguments.of( Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.TRUE ), | |
100 | // Arguments.of( Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE ), | |
101 | ||
102 | Arguments.of( Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.TRUE ), | |
103 | Arguments.of( Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE ), | |
104 | // Arguments.of( Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE ), | |
105 | Arguments.of( Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE ) | |
106 | ); | |
fe6a3925 AM |
107 | } |
108 | ||
109 | protected ILttngSession getSession() { | |
110 | return session; | |
111 | } | |
112 | ||
113 | // ------------------------------------------------------------------------ | |
114 | // Maintenance | |
115 | // ------------------------------------------------------------------------ | |
116 | ||
117 | /** | |
118 | * Common test setup | |
119 | */ | |
7a4f0255 | 120 | @BeforeEach |
fe6a3925 AM |
121 | public void testSetup() { |
122 | session = ILttngSession.createSession(null, getDomain()); | |
123 | } | |
124 | ||
125 | /** | |
126 | * Common test teardown | |
127 | */ | |
7a4f0255 | 128 | @AfterEach |
fe6a3925 AM |
129 | public void testTeardown() { |
130 | session.close(); | |
131 | } | |
132 | ||
133 | // ------------------------------------------------------------------------ | |
134 | // Abstract methods | |
135 | // ------------------------------------------------------------------------ | |
136 | ||
137 | protected abstract ILttngSession.Domain getDomain(); | |
138 | ||
7a4f0255 MJ |
139 | protected abstract void activateLoggers(boolean parentLoggerActive, |
140 | boolean parentLoggerHasHandler, | |
141 | boolean childLoggerActive, | |
142 | boolean childLoggerHasHandler) throws IOException; | |
fe6a3925 AM |
143 | |
144 | // ------------------------------------------------------------------------ | |
145 | // Common tests | |
146 | // ------------------------------------------------------------------------ | |
147 | ||
148 | /** | |
149 | * Test the output of the "lttng list" command. | |
150 | * | |
7a4f0255 MJ |
151 | * @param parentLoggerActive |
152 | * Parent logger has been instantiated | |
153 | * @param parentLoggerHasHandler | |
154 | * Parent logger has a LTTng handler attached to it | |
155 | * @param childLoggerActive | |
156 | * Child logger has been instantiated | |
157 | * @param childLoggerHasHandler | |
158 | * Child logger has a LTTng handler attached to it | |
159 | * | |
fe6a3925 AM |
160 | * @throws IOException |
161 | * Fails the test | |
162 | */ | |
7a4f0255 MJ |
163 | @ParameterizedTest |
164 | @MethodSource("provideArguments") | |
165 | public void testList(boolean parentLoggerActive, | |
166 | boolean parentLoggerHasHandler, | |
167 | boolean childLoggerActive, | |
168 | boolean childLoggerHasHandler) throws IOException { | |
169 | ||
170 | activateLoggers(parentLoggerActive, | |
171 | parentLoggerHasHandler, | |
172 | childLoggerActive, | |
173 | childLoggerHasHandler); | |
fe6a3925 AM |
174 | |
175 | List<String> enabledEvents = session.listEvents(); | |
176 | List<String> expectedEvents = new ArrayList<>(); | |
177 | ||
178 | /* Reminder: "hasHandler" implies "isActive" */ | |
179 | ||
180 | if (parentLoggerHasHandler) { | |
181 | expectedEvents.add(PARENT_LOGGER); | |
182 | } | |
183 | if (childLoggerHasHandler || | |
184 | (childLoggerActive && parentLoggerHasHandler)) { | |
185 | expectedEvents.add(CHILD_LOGGER); | |
186 | } | |
187 | ||
188 | Collections.sort(enabledEvents); | |
189 | Collections.sort(expectedEvents); | |
190 | assertEquals(expectedEvents, enabledEvents); | |
191 | } | |
192 | } |