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 to implement all sorts of integration tests verifying the
38 * presence of enabled events in resulting traces.
40 @RunWith(TestPrintRunner.class)
41 public abstract class EnabledEventsITBase {
43 protected static final String EVENT_NAME_A = "EventA";
44 protected static final String EVENT_NAME_B = "EventAB";
45 protected static final String EVENT_NAME_C = "EventABC";
46 protected static final String EVENT_NAME_D = "EventABCD";
48 private ILttngSession session;
50 /* Fields defined by the sub-class */
51 protected ILttngHandler handlerA;
52 protected ILttngHandler handlerB;
53 protected ILttngHandler handlerC;
55 protected abstract Domain getDomain();
57 protected abstract void sendEventsToLoggers();
63 public void testSetup() {
64 session = ILttngSession.createSession(null, getDomain());
71 public void testTeardown() {
84 * Test sending events on the Java side, but no events enabled in the
85 * tracing session. There should be nothing in the resulting trace, and
86 * handlers should not have logged anything.
89 public void testNoEvents() {
90 assertTrue(session.start());
92 sendEventsToLoggers();
94 assertTrue(session.stop());
96 List<String> output = session.view();
97 assertNotNull(output);
98 assertTrue(output.isEmpty());
100 assertEquals(0, handlerA.getEventCount());
101 assertEquals(0, handlerB.getEventCount());
102 assertEquals(0, handlerC.getEventCount());
106 * Test sending events on the Java side, and all events enabled in the
107 * tracing session. All handlers should have sent their events.
110 public void testAllEvents() {
111 assertTrue(session.enableAllEvents());
112 assertTrue(session.start());
114 sendEventsToLoggers();
116 assertTrue(session.stop());
118 List<String> output = session.view();
119 assertNotNull(output);
120 assertEquals(30, output.size()); // loggerD has no handler attached
122 assertEquals(10, handlerA.getEventCount());
123 assertEquals(10, handlerB.getEventCount());
124 assertEquals(10, handlerC.getEventCount());
128 * Test sending events on the Java side, with only some of them enabled in
129 * the tracing session. Only the subset that is enabled should be received.
132 public void testSomeEvents() {
133 assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D));
134 assertTrue(session.start());
136 sendEventsToLoggers();
138 assertTrue(session.stop());
140 List<String> output = session.view();
141 assertNotNull(output);
142 assertEquals(20, output.size());
144 assertEquals(10, handlerA.getEventCount());
145 assertEquals(0, handlerB.getEventCount());
146 assertEquals(10, handlerC.getEventCount());
150 * Test with all events enabled (-a), plus some other events added manually.
151 * Events should still be retained, but there should be no duplicates.
154 public void testAllEventsAndSome() {
155 assertTrue(session.enableAllEvents());
156 assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_B));
157 assertTrue(session.start());
159 sendEventsToLoggers();
161 assertTrue(session.stop());
163 List<String> output = session.view();
164 assertNotNull(output);
165 assertEquals(30, output.size());
167 assertEquals(10, handlerA.getEventCount());
168 assertEquals(10, handlerB.getEventCount());
169 assertEquals(10, handlerC.getEventCount());
173 * Same as {@link #testSomeEvents()}, but some events were enabled first,
174 * then disabled. Makes sure the enabled-event refcounting works properly.
177 public void testSomeEventsAfterDisabling() {
178 assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D));
179 assertTrue(session.disableEvents(EVENT_NAME_C));
180 assertTrue(session.start());
182 sendEventsToLoggers();
184 assertTrue(session.stop());
186 List<String> output = session.view();
187 assertNotNull(output);
188 assertEquals(10, output.size());
190 assertEquals(10, handlerA.getEventCount());
191 assertEquals(0, handlerB.getEventCount());
192 assertEquals(0, handlerC.getEventCount());
196 * Test enabling an event prefix, which means an event name ending with a *,
197 * to match all events starting with this name.
200 public void testEventPrefix() {
201 // should match event/loggers B and C, but not A.
202 assertTrue(session.enableEvents("EventAB*"));
203 assertTrue(session.start());
205 sendEventsToLoggers();
207 assertTrue(session.stop());
209 List<String> output = session.view();
210 assertNotNull(output);
211 assertEquals(20, output.size());
213 assertEquals(0, handlerA.getEventCount());
214 assertEquals(10, handlerB.getEventCount());
215 assertEquals(10, handlerC.getEventCount());
219 * Same as {@link #testEventPrefix()}, but with multiple prefixes that
220 * overlap. There should not be any duplicate events in the trace or in the
224 public void testEventPrefixOverlapping() {
225 // should still match B and C
226 assertTrue(session.enableEvents("EventAB*", "EventABC*"));
227 assertTrue(session.start());
229 sendEventsToLoggers();
231 assertTrue(session.stop());
233 List<String> output = session.view();
234 assertNotNull(output);
235 assertEquals(20, output.size());
237 assertEquals(0, handlerA.getEventCount());
238 assertEquals(10, handlerB.getEventCount());
239 assertEquals(10, handlerC.getEventCount());
243 * Test with all events enabled (-a), plus an event prefix. Once again,
244 * there should be no duplicates.
247 public void testAllEventsAndPrefix() {
248 assertTrue(session.enableAllEvents());
249 assertTrue(session.enableEvents("EventAB*"));
250 assertTrue(session.start());
252 sendEventsToLoggers();
254 assertTrue(session.stop());
256 List<String> output = session.view();
257 assertNotNull(output);
258 assertEquals(30, output.size());
260 assertEquals(10, handlerA.getEventCount());
261 assertEquals(10, handlerB.getEventCount());
262 assertEquals(10, handlerC.getEventCount());