From b342ee75b8f1dd103fc049095de6e1242fc119a6 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Thu, 2 Jun 2016 18:41:18 -0400 Subject: [PATCH] Add workaround in log4j legacy API test log4j doesn't seem to make it possible clear loggers the way JUL does, so all loggers defined in previous tests are still present in subsequent ones. This coupled with the fact that the legacy agent attaches one handler to the root logger, all loggers defined in previous tests end up being visible by LTTng. Ease up the passing requirement for a test so that it can still work in these conditions. Signed-off-by: Alexandre Montplaisir --- .../integration/events/Log4jLegacyApiIT.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jLegacyApiIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jLegacyApiIT.java index 50e824e..b824ef0 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jLegacyApiIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jLegacyApiIT.java @@ -29,6 +29,7 @@ import java.util.Collections; import java.util.List; import org.apache.log4j.Level; +import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.junit.After; import org.junit.AfterClass; @@ -176,10 +177,16 @@ public class Log4jLegacyApiIT { List enabledEvents = session.listEvents(); List expectedEvents = Arrays.asList(EVENT_NAME_A, EVENT_NAME_B); - Collections.sort(enabledEvents); - Collections.sort(expectedEvents); - - assertEquals(expectedEvents, enabledEvents); + /* + * It doesn't seem possible to forcibly remove Loggers with log4j 1.2. + * This, coupled with the way the legacy agent works, makes it so + * loggers defined in other tests will always "leak" into this one when + * running the whole test suite. + * + * For this test, simply check that the expected names are present, and + * let pass the case where other loggers may the present too. + */ + expectedEvents.forEach(event -> assertTrue(enabledEvents.contains(event))); } /** -- 2.34.1