2 * Copyright (C) 2016, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
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.
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.
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.
19 package org.lttng.ust.agent.integration.events;
21 import static org.junit.jupiter.api.Assertions.assertEquals;
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;
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;
41 * Implementation of {@link LoggerHierachyListITBase} for the JUL part of the
42 * legacy LTTngAgent API.
44 * @author Alexandre Montplaisir
46 @SuppressWarnings("deprecation")
47 //@RunWith(Parameterized.class)
48 public class JulLegacyApiLoggerHierarchyListIT extends LoggerHierachyListITBase {
50 private LTTngAgent agent;
51 private Logger parentLogger;
52 private Logger childLogger;
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
62 public static void julClassSetup() {
63 JulTestUtils.testClassSetup();
70 public static void julClassCleanup() {
71 JulTestUtils.testClassCleanup();
77 @SuppressWarnings("static-method")
80 LogManager.getLogManager().reset();
88 public void cleanup() {
91 if (parentLogger != null) {
95 if (childLogger != null) {
99 LogManager.getLogManager().reset();
103 // ------------------------------------------------------------------------
105 // ------------------------------------------------------------------------
108 protected Domain getDomain() {
113 protected void activateLoggers(boolean parentLoggerActive,
114 boolean parentLoggerHasHandler,
115 boolean childLoggerActive,
116 boolean childLoggerHasHandler) throws IOException {
117 agent = LTTngAgent.getLTTngAgent();
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.
125 if (parentLoggerActive) {
126 parentLogger = Logger.getLogger(PARENT_LOGGER);
129 if (childLoggerActive) {
130 childLogger = Logger.getLogger(CHILD_LOGGER);
134 // ------------------------------------------------------------------------
136 // ------------------------------------------------------------------------
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.
143 @SuppressWarnings("resource")
146 @MethodSource("provideArguments")
147 public void testList(boolean parentLoggerActive,
148 boolean parentLoggerHasHandler,
149 boolean childLoggerActive,
150 boolean childLoggerHasHandler) throws IOException {
152 activateLoggers(parentLoggerActive,
153 parentLoggerHasHandler,
155 childLoggerHasHandler);
157 List<String> enabledEvents = getSession().listEvents();
158 List<String> expectedEvents = new ArrayList<>();
160 if (parentLoggerActive) {
161 expectedEvents.add(PARENT_LOGGER);
163 if (childLoggerActive) {
164 expectedEvents.add(CHILD_LOGGER);
167 Collections.sort(enabledEvents);
168 Collections.sort(expectedEvents);
169 assertEquals(expectedEvents, enabledEvents);