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