1 package org
.lttng
.ust
.agent
.integration
.common
;
3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertNotNull
;
5 import static org
.junit
.Assert
.assertTrue
;
9 import org
.junit
.After
;
10 import org
.junit
.Before
;
11 import org
.junit
.Test
;
12 import org
.lttng
.ust
.agent
.ILttngHandler
;
13 import org
.lttng
.ust
.agent
.utils
.LttngSessionControl
;
14 import org
.lttng
.ust
.agent
.utils
.LttngSessionControl
.Domain
;
16 public abstract class EnabledEventsTest
{
18 protected static final String EVENT_NAME_A
= "EventA";
19 protected static final String EVENT_NAME_B
= "EventAB";
20 protected static final String EVENT_NAME_C
= "EventABC";
21 protected static final String EVENT_NAME_D
= "EventABCD";
23 /* Fields defined by the sub-class */
24 protected ILttngHandler handlerA
;
25 protected ILttngHandler handlerB
;
26 protected ILttngHandler handlerC
;
28 protected abstract Domain
getDomain();
30 protected abstract void sendEventsToLoggers();
33 public void testSetup() {
38 public void testTeardown() {
39 /* In case the test fails before destroying the session */
40 LttngSessionControl
.tryDestroySession(null);
52 * Test sending events on the Java side, but no events enabled in the
53 * tracing session. There should be nothing in the resulting trace, and
54 * handlers should not have logged anything.
57 public void testNoEvents() {
58 assertTrue(LttngSessionControl
.setupSession(null, getDomain()));
60 sendEventsToLoggers();
62 assertTrue(LttngSessionControl
.stopSession(null));
64 List
<String
> output
= LttngSessionControl
.viewSession(null);
65 assertNotNull(output
);
66 assertTrue(output
.isEmpty());
68 assertTrue(LttngSessionControl
.destroySession(null));
70 assertEquals(0, handlerA
.getEventCount());
71 assertEquals(0, handlerB
.getEventCount());
72 assertEquals(0, handlerC
.getEventCount());
76 * Test sending events on the Java side, and all events enabled in the
77 * tracing session. All handlers should have sent their events.
80 public void testAllEvents() {
81 assertTrue(LttngSessionControl
.setupSessionAllEvents(null, getDomain()));
83 sendEventsToLoggers();
85 assertTrue(LttngSessionControl
.stopSession(null));
87 List
<String
> output
= LttngSessionControl
.viewSession(null);
88 assertNotNull(output
);
89 assertEquals(30, output
.size()); // loggerD has no handler attached
91 assertTrue(LttngSessionControl
.destroySession(null));
93 assertEquals(10, handlerA
.getEventCount());
94 assertEquals(10, handlerB
.getEventCount());
95 assertEquals(10, handlerC
.getEventCount());
99 * Test sending events on the Java side, with only some of them enabled in
100 * the tracing session. Only the subset that is enabled should be received.
103 public void testSomeEvents() {
104 assertTrue(LttngSessionControl
.setupSession(null, getDomain(),
105 EVENT_NAME_A
, EVENT_NAME_C
, EVENT_NAME_D
));
107 sendEventsToLoggers();
109 assertTrue(LttngSessionControl
.stopSession(null));
111 List
<String
> output
= LttngSessionControl
.viewSession(null);
112 assertNotNull(output
);
113 assertEquals(20, output
.size());
115 assertTrue(LttngSessionControl
.destroySession(null));
117 assertEquals(10, handlerA
.getEventCount());
118 assertEquals(0, handlerB
.getEventCount());
119 assertEquals(10, handlerC
.getEventCount());
123 * Test with all events enabled (-a), plus some other events added manually.
124 * Events should still be retained, but there should be no duplicates.
127 public void testAllEventsAndSome() {
128 assertTrue(LttngSessionControl
.setupSessionAllEvents(null, getDomain()));
129 assertTrue(LttngSessionControl
.enableEvents(null, getDomain(),
130 EVENT_NAME_A
, EVENT_NAME_B
));
132 sendEventsToLoggers();
134 assertTrue(LttngSessionControl
.stopSession(null));
136 List
<String
> output
= LttngSessionControl
.viewSession(null);
137 assertNotNull(output
);
138 assertEquals(30, output
.size());
140 assertTrue(LttngSessionControl
.destroySession(null));
142 assertEquals(10, handlerA
.getEventCount());
143 assertEquals(10, handlerB
.getEventCount());
144 assertEquals(10, handlerC
.getEventCount());
148 * Same as {@link #testSomeEvents()}, but some events were enabled first,
149 * then disabled. Makes sure the enabled-event refcounting works properly.
152 public void testSomeEventsAfterDisabling() {
153 assertTrue(LttngSessionControl
.setupSession(null, getDomain(),
154 EVENT_NAME_A
, EVENT_NAME_C
, EVENT_NAME_D
));
156 assertTrue(LttngSessionControl
.disableEvents(null, getDomain(),
159 sendEventsToLoggers();
161 assertTrue(LttngSessionControl
.stopSession(null));
163 List
<String
> output
= LttngSessionControl
.viewSession(null);
164 assertNotNull(output
);
165 assertEquals(10, output
.size());
167 assertTrue(LttngSessionControl
.destroySession(null));
169 assertEquals(10, handlerA
.getEventCount());
170 assertEquals(0, handlerB
.getEventCount());
171 assertEquals(0, handlerC
.getEventCount());
175 * Test enabling an event prefix, which means an event name ending with a *,
176 * to match all events starting with this name.
179 public void testEventPrefix() {
180 assertTrue(LttngSessionControl
.setupSession(null, getDomain(),
181 "EventAB*")); // should match event/loggers B and C, but not A.
183 sendEventsToLoggers();
185 assertTrue(LttngSessionControl
.stopSession(null));
187 List
<String
> output
= LttngSessionControl
.viewSession(null);
188 assertNotNull(output
);
189 assertEquals(20, output
.size());
191 assertTrue(LttngSessionControl
.destroySession(null));
193 assertEquals(0, handlerA
.getEventCount());
194 assertEquals(10, handlerB
.getEventCount());
195 assertEquals(10, handlerC
.getEventCount());
199 * Same as {@link #testEventPrefix()}, but with multiple prefixes that
200 * overlap. There should not be any duplicate events in the trace or in the
204 public void testEventPrefixOverlapping() {
205 assertTrue(LttngSessionControl
.setupSession(null, getDomain(),
206 "EventAB*", "EventABC*")); // should still match B and C
208 sendEventsToLoggers();
210 assertTrue(LttngSessionControl
.stopSession(null));
212 List
<String
> output
= LttngSessionControl
.viewSession(null);
213 assertNotNull(output
);
214 assertEquals(20, output
.size());
216 assertTrue(LttngSessionControl
.destroySession(null));
218 assertEquals(0, handlerA
.getEventCount());
219 assertEquals(10, handlerB
.getEventCount());
220 assertEquals(10, handlerC
.getEventCount());
224 * Test with all events enabled (-a), plus an event prefix. Once again,
225 * there should be no duplicates.
228 public void testAllEventsAndPrefix() {
229 assertTrue(LttngSessionControl
.setupSessionAllEvents(null, getDomain()));
230 assertTrue(LttngSessionControl
.enableEvents(null, getDomain(),
231 "EventAB*")); // should match B and C
233 sendEventsToLoggers();
235 assertTrue(LttngSessionControl
.stopSession(null));
237 List
<String
> output
= LttngSessionControl
.viewSession(null);
238 assertNotNull(output
);
239 assertEquals(30, output
.size());
241 assertTrue(LttngSessionControl
.destroySession(null));
243 assertEquals(10, handlerA
.getEventCount());
244 assertEquals(10, handlerB
.getEventCount());
245 assertEquals(10, handlerC
.getEventCount());
This page took 0.035079 seconds and 4 git commands to generate.