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