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