Migrate to Junit 5 Jupiter
[lttng-ust-java-tests.git] / lttng-ust-java-tests-common / src / main / java / org / lttng / ust / agent / integration / events / LoggerHierachyListITBase.java
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
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
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;
35 import org.lttng.tools.ILttngSession;
36 import org.lttng.ust.agent.utils.TestPrintExtension;
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 */
49 @ExtendWith(TestPrintExtension.class)
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
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 *
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
76 *
77 * @return The test parameters
78 */
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 );
107 }
108
109 protected ILttngSession getSession() {
110 return session;
111 }
112
113 // ------------------------------------------------------------------------
114 // Maintenance
115 // ------------------------------------------------------------------------
116
117 /**
118 * Common test setup
119 */
120 @BeforeEach
121 public void testSetup() {
122 session = ILttngSession.createSession(null, getDomain());
123 }
124
125 /**
126 * Common test teardown
127 */
128 @AfterEach
129 public void testTeardown() {
130 session.close();
131 }
132
133 // ------------------------------------------------------------------------
134 // Abstract methods
135 // ------------------------------------------------------------------------
136
137 protected abstract ILttngSession.Domain getDomain();
138
139 protected abstract void activateLoggers(boolean parentLoggerActive,
140 boolean parentLoggerHasHandler,
141 boolean childLoggerActive,
142 boolean childLoggerHasHandler) throws IOException;
143
144 // ------------------------------------------------------------------------
145 // Common tests
146 // ------------------------------------------------------------------------
147
148 /**
149 * Test the output of the "lttng list" command.
150 *
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 *
160 * @throws IOException
161 * Fails the test
162 */
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);
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 }
This page took 0.036968 seconds and 4 git commands to generate.