Add Javadoc and related settings
[lttng-ust-java-tests.git] / src / test / java / org / lttng / ust / agent / integration / EnabledEventsTestBase.java
1 /*
2 * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
3 *
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.
8 *
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.
13 *
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.
17 */
18
19 package org.lttng.ust.agent.integration;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertTrue;
24
25 import java.util.List;
26
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;
33
34 /**
35 * Base abstract class to implement all sorts of integration tests verifying the
36 * presence of enabled events in resulting traces.
37 */
38 public abstract class EnabledEventsTestBase {
39
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";
44
45 private LttngSession session;
46
47 /* Fields defined by the sub-class */
48 protected ILttngHandler handlerA;
49 protected ILttngHandler handlerB;
50 protected ILttngHandler handlerC;
51
52 protected abstract Domain getDomain();
53
54 protected abstract void sendEventsToLoggers();
55
56 /**
57 * Base test setup
58 */
59 @Before
60 public void testSetup() {
61 session = new LttngSession(null, getDomain());
62 }
63
64 /**
65 * Base test teardown
66 */
67 @After
68 public void testTeardown() {
69 session.close();
70
71 handlerA.close();
72 handlerB.close();
73 handlerC.close();
74
75 handlerA = null;
76 handlerB = null;
77 handlerC = null;
78 }
79
80 /**
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.
84 */
85 @Test
86 public void testNoEvents() {
87 assertTrue(session.start());
88
89 sendEventsToLoggers();
90
91 assertTrue(session.stop());
92
93 List<String> output = session.view();
94 assertNotNull(output);
95 assertTrue(output.isEmpty());
96
97 assertEquals(0, handlerA.getEventCount());
98 assertEquals(0, handlerB.getEventCount());
99 assertEquals(0, handlerC.getEventCount());
100 }
101
102 /**
103 * Test sending events on the Java side, and all events enabled in the
104 * tracing session. All handlers should have sent their events.
105 */
106 @Test
107 public void testAllEvents() {
108 assertTrue(session.enableAllEvents());
109 assertTrue(session.start());
110
111 sendEventsToLoggers();
112
113 assertTrue(session.stop());
114
115 List<String> output = session.view();
116 assertNotNull(output);
117 assertEquals(30, output.size()); // loggerD has no handler attached
118
119 assertEquals(10, handlerA.getEventCount());
120 assertEquals(10, handlerB.getEventCount());
121 assertEquals(10, handlerC.getEventCount());
122 }
123
124 /**
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.
127 */
128 @Test
129 public void testSomeEvents() {
130 assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D));
131 assertTrue(session.start());
132
133 sendEventsToLoggers();
134
135 assertTrue(session.stop());
136
137 List<String> output = session.view();
138 assertNotNull(output);
139 assertEquals(20, output.size());
140
141 assertEquals(10, handlerA.getEventCount());
142 assertEquals(0, handlerB.getEventCount());
143 assertEquals(10, handlerC.getEventCount());
144 }
145
146 /**
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.
149 */
150 @Test
151 public void testAllEventsAndSome() {
152 assertTrue(session.enableAllEvents());
153 assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_B));
154 assertTrue(session.start());
155
156 sendEventsToLoggers();
157
158 assertTrue(session.stop());
159
160 List<String> output = session.view();
161 assertNotNull(output);
162 assertEquals(30, output.size());
163
164 assertEquals(10, handlerA.getEventCount());
165 assertEquals(10, handlerB.getEventCount());
166 assertEquals(10, handlerC.getEventCount());
167 }
168
169 /**
170 * Same as {@link #testSomeEvents()}, but some events were enabled first,
171 * then disabled. Makes sure the enabled-event refcounting works properly.
172 */
173 @Test
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());
178
179 sendEventsToLoggers();
180
181 assertTrue(session.stop());
182
183 List<String> output = session.view();
184 assertNotNull(output);
185 assertEquals(10, output.size());
186
187 assertEquals(10, handlerA.getEventCount());
188 assertEquals(0, handlerB.getEventCount());
189 assertEquals(0, handlerC.getEventCount());
190 }
191
192 /**
193 * Test enabling an event prefix, which means an event name ending with a *,
194 * to match all events starting with this name.
195 */
196 @Test
197 public void testEventPrefix() {
198 // should match event/loggers B and C, but not A.
199 assertTrue(session.enableEvents("EventAB*"));
200 assertTrue(session.start());
201
202 sendEventsToLoggers();
203
204 assertTrue(session.stop());
205
206 List<String> output = session.view();
207 assertNotNull(output);
208 assertEquals(20, output.size());
209
210 assertEquals(0, handlerA.getEventCount());
211 assertEquals(10, handlerB.getEventCount());
212 assertEquals(10, handlerC.getEventCount());
213 }
214
215 /**
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
218 * handlers.
219 */
220 @Test
221 public void testEventPrefixOverlapping() {
222 // should still match B and C
223 assertTrue(session.enableEvents("EventAB*", "EventABC*"));
224 assertTrue(session.start());
225
226 sendEventsToLoggers();
227
228 assertTrue(session.stop());
229
230 List<String> output = session.view();
231 assertNotNull(output);
232 assertEquals(20, output.size());
233
234 assertEquals(0, handlerA.getEventCount());
235 assertEquals(10, handlerB.getEventCount());
236 assertEquals(10, handlerC.getEventCount());
237 }
238
239 /**
240 * Test with all events enabled (-a), plus an event prefix. Once again,
241 * there should be no duplicates.
242 */
243 @Test
244 public void testAllEventsAndPrefix() {
245 assertTrue(session.enableAllEvents());
246 assertTrue(session.enableEvents("EventAB*"));
247 assertTrue(session.start());
248
249 sendEventsToLoggers();
250
251 assertTrue(session.stop());
252
253 List<String> output = session.view();
254 assertNotNull(output);
255 assertEquals(30, output.size());
256
257 assertEquals(10, handlerA.getEventCount());
258 assertEquals(10, handlerB.getEventCount());
259 assertEquals(10, handlerC.getEventCount());
260 }
261 }
This page took 0.036274 seconds and 4 git commands to generate.