Commit | Line | Data |
---|---|---|
f37120c3 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 | ||
19 | package org.lttng.ust.agent.integration.client; | |
20 | ||
21 | import static org.junit.Assert.assertEquals; | |
22 | import static org.junit.Assert.assertTrue; | |
f37120c3 AM |
23 | |
24 | import java.util.ArrayList; | |
25 | import java.util.Arrays; | |
26 | import java.util.Collections; | |
27 | import java.util.List; | |
28 | ||
29 | import org.junit.After; | |
30 | import org.junit.AfterClass; | |
31 | import org.junit.Before; | |
32 | import org.junit.BeforeClass; | |
f37120c3 | 33 | import org.junit.Test; |
1df8e5d7 | 34 | import org.junit.runner.RunWith; |
f37120c3 AM |
35 | import org.lttng.tools.ILttngSession; |
36 | import org.lttng.tools.LttngToolsHelper; | |
37 | import org.lttng.ust.agent.ILttngAgent; | |
38 | import org.lttng.ust.agent.client.LttngTcpSessiondClient; | |
39 | import org.lttng.ust.agent.session.EventRule; | |
329f5794 AM |
40 | import org.lttng.ust.agent.session.LogLevelSelector; |
41 | import org.lttng.ust.agent.session.LogLevelSelector.LogLevelType; | |
1df8e5d7 | 42 | import org.lttng.ust.agent.utils.EventRuleFactory; |
f37120c3 | 43 | import org.lttng.ust.agent.utils.ILogLevelStrings; |
1df8e5d7 | 44 | import org.lttng.ust.agent.utils.TestPrintRunner; |
f37120c3 AM |
45 | |
46 | /** | |
47 | * Tests for the TCP client only, without using an agent. | |
48 | * | |
49 | * This test suite requires that a *root* session daemon is running on the | |
50 | * system. Since we have to explicitly tell the TCP client which sessiond to | |
51 | * connect to, we have to hard-code it in here. | |
52 | * | |
53 | * @author Alexandre Montplaisir | |
54 | */ | |
1df8e5d7 | 55 | @RunWith(TestPrintRunner.class) |
f37120c3 AM |
56 | public class TcpClientIT { |
57 | ||
58 | // ------------------------------------------------------------------------ | |
59 | // Attributes | |
60 | // ------------------------------------------------------------------------ | |
61 | ||
f37120c3 AM |
62 | private static final String EVENT_NAME_A = "eventA"; |
63 | private static final String EVENT_NAME_B = "eventB"; | |
64 | private static final String EVENT_NAME_C = "eventC"; | |
f37120c3 | 65 | |
73fb6785 AM |
66 | private static final String CONTEXT_RETRIEVER_NAME_A = "retrieverA"; |
67 | private static final String CONTEXT_RETRIEVER_NAME_B = "retrieverB"; | |
68 | private static final String CONTEXT_NAME_A = "contextA"; | |
69 | private static final String CONTEXT_NAME_B = "contextB"; | |
70 | ||
f37120c3 AM |
71 | /* Test configuration */ |
72 | private static final int DOMAIN_VALUE = ILttngAgent.Domain.JUL.value(); | |
73 | private static final ILttngSession.Domain SESSION_DOMAIN = ILttngSession.Domain.JUL; | |
74 | private static final boolean ROOT_SESSIOND = true; | |
75 | ||
76 | private static TcpClientDebugListener clientListener; | |
77 | private static LttngTcpSessiondClient client; | |
78 | private static Thread clientThread; | |
79 | ||
80 | private ILttngSession session; | |
81 | ||
82 | // ------------------------------------------------------------------------ | |
83 | // Maintenance | |
84 | // ------------------------------------------------------------------------ | |
85 | ||
86 | /** | |
87 | * Class setup | |
88 | */ | |
89 | @BeforeClass | |
90 | public static void setupClass() { | |
91 | LttngToolsHelper.destroyAllSessions(); | |
92 | ||
93 | clientListener = new TcpClientDebugListener(); | |
94 | client = new LttngTcpSessiondClient(clientListener, DOMAIN_VALUE, ROOT_SESSIOND); | |
95 | ||
96 | clientThread = new Thread(client); | |
97 | clientThread.start(); | |
98 | ||
65a36bff | 99 | assertTrue("Timed out waiting for root sessiond", client.waitForConnection(5)); |
f37120c3 AM |
100 | } |
101 | ||
102 | /** | |
103 | * Class teardown | |
104 | */ | |
105 | @AfterClass | |
106 | public static void teardownClass() { | |
107 | if (client != null) { | |
108 | client.close(); | |
109 | } | |
110 | if (clientThread != null) { | |
111 | try { | |
112 | clientThread.join(); | |
113 | } catch (InterruptedException e) { | |
114 | } | |
115 | } | |
116 | } | |
117 | ||
118 | /** | |
119 | * Test setup | |
120 | */ | |
121 | @Before | |
122 | public void setup() { | |
123 | session = ILttngSession.createSession(null, SESSION_DOMAIN); | |
124 | clientListener.clearAllCommands(); | |
125 | } | |
126 | ||
127 | /** | |
128 | * Test teardown | |
129 | */ | |
130 | @After | |
131 | public void teardown() { | |
132 | session.close(); | |
133 | } | |
134 | ||
135 | ||
136 | private static ILogLevelStrings getLogLevelStrings() { | |
137 | return ILogLevelStrings.JUL_LOGLEVEL_STRINGS; | |
138 | } | |
139 | ||
140 | /** | |
141 | * Check that two lists contain the exact same element (including | |
142 | * duplicates), but their order does not matter. | |
143 | */ | |
144 | private static <T extends Comparable<T>> boolean containSameElements(List<T> list1, List<T> list2) { | |
145 | List<T> newlist1 = new ArrayList<>(list1); | |
146 | List<T> newlist2 = new ArrayList<>(list2); | |
147 | Collections.sort(newlist1); | |
148 | Collections.sort(newlist2); | |
149 | return (newlist1.equals(newlist2)); | |
150 | ||
151 | } | |
152 | ||
153 | // ------------------------------------------------------------------------ | |
73fb6785 | 154 | // Event enabling/disabling test cases |
f37120c3 AM |
155 | // ------------------------------------------------------------------------ |
156 | ||
157 | /** | |
158 | * Test enabling one event. | |
159 | */ | |
160 | @Test | |
161 | public void testEnableEvent() { | |
162 | session.enableEvent(EVENT_NAME_A, null, false, null); | |
163 | ||
164 | List<EventRule> expectedCommands = Collections.singletonList( | |
1df8e5d7 | 165 | EventRuleFactory.createRule(EVENT_NAME_A)); |
f37120c3 AM |
166 | |
167 | List<EventRule> actualCommands = clientListener.getEnabledEventCommands(); | |
168 | assertEquals(expectedCommands, actualCommands); | |
169 | } | |
170 | ||
171 | /** | |
172 | * Test an "enable-event -a" command. | |
173 | */ | |
174 | @Test | |
175 | public void testEnableAllEvents() { | |
176 | session.enableAllEvents(); | |
177 | ||
178 | List<EventRule> expectedCommands = Collections.singletonList( | |
1df8e5d7 | 179 | EventRuleFactory.createRuleAllEvents()); |
f37120c3 AM |
180 | List<EventRule> actualCommands = clientListener.getEnabledEventCommands(); |
181 | ||
182 | assertEquals(expectedCommands, actualCommands); | |
183 | } | |
184 | ||
185 | /** | |
186 | * Test enabling then disabling one event. | |
187 | */ | |
188 | @Test | |
189 | public void testEnableThenDisableOneEvent() { | |
190 | session.enableEvent(EVENT_NAME_A, null, false, null); | |
191 | session.disableEvents(EVENT_NAME_A); | |
192 | ||
193 | List<EventRule> expectedEnableCommands = Collections.singletonList( | |
1df8e5d7 | 194 | EventRuleFactory.createRule(EVENT_NAME_A)); |
f37120c3 AM |
195 | List<String> expectedDisableCommands = Collections.singletonList(EVENT_NAME_A); |
196 | ||
197 | assertEquals(expectedEnableCommands, clientListener.getEnabledEventCommands()); | |
198 | assertTrue(containSameElements(expectedDisableCommands, clientListener.getDisabledEventCommands())); | |
199 | } | |
200 | ||
201 | /** | |
202 | * Test enabling some events manually, then disabling all events (-a). | |
203 | */ | |
204 | @Test | |
205 | public void testEnableSomeThenDisableAll() { | |
206 | session.enableEvent(EVENT_NAME_A, null, false, null); | |
207 | session.enableEvent(EVENT_NAME_B, null, false, null); | |
208 | session.enableEvent(EVENT_NAME_C, null, false, null); | |
209 | session.disableAllEvents(); | |
210 | ||
211 | List<EventRule> expectedEnableCommands = Arrays.asList( | |
1df8e5d7 AM |
212 | EventRuleFactory.createRule(EVENT_NAME_A), |
213 | EventRuleFactory.createRule(EVENT_NAME_B), | |
214 | EventRuleFactory.createRule(EVENT_NAME_C)); | |
f37120c3 AM |
215 | /* |
216 | * A "disable-event -a" will send one command for each enabled event. | |
217 | * The order may be different though. | |
218 | */ | |
219 | List<String> expectedDisableCommands = Arrays.asList( | |
220 | EVENT_NAME_A, EVENT_NAME_B, EVENT_NAME_C); | |
221 | ||
222 | assertEquals(expectedEnableCommands, clientListener.getEnabledEventCommands()); | |
223 | assertTrue(containSameElements(expectedDisableCommands, clientListener.getDisabledEventCommands())); | |
224 | } | |
225 | ||
226 | /** | |
227 | * Test enabling then (enable-event -a) then disabling all (disable-event -a) events. | |
228 | */ | |
229 | @Test | |
230 | public void testEnableAllThenDisableAll() { | |
231 | session.enableAllEvents(); | |
232 | session.disableAllEvents(); | |
233 | ||
1df8e5d7 AM |
234 | List<EventRule> expectedEnableCommands = Arrays.asList(EventRuleFactory.createRuleAllEvents()); |
235 | List<String> expectedDisableCommands = Arrays.asList(EventRuleFactory.EVENT_NAME_ALL); | |
f37120c3 AM |
236 | |
237 | assertEquals(expectedEnableCommands, clientListener.getEnabledEventCommands()); | |
238 | assertTrue(containSameElements(expectedDisableCommands, clientListener.getDisabledEventCommands())); | |
239 | } | |
240 | ||
c5796c3e AM |
241 | /** |
242 | * Test enabling then destroying the session (should send corresponding | |
243 | * disable event messages). | |
244 | */ | |
245 | @SuppressWarnings("static-method") | |
246 | @Test | |
247 | public void testEnableEventThenDestroy() { | |
248 | try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) { | |
249 | session2.enableEvent(EVENT_NAME_A, null, false, null); | |
250 | session2.enableEvent(EVENT_NAME_B, null, false, null); | |
251 | } // close(), aka destroy the session, sending "disable event" messages | |
252 | ||
253 | List<EventRule> expectedEnabledCommands = Arrays.asList(EventRuleFactory.createRule(EVENT_NAME_A), EventRuleFactory.createRule(EVENT_NAME_B)); | |
254 | List<String> expectedDisabledCommands = Arrays.asList(EVENT_NAME_A, EVENT_NAME_B); | |
255 | ||
256 | assertEquals(expectedEnabledCommands, clientListener.getEnabledEventCommands()); | |
d838d835 | 257 | assertTrue(clientListener.getDisabledEventCommands().containsAll(expectedDisabledCommands)); |
c5796c3e AM |
258 | } |
259 | ||
f37120c3 AM |
260 | /** |
261 | * Test specifying an event with a --loglevel option. | |
262 | */ | |
263 | @Test | |
264 | public void testEnableEventLogLevelRange() { | |
329f5794 | 265 | LogLevelSelector lls = new LogLevelSelector(getLogLevelStrings().warningInt(), LogLevelType.LTTNG_EVENT_LOGLEVEL_RANGE); |
f37120c3 AM |
266 | |
267 | session.enableEvent(EVENT_NAME_A, getLogLevelStrings().warningName(), false, null); | |
268 | ||
269 | List<EventRule> expectedCommands = Collections.singletonList( | |
1df8e5d7 | 270 | EventRuleFactory.createRule(EVENT_NAME_A, lls)); |
f37120c3 AM |
271 | List<EventRule> actualCommands = clientListener.getEnabledEventCommands(); |
272 | ||
273 | assertEquals(expectedCommands, actualCommands); | |
274 | } | |
275 | ||
276 | /** | |
277 | * Test enabling an event with a --loglevel-only option. | |
278 | */ | |
279 | @Test | |
280 | public void testEnableEventLogLevelSingle() { | |
329f5794 | 281 | LogLevelSelector lls = new LogLevelSelector(getLogLevelStrings().warningInt(), LogLevelType.LTTNG_EVENT_LOGLEVEL_SINGLE); |
f37120c3 AM |
282 | |
283 | session.enableEvent(EVENT_NAME_A, getLogLevelStrings().warningName(), true, null); | |
284 | ||
285 | List<EventRule> expectedCommands = Collections.singletonList( | |
1df8e5d7 | 286 | EventRuleFactory.createRule(EVENT_NAME_A, lls)); |
f37120c3 AM |
287 | List<EventRule> actualCommands = clientListener.getEnabledEventCommands(); |
288 | ||
289 | assertEquals(expectedCommands, actualCommands); | |
290 | } | |
291 | ||
292 | /** | |
293 | * Test enabling an event twice, for the same loglevel, with --loglevel followed by --loglevel-only. | |
294 | */ | |
f37120c3 AM |
295 | @Test |
296 | public void testEnableEventsLogLevelRangeAndSingle() { | |
329f5794 AM |
297 | LogLevelSelector lls1 = new LogLevelSelector(getLogLevelStrings().warningInt(), LogLevelType.LTTNG_EVENT_LOGLEVEL_RANGE); |
298 | LogLevelSelector lls2 = new LogLevelSelector(getLogLevelStrings().warningInt(), LogLevelType.LTTNG_EVENT_LOGLEVEL_SINGLE); | |
f37120c3 AM |
299 | |
300 | session.enableEvent(EVENT_NAME_A, getLogLevelStrings().warningName(), false, null); | |
301 | session.enableEvent(EVENT_NAME_A, getLogLevelStrings().warningName(), true, null); | |
302 | ||
303 | List<EventRule> expectedCommands = Arrays.asList( | |
1df8e5d7 AM |
304 | EventRuleFactory.createRule(EVENT_NAME_A, lls1), |
305 | EventRuleFactory.createRule(EVENT_NAME_A, lls2) | |
f37120c3 AM |
306 | ); |
307 | List<EventRule> actualCommands = clientListener.getEnabledEventCommands(); | |
308 | ||
309 | assertEquals(expectedCommands, actualCommands); | |
310 | } | |
311 | ||
312 | /** | |
1df8e5d7 | 313 | * Test enabling an event twice, for the same loglevel, with --loglevel-only followed by --loglevel. |
f37120c3 | 314 | */ |
f37120c3 AM |
315 | @Test |
316 | public void testEnableEventsLogLevelSingleAndRange() { | |
329f5794 AM |
317 | LogLevelSelector lls1 = new LogLevelSelector(getLogLevelStrings().warningInt(), LogLevelType.LTTNG_EVENT_LOGLEVEL_SINGLE); |
318 | LogLevelSelector lls2 = new LogLevelSelector(getLogLevelStrings().warningInt(), LogLevelType.LTTNG_EVENT_LOGLEVEL_RANGE); | |
f37120c3 AM |
319 | |
320 | session.enableEvent(EVENT_NAME_A, getLogLevelStrings().warningName(), true, null); | |
321 | session.enableEvent(EVENT_NAME_A, getLogLevelStrings().warningName(), false, null); | |
322 | ||
323 | List<EventRule> expectedCommands = Arrays.asList( | |
1df8e5d7 AM |
324 | EventRuleFactory.createRule(EVENT_NAME_A, lls1), |
325 | EventRuleFactory.createRule(EVENT_NAME_A, lls2) | |
f37120c3 AM |
326 | ); |
327 | List<EventRule> actualCommands = clientListener.getEnabledEventCommands(); | |
328 | ||
329 | assertEquals(expectedCommands, actualCommands); | |
330 | } | |
331 | ||
332 | /** | |
333 | * Test enabling the same event, same loglevel, but different loglevel types | |
334 | * (--loglevel vs --loglevel-only) in two separate sessions. | |
335 | */ | |
336 | @Test | |
337 | public void testEnableEventsLogLevelRangeAndSingleDiffSessions() { | |
338 | try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) { | |
339 | ||
329f5794 AM |
340 | LogLevelSelector lls1 = new LogLevelSelector(getLogLevelStrings().warningInt(), LogLevelType.LTTNG_EVENT_LOGLEVEL_RANGE); |
341 | LogLevelSelector lls2 = new LogLevelSelector(getLogLevelStrings().warningInt(), LogLevelType.LTTNG_EVENT_LOGLEVEL_SINGLE); | |
f37120c3 AM |
342 | |
343 | session.enableEvent(EVENT_NAME_A, getLogLevelStrings().warningName(), false, null); | |
344 | session2.enableEvent(EVENT_NAME_A, getLogLevelStrings().warningName(), true, null); | |
345 | ||
1df8e5d7 AM |
346 | List<EventRule> expectedCommands = Arrays.asList( |
347 | EventRuleFactory.createRule(EVENT_NAME_A, lls1), | |
348 | EventRuleFactory.createRule(EVENT_NAME_A, lls2)); | |
f37120c3 AM |
349 | List<EventRule> actualCommands = clientListener.getEnabledEventCommands(); |
350 | ||
351 | assertEquals(expectedCommands, actualCommands); | |
352 | } | |
353 | } | |
1df8e5d7 AM |
354 | |
355 | /** | |
356 | * Enable the same event multiple times with different filter strings. | |
357 | */ | |
358 | @Test | |
359 | public void testEnableEventsDiffFilters() { | |
360 | final String filter1 = "filter1"; | |
361 | final String filter2 = "filter2"; | |
362 | ||
363 | session.enableEvent(EVENT_NAME_A, null, false, null); | |
364 | session.enableEvent(EVENT_NAME_A, null, false, filter1); | |
365 | session.enableEvent(EVENT_NAME_A, null, false, filter2); | |
366 | ||
367 | List<EventRule> expectedCommands = Arrays.asList( | |
368 | EventRuleFactory.createRule(EVENT_NAME_A), | |
369 | EventRuleFactory.createRule(EVENT_NAME_A, EventRuleFactory.LOG_LEVEL_UNSPECIFIED, filter1), | |
370 | EventRuleFactory.createRule(EVENT_NAME_A, EventRuleFactory.LOG_LEVEL_UNSPECIFIED, filter2)); | |
371 | List<EventRule> actualCommands = clientListener.getEnabledEventCommands(); | |
372 | ||
373 | assertEquals(expectedCommands, actualCommands); | |
374 | } | |
375 | ||
376 | /** | |
377 | * Enable the same event multiple times with different log levels and | |
378 | * filters. | |
379 | */ | |
380 | @Test | |
381 | public void testEnableEventsLogLevelAndFilters() { | |
382 | final LogLevelSelector lls = new LogLevelSelector(getLogLevelStrings().warningInt(), LogLevelType.LTTNG_EVENT_LOGLEVEL_RANGE); | |
383 | final String filter = "filter1"; | |
384 | ||
385 | session.enableEvent(EVENT_NAME_A, null, false, null); | |
386 | session.enableEvent(EVENT_NAME_A, getLogLevelStrings().warningName(), false, null); | |
387 | session.enableEvent(EVENT_NAME_A, null, false, filter); | |
388 | session.enableEvent(EVENT_NAME_A, getLogLevelStrings().warningName(), false, filter); | |
389 | ||
390 | List<EventRule> expectedCommands = Arrays.asList( | |
391 | EventRuleFactory.createRule(EVENT_NAME_A), | |
392 | EventRuleFactory.createRule(EVENT_NAME_A, lls), | |
393 | EventRuleFactory.createRule(EVENT_NAME_A, EventRuleFactory.LOG_LEVEL_UNSPECIFIED, filter), | |
394 | EventRuleFactory.createRule(EVENT_NAME_A, lls, filter)); | |
395 | List<EventRule> actualCommands = clientListener.getEnabledEventCommands(); | |
396 | ||
397 | assertEquals(expectedCommands, actualCommands); | |
398 | } | |
73fb6785 AM |
399 | |
400 | // ------------------------------------------------------------------------ | |
401 | // Application context enabling/disabling test cases | |
402 | // ------------------------------------------------------------------------ | |
403 | ||
404 | /** | |
405 | * Test enabling one application context. | |
406 | */ | |
407 | @Test | |
408 | public void testEnableAppContext() { | |
409 | session.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); | |
410 | ||
411 | List<String> expectedCommands = Collections.singletonList( | |
412 | CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); | |
413 | ||
414 | List<String> actualCommands = clientListener.getEnabledAppContextCommands(); | |
415 | assertEquals(expectedCommands, actualCommands); | |
416 | } | |
417 | ||
418 | /** | |
419 | * Test enabling two application contexts sharing the same retriever name. | |
420 | */ | |
421 | @Test | |
422 | public void testEnableAppContextsSameRetriever() { | |
423 | session.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); | |
424 | session.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_B); | |
425 | ||
426 | List<String> expectedCommands = Arrays.asList( | |
427 | CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A, | |
428 | CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_B); | |
429 | ||
430 | List<String> actualCommands = clientListener.getEnabledAppContextCommands(); | |
431 | assertEquals(expectedCommands, actualCommands); | |
432 | } | |
433 | ||
434 | /** | |
435 | * Test enabling two application contexts sharing the same context name, but | |
436 | * with different retrievers. Unusual, but they should still be recognized | |
437 | * separately. | |
438 | */ | |
439 | @Test | |
440 | public void testEnableAppContextsSameContext() { | |
441 | session.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); | |
442 | session.enableAppContext(CONTEXT_RETRIEVER_NAME_B, CONTEXT_NAME_A); | |
443 | ||
444 | List<String> expectedCommands = Arrays.asList( | |
445 | CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A, | |
446 | CONTEXT_RETRIEVER_NAME_B + ':' + CONTEXT_NAME_A); | |
447 | ||
448 | List<String> actualCommands = clientListener.getEnabledAppContextCommands(); | |
449 | assertEquals(expectedCommands, actualCommands); | |
450 | } | |
451 | ||
452 | /** | |
453 | * Test enabling one application context, then destroying the session. We | |
454 | * should receive the corresponding "context removed" message. | |
455 | */ | |
456 | @Test | |
457 | @SuppressWarnings("static-method") | |
458 | public void testEnableAppContextThenDestroy() { | |
459 | try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) { | |
460 | session2.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); | |
461 | } // close(), aka destroy the session, sending "disable context" messages | |
462 | ||
463 | List<String> expectedEnabledCommands = Collections.singletonList(CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); | |
464 | List<String> expectedDisabledCommands = Collections.singletonList(CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); | |
465 | List<String> actualEnabledCommands = clientListener.getEnabledAppContextCommands(); | |
466 | List<String> actualDisabledCommands = clientListener.getDisabledAppContextCommands(); | |
467 | ||
468 | assertEquals(expectedEnabledCommands, actualEnabledCommands); | |
469 | assertEquals(expectedDisabledCommands, actualDisabledCommands); | |
470 | } | |
471 | ||
472 | /** | |
473 | * Test enabling the same application context in two different sessions. | |
474 | * Upon destroying one, we should only receive one "destroyed" message. | |
475 | */ | |
476 | @Test | |
477 | public void testEnableSameAppContextTwoSessions() { | |
478 | List<String> expectedEnabledCommands = Arrays.asList( | |
479 | CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A, | |
480 | CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); | |
481 | List<String> actualEnabledCommands; | |
482 | ||
483 | try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) { | |
484 | session.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); | |
485 | session2.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); | |
486 | ||
487 | actualEnabledCommands = clientListener.getEnabledAppContextCommands(); | |
488 | assertEquals(expectedEnabledCommands, actualEnabledCommands); | |
489 | } // close/destroy session2 | |
490 | ||
491 | actualEnabledCommands = clientListener.getEnabledAppContextCommands(); | |
492 | assertEquals(expectedEnabledCommands, actualEnabledCommands); | |
493 | ||
494 | List<String> expectedDisabledCommands = Collections.singletonList(CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); | |
495 | List<String> actualDisabledCommands = clientListener.getDisabledAppContextCommands(); | |
496 | ||
497 | assertEquals(expectedDisabledCommands, actualDisabledCommands); | |
498 | } | |
499 | ||
500 | /** | |
501 | * Test enabling two different application context in two different | |
502 | * sessions. Upon destroying one, we should receive the correct "destroyed" | |
503 | * message. | |
504 | */ | |
505 | @Test | |
506 | public void testEnableDiffAppContextTwoSessions() { | |
507 | List<String> expectedEnabledCommands = Arrays.asList( | |
508 | CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A, | |
509 | CONTEXT_RETRIEVER_NAME_B + ':' + CONTEXT_NAME_B); | |
510 | List<String> actualEnabledCommands; | |
511 | ||
512 | try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) { | |
513 | session.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); | |
514 | session2.enableAppContext(CONTEXT_RETRIEVER_NAME_B, CONTEXT_NAME_B); | |
515 | ||
516 | actualEnabledCommands = clientListener.getEnabledAppContextCommands(); | |
517 | assertEquals(expectedEnabledCommands, actualEnabledCommands); | |
518 | } // close/destroy session2 | |
519 | ||
520 | actualEnabledCommands = clientListener.getEnabledAppContextCommands(); | |
521 | assertEquals(expectedEnabledCommands, actualEnabledCommands); | |
522 | ||
523 | List<String> expectedDisabledCommands = Collections.singletonList(CONTEXT_RETRIEVER_NAME_B + ':' + CONTEXT_NAME_B); | |
524 | List<String> actualDisabledCommands = clientListener.getDisabledAppContextCommands(); | |
525 | ||
526 | assertEquals(expectedDisabledCommands, actualDisabledCommands); | |
527 | } | |
8c202b54 AM |
528 | |
529 | // ------------------------------------------------------------------------ | |
530 | // Application context filtering | |
531 | // ------------------------------------------------------------------------ | |
532 | ||
533 | /** | |
534 | * Test that enabling an event with a filter string referring to a context | |
535 | * should send an agent message about this context now being "enabled". | |
536 | * | |
537 | * This is because we will pass the context information to UST for the | |
538 | * filtering step, even if the actual context won't be present in the trace. | |
539 | */ | |
540 | @SuppressWarnings("static-method") | |
541 | @Test | |
542 | public void testContextInFilterString() { | |
543 | try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) { | |
d838d835 | 544 | session2.enableEvent(EVENT_NAME_A, null, false, "$app." + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A + "==\"bozo\""); |
8c202b54 AM |
545 | |
546 | List<String> expectedEnabledCommands = Collections.singletonList(CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); | |
547 | assertEquals(expectedEnabledCommands, clientListener.getEnabledAppContextCommands()); | |
548 | } // close(), aka destroy the session, sending "disable context" messages | |
549 | ||
550 | List<String> expectedDisabledCommands = Collections.singletonList(CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); | |
551 | assertEquals(expectedDisabledCommands, clientListener.getDisabledAppContextCommands()); | |
552 | } | |
553 | ||
554 | /** | |
555 | * Test that if we the context is both referred to by a filter string *and* | |
556 | * enabled directly, we receive *2* messages about this context being | |
557 | * enabled (and disabled on session teardown). | |
558 | */ | |
559 | @SuppressWarnings("static-method") | |
560 | @Test | |
561 | public void testContextEnabledAndInFilterString() { | |
562 | try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) { | |
d838d835 | 563 | session2.enableEvent(EVENT_NAME_A, null, false, "$app." + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A + "==\"bozo\""); |
8c202b54 AM |
564 | session2.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); |
565 | ||
566 | List<String> expectedEnabledCommands = Collections.nCopies(2, CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); | |
567 | assertEquals(expectedEnabledCommands, clientListener.getEnabledAppContextCommands()); | |
568 | } // close(), aka destroy the session, sending "disable context" messages | |
569 | ||
570 | List<String> expectedDisabledCommands = Collections.nCopies(2, CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); | |
571 | assertEquals(expectedDisabledCommands, clientListener.getDisabledAppContextCommands()); | |
572 | } | |
f37120c3 | 573 | } |