Commit | Line | Data |
---|---|---|
eca1a136 MJ |
1 | /* |
2 | * Copyright (C) 2022, EfficiOS Inc. | |
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; | |
eca1a136 | 22 | |
eca1a136 | 23 | import org.apache.logging.log4j.core.Logger; |
7a4f0255 MJ |
24 | import org.junit.jupiter.api.AfterAll; |
25 | import org.junit.jupiter.api.AfterEach; | |
26 | import org.junit.jupiter.api.BeforeAll; | |
27 | import org.junit.jupiter.api.BeforeEach; | |
28 | import org.junit.jupiter.api.Test; | |
eca1a136 MJ |
29 | import org.lttng.tools.ILttngSession.Domain; |
30 | import org.lttng.ust.agent.ILttngHandler; | |
eca1a136 MJ |
31 | import org.lttng.ust.agent.utils.Log4j2TestContext; |
32 | import org.lttng.ust.agent.utils.Log4j2TestUtils; | |
33 | ||
34 | /** | |
35 | * Enabled events test for the LTTng-UST Log4j log handler. | |
36 | */ | |
37 | public class Log4j2EnabledEventsIT extends EnabledEventsITBase { | |
38 | ||
39 | private static final String APPENDER_NAME_A = "LttngA"; | |
40 | private static final String APPENDER_NAME_B = "LttngB"; | |
41 | private static final String APPENDER_NAME_C = "LttngC"; | |
42 | ||
43 | private static final Domain DOMAIN = Domain.LOG4J; | |
44 | ||
45 | private Log4j2TestContext testContext; | |
46 | ||
47 | private Logger loggerA; | |
48 | private Logger loggerB; | |
49 | private Logger loggerC; | |
50 | private Logger loggerD; | |
51 | ||
52 | /** | |
53 | * Class setup | |
54 | */ | |
7a4f0255 | 55 | @BeforeAll |
eca1a136 MJ |
56 | public static void log4j2ClassSetup() { |
57 | Log4j2TestUtils.testClassSetup(); | |
58 | } | |
59 | ||
60 | /** | |
61 | * Class cleanup | |
62 | */ | |
7a4f0255 | 63 | @AfterAll |
eca1a136 MJ |
64 | public static void log4j2ClassCleanup() { |
65 | Log4j2TestUtils.testClassCleanup(); | |
66 | } | |
67 | ||
68 | /** | |
69 | * Test setup | |
70 | * | |
71 | * @throws SecurityException | |
72 | * @throws IOException | |
73 | */ | |
74 | @SuppressWarnings("resource") | |
7a4f0255 | 75 | @BeforeEach |
eca1a136 MJ |
76 | public void log4j2Setup() throws SecurityException, IOException { |
77 | ||
78 | testContext = new Log4j2TestContext("log4j2.Log4j2EnabledEventsIT.xml"); | |
79 | ||
80 | testContext.beforeTest(); | |
81 | ||
82 | loggerA = testContext.getLoggerContext().getLogger(EVENT_NAME_A); | |
83 | loggerB = testContext.getLoggerContext().getLogger(EVENT_NAME_B); | |
84 | loggerC = testContext.getLoggerContext().getLogger(EVENT_NAME_C); | |
85 | loggerD = testContext.getLoggerContext().getLogger(EVENT_NAME_D); | |
86 | ||
87 | handlerA = (ILttngHandler) loggerA.getAppenders().get(APPENDER_NAME_A); | |
88 | handlerB = (ILttngHandler) loggerB.getAppenders().get(APPENDER_NAME_B); | |
89 | handlerC = (ILttngHandler) loggerC.getAppenders().get(APPENDER_NAME_C); | |
90 | } | |
91 | ||
92 | /** | |
93 | * Test teardown | |
94 | */ | |
7a4f0255 | 95 | @AfterEach |
eca1a136 MJ |
96 | public void log4j2Teardown() { |
97 | loggerA = null; | |
98 | loggerB = null; | |
99 | loggerC = null; | |
100 | loggerD = null; | |
101 | ||
102 | testContext.afterTest(); | |
103 | } | |
104 | ||
105 | @Override | |
106 | protected Domain getDomain() { | |
107 | return DOMAIN; | |
108 | } | |
109 | ||
110 | @Override | |
111 | protected boolean closeHandlers() | |
112 | { | |
113 | return false; | |
114 | } | |
115 | ||
116 | @Override | |
117 | protected void sendEventsToLoggers() { | |
118 | Log4j2TestUtils.send10Events(loggerA); | |
119 | Log4j2TestUtils.send10Events(loggerB); | |
120 | Log4j2TestUtils.send10Events(loggerC); | |
121 | Log4j2TestUtils.send10Events(loggerD); | |
122 | } | |
123 | ||
124 | @Override | |
125 | protected void sendLocalizedEvent(String rawString, Object[] params) { | |
126 | throw new UnsupportedOperationException(); | |
127 | } | |
128 | ||
129 | @Override | |
130 | @Test | |
131 | public void testLocalizedMessage() { | |
132 | /* Does not apply to log4j 1.2.x */ | |
133 | } | |
134 | } |