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