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; |
e41ec02a | 20 | |
e41ec02a AM |
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.After; | |
27 | import org.junit.AfterClass; | |
28 | import org.junit.Before; | |
29 | import org.junit.BeforeClass; | |
45d1768c | 30 | import org.lttng.tools.ILttngSession.Domain; |
e41ec02a | 31 | import org.lttng.ust.agent.log4j.LttngLogAppender; |
4821eac9 | 32 | import org.lttng.ust.agent.utils.Log4jTestUtils; |
e41ec02a | 33 | |
8a0613fa AM |
34 | /** |
35 | * Log4j tests for multiple concurrent tracing sessions | |
36 | */ | |
7b82be36 | 37 | public class Log4jMultiSessionIT extends MultiSessionITBase { |
e41ec02a AM |
38 | |
39 | private static final Domain DOMAIN = Domain.LOG4J; | |
40 | ||
41 | private Logger loggerA; | |
42 | private Logger loggerB; | |
43 | private Logger loggerC; | |
44 | private Logger loggerD; | |
45 | ||
8a0613fa AM |
46 | /** |
47 | * Class setup | |
48 | */ | |
e41ec02a AM |
49 | @BeforeClass |
50 | public static void log4jClassSetup() { | |
eca27046 | 51 | Log4jTestUtils.testClassSetup(); |
e41ec02a AM |
52 | } |
53 | ||
8a0613fa | 54 | /** |
eca27046 | 55 | * Class cleanup |
8a0613fa | 56 | */ |
e41ec02a AM |
57 | @AfterClass |
58 | public static void log4jClassCleanup() { | |
eca27046 | 59 | Log4jTestUtils.testClassCleanup(); |
e41ec02a AM |
60 | } |
61 | ||
8a0613fa AM |
62 | /** |
63 | * Test setup | |
64 | * | |
65 | * @throws SecurityException | |
66 | * @throws IOException | |
67 | */ | |
e41ec02a AM |
68 | @Before |
69 | public void log4jSetup() throws SecurityException, IOException { | |
70 | // TODO Wipe all existing LTTng sessions? | |
71 | ||
72 | loggerA = Logger.getLogger(EVENT_NAME_A); | |
73 | loggerB = Logger.getLogger(EVENT_NAME_B); | |
74 | loggerC = Logger.getLogger(EVENT_NAME_C); | |
75 | loggerD = Logger.getLogger(EVENT_NAME_D); | |
76 | ||
77 | loggerA.setLevel(Level.ALL); | |
78 | loggerB.setLevel(Level.ALL); | |
79 | loggerC.setLevel(Level.ALL); | |
80 | loggerD.setLevel(Level.ALL); | |
81 | ||
82 | handlerA = new LttngLogAppender(); | |
83 | handlerB = new LttngLogAppender(); | |
84 | handlerC = new LttngLogAppender(); | |
85 | handlerD = new LttngLogAppender(); | |
86 | ||
87 | loggerA.addAppender((Appender) handlerA); | |
88 | loggerB.addAppender((Appender) handlerB); | |
89 | loggerC.addAppender((Appender) handlerC); | |
90 | loggerD.addAppender((Appender) handlerD); | |
91 | } | |
92 | ||
8a0613fa AM |
93 | /** |
94 | * Test teardown | |
95 | */ | |
e41ec02a AM |
96 | @After |
97 | public void log4jTeardown() { | |
98 | loggerA.removeAppender((Appender) handlerA); | |
99 | loggerB.removeAppender((Appender) handlerB); | |
100 | loggerC.removeAppender((Appender) handlerC); | |
101 | loggerD.removeAppender((Appender) handlerD); | |
102 | ||
103 | loggerA = null; | |
104 | loggerB = null; | |
105 | loggerC = null; | |
106 | loggerD = null; | |
107 | } | |
108 | ||
109 | @Override | |
110 | protected Domain getDomain() { | |
111 | return DOMAIN; | |
112 | } | |
113 | ||
114 | @Override | |
115 | protected void sendEventsToLoggers() { | |
116 | Log4jTestUtils.send10Events(loggerA); | |
117 | Log4jTestUtils.send10Events(loggerB); | |
118 | Log4jTestUtils.send10Events(loggerC); | |
119 | Log4jTestUtils.send10Events(loggerD); | |
120 | } | |
121 | } |