Add copyright header to all source files
[lttng-ust-java-tests.git] / 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;
30import org.lttng.ust.agent.ILttngHandler;
8576633f
AM
31import org.lttng.ust.agent.utils.LttngSession;
32import org.lttng.ust.agent.utils.LttngSession.Domain;
c5524c71 33
24b260d9 34public abstract class EnabledEventsTestBase {
c5524c71
AM
35
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";
40
8576633f
AM
41 private LttngSession session;
42
c5524c71
AM
43 /* Fields defined by the sub-class */
44 protected ILttngHandler handlerA;
45 protected ILttngHandler handlerB;
46 protected ILttngHandler handlerC;
47
48 protected abstract Domain getDomain();
49
50 protected abstract void sendEventsToLoggers();
51
52 @Before
53 public void testSetup() {
8576633f 54 session = new LttngSession(null, getDomain());
c5524c71
AM
55 }
56
57 @After
58 public void testTeardown() {
8576633f 59 session.close();
c5524c71
AM
60
61 handlerA.close();
62 handlerB.close();
63 handlerC.close();
64
65 handlerA = null;
66 handlerB = null;
67 handlerC = null;
68 }
69
70 /**
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.
74 */
75 @Test
76 public void testNoEvents() {
8576633f 77 assertTrue(session.start());
c5524c71
AM
78
79 sendEventsToLoggers();
80
8576633f 81 assertTrue(session.stop());
c5524c71 82
8576633f 83 List<String> output = session.view();
c5524c71
AM
84 assertNotNull(output);
85 assertTrue(output.isEmpty());
86
c5524c71
AM
87 assertEquals(0, handlerA.getEventCount());
88 assertEquals(0, handlerB.getEventCount());
89 assertEquals(0, handlerC.getEventCount());
90 }
91
92 /**
93 * Test sending events on the Java side, and all events enabled in the
94 * tracing session. All handlers should have sent their events.
95 */
96 @Test
97 public void testAllEvents() {
8576633f
AM
98 assertTrue(session.enableAllEvents());
99 assertTrue(session.start());
c5524c71
AM
100
101 sendEventsToLoggers();
102
8576633f 103 assertTrue(session.stop());
c5524c71 104
8576633f 105 List<String> output = session.view();
c5524c71
AM
106 assertNotNull(output);
107 assertEquals(30, output.size()); // loggerD has no handler attached
108
c5524c71
AM
109 assertEquals(10, handlerA.getEventCount());
110 assertEquals(10, handlerB.getEventCount());
111 assertEquals(10, handlerC.getEventCount());
112 }
113
114 /**
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.
117 */
118 @Test
119 public void testSomeEvents() {
8576633f
AM
120 assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D));
121 assertTrue(session.start());
c5524c71
AM
122
123 sendEventsToLoggers();
124
8576633f 125 assertTrue(session.stop());
c5524c71 126
8576633f 127 List<String> output = session.view();
c5524c71
AM
128 assertNotNull(output);
129 assertEquals(20, output.size());
130
c5524c71
AM
131 assertEquals(10, handlerA.getEventCount());
132 assertEquals(0, handlerB.getEventCount());
133 assertEquals(10, handlerC.getEventCount());
134 }
135
136 /**
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.
139 */
140 @Test
141 public void testAllEventsAndSome() {
8576633f
AM
142 assertTrue(session.enableAllEvents());
143 assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_B));
144 assertTrue(session.start());
c5524c71
AM
145
146 sendEventsToLoggers();
147
8576633f 148 assertTrue(session.stop());
c5524c71 149
8576633f 150 List<String> output = session.view();
c5524c71
AM
151 assertNotNull(output);
152 assertEquals(30, output.size());
153
c5524c71
AM
154 assertEquals(10, handlerA.getEventCount());
155 assertEquals(10, handlerB.getEventCount());
156 assertEquals(10, handlerC.getEventCount());
157 }
158
159 /**
160 * Same as {@link #testSomeEvents()}, but some events were enabled first,
161 * then disabled. Makes sure the enabled-event refcounting works properly.
162 */
163 @Test
164 public void testSomeEventsAfterDisabling() {
8576633f
AM
165 assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D));
166 assertTrue(session.disableEvents(EVENT_NAME_C));
167 assertTrue(session.start());
c5524c71
AM
168
169 sendEventsToLoggers();
170
8576633f 171 assertTrue(session.stop());
c5524c71 172
8576633f 173 List<String> output = session.view();
c5524c71
AM
174 assertNotNull(output);
175 assertEquals(10, output.size());
176
c5524c71
AM
177 assertEquals(10, handlerA.getEventCount());
178 assertEquals(0, handlerB.getEventCount());
179 assertEquals(0, handlerC.getEventCount());
180 }
181
182 /**
183 * Test enabling an event prefix, which means an event name ending with a *,
184 * to match all events starting with this name.
185 */
186 @Test
187 public void testEventPrefix() {
8576633f
AM
188 // should match event/loggers B and C, but not A.
189 assertTrue(session.enableEvents("EventAB*"));
190 assertTrue(session.start());
c5524c71
AM
191
192 sendEventsToLoggers();
193
8576633f 194 assertTrue(session.stop());
c5524c71 195
8576633f 196 List<String> output = session.view();
c5524c71
AM
197 assertNotNull(output);
198 assertEquals(20, output.size());
199
c5524c71
AM
200 assertEquals(0, handlerA.getEventCount());
201 assertEquals(10, handlerB.getEventCount());
202 assertEquals(10, handlerC.getEventCount());
203 }
204
205 /**
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
208 * handlers.
209 */
210 @Test
211 public void testEventPrefixOverlapping() {
8576633f
AM
212 // should still match B and C
213 assertTrue(session.enableEvents("EventAB*", "EventABC*"));
214 assertTrue(session.start());
c5524c71
AM
215
216 sendEventsToLoggers();
217
8576633f 218 assertTrue(session.stop());
c5524c71 219
8576633f 220 List<String> output = session.view();
c5524c71
AM
221 assertNotNull(output);
222 assertEquals(20, output.size());
223
c5524c71
AM
224 assertEquals(0, handlerA.getEventCount());
225 assertEquals(10, handlerB.getEventCount());
226 assertEquals(10, handlerC.getEventCount());
227 }
228
229 /**
230 * Test with all events enabled (-a), plus an event prefix. Once again,
231 * there should be no duplicates.
232 */
233 @Test
234 public void testAllEventsAndPrefix() {
8576633f
AM
235 assertTrue(session.enableAllEvents());
236 assertTrue(session.enableEvents("EventAB*"));
237 assertTrue(session.start());
c5524c71
AM
238
239 sendEventsToLoggers();
240
8576633f 241 assertTrue(session.stop());
c5524c71 242
8576633f 243 List<String> output = session.view();
c5524c71
AM
244 assertNotNull(output);
245 assertEquals(30, output.size());
246
c5524c71
AM
247 assertEquals(10, handlerA.getEventCount());
248 assertEquals(10, handlerB.getEventCount());
249 assertEquals(10, handlerC.getEventCount());
250 }
251}
This page took 0.038509 seconds and 4 git commands to generate.