Commit | Line | Data |
---|---|---|
2b408e85 AM |
1 | /* |
2 | * Copyright (C) 2015, 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 | ||
4821eac9 | 19 | package org.lttng.ust.agent.integration.events; |
c5524c71 | 20 | |
c5524c71 | 21 | import java.io.IOException; |
c5524c71 AM |
22 | |
23 | import org.apache.log4j.Appender; | |
24 | import org.apache.log4j.Level; | |
25 | import org.apache.log4j.Logger; | |
7a4f0255 MJ |
26 | import org.junit.jupiter.api.AfterAll; |
27 | import org.junit.jupiter.api.AfterEach; | |
28 | import org.junit.jupiter.api.BeforeAll; | |
29 | import org.junit.jupiter.api.BeforeEach; | |
9db2c69a | 30 | import org.junit.jupiter.api.Tag; |
7a4f0255 | 31 | import org.junit.jupiter.api.Test; |
45d1768c | 32 | import org.lttng.tools.ILttngSession.Domain; |
c5524c71 | 33 | import org.lttng.ust.agent.log4j.LttngLogAppender; |
4821eac9 | 34 | import org.lttng.ust.agent.utils.Log4jTestUtils; |
c5524c71 | 35 | |
8a0613fa AM |
36 | /** |
37 | * Enabled events test for the LTTng-UST Log4j log handler. | |
38 | */ | |
9db2c69a MJ |
39 | @Tag("agent:log4j") |
40 | @Tag("domain:log4j") | |
7b82be36 | 41 | public class Log4jEnabledEventsIT extends EnabledEventsITBase { |
c5524c71 AM |
42 | |
43 | private static final Domain DOMAIN = Domain.LOG4J; | |
44 | ||
45 | private Logger loggerA; | |
46 | private Logger loggerB; | |
47 | private Logger loggerC; | |
48 | private Logger loggerD; | |
49 | ||
8a0613fa AM |
50 | /** |
51 | * Class setup | |
52 | */ | |
7a4f0255 | 53 | @BeforeAll |
e41ec02a | 54 | public static void log4jClassSetup() { |
eca27046 | 55 | Log4jTestUtils.testClassSetup(); |
c5524c71 AM |
56 | } |
57 | ||
8a0613fa | 58 | /** |
eca27046 | 59 | * Class cleanup |
8a0613fa | 60 | */ |
7a4f0255 | 61 | @AfterAll |
e41ec02a | 62 | public static void log4jClassCleanup() { |
eca27046 | 63 | Log4jTestUtils.testClassCleanup(); |
c5524c71 AM |
64 | } |
65 | ||
8a0613fa AM |
66 | /** |
67 | * Test setup | |
68 | * | |
69 | * @throws SecurityException | |
70 | * @throws IOException | |
71 | */ | |
7a4f0255 | 72 | @BeforeEach |
e41ec02a | 73 | public void log4jSetup() throws SecurityException, IOException { |
c5524c71 AM |
74 | loggerA = Logger.getLogger(EVENT_NAME_A); |
75 | loggerB = Logger.getLogger(EVENT_NAME_B); | |
76 | loggerC = Logger.getLogger(EVENT_NAME_C); | |
77 | loggerD = Logger.getLogger(EVENT_NAME_D); | |
78 | ||
79 | loggerA.setLevel(Level.ALL); | |
80 | loggerB.setLevel(Level.ALL); | |
81 | loggerC.setLevel(Level.ALL); | |
82 | loggerD.setLevel(Level.ALL); | |
83 | ||
84 | handlerA = new LttngLogAppender(); | |
85 | handlerB = new LttngLogAppender(); | |
86 | handlerC = new LttngLogAppender(); | |
87 | ||
88 | loggerA.addAppender((Appender) handlerA); | |
89 | loggerB.addAppender((Appender) handlerB); | |
90 | loggerC.addAppender((Appender) handlerC); | |
91 | } | |
92 | ||
8a0613fa AM |
93 | /** |
94 | * Test teardown | |
95 | */ | |
7a4f0255 | 96 | @AfterEach |
e41ec02a | 97 | public void log4jTeardown() { |
c5524c71 AM |
98 | loggerA.removeAppender((Appender) handlerA); |
99 | loggerB.removeAppender((Appender) handlerB); | |
100 | loggerC.removeAppender((Appender) handlerC); | |
101 | ||
102 | loggerA = null; | |
103 | loggerB = null; | |
104 | loggerC = null; | |
105 | loggerD = null; | |
106 | } | |
107 | ||
108 | @Override | |
109 | protected Domain getDomain() { | |
110 | return DOMAIN; | |
111 | } | |
112 | ||
eca1a136 MJ |
113 | @Override |
114 | protected boolean closeHandlers() | |
115 | { | |
116 | return true; | |
117 | } | |
118 | ||
c5524c71 AM |
119 | @Override |
120 | protected void sendEventsToLoggers() { | |
8576633f AM |
121 | Log4jTestUtils.send10Events(loggerA); |
122 | Log4jTestUtils.send10Events(loggerB); | |
123 | Log4jTestUtils.send10Events(loggerC); | |
124 | Log4jTestUtils.send10Events(loggerD); | |
c5524c71 | 125 | } |
3fa81377 AM |
126 | |
127 | @Override | |
128 | protected void sendLocalizedEvent(String rawString, Object[] params) { | |
129 | throw new UnsupportedOperationException(); | |
130 | } | |
131 | ||
132 | @Override | |
133 | @Test | |
134 | public void testLocalizedMessage() { | |
135 | /* Does not apply to log4j 1.2.x */ | |
136 | } | |
c5524c71 | 137 | } |