2 * Copyright (C) 2022, EfficiOS Inc.
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.
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.
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.
19 package org
.lttng
.ust
.agent
.integration
.events
;
21 import java
.io
.IOException
;
23 import org
.apache
.logging
.log4j
.core
.Logger
;
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
.TestInstance
;
29 import org
.junit
.jupiter
.api
.TestInstance
.Lifecycle
;
30 import org
.lttng
.ust
.agent
.ILttngHandler
;
31 import org
.lttng
.ust
.agent
.utils
.Log4j2TestContext
;
32 import org
.lttng
.ust
.agent
.utils
.Log4j2TestUtils
;
35 * Log4j tests for multiple concurrent tracing sessions
37 @TestInstance(Lifecycle
.PER_CLASS
)
38 public abstract class Log4j2MultiSessionITBase
extends MultiSessionITBase
{
40 protected static final String APPENDER_NAME_A
= "LttngA";
41 protected static final String APPENDER_NAME_B
= "LttngB";
42 protected static final String APPENDER_NAME_C
= "LttngC";
43 protected static final String APPENDER_NAME_D
= "LttngD";
45 private Log4j2TestContext testContext
;
47 private Logger loggerA
;
48 private Logger loggerB
;
49 private Logger loggerC
;
50 private Logger loggerD
;
56 public void log4j2ClassSetup() {
57 Log4j2TestUtils
.testClassSetup(getDomain());
64 public static void log4j2ClassCleanup() {
65 Log4j2TestUtils
.testClassCleanup();
71 * @throws SecurityException
74 @SuppressWarnings("resource")
76 public void log4j2Setup() throws SecurityException
, IOException
{
78 testContext
= new Log4j2TestContext("log4j2." + this.getClass().getSimpleName() + ".xml");
80 testContext
.beforeTest();
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
);
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 handlerD
= (ILttngHandler
) loggerD
.getAppenders().get(APPENDER_NAME_D
);
97 public void log4j2Teardown() {
103 testContext
.afterTest();
107 protected boolean closeHandlers() {
112 protected void sendEventsToLoggers() {
113 Log4j2TestUtils
.send10Events(loggerA
);
114 Log4j2TestUtils
.send10Events(loggerB
);
115 Log4j2TestUtils
.send10Events(loggerC
);
116 Log4j2TestUtils
.send10Events(loggerD
);