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
.api
.Tag
;
35 import org
.junit
.jupiter
.params
.ParameterizedTest
;
36 import org
.junit
.jupiter
.params
.provider
.MethodSource
;
37 import org
.lttng
.tools
.ILttngSession
.Domain
;
38 import org
.lttng
.ust
.agent
.LTTngAgent
;
39 import org
.lttng
.ust
.agent
.utils
.JulTestUtils
;
42 * Implementation of {@link LoggerHierachyListITBase} for the JUL part of the
43 * legacy LTTngAgent API.
45 * @author Alexandre Montplaisir
47 @SuppressWarnings("deprecation")
48 //@RunWith(Parameterized.class)
51 public class JulLegacyApiLoggerHierarchyListIT
extends LoggerHierachyListITBase
{
53 private LTTngAgent agent
;
54 private Logger parentLogger
;
55 private Logger childLogger
;
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
65 public static void julClassSetup() {
66 JulTestUtils
.testClassSetup();
73 public static void julClassCleanup() {
74 JulTestUtils
.testClassCleanup();
80 @SuppressWarnings("static-method")
83 LogManager
.getLogManager().reset();
91 public void cleanup() {
94 if (parentLogger
!= null) {
98 if (childLogger
!= null) {
102 LogManager
.getLogManager().reset();
106 // ------------------------------------------------------------------------
108 // ------------------------------------------------------------------------
111 protected Domain
getDomain() {
116 protected void activateLoggers(boolean parentLoggerActive
,
117 boolean parentLoggerHasHandler
,
118 boolean childLoggerActive
,
119 boolean childLoggerHasHandler
) throws IOException
{
120 agent
= LTTngAgent
.getLTTngAgent();
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.
128 if (parentLoggerActive
) {
129 parentLogger
= Logger
.getLogger(PARENT_LOGGER
);
132 if (childLoggerActive
) {
133 childLogger
= Logger
.getLogger(CHILD_LOGGER
);
137 // ------------------------------------------------------------------------
139 // ------------------------------------------------------------------------
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.
146 @SuppressWarnings("resource")
149 @MethodSource("provideArguments")
150 public void testList(boolean parentLoggerActive
,
151 boolean parentLoggerHasHandler
,
152 boolean childLoggerActive
,
153 boolean childLoggerHasHandler
) throws IOException
{
155 activateLoggers(parentLoggerActive
,
156 parentLoggerHasHandler
,
158 childLoggerHasHandler
);
160 List
<String
> enabledEvents
= getSession().listEvents();
161 List
<String
> expectedEvents
= new ArrayList
<>();
163 if (parentLoggerActive
) {
164 expectedEvents
.add(PARENT_LOGGER
);
166 if (childLoggerActive
) {
167 expectedEvents
.add(CHILD_LOGGER
);
170 Collections
.sort(enabledEvents
);
171 Collections
.sort(expectedEvents
);
172 assertEquals(expectedEvents
, enabledEvents
);