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
.Arrays
;
26 import java
.util
.List
;
28 import org
.junit
.After
;
29 import org
.junit
.Before
;
30 import org
.junit
.Test
;
31 import org
.junit
.runner
.RunWith
;
32 import org
.lttng
.tools
.ILttngSession
;
33 import org
.lttng
.tools
.ILttngSession
.Domain
;
34 import org
.lttng
.ust
.agent
.ILttngHandler
;
35 import org
.lttng
.ust
.agent
.utils
.TestPrintRunner
;
38 * Base abstract class to implement all sorts of integration tests verifying the
39 * presence of enabled events in resulting traces.
41 @RunWith(TestPrintRunner
.class)
42 public abstract class EnabledEventsITBase
{
44 protected static final String EVENT_NAME_A
= "EventA";
45 protected static final String EVENT_NAME_B
= "EventAB";
46 protected static final String EVENT_NAME_C
= "EventABC";
47 protected static final String EVENT_NAME_D
= "EventABCDÉ";
49 private ILttngSession session
;
51 /* Fields defined by the sub-class */
52 protected ILttngHandler handlerA
;
53 protected ILttngHandler handlerB
;
54 protected ILttngHandler handlerC
;
56 protected abstract Domain
getDomain();
58 protected abstract boolean closeHandlers();
60 protected abstract void sendEventsToLoggers();
63 * Send one event using a localized API to logger/handler A.
65 protected abstract void sendLocalizedEvent(String rawString
, Object
[] params
);
71 public void testSetup() {
72 session
= ILttngSession
.createSession(null, getDomain());
79 public void testTeardown() {
82 if (closeHandlers()) {
94 * Test sending events on the Java side, but no events enabled in the
95 * tracing session. There should be nothing in the resulting trace, and
96 * handlers should not have logged anything.
99 public void testNoEvents() {
100 assertTrue(session
.start());
102 sendEventsToLoggers();
104 assertTrue(session
.stop());
106 List
<String
> output
= session
.view();
107 assertNotNull(output
);
108 assertTrue(output
.isEmpty());
110 assertEquals(0, handlerA
.getEventCount());
111 assertEquals(0, handlerB
.getEventCount());
112 assertEquals(0, handlerC
.getEventCount());
116 * Test sending events on the Java side, and all events enabled in the
117 * tracing session. All handlers should have sent their events.
120 public void testAllEvents() {
121 assertTrue(session
.enableAllEvents());
122 assertTrue(session
.start());
124 sendEventsToLoggers();
126 assertTrue(session
.stop());
128 List
<String
> output
= session
.view();
129 assertNotNull(output
);
130 assertEquals(30, output
.size()); // loggerD has no handler attached
132 assertEquals(10, handlerA
.getEventCount());
133 assertEquals(10, handlerB
.getEventCount());
134 assertEquals(10, handlerC
.getEventCount());
138 * Test sending events on the Java side, with only some of them enabled in
139 * the tracing session. Only the subset that is enabled should be received.
142 public void testSomeEvents() {
143 assertTrue(session
.enableEvents(EVENT_NAME_A
, EVENT_NAME_C
, EVENT_NAME_D
));
144 assertTrue(session
.start());
146 sendEventsToLoggers();
148 assertTrue(session
.stop());
150 List
<String
> output
= session
.view();
151 assertNotNull(output
);
152 assertEquals(20, output
.size());
154 assertEquals(10, handlerA
.getEventCount());
155 assertEquals(0, handlerB
.getEventCount());
156 assertEquals(10, handlerC
.getEventCount());
160 * Test with all events enabled (-a), plus some other events added manually.
161 * Events should still be retained, but there should be no duplicates.
164 public void testAllEventsAndSome() {
165 assertTrue(session
.enableAllEvents());
166 assertTrue(session
.enableEvents(EVENT_NAME_A
, EVENT_NAME_B
));
167 assertTrue(session
.start());
169 sendEventsToLoggers();
171 assertTrue(session
.stop());
173 List
<String
> output
= session
.view();
174 assertNotNull(output
);
175 assertEquals(30, output
.size());
177 assertEquals(10, handlerA
.getEventCount());
178 assertEquals(10, handlerB
.getEventCount());
179 assertEquals(10, handlerC
.getEventCount());
183 * Same as {@link #testSomeEvents()}, but some events were enabled first,
184 * then disabled. Makes sure the enabled-event refcounting works properly.
187 public void testSomeEventsAfterDisabling() {
188 assertTrue(session
.enableEvents(EVENT_NAME_A
, EVENT_NAME_C
, EVENT_NAME_D
));
189 assertTrue(session
.disableEvents(EVENT_NAME_C
));
190 assertTrue(session
.start());
192 sendEventsToLoggers();
194 assertTrue(session
.stop());
196 List
<String
> output
= session
.view();
197 assertNotNull(output
);
198 assertEquals(10, output
.size());
200 assertEquals(10, handlerA
.getEventCount());
201 assertEquals(0, handlerB
.getEventCount());
202 assertEquals(0, handlerC
.getEventCount());
206 * Test enabling an event prefix, which means an event name ending with a *,
207 * to match all events starting with this name.
210 public void testEventPrefix() {
211 // should match event/loggers B and C, but not A.
212 assertTrue(session
.enableEvents("EventAB*"));
213 assertTrue(session
.start());
215 sendEventsToLoggers();
217 assertTrue(session
.stop());
219 List
<String
> output
= session
.view();
220 assertNotNull(output
);
221 assertEquals(20, output
.size());
223 assertEquals(0, handlerA
.getEventCount());
224 assertEquals(10, handlerB
.getEventCount());
225 assertEquals(10, handlerC
.getEventCount());
229 * Same as {@link #testEventPrefix()}, but with multiple prefixes that
230 * overlap. There should not be any duplicate events in the trace or in the
234 public void testEventPrefixOverlapping() {
235 // should still match B and C
236 assertTrue(session
.enableEvents("EventAB*", "EventABC*"));
237 assertTrue(session
.start());
239 sendEventsToLoggers();
241 assertTrue(session
.stop());
243 List
<String
> output
= session
.view();
244 assertNotNull(output
);
245 assertEquals(20, output
.size());
247 assertEquals(0, handlerA
.getEventCount());
248 assertEquals(10, handlerB
.getEventCount());
249 assertEquals(10, handlerC
.getEventCount());
253 * Test with all events enabled (-a), plus an event prefix. Once again,
254 * there should be no duplicates.
257 public void testAllEventsAndPrefix() {
258 assertTrue(session
.enableAllEvents());
259 assertTrue(session
.enableEvents("EventAB*"));
260 assertTrue(session
.start());
262 sendEventsToLoggers();
264 assertTrue(session
.stop());
266 List
<String
> output
= session
.view();
267 assertNotNull(output
);
268 assertEquals(30, output
.size());
270 assertEquals(10, handlerA
.getEventCount());
271 assertEquals(10, handlerB
.getEventCount());
272 assertEquals(10, handlerC
.getEventCount());
276 * Test sending a localized message.
279 public void testLocalizedMessage() {
280 Integer value1
= Integer
.valueOf(10);
281 List
<Integer
> value2
= Arrays
.asList(Integer
.valueOf(1000), Integer
.valueOf(1001), Integer
.valueOf(1002));
283 assertTrue(session
.enableAllEvents());
284 assertTrue(session
.start());
286 sendLocalizedEvent("Message with a localized value: {0} and some others: {1}",
287 new Object
[] { value1
, value2
});
289 assertTrue(session
.stop());
290 assertEquals(1, handlerA
.getEventCount());
292 List
<String
> output
= session
.view();
294 assertNotNull(output
);
295 assertEquals(1, output
.size());
296 assertTrue(output
.get(0).contains("msg = \"Message with a localized value: 10 and some others: [1000, 1001, 1002]\""));
This page took 0.039447 seconds and 5 git commands to generate.