eb3df2b7a18827b5b39bf424124fc81a943a26e6
[lttng-ust-java-tests.git] / src / test / java / org / lttng / ust / agent / integration / log4j / Log4jMultiSessionTest.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.log4j;
20
21 import static org.junit.Assume.assumeTrue;
22
23 import java.io.IOException;
24
25 import org.apache.log4j.Appender;
26 import org.apache.log4j.Level;
27 import org.apache.log4j.Logger;
28 import org.junit.After;
29 import org.junit.AfterClass;
30 import org.junit.Before;
31 import org.junit.BeforeClass;
32 import org.lttng.ust.agent.integration.MultiSessionTestBase;
33 import org.lttng.ust.agent.log4j.LttngLogAppender;
34 import org.lttng.ust.agent.utils.LttngSession;
35 import org.lttng.ust.agent.utils.LttngSession.Domain;
36 import org.lttng.ust.agent.utils.MiscTestUtils;
37
38 public class Log4jMultiSessionTest extends MultiSessionTestBase {
39
40 private static final Domain DOMAIN = Domain.LOG4J;
41
42 private Logger loggerA;
43 private Logger loggerB;
44 private Logger loggerC;
45 private Logger loggerD;
46
47 @BeforeClass
48 public static void log4jClassSetup() {
49 /* Skip tests if we can't find the JNI library or lttng-tools */
50 assumeTrue(MiscTestUtils.checkForLog4jLibrary());
51 assumeTrue(MiscTestUtils.checkForLttngTools(Domain.LOG4J));
52
53 LttngSession.destroyAllSessions();
54 }
55
56 @AfterClass
57 public static void log4jClassCleanup() {
58 LttngSession.deleteAllTracee();
59 }
60
61 @Before
62 public void log4jSetup() throws SecurityException, IOException {
63 // TODO Wipe all existing LTTng sessions?
64
65 loggerA = Logger.getLogger(EVENT_NAME_A);
66 loggerB = Logger.getLogger(EVENT_NAME_B);
67 loggerC = Logger.getLogger(EVENT_NAME_C);
68 loggerD = Logger.getLogger(EVENT_NAME_D);
69
70 loggerA.setLevel(Level.ALL);
71 loggerB.setLevel(Level.ALL);
72 loggerC.setLevel(Level.ALL);
73 loggerD.setLevel(Level.ALL);
74
75 handlerA = new LttngLogAppender();
76 handlerB = new LttngLogAppender();
77 handlerC = new LttngLogAppender();
78 handlerD = new LttngLogAppender();
79
80 loggerA.addAppender((Appender) handlerA);
81 loggerB.addAppender((Appender) handlerB);
82 loggerC.addAppender((Appender) handlerC);
83 loggerD.addAppender((Appender) handlerD);
84 }
85
86 @After
87 public void log4jTeardown() {
88 loggerA.removeAppender((Appender) handlerA);
89 loggerB.removeAppender((Appender) handlerB);
90 loggerC.removeAppender((Appender) handlerC);
91 loggerD.removeAppender((Appender) handlerD);
92
93 loggerA = null;
94 loggerB = null;
95 loggerC = null;
96 loggerD = null;
97 }
98
99 @Override
100 protected Domain getDomain() {
101 return DOMAIN;
102 }
103
104 @Override
105 protected void sendEventsToLoggers() {
106 Log4jTestUtils.send10Events(loggerA);
107 Log4jTestUtils.send10Events(loggerB);
108 Log4jTestUtils.send10Events(loggerC);
109 Log4jTestUtils.send10Events(loggerD);
110 }
111 }
This page took 0.032851 seconds and 3 git commands to generate.