5e1af16e9854342225aef68261a3a4c27c52fb71
[lttng-ust-java-tests.git] /
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.Assert.assertEquals;
22
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Collections;
27 import java.util.List;
28
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runners.Parameterized.Parameters;
33 import org.lttng.tools.ILttngSession;
34
35 /**
36 * Base class testing the "lttng list" command when using loggers organized as a
37 * hierarchy.
38 *
39 * For example, if a "org.myapp" logger exists and has a LTTng handler attached,
40 * a "org.myapp.mycomponent" logger should show up in "lttng list", even if
41 * itself does not have a handler, because its parent's handler can catch the
42 * log events as UST tracepoints.
43 *
44 * @author Alexandre Montplaisir
45 */
46 public abstract class LoggerHierachyListITBase {
47
48 protected static final String PARENT_LOGGER = "org.lttng";
49 protected static final String CHILD_LOGGER = "org.lttng.mycomponent";
50
51 protected final boolean parentLoggerActive;
52 protected final boolean parentLoggerHasHandler;
53 protected final boolean childLoggerActive;
54 protected final boolean childLoggerHasHandler;
55
56 private ILttngSession session;
57
58 // ------------------------------------------------------------------------
59 // Test parameter definition
60 // ------------------------------------------------------------------------
61
62 /**
63 * Generator for the test parameters.
64 *
65 * Generates all possible combinations of the 4 constructor parameters,
66 * except "parentActive" is necessarily true when "hasHandler" is true for a
67 * given logger.
68 *
69 * @return The test parameters
70 */
71 @Parameters(name = "{index}: parentActive={0}, parentHasHandler={1}, childActive={2}, childHasHandler={3}")
72 public static Iterable<Object[]> testCases() {
73 /*
74 * Kept the whole array for clarity, but some cases are commented out:
75 * it is impossible to attach an handler if the logger itself is not
76 * defined!
77 */
78 return Arrays.asList(new Object[][] {
79 { Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE },
80 { Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE },
81 // { Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, Boolean.TRUE },
82 { Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE },
83
84 { Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.TRUE },
85 { Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE },
86 // { Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE },
87 { Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE },
88
89 // { Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE },
90 // { Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE },
91 // { Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.TRUE },
92 // { Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE },
93
94 { Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.TRUE },
95 { Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE },
96 // { Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE },
97 { Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE },
98 });
99 }
100
101 /**
102 * Test constructor
103 *
104 * @param parentLoggerActive
105 * Parent logger has been instantiated
106 * @param parentLoggerHasHandler
107 * Parent logger has a LTTng handler attached to it
108 * @param childLoggerActive
109 * Child logger has been instantiated
110 * @param childLoggerHasHandler
111 * Child logger has a LTTng handler attached to it
112 */
113 public LoggerHierachyListITBase(boolean parentLoggerActive,
114 boolean parentLoggerHasHandler,
115 boolean childLoggerActive,
116 boolean childLoggerHasHandler) {
117 this.parentLoggerActive = parentLoggerActive;
118 this.parentLoggerHasHandler = parentLoggerHasHandler;
119 this.childLoggerActive = childLoggerActive;
120 this.childLoggerHasHandler = childLoggerHasHandler;
121 }
122
123 protected ILttngSession getSession() {
124 return session;
125 }
126
127 // ------------------------------------------------------------------------
128 // Maintenance
129 // ------------------------------------------------------------------------
130
131 /**
132 * Common test setup
133 */
134 @Before
135 public void testSetup() {
136 session = ILttngSession.createSession(null, getDomain());
137 }
138
139 /**
140 * Common test teardown
141 */
142 @After
143 public void testTeardown() {
144 session.close();
145 }
146
147 // ------------------------------------------------------------------------
148 // Abstract methods
149 // ------------------------------------------------------------------------
150
151 protected abstract ILttngSession.Domain getDomain();
152
153 protected abstract void activateLoggers() throws IOException;
154
155 // ------------------------------------------------------------------------
156 // Common tests
157 // ------------------------------------------------------------------------
158
159 /**
160 * Test the output of the "lttng list" command.
161 *
162 * @throws IOException
163 * Fails the test
164 */
165 @Test
166 public void testList() throws IOException {
167 activateLoggers();
168
169 List<String> enabledEvents = session.listEvents();
170 List<String> expectedEvents = new ArrayList<>();
171
172 /* Reminder: "hasHandler" implies "isActive" */
173
174 if (parentLoggerHasHandler) {
175 expectedEvents.add(PARENT_LOGGER);
176 }
177 if (childLoggerHasHandler ||
178 (childLoggerActive && parentLoggerHasHandler)) {
179 expectedEvents.add(CHILD_LOGGER);
180 }
181
182 Collections.sort(enabledEvents);
183 Collections.sort(expectedEvents);
184 assertEquals(expectedEvents, enabledEvents);
185 }
186 }
This page took 0.03189 seconds and 3 git commands to generate.