1 package org
.lttng
.ust
.agent
.integration
;
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
.LttngSession
;
14 import org
.lttng
.ust
.agent
.utils
.LttngSession
.Domain
;
16 public abstract class EnabledEventsTestBase
{
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 private LttngSession session
;
25 /* Fields defined by the sub-class */
26 protected ILttngHandler handlerA
;
27 protected ILttngHandler handlerB
;
28 protected ILttngHandler handlerC
;
30 protected abstract Domain
getDomain();
32 protected abstract void sendEventsToLoggers();
35 public void testSetup() {
36 session
= new LttngSession(null, getDomain());
40 public void testTeardown() {
53 * Test sending events on the Java side, but no events enabled in the
54 * tracing session. There should be nothing in the resulting trace, and
55 * handlers should not have logged anything.
58 public void testNoEvents() {
59 assertTrue(session
.start());
61 sendEventsToLoggers();
63 assertTrue(session
.stop());
65 List
<String
> output
= session
.view();
66 assertNotNull(output
);
67 assertTrue(output
.isEmpty());
69 assertEquals(0, handlerA
.getEventCount());
70 assertEquals(0, handlerB
.getEventCount());
71 assertEquals(0, handlerC
.getEventCount());
75 * Test sending events on the Java side, and all events enabled in the
76 * tracing session. All handlers should have sent their events.
79 public void testAllEvents() {
80 assertTrue(session
.enableAllEvents());
81 assertTrue(session
.start());
83 sendEventsToLoggers();
85 assertTrue(session
.stop());
87 List
<String
> output
= session
.view();
88 assertNotNull(output
);
89 assertEquals(30, output
.size()); // loggerD has no handler attached
91 assertEquals(10, handlerA
.getEventCount());
92 assertEquals(10, handlerB
.getEventCount());
93 assertEquals(10, handlerC
.getEventCount());
97 * Test sending events on the Java side, with only some of them enabled in
98 * the tracing session. Only the subset that is enabled should be received.
101 public void testSomeEvents() {
102 assertTrue(session
.enableEvents(EVENT_NAME_A
, EVENT_NAME_C
, EVENT_NAME_D
));
103 assertTrue(session
.start());
105 sendEventsToLoggers();
107 assertTrue(session
.stop());
109 List
<String
> output
= session
.view();
110 assertNotNull(output
);
111 assertEquals(20, output
.size());
113 assertEquals(10, handlerA
.getEventCount());
114 assertEquals(0, handlerB
.getEventCount());
115 assertEquals(10, handlerC
.getEventCount());
119 * Test with all events enabled (-a), plus some other events added manually.
120 * Events should still be retained, but there should be no duplicates.
123 public void testAllEventsAndSome() {
124 assertTrue(session
.enableAllEvents());
125 assertTrue(session
.enableEvents(EVENT_NAME_A
, EVENT_NAME_B
));
126 assertTrue(session
.start());
128 sendEventsToLoggers();
130 assertTrue(session
.stop());
132 List
<String
> output
= session
.view();
133 assertNotNull(output
);
134 assertEquals(30, output
.size());
136 assertEquals(10, handlerA
.getEventCount());
137 assertEquals(10, handlerB
.getEventCount());
138 assertEquals(10, handlerC
.getEventCount());
142 * Same as {@link #testSomeEvents()}, but some events were enabled first,
143 * then disabled. Makes sure the enabled-event refcounting works properly.
146 public void testSomeEventsAfterDisabling() {
147 assertTrue(session
.enableEvents(EVENT_NAME_A
, EVENT_NAME_C
, EVENT_NAME_D
));
148 assertTrue(session
.disableEvents(EVENT_NAME_C
));
149 assertTrue(session
.start());
151 sendEventsToLoggers();
153 assertTrue(session
.stop());
155 List
<String
> output
= session
.view();
156 assertNotNull(output
);
157 assertEquals(10, output
.size());
159 assertEquals(10, handlerA
.getEventCount());
160 assertEquals(0, handlerB
.getEventCount());
161 assertEquals(0, handlerC
.getEventCount());
165 * Test enabling an event prefix, which means an event name ending with a *,
166 * to match all events starting with this name.
169 public void testEventPrefix() {
170 // should match event/loggers B and C, but not A.
171 assertTrue(session
.enableEvents("EventAB*"));
172 assertTrue(session
.start());
174 sendEventsToLoggers();
176 assertTrue(session
.stop());
178 List
<String
> output
= session
.view();
179 assertNotNull(output
);
180 assertEquals(20, output
.size());
182 assertEquals(0, handlerA
.getEventCount());
183 assertEquals(10, handlerB
.getEventCount());
184 assertEquals(10, handlerC
.getEventCount());
188 * Same as {@link #testEventPrefix()}, but with multiple prefixes that
189 * overlap. There should not be any duplicate events in the trace or in the
193 public void testEventPrefixOverlapping() {
194 // should still match B and C
195 assertTrue(session
.enableEvents("EventAB*", "EventABC*"));
196 assertTrue(session
.start());
198 sendEventsToLoggers();
200 assertTrue(session
.stop());
202 List
<String
> output
= session
.view();
203 assertNotNull(output
);
204 assertEquals(20, output
.size());
206 assertEquals(0, handlerA
.getEventCount());
207 assertEquals(10, handlerB
.getEventCount());
208 assertEquals(10, handlerC
.getEventCount());
212 * Test with all events enabled (-a), plus an event prefix. Once again,
213 * there should be no duplicates.
216 public void testAllEventsAndPrefix() {
217 assertTrue(session
.enableAllEvents());
218 assertTrue(session
.enableEvents("EventAB*"));
219 assertTrue(session
.start());
221 sendEventsToLoggers();
223 assertTrue(session
.stop());
225 List
<String
> output
= session
.view();
226 assertNotNull(output
);
227 assertEquals(30, output
.size());
229 assertEquals(10, handlerA
.getEventCount());
230 assertEquals(10, handlerB
.getEventCount());
231 assertEquals(10, handlerC
.getEventCount());
This page took 0.036611 seconds and 4 git commands to generate.