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 void sendEventsToLoggers();
65 public void testSetup() {
66 session1 = ILttngSession.createSession(null, getDomain());
67 session2 = ILttngSession.createSession(null, getDomain());
68 session3 = ILttngSession.createSession(null, getDomain());
75 public void testTeardown() {
92 * Test with no events in any session.
95 public void testNoEvents() {
96 assertTrue(session1.start());
97 assertTrue(session2.start());
98 assertTrue(session3.start());
100 sendEventsToLoggers();
102 assertTrue(session1.stop());
103 assertTrue(session2.stop());
104 assertTrue(session3.stop());
106 List<String> output1 = session1.view();
107 List<String> output2 = session2.view();
108 List<String> output3 = session3.view();
109 assertNotNull(output1);
110 assertNotNull(output2);
111 assertNotNull(output3);
112 assertTrue(output1.isEmpty());
113 assertTrue(output2.isEmpty());
114 assertTrue(output3.isEmpty());
116 assertEquals(0, handlerA.getEventCount());
117 assertEquals(0, handlerB.getEventCount());
118 assertEquals(0, handlerC.getEventCount());
119 assertEquals(0, handlerD.getEventCount());
123 * Test with all events enabled in one session only. Everything should be
124 * sent through JNI, but only that session should keep the trace events.
127 public void testAllEventsOneSession() {
128 assertTrue(session1.enableAllEvents());
129 assertTrue(session1.start());
130 assertTrue(session2.start());
131 assertTrue(session3.start());
133 sendEventsToLoggers();
135 assertTrue(session1.stop());
136 assertTrue(session2.stop());
137 assertTrue(session3.stop());
139 List<String> output1 = session1.view();
140 List<String> output2 = session2.view();
141 List<String> output3 = session3.view();
142 assertNotNull(output1);
143 assertNotNull(output2);
144 assertNotNull(output3);
145 assertEquals(40, output1.size());
146 assertTrue(output2.isEmpty());
147 assertTrue(output3.isEmpty());
149 assertEquals(10, handlerA.getEventCount());
150 assertEquals(10, handlerB.getEventCount());
151 assertEquals(10, handlerC.getEventCount());
152 assertEquals(10, handlerD.getEventCount());
156 * Test with all events enabled in all sessions. All traces and handlers
157 * should see every event that was logged.
160 public void testAllEventsAllSessions() {
161 assertTrue(session1.enableAllEvents());
162 assertTrue(session2.enableAllEvents());
163 assertTrue(session3.enableAllEvents());
164 assertTrue(session1.start());
165 assertTrue(session2.start());
166 assertTrue(session3.start());
168 sendEventsToLoggers();
170 assertTrue(session1.stop());
171 assertTrue(session2.stop());
172 assertTrue(session3.stop());
174 List<String> output1 = session1.view();
175 List<String> output2 = session2.view();
176 List<String> output3 = session3.view();
177 assertNotNull(output1);
178 assertNotNull(output2);
179 assertNotNull(output3);
180 assertEquals(40, output1.size());
181 assertEquals(40, output2.size());
182 assertEquals(40, output3.size());
184 assertEquals(10, handlerA.getEventCount());
185 assertEquals(10, handlerB.getEventCount());
186 assertEquals(10, handlerC.getEventCount());
187 assertEquals(10, handlerD.getEventCount());
191 * Test enabling some events in some sessions only.
194 public void testSomeEvents() {
195 assertTrue(session1.enableEvents(EVENT_NAME_A));
196 assertTrue(session2.enableEvents(EVENT_NAME_B));
197 assertTrue(session1.start());
198 assertTrue(session2.start());
199 assertTrue(session3.start());
201 sendEventsToLoggers();
203 assertTrue(session1.stop());
204 assertTrue(session2.stop());
205 assertTrue(session3.stop());
207 List<String> output1 = session1.view();
208 List<String> output2 = session2.view();
209 List<String> output3 = session3.view();
210 assertNotNull(output1);
211 assertNotNull(output2);
212 assertNotNull(output3);
213 assertEquals(10, output1.size());
214 assertEquals(10, output2.size());
215 assertEquals(0, output3.size());
217 assertEquals(10, handlerA.getEventCount());
218 assertEquals(10, handlerB.getEventCount());
219 assertEquals(0, handlerC.getEventCount());
220 assertEquals(0, handlerD.getEventCount());
224 * Test with all events enabled in one session, and some others in another.
225 * All events should arrive where expected, with no duplicates.
228 public void testAllEventsAndSome() {
229 assertTrue(session1.enableAllEvents());
230 assertTrue(session2.enableEvents(EVENT_NAME_D));
231 assertTrue(session1.start());
232 assertTrue(session2.start());
233 assertTrue(session3.start());
235 sendEventsToLoggers();
237 assertTrue(session1.stop());
238 assertTrue(session2.stop());
239 assertTrue(session3.stop());
241 List<String> output1 = session1.view();
242 List<String> output2 = session2.view();
243 List<String> output3 = session3.view();
244 assertNotNull(output1);
245 assertNotNull(output2);
246 assertNotNull(output3);
247 assertEquals(40, output1.size());
248 assertEquals(10, output2.size());
249 assertEquals(0, output3.size());
251 assertEquals(10, handlerA.getEventCount());
252 assertEquals(10, handlerB.getEventCount());
253 assertEquals(10, handlerC.getEventCount());
254 assertEquals(10, handlerD.getEventCount());
258 * Test with enabling then disabling some events. Makes sure the refcounting
262 public void testSomeEventsAfterDisabling() {
263 assertTrue(session1.enableEvents(EVENT_NAME_A, EVENT_NAME_B, EVENT_NAME_C));
264 assertTrue(session2.enableEvents(EVENT_NAME_B, EVENT_NAME_C, EVENT_NAME_D));
265 assertTrue(session3.enableEvents(EVENT_NAME_A));
267 assertTrue(session1.disableEvents(EVENT_NAME_C));
268 assertTrue(session2.disableEvents(EVENT_NAME_B, EVENT_NAME_C));
269 assertTrue(session3.disableEvents(EVENT_NAME_A));
271 assertTrue(session1.start());
272 assertTrue(session2.start());
273 assertTrue(session3.start());
275 sendEventsToLoggers();
277 assertTrue(session1.stop());
278 assertTrue(session2.stop());
279 assertTrue(session3.stop());
281 List<String> output1 = session1.view();
282 List<String> output2 = session2.view();
283 List<String> output3 = session3.view();
284 assertNotNull(output1);
285 assertNotNull(output2);
286 assertNotNull(output3);
287 assertEquals(20, output1.size());
288 assertEquals(10, output2.size());
289 assertEquals(0, output3.size());
291 assertEquals(10, handlerA.getEventCount());
292 assertEquals(10, handlerB.getEventCount());
293 assertEquals(0, handlerC.getEventCount());
294 assertEquals(10, handlerD.getEventCount());
298 * Test with a prefix in one session and a standard event in another.
301 public void testPrefixAndEvent() {
302 assertTrue(session1.enableEvents("EventAB*"));
303 assertTrue(session3.enableEvents(EVENT_NAME_A));
304 assertTrue(session1.start());
305 assertTrue(session2.start());
306 assertTrue(session3.start());
308 sendEventsToLoggers();
310 assertTrue(session1.stop());
311 assertTrue(session2.stop());
312 assertTrue(session3.stop());
314 List<String> output1 = session1.view();
315 List<String> output2 = session2.view();
316 List<String> output3 = session3.view();
317 assertNotNull(output1);
318 assertNotNull(output2);
319 assertNotNull(output3);
320 assertEquals(30, output1.size());
321 assertEquals(0, output2.size());
322 assertEquals(10, output3.size());
324 assertEquals(10, handlerA.getEventCount());
325 assertEquals(10, handlerB.getEventCount());
326 assertEquals(10, handlerC.getEventCount());
327 assertEquals(10, handlerD.getEventCount());
331 * Test with all events enabled in one session, and an event prefix in
332 * another. Once again, there should be no duplicates.
335 public void testAllEventsAndPrefix() {
336 assertTrue(session1.enableAllEvents());
337 assertTrue(session2.enableEvents("EventABC*"));
338 assertTrue(session1.start());
339 assertTrue(session2.start());
340 assertTrue(session3.start());
342 sendEventsToLoggers();
344 assertTrue(session1.stop());
345 assertTrue(session2.stop());
346 assertTrue(session3.stop());
348 List<String> output1 = session1.view();
349 List<String> output2 = session2.view();
350 List<String> output3 = session3.view();
351 assertNotNull(output1);
352 assertNotNull(output2);
353 assertNotNull(output3);
354 assertEquals(40, output1.size());
355 assertEquals(20, output2.size());
356 assertEquals(0, output3.size());
358 assertEquals(10, handlerA.getEventCount());
359 assertEquals(10, handlerB.getEventCount());
360 assertEquals(10, handlerC.getEventCount());
361 assertEquals(10, handlerD.getEventCount());