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
;
34 public abstract class EnabledEventsTestBase
{
36 protected static final String EVENT_NAME_A
= "EventA";
37 protected static final String EVENT_NAME_B
= "EventAB";
38 protected static final String EVENT_NAME_C
= "EventABC";
39 protected static final String EVENT_NAME_D
= "EventABCD";
41 private LttngSession session
;
43 /* Fields defined by the sub-class */
44 protected ILttngHandler handlerA
;
45 protected ILttngHandler handlerB
;
46 protected ILttngHandler handlerC
;
48 protected abstract Domain
getDomain();
50 protected abstract void sendEventsToLoggers();
53 public void testSetup() {
54 session
= new LttngSession(null, getDomain());
58 public void testTeardown() {
71 * Test sending events on the Java side, but no events enabled in the
72 * tracing session. There should be nothing in the resulting trace, and
73 * handlers should not have logged anything.
76 public void testNoEvents() {
77 assertTrue(session
.start());
79 sendEventsToLoggers();
81 assertTrue(session
.stop());
83 List
<String
> output
= session
.view();
84 assertNotNull(output
);
85 assertTrue(output
.isEmpty());
87 assertEquals(0, handlerA
.getEventCount());
88 assertEquals(0, handlerB
.getEventCount());
89 assertEquals(0, handlerC
.getEventCount());
93 * Test sending events on the Java side, and all events enabled in the
94 * tracing session. All handlers should have sent their events.
97 public void testAllEvents() {
98 assertTrue(session
.enableAllEvents());
99 assertTrue(session
.start());
101 sendEventsToLoggers();
103 assertTrue(session
.stop());
105 List
<String
> output
= session
.view();
106 assertNotNull(output
);
107 assertEquals(30, output
.size()); // loggerD has no handler attached
109 assertEquals(10, handlerA
.getEventCount());
110 assertEquals(10, handlerB
.getEventCount());
111 assertEquals(10, handlerC
.getEventCount());
115 * Test sending events on the Java side, with only some of them enabled in
116 * the tracing session. Only the subset that is enabled should be received.
119 public void testSomeEvents() {
120 assertTrue(session
.enableEvents(EVENT_NAME_A
, EVENT_NAME_C
, EVENT_NAME_D
));
121 assertTrue(session
.start());
123 sendEventsToLoggers();
125 assertTrue(session
.stop());
127 List
<String
> output
= session
.view();
128 assertNotNull(output
);
129 assertEquals(20, output
.size());
131 assertEquals(10, handlerA
.getEventCount());
132 assertEquals(0, handlerB
.getEventCount());
133 assertEquals(10, handlerC
.getEventCount());
137 * Test with all events enabled (-a), plus some other events added manually.
138 * Events should still be retained, but there should be no duplicates.
141 public void testAllEventsAndSome() {
142 assertTrue(session
.enableAllEvents());
143 assertTrue(session
.enableEvents(EVENT_NAME_A
, EVENT_NAME_B
));
144 assertTrue(session
.start());
146 sendEventsToLoggers();
148 assertTrue(session
.stop());
150 List
<String
> output
= session
.view();
151 assertNotNull(output
);
152 assertEquals(30, output
.size());
154 assertEquals(10, handlerA
.getEventCount());
155 assertEquals(10, handlerB
.getEventCount());
156 assertEquals(10, handlerC
.getEventCount());
160 * Same as {@link #testSomeEvents()}, but some events were enabled first,
161 * then disabled. Makes sure the enabled-event refcounting works properly.
164 public void testSomeEventsAfterDisabling() {
165 assertTrue(session
.enableEvents(EVENT_NAME_A
, EVENT_NAME_C
, EVENT_NAME_D
));
166 assertTrue(session
.disableEvents(EVENT_NAME_C
));
167 assertTrue(session
.start());
169 sendEventsToLoggers();
171 assertTrue(session
.stop());
173 List
<String
> output
= session
.view();
174 assertNotNull(output
);
175 assertEquals(10, output
.size());
177 assertEquals(10, handlerA
.getEventCount());
178 assertEquals(0, handlerB
.getEventCount());
179 assertEquals(0, handlerC
.getEventCount());
183 * Test enabling an event prefix, which means an event name ending with a *,
184 * to match all events starting with this name.
187 public void testEventPrefix() {
188 // should match event/loggers B and C, but not A.
189 assertTrue(session
.enableEvents("EventAB*"));
190 assertTrue(session
.start());
192 sendEventsToLoggers();
194 assertTrue(session
.stop());
196 List
<String
> output
= session
.view();
197 assertNotNull(output
);
198 assertEquals(20, output
.size());
200 assertEquals(0, handlerA
.getEventCount());
201 assertEquals(10, handlerB
.getEventCount());
202 assertEquals(10, handlerC
.getEventCount());
206 * Same as {@link #testEventPrefix()}, but with multiple prefixes that
207 * overlap. There should not be any duplicate events in the trace or in the
211 public void testEventPrefixOverlapping() {
212 // should still match B and C
213 assertTrue(session
.enableEvents("EventAB*", "EventABC*"));
214 assertTrue(session
.start());
216 sendEventsToLoggers();
218 assertTrue(session
.stop());
220 List
<String
> output
= session
.view();
221 assertNotNull(output
);
222 assertEquals(20, output
.size());
224 assertEquals(0, handlerA
.getEventCount());
225 assertEquals(10, handlerB
.getEventCount());
226 assertEquals(10, handlerC
.getEventCount());
230 * Test with all events enabled (-a), plus an event prefix. Once again,
231 * there should be no duplicates.
234 public void testAllEventsAndPrefix() {
235 assertTrue(session
.enableAllEvents());
236 assertTrue(session
.enableEvents("EventAB*"));
237 assertTrue(session
.start());
239 sendEventsToLoggers();
241 assertTrue(session
.stop());
243 List
<String
> output
= session
.view();
244 assertNotNull(output
);
245 assertEquals(30, output
.size());
247 assertEquals(10, handlerA
.getEventCount());
248 assertEquals(10, handlerB
.getEventCount());
249 assertEquals(10, handlerC
.getEventCount());
This page took 0.034599 seconds and 4 git commands to generate.