2 * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
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.
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.
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.
19 package org.lttng.ust.agent.integration.events;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertTrue;
25 import java.util.List;
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;
37 * Base abstract class for tests with multiple concurrent tracing sessions
39 @RunWith(TestPrintRunner.class)
40 public abstract class MultiSessionITBase {
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É";
47 private ILttngSession session1;
48 private ILttngSession session2;
49 private ILttngSession session3;
51 /* Fields defined by the sub-class */
52 protected ILttngHandler handlerA;
53 protected ILttngHandler handlerB;
54 protected ILttngHandler handlerC;
55 protected ILttngHandler handlerD;
57 protected abstract Domain getDomain();
59 protected abstract boolean closeHandlers();
61 protected abstract void sendEventsToLoggers();
67 public void testSetup() {
68 session1 = ILttngSession.createSession(null, getDomain());
69 session2 = ILttngSession.createSession(null, getDomain());
70 session3 = ILttngSession.createSession(null, getDomain());
77 public void testTeardown() {
82 if (closeHandlers()) {
96 * Test with no events in any session.
99 public void testNoEvents() {
100 assertTrue(session1.start());
101 assertTrue(session2.start());
102 assertTrue(session3.start());
104 sendEventsToLoggers();
106 assertTrue(session1.stop());
107 assertTrue(session2.stop());
108 assertTrue(session3.stop());
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());
120 assertEquals(0, handlerA.getEventCount());
121 assertEquals(0, handlerB.getEventCount());
122 assertEquals(0, handlerC.getEventCount());
123 assertEquals(0, handlerD.getEventCount());
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.
131 public void testAllEventsOneSession() {
132 assertTrue(session1.enableAllEvents());
133 assertTrue(session1.start());
134 assertTrue(session2.start());
135 assertTrue(session3.start());
137 sendEventsToLoggers();
139 assertTrue(session1.stop());
140 assertTrue(session2.stop());
141 assertTrue(session3.stop());
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());
153 assertEquals(10, handlerA.getEventCount());
154 assertEquals(10, handlerB.getEventCount());
155 assertEquals(10, handlerC.getEventCount());
156 assertEquals(10, handlerD.getEventCount());
160 * Test with all events enabled in all sessions. All traces and handlers
161 * should see every event that was logged.
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());
172 sendEventsToLoggers();
174 assertTrue(session1.stop());
175 assertTrue(session2.stop());
176 assertTrue(session3.stop());
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());
188 assertEquals(10, handlerA.getEventCount());
189 assertEquals(10, handlerB.getEventCount());
190 assertEquals(10, handlerC.getEventCount());
191 assertEquals(10, handlerD.getEventCount());
195 * Test enabling some events in some sessions only.
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());
205 sendEventsToLoggers();
207 assertTrue(session1.stop());
208 assertTrue(session2.stop());
209 assertTrue(session3.stop());
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());
221 assertEquals(10, handlerA.getEventCount());
222 assertEquals(10, handlerB.getEventCount());
223 assertEquals(0, handlerC.getEventCount());
224 assertEquals(0, handlerD.getEventCount());
228 * Test with all events enabled in one session, and some others in another.
229 * All events should arrive where expected, with no duplicates.
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());
239 sendEventsToLoggers();
241 assertTrue(session1.stop());
242 assertTrue(session2.stop());
243 assertTrue(session3.stop());
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());
255 assertEquals(10, handlerA.getEventCount());
256 assertEquals(10, handlerB.getEventCount());
257 assertEquals(10, handlerC.getEventCount());
258 assertEquals(10, handlerD.getEventCount());
262 * Test with enabling then disabling some events. Makes sure the refcounting
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));
271 assertTrue(session1.disableEvents(EVENT_NAME_C));
272 assertTrue(session2.disableEvents(EVENT_NAME_B, EVENT_NAME_C));
273 assertTrue(session3.disableEvents(EVENT_NAME_A));
275 assertTrue(session1.start());
276 assertTrue(session2.start());
277 assertTrue(session3.start());
279 sendEventsToLoggers();
281 assertTrue(session1.stop());
282 assertTrue(session2.stop());
283 assertTrue(session3.stop());
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());
295 assertEquals(10, handlerA.getEventCount());
296 assertEquals(10, handlerB.getEventCount());
297 assertEquals(0, handlerC.getEventCount());
298 assertEquals(10, handlerD.getEventCount());
302 * Test with a prefix in one session and a standard event in another.
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());
312 sendEventsToLoggers();
314 assertTrue(session1.stop());
315 assertTrue(session2.stop());
316 assertTrue(session3.stop());
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());
328 assertEquals(10, handlerA.getEventCount());
329 assertEquals(10, handlerB.getEventCount());
330 assertEquals(10, handlerC.getEventCount());
331 assertEquals(10, handlerD.getEventCount());
335 * Test with all events enabled in one session, and an event prefix in
336 * another. Once again, there should be no duplicates.
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());
346 sendEventsToLoggers();
348 assertTrue(session1.stop());
349 assertTrue(session2.stop());
350 assertTrue(session3.stop());
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());
362 assertEquals(10, handlerA.getEventCount());
363 assertEquals(10, handlerB.getEventCount());
364 assertEquals(10, handlerC.getEventCount());
365 assertEquals(10, handlerD.getEventCount());