Add 'log4j2' domain tests to the Log4j 2.x agent
[lttng-ust-java-tests.git] / lttng-ust-java-tests-log4j / src / test / java / org / lttng / ust / agent / integration / events / Log4jMultiSessionIT.java
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
19 package org.lttng.ust.agent.integration.events;
20
21 import java.io.IOException;
22
23 import org.apache.log4j.Appender;
24 import org.apache.log4j.Level;
25 import org.apache.log4j.Logger;
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;
30 import org.junit.jupiter.api.Tag;
31 import org.lttng.tools.ILttngSession.Domain;
32 import org.lttng.ust.agent.log4j.LttngLogAppender;
33 import org.lttng.ust.agent.utils.Log4jTestUtils;
34
35 /**
36 * Log4j tests for multiple concurrent tracing sessions
37 */
38 @Tag("agent:log4j")
39 @Tag("domain:log4j")
40 public class Log4jMultiSessionIT extends MultiSessionITBase {
41
42 private static final Domain DOMAIN = Domain.LOG4J;
43
44 private Logger loggerA;
45 private Logger loggerB;
46 private Logger loggerC;
47 private Logger loggerD;
48
49 /**
50 * Class setup
51 */
52 @BeforeAll
53 public static void log4jClassSetup() {
54 Log4jTestUtils.testClassSetup();
55 }
56
57 /**
58 * Class cleanup
59 */
60 @AfterAll
61 public static void log4jClassCleanup() {
62 Log4jTestUtils.testClassCleanup();
63 }
64
65 /**
66 * Test setup
67 *
68 * @throws SecurityException
69 * @throws IOException
70 */
71 @BeforeEach
72 public void log4jSetup() throws SecurityException, IOException {
73 // TODO Wipe all existing LTTng sessions?
74
75 loggerA = Logger.getLogger(EVENT_NAME_A);
76 loggerB = Logger.getLogger(EVENT_NAME_B);
77 loggerC = Logger.getLogger(EVENT_NAME_C);
78 loggerD = Logger.getLogger(EVENT_NAME_D);
79
80 loggerA.setLevel(Level.ALL);
81 loggerB.setLevel(Level.ALL);
82 loggerC.setLevel(Level.ALL);
83 loggerD.setLevel(Level.ALL);
84
85 handlerA = new LttngLogAppender();
86 handlerB = new LttngLogAppender();
87 handlerC = new LttngLogAppender();
88 handlerD = new LttngLogAppender();
89
90 loggerA.addAppender((Appender) handlerA);
91 loggerB.addAppender((Appender) handlerB);
92 loggerC.addAppender((Appender) handlerC);
93 loggerD.addAppender((Appender) handlerD);
94 }
95
96 /**
97 * Test teardown
98 */
99 @AfterEach
100 public void log4jTeardown() {
101 loggerA.removeAppender((Appender) handlerA);
102 loggerB.removeAppender((Appender) handlerB);
103 loggerC.removeAppender((Appender) handlerC);
104 loggerD.removeAppender((Appender) handlerD);
105
106 loggerA = null;
107 loggerB = null;
108 loggerC = null;
109 loggerD = null;
110 }
111
112 @Override
113 protected Domain getDomain() {
114 return DOMAIN;
115 }
116
117 @Override
118 protected boolean closeHandlers()
119 {
120 return true;
121 }
122
123 @Override
124 protected void sendEventsToLoggers() {
125 Log4jTestUtils.send10Events(loggerA);
126 Log4jTestUtils.send10Events(loggerB);
127 Log4jTestUtils.send10Events(loggerC);
128 Log4jTestUtils.send10Events(loggerD);
129 }
130 }
This page took 0.032282 seconds and 4 git commands to generate.