49ee622ff96d64aa14a0a81a91ecf1a83eb42a84
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
;
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
.lttng
.ust
.agent
.ILttngHandler
;
31 import org
.lttng
.ust
.agent
.utils
.LttngSession
;
32 import org
.lttng
.ust
.agent
.utils
.LttngSession
.Domain
;
35 * Base abstract class to implement all sorts of integration tests verifying the
36 * presence of enabled events in resulting traces.
38 public abstract class EnabledEventsTestBase
{
40 protected static final String EVENT_NAME_A
= "EventA";
41 protected static final String EVENT_NAME_B
= "EventAB";
42 protected static final String EVENT_NAME_C
= "EventABC";
43 protected static final String EVENT_NAME_D
= "EventABCD";
45 private LttngSession session
;
47 /* Fields defined by the sub-class */
48 protected ILttngHandler handlerA
;
49 protected ILttngHandler handlerB
;
50 protected ILttngHandler handlerC
;
52 protected abstract Domain
getDomain();
54 protected abstract void sendEventsToLoggers();
60 public void testSetup() {
61 session
= new LttngSession(null, getDomain());
68 public void testTeardown() {
81 * Test sending events on the Java side, but no events enabled in the
82 * tracing session. There should be nothing in the resulting trace, and
83 * handlers should not have logged anything.
86 public void testNoEvents() {
87 assertTrue(session
.start());
89 sendEventsToLoggers();
91 assertTrue(session
.stop());
93 List
<String
> output
= session
.view();
94 assertNotNull(output
);
95 assertTrue(output
.isEmpty());
97 assertEquals(0, handlerA
.getEventCount());
98 assertEquals(0, handlerB
.getEventCount());
99 assertEquals(0, handlerC
.getEventCount());
103 * Test sending events on the Java side, and all events enabled in the
104 * tracing session. All handlers should have sent their events.
107 public void testAllEvents() {
108 assertTrue(session
.enableAllEvents());
109 assertTrue(session
.start());
111 sendEventsToLoggers();
113 assertTrue(session
.stop());
115 List
<String
> output
= session
.view();
116 assertNotNull(output
);
117 assertEquals(30, output
.size()); // loggerD has no handler attached
119 assertEquals(10, handlerA
.getEventCount());
120 assertEquals(10, handlerB
.getEventCount());
121 assertEquals(10, handlerC
.getEventCount());
125 * Test sending events on the Java side, with only some of them enabled in
126 * the tracing session. Only the subset that is enabled should be received.
129 public void testSomeEvents() {
130 assertTrue(session
.enableEvents(EVENT_NAME_A
, EVENT_NAME_C
, EVENT_NAME_D
));
131 assertTrue(session
.start());
133 sendEventsToLoggers();
135 assertTrue(session
.stop());
137 List
<String
> output
= session
.view();
138 assertNotNull(output
);
139 assertEquals(20, output
.size());
141 assertEquals(10, handlerA
.getEventCount());
142 assertEquals(0, handlerB
.getEventCount());
143 assertEquals(10, handlerC
.getEventCount());
147 * Test with all events enabled (-a), plus some other events added manually.
148 * Events should still be retained, but there should be no duplicates.
151 public void testAllEventsAndSome() {
152 assertTrue(session
.enableAllEvents());
153 assertTrue(session
.enableEvents(EVENT_NAME_A
, EVENT_NAME_B
));
154 assertTrue(session
.start());
156 sendEventsToLoggers();
158 assertTrue(session
.stop());
160 List
<String
> output
= session
.view();
161 assertNotNull(output
);
162 assertEquals(30, output
.size());
164 assertEquals(10, handlerA
.getEventCount());
165 assertEquals(10, handlerB
.getEventCount());
166 assertEquals(10, handlerC
.getEventCount());
170 * Same as {@link #testSomeEvents()}, but some events were enabled first,
171 * then disabled. Makes sure the enabled-event refcounting works properly.
174 public void testSomeEventsAfterDisabling() {
175 assertTrue(session
.enableEvents(EVENT_NAME_A
, EVENT_NAME_C
, EVENT_NAME_D
));
176 assertTrue(session
.disableEvents(EVENT_NAME_C
));
177 assertTrue(session
.start());
179 sendEventsToLoggers();
181 assertTrue(session
.stop());
183 List
<String
> output
= session
.view();
184 assertNotNull(output
);
185 assertEquals(10, output
.size());
187 assertEquals(10, handlerA
.getEventCount());
188 assertEquals(0, handlerB
.getEventCount());
189 assertEquals(0, handlerC
.getEventCount());
193 * Test enabling an event prefix, which means an event name ending with a *,
194 * to match all events starting with this name.
197 public void testEventPrefix() {
198 // should match event/loggers B and C, but not A.
199 assertTrue(session
.enableEvents("EventAB*"));
200 assertTrue(session
.start());
202 sendEventsToLoggers();
204 assertTrue(session
.stop());
206 List
<String
> output
= session
.view();
207 assertNotNull(output
);
208 assertEquals(20, output
.size());
210 assertEquals(0, handlerA
.getEventCount());
211 assertEquals(10, handlerB
.getEventCount());
212 assertEquals(10, handlerC
.getEventCount());
216 * Same as {@link #testEventPrefix()}, but with multiple prefixes that
217 * overlap. There should not be any duplicate events in the trace or in the
221 public void testEventPrefixOverlapping() {
222 // should still match B and C
223 assertTrue(session
.enableEvents("EventAB*", "EventABC*"));
224 assertTrue(session
.start());
226 sendEventsToLoggers();
228 assertTrue(session
.stop());
230 List
<String
> output
= session
.view();
231 assertNotNull(output
);
232 assertEquals(20, output
.size());
234 assertEquals(0, handlerA
.getEventCount());
235 assertEquals(10, handlerB
.getEventCount());
236 assertEquals(10, handlerC
.getEventCount());
240 * Test with all events enabled (-a), plus an event prefix. Once again,
241 * there should be no duplicates.
244 public void testAllEventsAndPrefix() {
245 assertTrue(session
.enableAllEvents());
246 assertTrue(session
.enableEvents("EventAB*"));
247 assertTrue(session
.start());
249 sendEventsToLoggers();
251 assertTrue(session
.stop());
253 List
<String
> output
= session
.view();
254 assertNotNull(output
);
255 assertEquals(30, output
.size());
257 assertEquals(10, handlerA
.getEventCount());
258 assertEquals(10, handlerB
.getEventCount());
259 assertEquals(10, handlerC
.getEventCount());
This page took 0.038951 seconds and 4 git commands to generate.