| 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.After; |
| 27 | import org.junit.AfterClass; |
| 28 | import org.junit.Before; |
| 29 | import org.junit.BeforeClass; |
| 30 | import org.lttng.tools.ILttngSession.Domain; |
| 31 | import org.lttng.ust.agent.log4j.LttngLogAppender; |
| 32 | import org.lttng.ust.agent.utils.Log4jTestUtils; |
| 33 | |
| 34 | /** |
| 35 | * Log4j tests for multiple concurrent tracing sessions |
| 36 | */ |
| 37 | public class Log4jMultiSessionIT extends MultiSessionITBase { |
| 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 | |
| 46 | /** |
| 47 | * Class setup |
| 48 | */ |
| 49 | @BeforeClass |
| 50 | public static void log4jClassSetup() { |
| 51 | Log4jTestUtils.testClassSetup(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Class cleanup |
| 56 | */ |
| 57 | @AfterClass |
| 58 | public static void log4jClassCleanup() { |
| 59 | Log4jTestUtils.testClassCleanup(); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Test setup |
| 64 | * |
| 65 | * @throws SecurityException |
| 66 | * @throws IOException |
| 67 | */ |
| 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 | |
| 93 | /** |
| 94 | * Test teardown |
| 95 | */ |
| 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 boolean closeHandlers() |
| 116 | { |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | protected void sendEventsToLoggers() { |
| 122 | Log4jTestUtils.send10Events(loggerA); |
| 123 | Log4jTestUtils.send10Events(loggerB); |
| 124 | Log4jTestUtils.send10Events(loggerC); |
| 125 | Log4jTestUtils.send10Events(loggerD); |
| 126 | } |
| 127 | } |