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