a9ecf8c403b812bbeab59a11546794a9fa961e72
[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.Assert.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.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;
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")
48 @RunWith(Parameterized.class)
49 public class JulLegacyApiLoggerHierarchyListIT extends LoggerHierachyListITBase {
50
51 private LTTngAgent agent;
52 private Logger parentLogger;
53 private Logger childLogger;
54
55 /**
56 * Test constructor
57 *
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
66 */
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,
74 childLoggerActive,
75 childLoggerHasHandler);
76 }
77
78 // ------------------------------------------------------------------------
79 // Maintenance
80 // ------------------------------------------------------------------------
81
82 /**
83 * Class setup
84 */
85 @BeforeClass
86 public static void julClassSetup() {
87 JulTestUtils.testClassSetup();
88 }
89
90 /**
91 * Class cleanup
92 */
93 @AfterClass
94 public static void julClassCleanup() {
95 JulTestUtils.testClassCleanup();
96 }
97
98 /**
99 * Test setup
100 */
101 @SuppressWarnings("static-method")
102 @Before
103 public void setup() {
104 LogManager.getLogManager().reset();
105 System.gc();
106 }
107
108 /**
109 * Test cleanup
110 */
111 @After
112 public void cleanup() {
113 agent.dispose();
114
115 if (parentLogger != null) {
116 parentLogger = null;
117 }
118
119 if (childLogger != null) {
120 childLogger = null;
121 }
122
123 LogManager.getLogManager().reset();
124 System.gc();
125 }
126
127 // ------------------------------------------------------------------------
128 // Abstract methods
129 // ------------------------------------------------------------------------
130
131 @Override
132 protected Domain getDomain() {
133 return Domain.JUL;
134 }
135
136 @Override
137 protected void activateLoggers() throws IOException {
138 agent = LTTngAgent.getLTTngAgent();
139
140 /*
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.
144 */
145
146 if (parentLoggerActive) {
147 parentLogger = Logger.getLogger(PARENT_LOGGER);
148 }
149
150 if (childLoggerActive) {
151 childLogger = Logger.getLogger(CHILD_LOGGER);
152 }
153 }
154
155 // ------------------------------------------------------------------------
156 // Overridden tests
157 // ------------------------------------------------------------------------
158
159 /**
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.
163 */
164 @Override
165 @Test
166 public void testList() throws IOException {
167 activateLoggers();
168
169 List<String> enabledEvents = getSession().listEvents();
170 List<String> expectedEvents = new ArrayList<>();
171
172 if (parentLoggerActive) {
173 expectedEvents.add(PARENT_LOGGER);
174 }
175 if (childLoggerActive) {
176 expectedEvents.add(CHILD_LOGGER);
177 }
178
179 Collections.sort(enabledEvents);
180 Collections.sort(expectedEvents);
181 assertEquals(expectedEvents, enabledEvents);
182 }
183
184 }
This page took 0.032631 seconds and 3 git commands to generate.