X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=lttng-ust-java-tests-log4j%2Fsrc%2Ftest%2Fjava%2Forg%2Flttng%2Fust%2Fagent%2Fintegration%2Fevents%2FLog4jLegacyApiIT.java;h=2630101d94ce94b52becef5f4e68c6d6b28908f8;hb=89fe6fa651ed51225678c8c2adef0a26d2df85d4;hp=fe613d39d2b5aa1c123aa4e4754a3bdc6586478e;hpb=1f3dd43c2dd89d3bd01edd9edf2fb72946e4e447;p=lttng-ust-java-tests.git 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 fe613d3..2630101 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 @@ -22,9 +22,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; import java.lang.reflect.Field; +import java.util.Arrays; import java.util.List; import org.apache.log4j.Level; @@ -37,11 +37,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.lttng.tools.ILttngSession; import org.lttng.tools.ILttngSession.Domain; -import org.lttng.tools.LttngToolsHelper; import org.lttng.ust.agent.ILttngHandler; import org.lttng.ust.agent.LTTngAgent; import org.lttng.ust.agent.utils.Log4jTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; import org.lttng.ust.agent.utils.TestPrintRunner; /** @@ -58,6 +56,7 @@ public class Log4jLegacyApiIT { private static final String EVENT_NAME_B = "EventB"; private ILttngSession session; + private LTTngAgent agent; private Logger loggerA; private Logger loggerB; @@ -66,20 +65,16 @@ public class Log4jLegacyApiIT { * Class setup */ @BeforeClass - public static void classSetup() { - /* Skip tests if we can't find the JNI library or lttng-tools */ - assumeTrue(Log4jTestUtils.checkForLog4jLibrary()); - assumeTrue(LttngUtils.checkForLttngTools(Domain.LOG4J)); - - LttngToolsHelper.destroyAllSessions(); + public static void log4jClassSetup() { + Log4jTestUtils.testClassSetup(); } /** * Class cleanup */ @AfterClass - public static void classCleanup() { - LttngToolsHelper.deleteAllTraces(); + public static void log4jClassCleanup() { + Log4jTestUtils.testClassCleanup(); } /** @@ -88,7 +83,7 @@ public class Log4jLegacyApiIT { @Before public void setup() { loggerA = Logger.getLogger(EVENT_NAME_A); - LTTngAgent.getLTTngAgent(); + agent = LTTngAgent.getLTTngAgent(); loggerB = Logger.getLogger(EVENT_NAME_B); loggerA.setLevel(Level.ALL); @@ -104,7 +99,7 @@ public class Log4jLegacyApiIT { public void tearDown() { session.close(); - LTTngAgent.dispose(); + agent.dispose(); loggerA = null; loggerB = null; @@ -172,6 +167,26 @@ public class Log4jLegacyApiIT { assertEquals(10, handler.getEventCount()); } + /** + * Test that the "lttng list" commands lists the expected events. + */ + @Test + public void testListEvents() { + List enabledEvents = session.listEvents(); + List expectedEvents = Arrays.asList(EVENT_NAME_A, EVENT_NAME_B); + + /* + * 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))); + } + /** * Get the singleton Log4j Handler currently managed by the LTTngAgent. It * is not public, so we need reflection to access it.