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
.Assert
.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
.After
;
31 import org
.junit
.AfterClass
;
32 import org
.junit
.Before
;
33 import org
.junit
.BeforeClass
;
34 import org
.junit
.Test
;
35 import org
.junit
.runner
.RunWith
;
36 import org
.junit
.runners
.Parameterized
;
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)
49 public class JulLegacyApiLoggerHierarchyListIT
extends LoggerHierachyListITBase
{
51 private LTTngAgent agent
;
52 private Logger parentLogger
;
53 private Logger childLogger
;
58 * @param parentLoggerActive
59 * Parent logger has been instantiated
60 * @param parentLoggerHasHandler
61 * Parent logger has a LTTng handler attached to it
62 * @param childLoggerActive
63 * Child logger has been instantiated
64 * @param childLoggerHasHandler
65 * Child logger has a LTTng handler attached to it
67 public JulLegacyApiLoggerHierarchyListIT(boolean parentLoggerActive
,
68 boolean parentLoggerHasHandler
,
69 boolean childLoggerActive
,
70 boolean childLoggerHasHandler
) {
71 /* Set by parameters defined in the base class */
72 super(parentLoggerActive
,
73 parentLoggerHasHandler
,
75 childLoggerHasHandler
);
78 // ------------------------------------------------------------------------
80 // ------------------------------------------------------------------------
86 public static void julClassSetup() {
87 JulTestUtils
.testClassSetup();
94 public static void julClassCleanup() {
95 JulTestUtils
.testClassCleanup();
101 @SuppressWarnings("static-method")
103 public void setup() {
104 LogManager
.getLogManager().reset();
112 public void cleanup() {
115 if (parentLogger
!= null) {
119 if (childLogger
!= null) {
123 LogManager
.getLogManager().reset();
127 // ------------------------------------------------------------------------
129 // ------------------------------------------------------------------------
132 protected Domain
getDomain() {
137 protected void activateLoggers() throws IOException
{
138 agent
= LTTngAgent
.getLTTngAgent();
141 * There is no notion of "hasHandler" for the legacy API: there is only
142 * one log handler attached to the root logger, so there are no handlers
143 * to specific events/loggers.
146 if (parentLoggerActive
) {
147 parentLogger
= Logger
.getLogger(PARENT_LOGGER
);
150 if (childLoggerActive
) {
151 childLogger
= Logger
.getLogger(CHILD_LOGGER
);
155 // ------------------------------------------------------------------------
157 // ------------------------------------------------------------------------
160 * Due to how the legacy agent works, there is no notion of "hasHandler". If
161 * the logger exists, it will be visible in "lttng list" because the single
162 * log handler is attached to the root logger.
166 public void testList() throws IOException
{
169 List
<String
> enabledEvents
= getSession().listEvents();
170 List
<String
> expectedEvents
= new ArrayList
<>();
172 if (parentLoggerActive
) {
173 expectedEvents
.add(PARENT_LOGGER
);
175 if (childLoggerActive
) {
176 expectedEvents
.add(CHILD_LOGGER
);
179 Collections
.sort(enabledEvents
);
180 Collections
.sort(expectedEvents
);
181 assertEquals(expectedEvents
, enabledEvents
);