ed8a08d178e7d708d8fc22bcd79fd311fd4ffb82
[lttng-ust-java-tests.git] / lttng-ust-java-tests-jul / src / test / java / org / lttng / ust / agent / integration / events / JulLegacyApiLoggerHierarchyListIT.java
1 /*
2 * Copyright (C) 2016, 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.events;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
27 import java.util.logging.LogManager;
28 import java.util.logging.Logger;
29
30 import org.junit.jupiter.api.AfterAll;
31 import org.junit.jupiter.api.AfterEach;
32 import org.junit.jupiter.api.BeforeAll;
33 import org.junit.jupiter.api.BeforeEach;
34 import org.junit.jupiter.params.ParameterizedTest;
35 import org.junit.jupiter.params.provider.MethodSource;
36 import org.lttng.tools.ILttngSession.Domain;
37 import org.lttng.ust.agent.LTTngAgent;
38 import org.lttng.ust.agent.utils.JulTestUtils;
39
40 /**
41 * Implementation of {@link LoggerHierachyListITBase} for the JUL part of the
42 * legacy LTTngAgent API.
43 *
44 * @author Alexandre Montplaisir
45 */
46 @SuppressWarnings("deprecation")
47 //@RunWith(Parameterized.class)
48 public class JulLegacyApiLoggerHierarchyListIT extends LoggerHierachyListITBase {
49
50 private LTTngAgent agent;
51 private Logger parentLogger;
52 private Logger childLogger;
53
54 // ------------------------------------------------------------------------
55 // Maintenance
56 // ------------------------------------------------------------------------
57
58 /**
59 * Class setup
60 */
61 @BeforeAll
62 public static void julClassSetup() {
63 JulTestUtils.testClassSetup();
64 }
65
66 /**
67 * Class cleanup
68 */
69 @AfterAll
70 public static void julClassCleanup() {
71 JulTestUtils.testClassCleanup();
72 }
73
74 /**
75 * Test setup
76 */
77 @SuppressWarnings("static-method")
78 @BeforeEach
79 public void setup() {
80 LogManager.getLogManager().reset();
81 System.gc();
82 }
83
84 /**
85 * Test cleanup
86 */
87 @AfterEach
88 public void cleanup() {
89 agent.dispose();
90
91 if (parentLogger != null) {
92 parentLogger = null;
93 }
94
95 if (childLogger != null) {
96 childLogger = null;
97 }
98
99 LogManager.getLogManager().reset();
100 System.gc();
101 }
102
103 // ------------------------------------------------------------------------
104 // Abstract methods
105 // ------------------------------------------------------------------------
106
107 @Override
108 protected Domain getDomain() {
109 return Domain.JUL;
110 }
111
112 @Override
113 protected void activateLoggers(boolean parentLoggerActive,
114 boolean parentLoggerHasHandler,
115 boolean childLoggerActive,
116 boolean childLoggerHasHandler) throws IOException {
117 agent = LTTngAgent.getLTTngAgent();
118
119 /*
120 * There is no notion of "hasHandler" for the legacy API: there is only
121 * one log handler attached to the root logger, so there are no handlers
122 * to specific events/loggers.
123 */
124
125 if (parentLoggerActive) {
126 parentLogger = Logger.getLogger(PARENT_LOGGER);
127 }
128
129 if (childLoggerActive) {
130 childLogger = Logger.getLogger(CHILD_LOGGER);
131 }
132 }
133
134 // ------------------------------------------------------------------------
135 // Overridden tests
136 // ------------------------------------------------------------------------
137
138 /**
139 * Due to how the legacy agent works, there is no notion of "hasHandler". If
140 * the logger exists, it will be visible in "lttng list" because the single
141 * log handler is attached to the root logger.
142 */
143 @SuppressWarnings("resource")
144 @Override
145 @ParameterizedTest
146 @MethodSource("provideArguments")
147 public void testList(boolean parentLoggerActive,
148 boolean parentLoggerHasHandler,
149 boolean childLoggerActive,
150 boolean childLoggerHasHandler) throws IOException {
151
152 activateLoggers(parentLoggerActive,
153 parentLoggerHasHandler,
154 childLoggerActive,
155 childLoggerHasHandler);
156
157 List<String> enabledEvents = getSession().listEvents();
158 List<String> expectedEvents = new ArrayList<>();
159
160 if (parentLoggerActive) {
161 expectedEvents.add(PARENT_LOGGER);
162 }
163 if (childLoggerActive) {
164 expectedEvents.add(CHILD_LOGGER);
165 }
166
167 Collections.sort(enabledEvents);
168 Collections.sort(expectedEvents);
169 assertEquals(expectedEvents, enabledEvents);
170 }
171
172 }
This page took 0.032963 seconds and 3 git commands to generate.