bc75961da6f995337041aeb30c24790512bd8a6d
[lttng-ust-java-tests.git] /
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
19 package org.lttng.ust.agent.integration.events;
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.junit.runner.RunWith;
31 import org.lttng.tools.ILttngSession;
32 import org.lttng.tools.ILttngSession.Domain;
33 import org.lttng.ust.agent.ILttngHandler;
34 import org.lttng.ust.agent.utils.TestPrintRunner;
35
36 /**
37 * Base abstract class for tests with multiple concurrent tracing sessions
38 */
39 @RunWith(TestPrintRunner.class)
40 public abstract class MultiSessionITBase {
41
42 protected static final String EVENT_NAME_A = "EventA";
43 protected static final String EVENT_NAME_B = "EventAB";
44 protected static final String EVENT_NAME_C = "EventABC";
45 protected static final String EVENT_NAME_D = "EventABCDÉ";
46
47 private ILttngSession session1;
48 private ILttngSession session2;
49 private ILttngSession session3;
50
51 /* Fields defined by the sub-class */
52 protected ILttngHandler handlerA;
53 protected ILttngHandler handlerB;
54 protected ILttngHandler handlerC;
55 protected ILttngHandler handlerD;
56
57 protected abstract Domain getDomain();
58
59 protected abstract boolean closeHandlers();
60
61 protected abstract void sendEventsToLoggers();
62
63 /**
64 * Base test setup
65 */
66 @Before
67 public void testSetup() {
68 session1 = ILttngSession.createSession(null, getDomain());
69 session2 = ILttngSession.createSession(null, getDomain());
70 session3 = ILttngSession.createSession(null, getDomain());
71 }
72
73 /**
74 * Base test teardown
75 */
76 @After
77 public void testTeardown() {
78 session1.close();
79 session2.close();
80 session3.close();
81
82 if (closeHandlers()) {
83 handlerA.close();
84 handlerB.close();
85 handlerC.close();
86 handlerD.close();
87 }
88
89 handlerA = null;
90 handlerB = null;
91 handlerC = null;
92 handlerD = null;
93 }
94
95 /**
96 * Test with no events in any session.
97 */
98 @Test
99 public void testNoEvents() {
100 assertTrue(session1.start());
101 assertTrue(session2.start());
102 assertTrue(session3.start());
103
104 sendEventsToLoggers();
105
106 assertTrue(session1.stop());
107 assertTrue(session2.stop());
108 assertTrue(session3.stop());
109
110 List<String> output1 = session1.view();
111 List<String> output2 = session2.view();
112 List<String> output3 = session3.view();
113 assertNotNull(output1);
114 assertNotNull(output2);
115 assertNotNull(output3);
116 assertTrue(output1.isEmpty());
117 assertTrue(output2.isEmpty());
118 assertTrue(output3.isEmpty());
119
120 assertEquals(0, handlerA.getEventCount());
121 assertEquals(0, handlerB.getEventCount());
122 assertEquals(0, handlerC.getEventCount());
123 assertEquals(0, handlerD.getEventCount());
124 }
125
126 /**
127 * Test with all events enabled in one session only. Everything should be
128 * sent through JNI, but only that session should keep the trace events.
129 */
130 @Test
131 public void testAllEventsOneSession() {
132 assertTrue(session1.enableAllEvents());
133 assertTrue(session1.start());
134 assertTrue(session2.start());
135 assertTrue(session3.start());
136
137 sendEventsToLoggers();
138
139 assertTrue(session1.stop());
140 assertTrue(session2.stop());
141 assertTrue(session3.stop());
142
143 List<String> output1 = session1.view();
144 List<String> output2 = session2.view();
145 List<String> output3 = session3.view();
146 assertNotNull(output1);
147 assertNotNull(output2);
148 assertNotNull(output3);
149 assertEquals(40, output1.size());
150 assertTrue(output2.isEmpty());
151 assertTrue(output3.isEmpty());
152
153 assertEquals(10, handlerA.getEventCount());
154 assertEquals(10, handlerB.getEventCount());
155 assertEquals(10, handlerC.getEventCount());
156 assertEquals(10, handlerD.getEventCount());
157 }
158
159 /**
160 * Test with all events enabled in all sessions. All traces and handlers
161 * should see every event that was logged.
162 */
163 @Test
164 public void testAllEventsAllSessions() {
165 assertTrue(session1.enableAllEvents());
166 assertTrue(session2.enableAllEvents());
167 assertTrue(session3.enableAllEvents());
168 assertTrue(session1.start());
169 assertTrue(session2.start());
170 assertTrue(session3.start());
171
172 sendEventsToLoggers();
173
174 assertTrue(session1.stop());
175 assertTrue(session2.stop());
176 assertTrue(session3.stop());
177
178 List<String> output1 = session1.view();
179 List<String> output2 = session2.view();
180 List<String> output3 = session3.view();
181 assertNotNull(output1);
182 assertNotNull(output2);
183 assertNotNull(output3);
184 assertEquals(40, output1.size());
185 assertEquals(40, output2.size());
186 assertEquals(40, output3.size());
187
188 assertEquals(10, handlerA.getEventCount());
189 assertEquals(10, handlerB.getEventCount());
190 assertEquals(10, handlerC.getEventCount());
191 assertEquals(10, handlerD.getEventCount());
192 }
193
194 /**
195 * Test enabling some events in some sessions only.
196 */
197 @Test
198 public void testSomeEvents() {
199 assertTrue(session1.enableEvents(EVENT_NAME_A));
200 assertTrue(session2.enableEvents(EVENT_NAME_B));
201 assertTrue(session1.start());
202 assertTrue(session2.start());
203 assertTrue(session3.start());
204
205 sendEventsToLoggers();
206
207 assertTrue(session1.stop());
208 assertTrue(session2.stop());
209 assertTrue(session3.stop());
210
211 List<String> output1 = session1.view();
212 List<String> output2 = session2.view();
213 List<String> output3 = session3.view();
214 assertNotNull(output1);
215 assertNotNull(output2);
216 assertNotNull(output3);
217 assertEquals(10, output1.size());
218 assertEquals(10, output2.size());
219 assertEquals(0, output3.size());
220
221 assertEquals(10, handlerA.getEventCount());
222 assertEquals(10, handlerB.getEventCount());
223 assertEquals(0, handlerC.getEventCount());
224 assertEquals(0, handlerD.getEventCount());
225 }
226
227 /**
228 * Test with all events enabled in one session, and some others in another.
229 * All events should arrive where expected, with no duplicates.
230 */
231 @Test
232 public void testAllEventsAndSome() {
233 assertTrue(session1.enableAllEvents());
234 assertTrue(session2.enableEvents(EVENT_NAME_D));
235 assertTrue(session1.start());
236 assertTrue(session2.start());
237 assertTrue(session3.start());
238
239 sendEventsToLoggers();
240
241 assertTrue(session1.stop());
242 assertTrue(session2.stop());
243 assertTrue(session3.stop());
244
245 List<String> output1 = session1.view();
246 List<String> output2 = session2.view();
247 List<String> output3 = session3.view();
248 assertNotNull(output1);
249 assertNotNull(output2);
250 assertNotNull(output3);
251 assertEquals(40, output1.size());
252 assertEquals(10, output2.size());
253 assertEquals(0, output3.size());
254
255 assertEquals(10, handlerA.getEventCount());
256 assertEquals(10, handlerB.getEventCount());
257 assertEquals(10, handlerC.getEventCount());
258 assertEquals(10, handlerD.getEventCount());
259 }
260
261 /**
262 * Test with enabling then disabling some events. Makes sure the refcounting
263 * works properly.
264 */
265 @Test
266 public void testSomeEventsAfterDisabling() {
267 assertTrue(session1.enableEvents(EVENT_NAME_A, EVENT_NAME_B, EVENT_NAME_C));
268 assertTrue(session2.enableEvents(EVENT_NAME_B, EVENT_NAME_C, EVENT_NAME_D));
269 assertTrue(session3.enableEvents(EVENT_NAME_A));
270
271 assertTrue(session1.disableEvents(EVENT_NAME_C));
272 assertTrue(session2.disableEvents(EVENT_NAME_B, EVENT_NAME_C));
273 assertTrue(session3.disableEvents(EVENT_NAME_A));
274
275 assertTrue(session1.start());
276 assertTrue(session2.start());
277 assertTrue(session3.start());
278
279 sendEventsToLoggers();
280
281 assertTrue(session1.stop());
282 assertTrue(session2.stop());
283 assertTrue(session3.stop());
284
285 List<String> output1 = session1.view();
286 List<String> output2 = session2.view();
287 List<String> output3 = session3.view();
288 assertNotNull(output1);
289 assertNotNull(output2);
290 assertNotNull(output3);
291 assertEquals(20, output1.size());
292 assertEquals(10, output2.size());
293 assertEquals(0, output3.size());
294
295 assertEquals(10, handlerA.getEventCount());
296 assertEquals(10, handlerB.getEventCount());
297 assertEquals(0, handlerC.getEventCount());
298 assertEquals(10, handlerD.getEventCount());
299 }
300
301 /**
302 * Test with a prefix in one session and a standard event in another.
303 */
304 @Test
305 public void testPrefixAndEvent() {
306 assertTrue(session1.enableEvents("EventAB*"));
307 assertTrue(session3.enableEvents(EVENT_NAME_A));
308 assertTrue(session1.start());
309 assertTrue(session2.start());
310 assertTrue(session3.start());
311
312 sendEventsToLoggers();
313
314 assertTrue(session1.stop());
315 assertTrue(session2.stop());
316 assertTrue(session3.stop());
317
318 List<String> output1 = session1.view();
319 List<String> output2 = session2.view();
320 List<String> output3 = session3.view();
321 assertNotNull(output1);
322 assertNotNull(output2);
323 assertNotNull(output3);
324 assertEquals(30, output1.size());
325 assertEquals(0, output2.size());
326 assertEquals(10, output3.size());
327
328 assertEquals(10, handlerA.getEventCount());
329 assertEquals(10, handlerB.getEventCount());
330 assertEquals(10, handlerC.getEventCount());
331 assertEquals(10, handlerD.getEventCount());
332 }
333
334 /**
335 * Test with all events enabled in one session, and an event prefix in
336 * another. Once again, there should be no duplicates.
337 */
338 @Test
339 public void testAllEventsAndPrefix() {
340 assertTrue(session1.enableAllEvents());
341 assertTrue(session2.enableEvents("EventABC*"));
342 assertTrue(session1.start());
343 assertTrue(session2.start());
344 assertTrue(session3.start());
345
346 sendEventsToLoggers();
347
348 assertTrue(session1.stop());
349 assertTrue(session2.stop());
350 assertTrue(session3.stop());
351
352 List<String> output1 = session1.view();
353 List<String> output2 = session2.view();
354 List<String> output3 = session3.view();
355 assertNotNull(output1);
356 assertNotNull(output2);
357 assertNotNull(output3);
358 assertEquals(40, output1.size());
359 assertEquals(20, output2.size());
360 assertEquals(0, output3.size());
361
362 assertEquals(10, handlerA.getEventCount());
363 assertEquals(10, handlerB.getEventCount());
364 assertEquals(10, handlerC.getEventCount());
365 assertEquals(10, handlerD.getEventCount());
366 }
367 }
This page took 0.035371 seconds and 3 git commands to generate.