X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=lttng-ust-java-tests-jul%2Fsrc%2Ftest%2Fjava%2Forg%2Flttng%2Fust%2Fagent%2Fintegration%2Fevents%2FJulLegacyApiIT.java;h=9a21701904576cf990cebf3ac2817f8b4ea2ac35;hb=HEAD;hp=9a20f89a48b06627948f7a8f10cc850dde7a2277;hpb=4821eac962d2f707558b6d9a5b66af9dbe89b933;p=lttng-ust-java-tests.git diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiIT.java index 9a20f89..9a21701 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiIT.java @@ -18,37 +18,40 @@ package org.lttng.ust.agent.integration.events; -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 static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.logging.Level; +import java.util.logging.LogManager; import java.util.logging.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; 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.JulTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; -import org.lttng.ust.agent.utils.TestPrintRunner; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * Enabled events test for the LTTng-UST JUL log handler, using the legacy API. */ -@RunWith(TestPrintRunner.class) +@ExtendWith(TestPrintExtension.class) @SuppressWarnings("deprecation") +@Tag("agent:jul") +@Tag("domain:jul") public class JulLegacyApiIT { private static final Domain DOMAIN = Domain.JUL; @@ -57,6 +60,7 @@ public class JulLegacyApiIT { private static final String EVENT_NAME_B = "EventB"; private ILttngSession session; + private LTTngAgent agent; private Logger loggerA; private Logger loggerB; @@ -64,30 +68,30 @@ public class JulLegacyApiIT { /** * Class setup */ - @BeforeClass + @BeforeAll public static void julClassSetup() { - /* Skip tests if we can't find the JNI library or lttng-tools */ - assumeTrue(JulTestUtils.checkForJulLibrary()); - assumeTrue(LttngUtils.checkForLttngTools(Domain.JUL)); - - LttngToolsHelper.destroyAllSessions(); + JulTestUtils.testClassSetup(); } /** * Class cleanup */ - @AfterClass + @AfterAll public static void julClassCleanup() { - LttngToolsHelper.deleteAllTraces(); + JulTestUtils.testClassCleanup(); } /** * Test setup */ - @Before + @BeforeEach public void setup() { + /* Clear the JUL logger configuration */ + LogManager.getLogManager().reset(); + System.gc(); + loggerA = Logger.getLogger(EVENT_NAME_A); - LTTngAgent.getLTTngAgent(); + agent = LTTngAgent.getLTTngAgent(); loggerB = Logger.getLogger(EVENT_NAME_B); loggerA.setLevel(Level.ALL); @@ -99,11 +103,11 @@ public class JulLegacyApiIT { /** * Test cleanup */ - @After + @AfterEach public void tearDown() { session.close(); - LTTngAgent.dispose(); + agent.dispose(); loggerA = null; loggerB = null; @@ -171,6 +175,20 @@ public class JulLegacyApiIT { 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); + + Collections.sort(enabledEvents); + Collections.sort(expectedEvents); + + assertEquals(expectedEvents, enabledEvents); + } + /** * Get the singleton JUL Handler currently managed by the LTTngAgent. It is * not public, so we need reflection to access it. @@ -183,7 +201,7 @@ public class JulLegacyApiIT { julHandlerField.setAccessible(true); return (ILttngHandler) julHandlerField.get(LTTngAgent.getLTTngAgent()); } catch (ReflectiveOperationException | SecurityException e) { - fail(); + fail(e.getMessage()); return null; } }