e53e4a7e664ed63510831e7271e7d5d1eb22e821
[lttng-ust-java-tests.git] /
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 java.io.IOException;
22 import java.util.logging.Handler;
23 import java.util.logging.LogManager;
24 import java.util.logging.Logger;
25
26 import org.junit.After;
27 import org.junit.AfterClass;
28 import org.junit.Before;
29 import org.junit.BeforeClass;
30 import org.junit.runner.RunWith;
31 import org.junit.runners.Parameterized;
32 import org.lttng.tools.ILttngSession.Domain;
33 import org.lttng.ust.agent.jul.LttngLogHandler;
34 import org.lttng.ust.agent.utils.JulTestUtils;
35
36 /**
37 * Implementation of {@link LoggerHierachyListITBase} for JUL log handlers.
38 *
39 * @author Alexandre Montplaisir
40 */
41 @RunWith(Parameterized.class)
42 public class JulLoggerHierarchyListIT extends LoggerHierachyListITBase {
43
44 private Logger parentLogger;
45 private Logger childLogger;
46
47 private Handler parentHandler;
48 private Handler childHandler;
49
50 /**
51 * Test constructor
52 *
53 * @param parentLoggerActive
54 * Parent logger has been instantiated
55 * @param parentLoggerHasHandler
56 * Parent logger has a LTTng handler attached to it
57 * @param childLoggerActive
58 * Child logger has been instantiated
59 * @param childLoggerHasHandler
60 * Child logger has a LTTng handler attached to it
61 */
62 public JulLoggerHierarchyListIT(boolean parentLoggerActive,
63 boolean parentLoggerHasHandler,
64 boolean childLoggerActive,
65 boolean childLoggerHasHandler) {
66 /* Set by parameters defined in the base class */
67 super(parentLoggerActive,
68 parentLoggerHasHandler,
69 childLoggerActive,
70 childLoggerHasHandler);
71 }
72
73 // ------------------------------------------------------------------------
74 // Maintenance
75 // ------------------------------------------------------------------------
76
77 /**
78 * Class setup
79 */
80 @BeforeClass
81 public static void julClassSetup() {
82 JulTestUtils.testClassSetup();
83 }
84
85 /**
86 * Class cleanup
87 */
88 @AfterClass
89 public static void julClassCleanup() {
90 JulTestUtils.testClassCleanup();
91 }
92
93 /**
94 * Test setup
95 */
96 @SuppressWarnings("static-method")
97 @Before
98 public void setup() {
99 /*
100 * Kind of hackish, but it's the only way to ensure that loggers are
101 * really removed in-between tests, since LogManager does not provide a
102 * way to forcibly remove a logger, and it doesn't seem like it will any
103 * time soon, see http://bugs.java.com/view_bug.do?bug_id=4811930
104 */
105 LogManager.getLogManager().reset();
106 System.gc();
107 }
108
109 /**
110 * Test cleanup
111 */
112 @After
113 public void cleanup() {
114 if (parentLogger != null) {
115 if (parentHandler != null) {
116 parentLogger.removeHandler(parentHandler);
117 parentHandler.close();
118 parentHandler = null;
119 }
120 parentLogger = null;
121 }
122
123 if (childLogger != null) {
124 if (childHandler != null) {
125 childLogger.removeHandler(childHandler);
126 childHandler.close();
127 childHandler = null;
128 }
129 childLogger = null;
130 }
131 }
132
133 // ------------------------------------------------------------------------
134 // Abstract methods
135 // ------------------------------------------------------------------------
136
137 @Override
138 protected Domain getDomain() {
139 return Domain.JUL;
140 }
141
142 @Override
143 protected void activateLoggers() throws IOException {
144 if (parentLoggerActive) {
145 parentLogger = Logger.getLogger(PARENT_LOGGER);
146 if (parentLoggerHasHandler) {
147 parentHandler = new LttngLogHandler();
148 parentLogger.addHandler(parentHandler);
149 }
150 }
151
152 if (childLoggerActive) {
153 childLogger = Logger.getLogger(CHILD_LOGGER);
154 if (childLoggerHasHandler) {
155 childHandler = new LttngLogHandler();
156 childLogger.addHandler(childHandler);
157 }
158 }
159 }
160
161 }
This page took 0.0309 seconds and 3 git commands to generate.