Commit | Line | Data |
---|---|---|
2b408e85 AM |
1 | /* |
2 | * Copyright (C) 2015, 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 | ||
24b260d9 | 19 | package org.lttng.ust.agent.integration; |
c5524c71 AM |
20 | |
21 | import static org.junit.Assert.assertEquals; | |
22 | import static org.junit.Assert.assertNotNull; | |
23 | import static org.junit.Assert.assertTrue; | |
24 | ||
25 | import java.util.List; | |
26 | ||
27 | import org.junit.After; | |
28 | import org.junit.Before; | |
29 | import org.junit.Test; | |
30 | import org.lttng.ust.agent.ILttngHandler; | |
8576633f AM |
31 | import org.lttng.ust.agent.utils.LttngSession; |
32 | import org.lttng.ust.agent.utils.LttngSession.Domain; | |
c5524c71 | 33 | |
8a0613fa AM |
34 | /** |
35 | * Base abstract class to implement all sorts of integration tests verifying the | |
36 | * presence of enabled events in resulting traces. | |
37 | */ | |
24b260d9 | 38 | public abstract class EnabledEventsTestBase { |
c5524c71 AM |
39 | |
40 | protected static final String EVENT_NAME_A = "EventA"; | |
41 | protected static final String EVENT_NAME_B = "EventAB"; | |
42 | protected static final String EVENT_NAME_C = "EventABC"; | |
43 | protected static final String EVENT_NAME_D = "EventABCD"; | |
44 | ||
8576633f AM |
45 | private LttngSession session; |
46 | ||
c5524c71 AM |
47 | /* Fields defined by the sub-class */ |
48 | protected ILttngHandler handlerA; | |
49 | protected ILttngHandler handlerB; | |
50 | protected ILttngHandler handlerC; | |
51 | ||
52 | protected abstract Domain getDomain(); | |
53 | ||
54 | protected abstract void sendEventsToLoggers(); | |
55 | ||
8a0613fa AM |
56 | /** |
57 | * Base test setup | |
58 | */ | |
c5524c71 AM |
59 | @Before |
60 | public void testSetup() { | |
8576633f | 61 | session = new LttngSession(null, getDomain()); |
c5524c71 AM |
62 | } |
63 | ||
8a0613fa AM |
64 | /** |
65 | * Base test teardown | |
66 | */ | |
c5524c71 AM |
67 | @After |
68 | public void testTeardown() { | |
8576633f | 69 | session.close(); |
c5524c71 AM |
70 | |
71 | handlerA.close(); | |
72 | handlerB.close(); | |
73 | handlerC.close(); | |
74 | ||
75 | handlerA = null; | |
76 | handlerB = null; | |
77 | handlerC = null; | |
78 | } | |
79 | ||
80 | /** | |
81 | * Test sending events on the Java side, but no events enabled in the | |
82 | * tracing session. There should be nothing in the resulting trace, and | |
83 | * handlers should not have logged anything. | |
84 | */ | |
85 | @Test | |
86 | public void testNoEvents() { | |
8576633f | 87 | assertTrue(session.start()); |
c5524c71 AM |
88 | |
89 | sendEventsToLoggers(); | |
90 | ||
8576633f | 91 | assertTrue(session.stop()); |
c5524c71 | 92 | |
8576633f | 93 | List<String> output = session.view(); |
c5524c71 AM |
94 | assertNotNull(output); |
95 | assertTrue(output.isEmpty()); | |
96 | ||
c5524c71 AM |
97 | assertEquals(0, handlerA.getEventCount()); |
98 | assertEquals(0, handlerB.getEventCount()); | |
99 | assertEquals(0, handlerC.getEventCount()); | |
100 | } | |
101 | ||
102 | /** | |
103 | * Test sending events on the Java side, and all events enabled in the | |
104 | * tracing session. All handlers should have sent their events. | |
105 | */ | |
106 | @Test | |
107 | public void testAllEvents() { | |
8576633f AM |
108 | assertTrue(session.enableAllEvents()); |
109 | assertTrue(session.start()); | |
c5524c71 AM |
110 | |
111 | sendEventsToLoggers(); | |
112 | ||
8576633f | 113 | assertTrue(session.stop()); |
c5524c71 | 114 | |
8576633f | 115 | List<String> output = session.view(); |
c5524c71 AM |
116 | assertNotNull(output); |
117 | assertEquals(30, output.size()); // loggerD has no handler attached | |
118 | ||
c5524c71 AM |
119 | assertEquals(10, handlerA.getEventCount()); |
120 | assertEquals(10, handlerB.getEventCount()); | |
121 | assertEquals(10, handlerC.getEventCount()); | |
122 | } | |
123 | ||
124 | /** | |
125 | * Test sending events on the Java side, with only some of them enabled in | |
126 | * the tracing session. Only the subset that is enabled should be received. | |
127 | */ | |
128 | @Test | |
129 | public void testSomeEvents() { | |
8576633f AM |
130 | assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D)); |
131 | assertTrue(session.start()); | |
c5524c71 AM |
132 | |
133 | sendEventsToLoggers(); | |
134 | ||
8576633f | 135 | assertTrue(session.stop()); |
c5524c71 | 136 | |
8576633f | 137 | List<String> output = session.view(); |
c5524c71 AM |
138 | assertNotNull(output); |
139 | assertEquals(20, output.size()); | |
140 | ||
c5524c71 AM |
141 | assertEquals(10, handlerA.getEventCount()); |
142 | assertEquals(0, handlerB.getEventCount()); | |
143 | assertEquals(10, handlerC.getEventCount()); | |
144 | } | |
145 | ||
146 | /** | |
147 | * Test with all events enabled (-a), plus some other events added manually. | |
148 | * Events should still be retained, but there should be no duplicates. | |
149 | */ | |
150 | @Test | |
151 | public void testAllEventsAndSome() { | |
8576633f AM |
152 | assertTrue(session.enableAllEvents()); |
153 | assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_B)); | |
154 | assertTrue(session.start()); | |
c5524c71 AM |
155 | |
156 | sendEventsToLoggers(); | |
157 | ||
8576633f | 158 | assertTrue(session.stop()); |
c5524c71 | 159 | |
8576633f | 160 | List<String> output = session.view(); |
c5524c71 AM |
161 | assertNotNull(output); |
162 | assertEquals(30, output.size()); | |
163 | ||
c5524c71 AM |
164 | assertEquals(10, handlerA.getEventCount()); |
165 | assertEquals(10, handlerB.getEventCount()); | |
166 | assertEquals(10, handlerC.getEventCount()); | |
167 | } | |
168 | ||
169 | /** | |
170 | * Same as {@link #testSomeEvents()}, but some events were enabled first, | |
171 | * then disabled. Makes sure the enabled-event refcounting works properly. | |
172 | */ | |
173 | @Test | |
174 | public void testSomeEventsAfterDisabling() { | |
8576633f AM |
175 | assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D)); |
176 | assertTrue(session.disableEvents(EVENT_NAME_C)); | |
177 | assertTrue(session.start()); | |
c5524c71 AM |
178 | |
179 | sendEventsToLoggers(); | |
180 | ||
8576633f | 181 | assertTrue(session.stop()); |
c5524c71 | 182 | |
8576633f | 183 | List<String> output = session.view(); |
c5524c71 AM |
184 | assertNotNull(output); |
185 | assertEquals(10, output.size()); | |
186 | ||
c5524c71 AM |
187 | assertEquals(10, handlerA.getEventCount()); |
188 | assertEquals(0, handlerB.getEventCount()); | |
189 | assertEquals(0, handlerC.getEventCount()); | |
190 | } | |
191 | ||
192 | /** | |
193 | * Test enabling an event prefix, which means an event name ending with a *, | |
194 | * to match all events starting with this name. | |
195 | */ | |
196 | @Test | |
197 | public void testEventPrefix() { | |
8576633f AM |
198 | // should match event/loggers B and C, but not A. |
199 | assertTrue(session.enableEvents("EventAB*")); | |
200 | assertTrue(session.start()); | |
c5524c71 AM |
201 | |
202 | sendEventsToLoggers(); | |
203 | ||
8576633f | 204 | assertTrue(session.stop()); |
c5524c71 | 205 | |
8576633f | 206 | List<String> output = session.view(); |
c5524c71 AM |
207 | assertNotNull(output); |
208 | assertEquals(20, output.size()); | |
209 | ||
c5524c71 AM |
210 | assertEquals(0, handlerA.getEventCount()); |
211 | assertEquals(10, handlerB.getEventCount()); | |
212 | assertEquals(10, handlerC.getEventCount()); | |
213 | } | |
214 | ||
215 | /** | |
216 | * Same as {@link #testEventPrefix()}, but with multiple prefixes that | |
217 | * overlap. There should not be any duplicate events in the trace or in the | |
218 | * handlers. | |
219 | */ | |
220 | @Test | |
221 | public void testEventPrefixOverlapping() { | |
8576633f AM |
222 | // should still match B and C |
223 | assertTrue(session.enableEvents("EventAB*", "EventABC*")); | |
224 | assertTrue(session.start()); | |
c5524c71 AM |
225 | |
226 | sendEventsToLoggers(); | |
227 | ||
8576633f | 228 | assertTrue(session.stop()); |
c5524c71 | 229 | |
8576633f | 230 | List<String> output = session.view(); |
c5524c71 AM |
231 | assertNotNull(output); |
232 | assertEquals(20, output.size()); | |
233 | ||
c5524c71 AM |
234 | assertEquals(0, handlerA.getEventCount()); |
235 | assertEquals(10, handlerB.getEventCount()); | |
236 | assertEquals(10, handlerC.getEventCount()); | |
237 | } | |
238 | ||
239 | /** | |
240 | * Test with all events enabled (-a), plus an event prefix. Once again, | |
241 | * there should be no duplicates. | |
242 | */ | |
243 | @Test | |
244 | public void testAllEventsAndPrefix() { | |
8576633f AM |
245 | assertTrue(session.enableAllEvents()); |
246 | assertTrue(session.enableEvents("EventAB*")); | |
247 | assertTrue(session.start()); | |
c5524c71 AM |
248 | |
249 | sendEventsToLoggers(); | |
250 | ||
8576633f | 251 | assertTrue(session.stop()); |
c5524c71 | 252 | |
8576633f | 253 | List<String> output = session.view(); |
c5524c71 AM |
254 | assertNotNull(output); |
255 | assertEquals(30, output.size()); | |
256 | ||
c5524c71 AM |
257 | assertEquals(10, handlerA.getEventCount()); |
258 | assertEquals(10, handlerB.getEventCount()); | |
259 | assertEquals(10, handlerC.getEventCount()); | |
260 | } | |
261 | } |