Commit | Line | Data |
---|---|---|
c5524c71 AM |
1 | package org.lttng.ust.agent.integration.common; |
2 | ||
3 | import static org.junit.Assert.assertEquals; | |
4 | import static org.junit.Assert.assertNotNull; | |
5 | import static org.junit.Assert.assertTrue; | |
6 | ||
7 | import java.util.List; | |
8 | ||
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; | |
15 | ||
16 | public abstract class EnabledEventsTest { | |
17 | ||
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"; | |
22 | ||
23 | /* Fields defined by the sub-class */ | |
24 | protected ILttngHandler handlerA; | |
25 | protected ILttngHandler handlerB; | |
26 | protected ILttngHandler handlerC; | |
27 | ||
28 | protected abstract Domain getDomain(); | |
29 | ||
30 | protected abstract void sendEventsToLoggers(); | |
31 | ||
32 | @Before | |
33 | public void testSetup() { | |
34 | ||
35 | } | |
36 | ||
37 | @After | |
38 | public void testTeardown() { | |
39 | /* In case the test fails before destroying the session */ | |
40 | LttngSessionControl.tryDestroySession(null); | |
41 | ||
42 | handlerA.close(); | |
43 | handlerB.close(); | |
44 | handlerC.close(); | |
45 | ||
46 | handlerA = null; | |
47 | handlerB = null; | |
48 | handlerC = null; | |
49 | } | |
50 | ||
51 | /** | |
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. | |
55 | */ | |
56 | @Test | |
57 | public void testNoEvents() { | |
58 | assertTrue(LttngSessionControl.setupSession(null, getDomain())); | |
59 | ||
60 | sendEventsToLoggers(); | |
61 | ||
62 | assertTrue(LttngSessionControl.stopSession(null)); | |
63 | ||
64 | List<String> output = LttngSessionControl.viewSession(null); | |
65 | assertNotNull(output); | |
66 | assertTrue(output.isEmpty()); | |
67 | ||
68 | assertTrue(LttngSessionControl.destroySession(null)); | |
69 | ||
70 | assertEquals(0, handlerA.getEventCount()); | |
71 | assertEquals(0, handlerB.getEventCount()); | |
72 | assertEquals(0, handlerC.getEventCount()); | |
73 | } | |
74 | ||
75 | /** | |
76 | * Test sending events on the Java side, and all events enabled in the | |
77 | * tracing session. All handlers should have sent their events. | |
78 | */ | |
79 | @Test | |
80 | public void testAllEvents() { | |
81 | assertTrue(LttngSessionControl.setupSessionAllEvents(null, getDomain())); | |
82 | ||
83 | sendEventsToLoggers(); | |
84 | ||
85 | assertTrue(LttngSessionControl.stopSession(null)); | |
86 | ||
87 | List<String> output = LttngSessionControl.viewSession(null); | |
88 | assertNotNull(output); | |
89 | assertEquals(30, output.size()); // loggerD has no handler attached | |
90 | ||
91 | assertTrue(LttngSessionControl.destroySession(null)); | |
92 | ||
93 | assertEquals(10, handlerA.getEventCount()); | |
94 | assertEquals(10, handlerB.getEventCount()); | |
95 | assertEquals(10, handlerC.getEventCount()); | |
96 | } | |
97 | ||
98 | /** | |
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. | |
101 | */ | |
102 | @Test | |
103 | public void testSomeEvents() { | |
104 | assertTrue(LttngSessionControl.setupSession(null, getDomain(), | |
105 | EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D)); | |
106 | ||
107 | sendEventsToLoggers(); | |
108 | ||
109 | assertTrue(LttngSessionControl.stopSession(null)); | |
110 | ||
111 | List<String> output = LttngSessionControl.viewSession(null); | |
112 | assertNotNull(output); | |
113 | assertEquals(20, output.size()); | |
114 | ||
115 | assertTrue(LttngSessionControl.destroySession(null)); | |
116 | ||
117 | assertEquals(10, handlerA.getEventCount()); | |
118 | assertEquals(0, handlerB.getEventCount()); | |
119 | assertEquals(10, handlerC.getEventCount()); | |
120 | } | |
121 | ||
122 | /** | |
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. | |
125 | */ | |
126 | @Test | |
127 | public void testAllEventsAndSome() { | |
128 | assertTrue(LttngSessionControl.setupSessionAllEvents(null, getDomain())); | |
129 | assertTrue(LttngSessionControl.enableEvents(null, getDomain(), | |
130 | EVENT_NAME_A, EVENT_NAME_B)); | |
131 | ||
132 | sendEventsToLoggers(); | |
133 | ||
134 | assertTrue(LttngSessionControl.stopSession(null)); | |
135 | ||
136 | List<String> output = LttngSessionControl.viewSession(null); | |
137 | assertNotNull(output); | |
138 | assertEquals(30, output.size()); | |
139 | ||
140 | assertTrue(LttngSessionControl.destroySession(null)); | |
141 | ||
142 | assertEquals(10, handlerA.getEventCount()); | |
143 | assertEquals(10, handlerB.getEventCount()); | |
144 | assertEquals(10, handlerC.getEventCount()); | |
145 | } | |
146 | ||
147 | /** | |
148 | * Same as {@link #testSomeEvents()}, but some events were enabled first, | |
149 | * then disabled. Makes sure the enabled-event refcounting works properly. | |
150 | */ | |
151 | @Test | |
152 | public void testSomeEventsAfterDisabling() { | |
153 | assertTrue(LttngSessionControl.setupSession(null, getDomain(), | |
154 | EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D)); | |
155 | ||
156 | assertTrue(LttngSessionControl.disableEvents(null, getDomain(), | |
157 | EVENT_NAME_C)); | |
158 | ||
159 | sendEventsToLoggers(); | |
160 | ||
161 | assertTrue(LttngSessionControl.stopSession(null)); | |
162 | ||
163 | List<String> output = LttngSessionControl.viewSession(null); | |
164 | assertNotNull(output); | |
165 | assertEquals(10, output.size()); | |
166 | ||
167 | assertTrue(LttngSessionControl.destroySession(null)); | |
168 | ||
169 | assertEquals(10, handlerA.getEventCount()); | |
170 | assertEquals(0, handlerB.getEventCount()); | |
171 | assertEquals(0, handlerC.getEventCount()); | |
172 | } | |
173 | ||
174 | /** | |
175 | * Test enabling an event prefix, which means an event name ending with a *, | |
176 | * to match all events starting with this name. | |
177 | */ | |
178 | @Test | |
179 | public void testEventPrefix() { | |
180 | assertTrue(LttngSessionControl.setupSession(null, getDomain(), | |
181 | "EventAB*")); // should match event/loggers B and C, but not A. | |
182 | ||
183 | sendEventsToLoggers(); | |
184 | ||
185 | assertTrue(LttngSessionControl.stopSession(null)); | |
186 | ||
187 | List<String> output = LttngSessionControl.viewSession(null); | |
188 | assertNotNull(output); | |
189 | assertEquals(20, output.size()); | |
190 | ||
191 | assertTrue(LttngSessionControl.destroySession(null)); | |
192 | ||
193 | assertEquals(0, handlerA.getEventCount()); | |
194 | assertEquals(10, handlerB.getEventCount()); | |
195 | assertEquals(10, handlerC.getEventCount()); | |
196 | } | |
197 | ||
198 | /** | |
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 | |
201 | * handlers. | |
202 | */ | |
203 | @Test | |
204 | public void testEventPrefixOverlapping() { | |
205 | assertTrue(LttngSessionControl.setupSession(null, getDomain(), | |
206 | "EventAB*", "EventABC*")); // should still match B and C | |
207 | ||
208 | sendEventsToLoggers(); | |
209 | ||
210 | assertTrue(LttngSessionControl.stopSession(null)); | |
211 | ||
212 | List<String> output = LttngSessionControl.viewSession(null); | |
213 | assertNotNull(output); | |
214 | assertEquals(20, output.size()); | |
215 | ||
216 | assertTrue(LttngSessionControl.destroySession(null)); | |
217 | ||
218 | assertEquals(0, handlerA.getEventCount()); | |
219 | assertEquals(10, handlerB.getEventCount()); | |
220 | assertEquals(10, handlerC.getEventCount()); | |
221 | } | |
222 | ||
223 | /** | |
224 | * Test with all events enabled (-a), plus an event prefix. Once again, | |
225 | * there should be no duplicates. | |
226 | */ | |
227 | @Test | |
228 | public void testAllEventsAndPrefix() { | |
229 | assertTrue(LttngSessionControl.setupSessionAllEvents(null, getDomain())); | |
230 | assertTrue(LttngSessionControl.enableEvents(null, getDomain(), | |
231 | "EventAB*")); // should match B and C | |
232 | ||
233 | sendEventsToLoggers(); | |
234 | ||
235 | assertTrue(LttngSessionControl.stopSession(null)); | |
236 | ||
237 | List<String> output = LttngSessionControl.viewSession(null); | |
238 | assertNotNull(output); | |
239 | assertEquals(30, output.size()); | |
240 | ||
241 | assertTrue(LttngSessionControl.destroySession(null)); | |
242 | ||
243 | assertEquals(10, handlerA.getEventCount()); | |
244 | assertEquals(10, handlerB.getEventCount()); | |
245 | assertEquals(10, handlerC.getEventCount()); | |
246 | } | |
247 | } |