Clear the logger configuration before "list" tests
[lttng-ust-java-tests.git] / lttng-ust-java-tests-jul / src / test / java / org / lttng / ust / agent / integration / events / JulLegacyApiIT.java
index 9a20f89a48b06627948f7a8f10cc850dde7a2277..97ba4b694049299795b686e4aecde7b66c7d83d0 100644 (file)
@@ -22,11 +22,13 @@ 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.Collections;
 import java.util.List;
 import java.util.logging.Level;
+import java.util.logging.LogManager;
 import java.util.logging.Logger;
 
 import org.junit.After;
@@ -37,11 +39,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.JulTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 import org.lttng.ust.agent.utils.TestPrintRunner;
 
 /**
@@ -57,6 +57,7 @@ public class JulLegacyApiIT {
     private static final String EVENT_NAME_B = "EventB";
 
     private ILttngSession session;
+    private LTTngAgent agent;
 
     private Logger loggerA;
     private Logger loggerB;
@@ -66,11 +67,7 @@ public class JulLegacyApiIT {
      */
     @BeforeClass
     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();
     }
 
     /**
@@ -78,7 +75,7 @@ public class JulLegacyApiIT {
      */
     @AfterClass
     public static void julClassCleanup() {
-        LttngToolsHelper.deleteAllTraces();
+        JulTestUtils.testClassCleanup();
     }
 
     /**
@@ -86,8 +83,12 @@ public class JulLegacyApiIT {
      */
     @Before
     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);
@@ -103,7 +104,7 @@ public class JulLegacyApiIT {
     public void tearDown() {
         session.close();
 
-        LTTngAgent.dispose();
+        agent.dispose();
 
         loggerA = null;
         loggerB = null;
@@ -171,6 +172,20 @@ public class JulLegacyApiIT {
         assertEquals(10, handler.getEventCount());
     }
 
+    /**
+     * Test that the "lttng list" commands lists the expected events.
+     */
+    @Test
+    public void testListEvents() {
+        List<String> enabledEvents = session.listEvents();
+        List<String> 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 +198,7 @@ public class JulLegacyApiIT {
             julHandlerField.setAccessible(true);
             return (ILttngHandler) julHandlerField.get(LTTngAgent.getLTTngAgent());
         } catch (ReflectiveOperationException | SecurityException e) {
-            fail();
+            fail(e.getMessage());
             return null;
         }
     }
This page took 0.024081 seconds and 4 git commands to generate.