Add log4j and legacy-API tests
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 24 Jul 2015 04:31:50 +0000 (00:31 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 24 Jul 2015 04:53:25 +0000 (00:53 -0400)
We can re-use the existing tests into an abstract class.

Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
12 files changed:
.classpath
.settings/org.eclipse.jdt.ui.prefs
src/org/lttng/ust/agent/benchmarks/jul/RunAllBenchmarks.java [deleted file]
src/org/lttng/ust/agent/benchmarks/jul/RunAllJulBenchmarks.java [new file with mode: 0644]
src/org/lttng/ust/agent/integration/RunAllIntegrationTests.java [new file with mode: 0644]
src/org/lttng/ust/agent/integration/common/EnabledEventsTest.java [new file with mode: 0644]
src/org/lttng/ust/agent/integration/jul/AllTests.java [new file with mode: 0644]
src/org/lttng/ust/agent/integration/jul/JulEnabledEventsTest.java
src/org/lttng/ust/agent/integration/jul/JulLegacyApiTest.java [new file with mode: 0644]
src/org/lttng/ust/agent/integration/log4j/AllTests.java [new file with mode: 0644]
src/org/lttng/ust/agent/integration/log4j/Log4jEnabledEventsTest.java [new file with mode: 0644]
src/org/lttng/ust/agent/integration/log4j/Log4jLegacyApiTest.java [new file with mode: 0644]

index 0b8166efaf87e7ff0a16b107191ee5635b6a03b1..fea8a52e9e3d69b304238c0548bf56507cd00297 100644 (file)
@@ -5,5 +5,7 @@
        <classpathentry combineaccessrules="false" kind="src" path="/lttng-ust-agent-jul"/>
        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
        <classpathentry combineaccessrules="false" kind="src" path="/lttng-ust-agent-common"/>
+       <classpathentry kind="lib" path="/usr/share/java/log4j-1.2.jar"/>
+       <classpathentry combineaccessrules="false" kind="src" path="/lttng-ust-agent-log4j"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
index b4be934c851c369ed5cb20ad27d3fa3b0fd59967..b883c15c77f2f16caa22a10d1c2f50286c7317e0 100644 (file)
@@ -4,7 +4,7 @@ formatter_profile=_Spaces
 formatter_settings_version=12
 sp_cleanup.add_default_serial_version_id=true
 sp_cleanup.add_generated_serial_version_id=false
-sp_cleanup.add_missing_annotations=true
+sp_cleanup.add_missing_annotations=false
 sp_cleanup.add_missing_deprecated_annotations=true
 sp_cleanup.add_missing_methods=false
 sp_cleanup.add_missing_nls_tags=false
@@ -29,7 +29,7 @@ sp_cleanup.make_variable_declarations_final=false
 sp_cleanup.never_use_blocks=false
 sp_cleanup.never_use_parentheses_in_expressions=true
 sp_cleanup.on_save_use_additional_actions=true
-sp_cleanup.organize_imports=true
+sp_cleanup.organize_imports=false
 sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
 sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
 sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
@@ -40,7 +40,7 @@ sp_cleanup.remove_redundant_type_arguments=true
 sp_cleanup.remove_trailing_whitespaces=true
 sp_cleanup.remove_trailing_whitespaces_all=true
 sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
-sp_cleanup.remove_unnecessary_casts=true
+sp_cleanup.remove_unnecessary_casts=false
 sp_cleanup.remove_unnecessary_nls_tags=false
 sp_cleanup.remove_unused_imports=false
 sp_cleanup.remove_unused_local_variables=false
diff --git a/src/org/lttng/ust/agent/benchmarks/jul/RunAllBenchmarks.java b/src/org/lttng/ust/agent/benchmarks/jul/RunAllBenchmarks.java
deleted file mode 100644 (file)
index e8fa16d..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.lttng.ust.agent.benchmarks.jul;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
-    org.lttng.ust.agent.benchmarks.jul.handler.NoHandlerBenchmark.class,
-    org.lttng.ust.agent.benchmarks.jul.handler.DummyHandlerBenchmark.class,
-//    org.lttng.ust.agent.jul.benchmarks.handler.FileHandlerBenchmark.class,
-    org.lttng.ust.agent.benchmarks.jul.handler.lttng.LttngJulHandlerTracingDisabledBenchmark.class,
-    org.lttng.ust.agent.benchmarks.jul.handler.lttng.LttngJulHandlerTracingEnabledBenchmark.class,
-    org.lttng.ust.agent.benchmarks.jul.handler.lttng.old.OldLttngJulHandlerTracingDisabledBenchmark.class,
-    org.lttng.ust.agent.benchmarks.jul.handler.lttng.old.OldLttngJulHandlerTracingEnabledBenchmark.class
-})
-public class RunAllBenchmarks {
-}
diff --git a/src/org/lttng/ust/agent/benchmarks/jul/RunAllJulBenchmarks.java b/src/org/lttng/ust/agent/benchmarks/jul/RunAllJulBenchmarks.java
new file mode 100644 (file)
index 0000000..35ef742
--- /dev/null
@@ -0,0 +1,17 @@
+package org.lttng.ust.agent.benchmarks.jul;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    org.lttng.ust.agent.benchmarks.jul.handler.NoHandlerBenchmark.class,
+    org.lttng.ust.agent.benchmarks.jul.handler.DummyHandlerBenchmark.class,
+//    org.lttng.ust.agent.jul.benchmarks.handler.FileHandlerBenchmark.class,
+    org.lttng.ust.agent.benchmarks.jul.handler.lttng.LttngJulHandlerTracingDisabledBenchmark.class,
+    org.lttng.ust.agent.benchmarks.jul.handler.lttng.LttngJulHandlerTracingEnabledBenchmark.class,
+    org.lttng.ust.agent.benchmarks.jul.handler.lttng.old.OldLttngJulHandlerTracingDisabledBenchmark.class,
+    org.lttng.ust.agent.benchmarks.jul.handler.lttng.old.OldLttngJulHandlerTracingEnabledBenchmark.class
+})
+public class RunAllJulBenchmarks {
+}
diff --git a/src/org/lttng/ust/agent/integration/RunAllIntegrationTests.java b/src/org/lttng/ust/agent/integration/RunAllIntegrationTests.java
new file mode 100644 (file)
index 0000000..5be1343
--- /dev/null
@@ -0,0 +1,13 @@
+package org.lttng.ust.agent.integration;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    org.lttng.ust.agent.integration.jul.AllTests.class,
+    org.lttng.ust.agent.integration.log4j.AllTests.class,
+})
+public class RunAllIntegrationTests {
+
+}
diff --git a/src/org/lttng/ust/agent/integration/common/EnabledEventsTest.java b/src/org/lttng/ust/agent/integration/common/EnabledEventsTest.java
new file mode 100644 (file)
index 0000000..28389be
--- /dev/null
@@ -0,0 +1,247 @@
+package org.lttng.ust.agent.integration.common;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.lttng.ust.agent.ILttngHandler;
+import org.lttng.ust.agent.utils.LttngSessionControl;
+import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
+
+public abstract class EnabledEventsTest {
+
+    protected static final String EVENT_NAME_A = "EventA";
+    protected static final String EVENT_NAME_B = "EventAB";
+    protected static final String EVENT_NAME_C = "EventABC";
+    protected static final String EVENT_NAME_D = "EventABCD";
+
+    /* Fields defined by the sub-class */
+    protected ILttngHandler handlerA;
+    protected ILttngHandler handlerB;
+    protected ILttngHandler handlerC;
+
+    protected abstract Domain getDomain();
+
+    protected abstract void sendEventsToLoggers();
+
+    @Before
+    public void testSetup() {
+
+    }
+
+    @After
+    public void testTeardown() {
+        /* In case the test fails before destroying the session */
+        LttngSessionControl.tryDestroySession(null);
+
+        handlerA.close();
+        handlerB.close();
+        handlerC.close();
+
+        handlerA = null;
+        handlerB = null;
+        handlerC = null;
+    }
+
+    /**
+     * Test sending events on the Java side, but no events enabled in the
+     * tracing session. There should be nothing in the resulting trace, and
+     * handlers should not have logged anything.
+     */
+    @Test
+    public void testNoEvents() {
+        assertTrue(LttngSessionControl.setupSession(null, getDomain()));
+
+        sendEventsToLoggers();
+
+        assertTrue(LttngSessionControl.stopSession(null));
+
+        List<String> output = LttngSessionControl.viewSession(null);
+        assertNotNull(output);
+        assertTrue(output.isEmpty());
+
+        assertTrue(LttngSessionControl.destroySession(null));
+
+        assertEquals(0, handlerA.getEventCount());
+        assertEquals(0, handlerB.getEventCount());
+        assertEquals(0, handlerC.getEventCount());
+    }
+
+    /**
+     * Test sending events on the Java side, and all events enabled in the
+     * tracing session. All handlers should have sent their events.
+     */
+    @Test
+    public void testAllEvents() {
+        assertTrue(LttngSessionControl.setupSessionAllEvents(null, getDomain()));
+
+        sendEventsToLoggers();
+
+        assertTrue(LttngSessionControl.stopSession(null));
+
+        List<String> output = LttngSessionControl.viewSession(null);
+        assertNotNull(output);
+        assertEquals(30, output.size()); // loggerD has no handler attached
+
+        assertTrue(LttngSessionControl.destroySession(null));
+
+        assertEquals(10, handlerA.getEventCount());
+        assertEquals(10, handlerB.getEventCount());
+        assertEquals(10, handlerC.getEventCount());
+    }
+
+    /**
+     * Test sending events on the Java side, with only some of them enabled in
+     * the tracing session. Only the subset that is enabled should be received.
+     */
+    @Test
+    public void testSomeEvents() {
+        assertTrue(LttngSessionControl.setupSession(null, getDomain(),
+                EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D));
+
+        sendEventsToLoggers();
+
+        assertTrue(LttngSessionControl.stopSession(null));
+
+        List<String> output = LttngSessionControl.viewSession(null);
+        assertNotNull(output);
+        assertEquals(20, output.size());
+
+        assertTrue(LttngSessionControl.destroySession(null));
+
+        assertEquals(10, handlerA.getEventCount());
+        assertEquals(0, handlerB.getEventCount());
+        assertEquals(10, handlerC.getEventCount());
+    }
+
+    /**
+     * Test with all events enabled (-a), plus some other events added manually.
+     * Events should still be retained, but there should be no duplicates.
+     */
+    @Test
+    public void testAllEventsAndSome() {
+        assertTrue(LttngSessionControl.setupSessionAllEvents(null, getDomain()));
+        assertTrue(LttngSessionControl.enableEvents(null, getDomain(),
+                EVENT_NAME_A, EVENT_NAME_B));
+
+        sendEventsToLoggers();
+
+        assertTrue(LttngSessionControl.stopSession(null));
+
+        List<String> output = LttngSessionControl.viewSession(null);
+        assertNotNull(output);
+        assertEquals(30, output.size());
+
+        assertTrue(LttngSessionControl.destroySession(null));
+
+        assertEquals(10, handlerA.getEventCount());
+        assertEquals(10, handlerB.getEventCount());
+        assertEquals(10, handlerC.getEventCount());
+    }
+
+    /**
+     * Same as {@link #testSomeEvents()}, but some events were enabled first,
+     * then disabled. Makes sure the enabled-event refcounting works properly.
+     */
+    @Test
+    public void testSomeEventsAfterDisabling() {
+        assertTrue(LttngSessionControl.setupSession(null, getDomain(),
+                EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D));
+
+        assertTrue(LttngSessionControl.disableEvents(null, getDomain(),
+                EVENT_NAME_C));
+
+        sendEventsToLoggers();
+
+        assertTrue(LttngSessionControl.stopSession(null));
+
+        List<String> output = LttngSessionControl.viewSession(null);
+        assertNotNull(output);
+        assertEquals(10, output.size());
+
+        assertTrue(LttngSessionControl.destroySession(null));
+
+        assertEquals(10, handlerA.getEventCount());
+        assertEquals(0, handlerB.getEventCount());
+        assertEquals(0, handlerC.getEventCount());
+    }
+
+    /**
+     * Test enabling an event prefix, which means an event name ending with a *,
+     * to match all events starting with this name.
+     */
+    @Test
+    public void testEventPrefix() {
+        assertTrue(LttngSessionControl.setupSession(null, getDomain(),
+                "EventAB*")); // should match event/loggers B and C, but not A.
+
+        sendEventsToLoggers();
+
+        assertTrue(LttngSessionControl.stopSession(null));
+
+        List<String> output = LttngSessionControl.viewSession(null);
+        assertNotNull(output);
+        assertEquals(20, output.size());
+
+        assertTrue(LttngSessionControl.destroySession(null));
+
+        assertEquals(0, handlerA.getEventCount());
+        assertEquals(10, handlerB.getEventCount());
+        assertEquals(10, handlerC.getEventCount());
+    }
+
+    /**
+     * Same as {@link #testEventPrefix()}, but with multiple prefixes that
+     * overlap. There should not be any duplicate events in the trace or in the
+     * handlers.
+     */
+    @Test
+    public void testEventPrefixOverlapping() {
+        assertTrue(LttngSessionControl.setupSession(null, getDomain(),
+                "EventAB*", "EventABC*")); // should still match B and C
+
+        sendEventsToLoggers();
+
+        assertTrue(LttngSessionControl.stopSession(null));
+
+        List<String> output = LttngSessionControl.viewSession(null);
+        assertNotNull(output);
+        assertEquals(20, output.size());
+
+        assertTrue(LttngSessionControl.destroySession(null));
+
+        assertEquals(0, handlerA.getEventCount());
+        assertEquals(10, handlerB.getEventCount());
+        assertEquals(10, handlerC.getEventCount());
+    }
+
+    /**
+     * Test with all events enabled (-a), plus an event prefix. Once again,
+     * there should be no duplicates.
+     */
+    @Test
+    public void testAllEventsAndPrefix() {
+        assertTrue(LttngSessionControl.setupSessionAllEvents(null, getDomain()));
+        assertTrue(LttngSessionControl.enableEvents(null, getDomain(),
+                "EventAB*")); // should match B and C
+
+        sendEventsToLoggers();
+
+        assertTrue(LttngSessionControl.stopSession(null));
+
+        List<String> output = LttngSessionControl.viewSession(null);
+        assertNotNull(output);
+        assertEquals(30, output.size());
+
+        assertTrue(LttngSessionControl.destroySession(null));
+
+        assertEquals(10, handlerA.getEventCount());
+        assertEquals(10, handlerB.getEventCount());
+        assertEquals(10, handlerC.getEventCount());
+    }
+}
diff --git a/src/org/lttng/ust/agent/integration/jul/AllTests.java b/src/org/lttng/ust/agent/integration/jul/AllTests.java
new file mode 100644 (file)
index 0000000..aa5cd80
--- /dev/null
@@ -0,0 +1,13 @@
+package org.lttng.ust.agent.integration.jul;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    JulEnabledEventsTest.class,
+    JulLegacyApiTest.class
+})
+public class AllTests {
+
+}
index 53fdafe78f8a9b878069a128a2ed20685334239e..9493379340b483a2bbe277c32f88edeb08d0dbc8 100644 (file)
@@ -1,12 +1,10 @@
 package org.lttng.ust.agent.integration.jul;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assume.assumeTrue;
 
 import java.io.IOException;
 import java.util.List;
+import java.util.logging.Handler;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -14,33 +12,22 @@ import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
-import org.junit.Test;
+import org.lttng.ust.agent.integration.common.EnabledEventsTest;
 import org.lttng.ust.agent.jul.LttngLogHandler;
 import org.lttng.ust.agent.utils.LttngSessionControl;
 import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
 
-public class JulEnabledEventsTest {
+public class JulEnabledEventsTest extends EnabledEventsTest {
 
     private static final Domain DOMAIN = Domain.JUL;
 
-    private static final String SESSION_NAME = JulEnabledEventsTest.class.getSimpleName();
-
-    private static final String EVENT_NAME_A = "EventA";
-    private static final String EVENT_NAME_B = "EventAB";
-    private static final String EVENT_NAME_C = "EventABC";
-    private static final String EVENT_NAME_D = "EventABCD";
-
     private Logger loggerA;
     private Logger loggerB;
     private Logger loggerC;
     private Logger loggerD;
 
-    private LttngLogHandler handlerA;
-    private LttngLogHandler handlerB;
-    private LttngLogHandler handlerC;
-
     @BeforeClass
-    public static void classSetup() {
+    public static void julClassSetup() {
         /* Skip tests if we can't find the JNI library or lttng-tools */
         try {
             LttngLogHandler testHandler = new LttngLogHandler();
@@ -59,12 +46,12 @@ public class JulEnabledEventsTest {
     }
 
     @AfterClass
-    public static void classCleanup() {
+    public static void julClassCleanup() {
         LttngSessionControl.deleteAllTracee();
     }
 
     @Before
-    public void setup() throws SecurityException, IOException {
+    public void julSetup() throws SecurityException, IOException {
         // TODO Wipe all existing LTTng sessions?
 
         loggerA = Logger.getLogger(EVENT_NAME_A);
@@ -81,255 +68,37 @@ public class JulEnabledEventsTest {
         handlerB = new LttngLogHandler();
         handlerC = new LttngLogHandler();
 
-        loggerA.addHandler(handlerA);
-        loggerB.addHandler(handlerB);
-        loggerC.addHandler(handlerC);
+        loggerA.addHandler((Handler) handlerA);
+        loggerB.addHandler((Handler) handlerB);
+        loggerC.addHandler((Handler) handlerC);
     }
 
     @After
-    public void teardown() {
-        /* Just in case the test failed */
-        LttngSessionControl.tryDestroySession(SESSION_NAME);
-
-        loggerA.removeHandler(handlerA);
-        loggerB.removeHandler(handlerB);
-        loggerC.removeHandler(handlerC);
-
-        handlerA.close();
-        handlerB.close();
-        handlerC.close();
+    public void julTeardown() {
+        loggerA.removeHandler((Handler) handlerA);
+        loggerB.removeHandler((Handler) handlerB);
+        loggerC.removeHandler((Handler) handlerC);
 
         loggerA = null;
         loggerB = null;
         loggerC = null;
         loggerD = null;
-        handlerA = null;
-        handlerB = null;
-        handlerC = null;
-    }
-
-    /**
-     * Test sending events on the Java side, but no events enabled in the
-     * tracing session. There should be nothing in the resulting trace, and
-     * handlers should not have logged anything.
-     */
-    @Test
-    public void testNoEvents() {
-        assertTrue(LttngSessionControl.setupSession(SESSION_NAME, DOMAIN));
-
-        send10Events(loggerA);
-        send10Events(loggerB);
-        send10Events(loggerC);
-        send10Events(loggerD);
-
-        assertTrue(LttngSessionControl.stopSession(SESSION_NAME));
-
-        List<String> output = LttngSessionControl.viewSession(SESSION_NAME);
-        assertNotNull(output);
-        assertTrue(output.isEmpty());
-
-        assertTrue(LttngSessionControl.destroySession(SESSION_NAME));
-
-        assertEquals(0, handlerA.getEventCount());
-        assertEquals(0, handlerB.getEventCount());
-        assertEquals(0, handlerC.getEventCount());
-    }
-
-    /**
-     * Test sending events on the Java side, and all events enabled in the
-     * tracing session. All handlers should have sent their events.
-     */
-    @Test
-    public void testAllEvents() {
-        assertTrue(LttngSessionControl.setupSessionAllEvents(SESSION_NAME, DOMAIN));
-
-        send10Events(loggerA);
-        send10Events(loggerB);
-        send10Events(loggerC);
-        send10Events(loggerD);
-
-        assertTrue(LttngSessionControl.stopSession(SESSION_NAME));
-
-        List<String> output = LttngSessionControl.viewSession(SESSION_NAME);
-        assertNotNull(output);
-        assertEquals(30, output.size()); // loggerD has no handler attached
-
-        assertTrue(LttngSessionControl.destroySession(SESSION_NAME));
-
-        assertEquals(10, handlerA.getEventCount());
-        assertEquals(10, handlerB.getEventCount());
-        assertEquals(10, handlerC.getEventCount());
     }
 
-    /**
-     * Test sending events on the Java side, with only some of them enabled in
-     * the tracing session. Only the subset that is enabled should be received.
-     */
-    @Test
-    public void testSomeEvents() {
-        assertTrue(LttngSessionControl.setupSession(SESSION_NAME, DOMAIN,
-                EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D));
-
-        send10Events(loggerA);
-        send10Events(loggerB);
-        send10Events(loggerC);
-        send10Events(loggerD);
-
-        assertTrue(LttngSessionControl.stopSession(SESSION_NAME));
-
-        List<String> output = LttngSessionControl.viewSession(SESSION_NAME);
-        assertNotNull(output);
-        assertEquals(20, output.size());
-
-        assertTrue(LttngSessionControl.destroySession(SESSION_NAME));
-
-        assertEquals(10, handlerA.getEventCount());
-        assertEquals(0, handlerB.getEventCount());
-        assertEquals(10, handlerC.getEventCount());
+    @Override
+    protected Domain getDomain() {
+        return DOMAIN;
     }
 
-    /**
-     * Test with all events enabled (-a), plus some other events added manually.
-     * Events should still be retained, but there should be no duplicates.
-     */
-    @Test
-    public void testAllEventsAndSome() {
-        assertTrue(LttngSessionControl.setupSessionAllEvents(SESSION_NAME, DOMAIN));
-        assertTrue(LttngSessionControl.enableEvents(SESSION_NAME, DOMAIN,
-                EVENT_NAME_A, EVENT_NAME_B));
-
+    @Override
+    protected void sendEventsToLoggers() {
         send10Events(loggerA);
         send10Events(loggerB);
         send10Events(loggerC);
         send10Events(loggerD);
-
-        assertTrue(LttngSessionControl.stopSession(SESSION_NAME));
-
-        List<String> output = LttngSessionControl.viewSession(SESSION_NAME);
-        assertNotNull(output);
-        assertEquals(30, output.size());
-
-        assertTrue(LttngSessionControl.destroySession(SESSION_NAME));
-
-        assertEquals(10, handlerA.getEventCount());
-        assertEquals(10, handlerB.getEventCount());
-        assertEquals(10, handlerC.getEventCount());
     }
 
-    /**
-     * Same as {@link #testSomeEvents()}, but some events were enabled first,
-     * then disabled. Makes sure the enabled-event refcounting works properly.
-     */
-    @Test
-    public void testSomeEventsAfterDisabling() {
-        assertTrue(LttngSessionControl.setupSession(SESSION_NAME, DOMAIN,
-                EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D));
-
-        assertTrue(LttngSessionControl.disableEvents(SESSION_NAME, DOMAIN,
-                EVENT_NAME_C));
-
-        send10Events(loggerA);
-        send10Events(loggerB);
-        send10Events(loggerC);
-        send10Events(loggerD);
-
-        assertTrue(LttngSessionControl.stopSession(SESSION_NAME));
-
-        List<String> output = LttngSessionControl.viewSession(SESSION_NAME);
-        assertNotNull(output);
-        assertEquals(10, output.size());
-
-        assertTrue(LttngSessionControl.destroySession(SESSION_NAME));
-
-        assertEquals(10, handlerA.getEventCount());
-        assertEquals(0, handlerB.getEventCount());
-        assertEquals(0, handlerC.getEventCount());
-    }
-
-    /**
-     * Test enabling an event prefix, which means an event name ending with a *,
-     * to match all events starting with this name.
-     */
-    @Test
-    public void testEventPrefix() {
-        assertTrue(LttngSessionControl.setupSession(SESSION_NAME, DOMAIN,
-                "EventAB*")); // should match event/loggers B and C, but not A.
-
-        send10Events(loggerA);
-        send10Events(loggerB);
-        send10Events(loggerC);
-        send10Events(loggerD);
-
-        assertTrue(LttngSessionControl.stopSession(SESSION_NAME));
-
-        List<String> output = LttngSessionControl.viewSession(SESSION_NAME);
-        assertNotNull(output);
-        assertEquals(20, output.size());
-
-        assertTrue(LttngSessionControl.destroySession(SESSION_NAME));
-
-        assertEquals(0, handlerA.getEventCount());
-        assertEquals(10, handlerB.getEventCount());
-        assertEquals(10, handlerC.getEventCount());
-    }
-
-    /**
-     * Same as {@link #testEventPrefix()}, but with multiple prefixes that
-     * overlap. There should not be any duplicate events in the trace or in the
-     * handlers.
-     */
-    @Test
-    public void testEventPrefixOverlapping() {
-        assertTrue(LttngSessionControl.setupSession(SESSION_NAME, DOMAIN,
-                "EventAB*", "EventABC*")); // should still match B and C
-
-        send10Events(loggerA);
-        send10Events(loggerB);
-        send10Events(loggerC);
-        send10Events(loggerD);
-
-        assertTrue(LttngSessionControl.stopSession(SESSION_NAME));
-
-        List<String> output = LttngSessionControl.viewSession(SESSION_NAME);
-        assertNotNull(output);
-        assertEquals(20, output.size());
-
-        assertTrue(LttngSessionControl.destroySession(SESSION_NAME));
-
-        assertEquals(0, handlerA.getEventCount());
-        assertEquals(10, handlerB.getEventCount());
-        assertEquals(10, handlerC.getEventCount());
-    }
-
-    /**
-     * Test with all events enabled (-a), plus an event prefix. Once again,
-     * there should be no duplicates.
-     */
-    @Test
-    public void testAllEventsAndPrefix() {
-        assertTrue(LttngSessionControl.setupSessionAllEvents(SESSION_NAME, DOMAIN));
-        assertTrue(LttngSessionControl.enableEvents(SESSION_NAME, DOMAIN,
-                "EventAB*")); // should match B and C
-
-        send10Events(loggerA);
-        send10Events(loggerB);
-        send10Events(loggerC);
-        send10Events(loggerD);
-
-        assertTrue(LttngSessionControl.stopSession(SESSION_NAME));
-
-        List<String> output = LttngSessionControl.viewSession(SESSION_NAME);
-        assertNotNull(output);
-        assertEquals(30, output.size());
-
-        assertTrue(LttngSessionControl.destroySession(SESSION_NAME));
-
-        assertEquals(10, handlerA.getEventCount());
-        assertEquals(10, handlerB.getEventCount());
-        assertEquals(10, handlerC.getEventCount());
-    }
-
-    private static void send10Events(Logger logger) {
+    static void send10Events(Logger logger) {
         String a = new String("a");
         Object[] params = { a, new String("b"), new Object() };
 
@@ -345,5 +114,4 @@ public class JulEnabledEventsTest {
         logger.log(Level.INFO, "A message with one parameter", a);
         logger.log(Level.INFO, "A message with parameters", params);
     }
-
 }
diff --git a/src/org/lttng/ust/agent/integration/jul/JulLegacyApiTest.java b/src/org/lttng/ust/agent/integration/jul/JulLegacyApiTest.java
new file mode 100644 (file)
index 0000000..808cf27
--- /dev/null
@@ -0,0 +1,158 @@
+package org.lttng.ust.agent.integration.jul;
+
+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.io.IOException;
+import java.lang.reflect.Field;
+import java.util.List;
+import java.util.logging.Level;
+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.lttng.ust.agent.ILttngHandler;
+import org.lttng.ust.agent.LTTngAgent;
+import org.lttng.ust.agent.jul.LttngLogHandler;
+import org.lttng.ust.agent.utils.LttngSessionControl;
+import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
+
+@SuppressWarnings("deprecation")
+public class JulLegacyApiTest {
+
+    private static final Domain DOMAIN = Domain.JUL;
+
+    private static final String EVENT_NAME_A = "EventA";
+    private static final String EVENT_NAME_B = "EventB";
+
+    private Logger loggerA;
+    private Logger loggerB;
+
+    @BeforeClass
+    public static void julClassSetup() {
+        /* Skip tests if we can't find the JNI library or lttng-tools */
+        try {
+            LttngLogHandler testHandler = new LttngLogHandler();
+            testHandler.close();
+        } catch (SecurityException | IOException e) {
+            assumeTrue(false);
+        }
+
+        boolean ret1 = LttngSessionControl.setupSession(null, DOMAIN);
+        boolean ret2 = LttngSessionControl.stopSession(null);
+        /* "lttng view" also tests that Babeltrace is installed and working */
+        List<String> contents = LttngSessionControl.viewSession(null);
+        boolean ret3 = LttngSessionControl.destroySession(null);
+        assumeTrue(ret1 && ret2 && ret3);
+        assumeTrue(contents.isEmpty());
+    }
+
+    @AfterClass
+    public static void julClassCleanup() {
+        LttngSessionControl.deleteAllTracee();
+    }
+
+    @Before
+    public void setup() {
+        loggerA = Logger.getLogger(EVENT_NAME_A);
+        LTTngAgent.getLTTngAgent();
+        loggerB = Logger.getLogger(EVENT_NAME_B);
+
+        loggerA.setLevel(Level.ALL);
+        loggerB.setLevel(Level.ALL);
+    }
+
+    @After
+    public void tearDown() {
+        /* In case the test fails before destroying the session */
+        LttngSessionControl.tryDestroySession(null);
+
+        LTTngAgent.dispose();
+
+        loggerA = null;
+        loggerB = null;
+    }
+
+    @Test
+    public void testNoEvents() {
+        assertTrue(LttngSessionControl.setupSession(null, DOMAIN));
+
+        JulEnabledEventsTest.send10Events(loggerA);
+        JulEnabledEventsTest.send10Events(loggerB);
+
+        assertTrue(LttngSessionControl.stopSession(null));
+
+        List<String> output = LttngSessionControl.viewSession(null);
+        assertNotNull(output);
+        assertTrue(output.isEmpty());
+
+        assertTrue(LttngSessionControl.destroySession(null));
+
+        ILttngHandler handler = getAgentHandler();
+        assertEquals(0, handler.getEventCount());
+    }
+
+    @Test
+    public void testAllEvents() {
+        assertTrue(LttngSessionControl.setupSessionAllEvents(null, DOMAIN));
+
+        JulEnabledEventsTest.send10Events(loggerA);
+        JulEnabledEventsTest.send10Events(loggerB);
+
+        assertTrue(LttngSessionControl.stopSession(null));
+
+        List<String> output = LttngSessionControl.viewSession(null);
+        assertNotNull(output);
+        assertEquals(20, output.size());
+
+        assertTrue(LttngSessionControl.destroySession(null));
+
+        ILttngHandler handler = getAgentHandler();
+        assertEquals(20, handler.getEventCount());
+    }
+
+    @Test
+    public void testSomeEvents() {
+        assertTrue(LttngSessionControl.setupSession(null, DOMAIN,
+                EVENT_NAME_A));
+
+        JulEnabledEventsTest.send10Events(loggerA);
+        JulEnabledEventsTest.send10Events(loggerB);
+
+        assertTrue(LttngSessionControl.stopSession(null));
+
+        List<String> output = LttngSessionControl.viewSession(null);
+        assertNotNull(output);
+        assertEquals(10, output.size());
+
+        assertTrue(LttngSessionControl.destroySession(null));
+
+        ILttngHandler handler = getAgentHandler();
+        assertEquals(10, handler.getEventCount());
+    }
+
+    /**
+     * Get the singleton JUL Handler currently managed by the LTTngAgent. It is
+     * not public, so we need reflection to access it.
+     *
+     * @return The agent's JUL handler
+     */
+    private ILttngHandler getAgentHandler() {
+        try {
+            Field julHandlerField = LTTngAgent.class.getDeclaredField("julHandler");
+            julHandlerField.setAccessible(true);
+            return (ILttngHandler) julHandlerField.get(LTTngAgent.getLTTngAgent());
+        } catch (ReflectiveOperationException | SecurityException e) {
+            fail();
+            return null;
+        }
+    }
+
+}
+
diff --git a/src/org/lttng/ust/agent/integration/log4j/AllTests.java b/src/org/lttng/ust/agent/integration/log4j/AllTests.java
new file mode 100644 (file)
index 0000000..3f99b13
--- /dev/null
@@ -0,0 +1,13 @@
+package org.lttng.ust.agent.integration.log4j;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    Log4jEnabledEventsTest.class,
+    Log4jLegacyApiTest.class
+})
+public class AllTests {
+
+}
diff --git a/src/org/lttng/ust/agent/integration/log4j/Log4jEnabledEventsTest.java b/src/org/lttng/ust/agent/integration/log4j/Log4jEnabledEventsTest.java
new file mode 100644 (file)
index 0000000..8118069
--- /dev/null
@@ -0,0 +1,114 @@
+package org.lttng.ust.agent.integration.log4j;
+
+import static org.junit.Assume.assumeTrue;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.log4j.Appender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.lttng.ust.agent.integration.common.EnabledEventsTest;
+import org.lttng.ust.agent.log4j.LttngLogAppender;
+import org.lttng.ust.agent.utils.LttngSessionControl;
+import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
+
+public class Log4jEnabledEventsTest extends EnabledEventsTest {
+
+    private static final Domain DOMAIN = Domain.LOG4J;
+
+    private Logger loggerA;
+    private Logger loggerB;
+    private Logger loggerC;
+    private Logger loggerD;
+
+    @BeforeClass
+    public static void julClassSetup() {
+        /* Skip tests if we can't find the JNI library or lttng-tools */
+        try {
+            LttngLogAppender testHandler = new LttngLogAppender();
+            testHandler.close();
+        } catch (SecurityException | IOException e) {
+            assumeTrue(false);
+        }
+
+        boolean ret1 = LttngSessionControl.setupSession(null, DOMAIN);
+        boolean ret2 = LttngSessionControl.stopSession(null);
+        /* "lttng view" also tests that Babeltrace is installed and working */
+        List<String> contents = LttngSessionControl.viewSession(null);
+        boolean ret3 = LttngSessionControl.destroySession(null);
+        assumeTrue(ret1 && ret2 && ret3);
+        assumeTrue(contents.isEmpty());
+    }
+
+    @AfterClass
+    public static void julClassCleanup() {
+        LttngSessionControl.deleteAllTracee();
+    }
+
+    @Before
+    public void julSetup() throws SecurityException, IOException {
+        // TODO Wipe all existing LTTng sessions?
+
+        loggerA = Logger.getLogger(EVENT_NAME_A);
+        loggerB = Logger.getLogger(EVENT_NAME_B);
+        loggerC = Logger.getLogger(EVENT_NAME_C);
+        loggerD = Logger.getLogger(EVENT_NAME_D);
+
+        loggerA.setLevel(Level.ALL);
+        loggerB.setLevel(Level.ALL);
+        loggerC.setLevel(Level.ALL);
+        loggerD.setLevel(Level.ALL);
+
+        handlerA = new LttngLogAppender();
+        handlerB = new LttngLogAppender();
+        handlerC = new LttngLogAppender();
+
+        loggerA.addAppender((Appender) handlerA);
+        loggerB.addAppender((Appender) handlerB);
+        loggerC.addAppender((Appender) handlerC);
+    }
+
+    @After
+    public void julTeardown() {
+        loggerA.removeAppender((Appender) handlerA);
+        loggerB.removeAppender((Appender) handlerB);
+        loggerC.removeAppender((Appender) handlerC);
+
+        loggerA = null;
+        loggerB = null;
+        loggerC = null;
+        loggerD = null;
+    }
+
+    @Override
+    protected Domain getDomain() {
+        return DOMAIN;
+    }
+
+    @Override
+    protected void sendEventsToLoggers() {
+        send10Events(loggerA);
+        send10Events(loggerB);
+        send10Events(loggerC);
+        send10Events(loggerD);
+    }
+
+    static void send10Events(Logger logger) {
+        // Levels/priorities are DEBUG, ERROR, FATAL, INFO, TRACE, WARN
+        logger.debug("Debug message. Lost among so many.");
+        logger.debug("Debug message with a throwable", new IOException());
+        logger.error("Error messsage. This might be bad.");
+        logger.error("Error message with a throwable", new IOException());
+        logger.fatal("A fatal message. You are already dead.");
+        logger.info("A info message. Lol, who cares.");
+        logger.trace("A trace message. No, no *that* trace");
+        logger.warn("A warn message. Yellow underline.");
+        logger.log(Level.DEBUG, "A debug message using .log()");
+        logger.log(Level.ERROR, "A error message using .log()");
+    }
+}
diff --git a/src/org/lttng/ust/agent/integration/log4j/Log4jLegacyApiTest.java b/src/org/lttng/ust/agent/integration/log4j/Log4jLegacyApiTest.java
new file mode 100644 (file)
index 0000000..98b6318
--- /dev/null
@@ -0,0 +1,158 @@
+package org.lttng.ust.agent.integration.log4j;
+
+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.io.IOException;
+import java.lang.reflect.Field;
+import java.util.List;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.lttng.ust.agent.ILttngHandler;
+import org.lttng.ust.agent.LTTngAgent;
+import org.lttng.ust.agent.log4j.LttngLogAppender;
+import org.lttng.ust.agent.utils.LttngSessionControl;
+import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
+
+@SuppressWarnings("deprecation")
+public class Log4jLegacyApiTest {
+
+    private static final Domain DOMAIN = Domain.LOG4J;
+
+    private static final String EVENT_NAME_A = "EventA";
+    private static final String EVENT_NAME_B = "EventB";
+
+    private Logger loggerA;
+    private Logger loggerB;
+
+    @BeforeClass
+    public static void classSetup() {
+        /* Skip tests if we can't find the JNI library or lttng-tools */
+        try {
+            LttngLogAppender testAppender = new LttngLogAppender();
+            testAppender.close();
+        } catch (SecurityException | IOException e) {
+            assumeTrue(false);
+        }
+
+        boolean ret1 = LttngSessionControl.setupSession(null, DOMAIN);
+        boolean ret2 = LttngSessionControl.stopSession(null);
+        /* "lttng view" also tests that Babeltrace is installed and working */
+        List<String> contents = LttngSessionControl.viewSession(null);
+        boolean ret3 = LttngSessionControl.destroySession(null);
+        assumeTrue(ret1 && ret2 && ret3);
+        assumeTrue(contents.isEmpty());
+    }
+
+    @AfterClass
+    public static void classCleanup() {
+        LttngSessionControl.deleteAllTracee();
+    }
+
+    @Before
+    public void setup() {
+        loggerA = Logger.getLogger(EVENT_NAME_A);
+        LTTngAgent.getLTTngAgent();
+        loggerB = Logger.getLogger(EVENT_NAME_B);
+
+        loggerA.setLevel(Level.ALL);
+        loggerB.setLevel(Level.ALL);
+    }
+
+    @After
+    public void tearDown() {
+        /* In case the test fails before destroying the session */
+        LttngSessionControl.tryDestroySession(null);
+
+        LTTngAgent.dispose();
+
+        loggerA = null;
+        loggerB = null;
+    }
+
+    @Test
+    public void testNoEvents() {
+        assertTrue(LttngSessionControl.setupSession(null, DOMAIN));
+
+        Log4jEnabledEventsTest.send10Events(loggerA);
+        Log4jEnabledEventsTest.send10Events(loggerB);
+
+        assertTrue(LttngSessionControl.stopSession(null));
+
+        List<String> output = LttngSessionControl.viewSession(null);
+        assertNotNull(output);
+        assertTrue(output.isEmpty());
+
+        assertTrue(LttngSessionControl.destroySession(null));
+
+        ILttngHandler handler = getAgentHandler();
+        assertEquals(0, handler.getEventCount());
+    }
+
+    @Test
+    public void testAllEvents() {
+        assertTrue(LttngSessionControl.setupSessionAllEvents(null, DOMAIN));
+
+        Log4jEnabledEventsTest.send10Events(loggerA);
+        Log4jEnabledEventsTest.send10Events(loggerB);
+
+        assertTrue(LttngSessionControl.stopSession(null));
+
+        List<String> output = LttngSessionControl.viewSession(null);
+        assertNotNull(output);
+        assertEquals(20, output.size());
+
+        assertTrue(LttngSessionControl.destroySession(null));
+
+        ILttngHandler handler = getAgentHandler();
+        assertEquals(20, handler.getEventCount());
+    }
+
+    @Test
+    public void testSomeEvents() {
+        assertTrue(LttngSessionControl.setupSession(null, DOMAIN,
+                EVENT_NAME_A));
+
+        Log4jEnabledEventsTest.send10Events(loggerA);
+        Log4jEnabledEventsTest.send10Events(loggerB);
+
+        assertTrue(LttngSessionControl.stopSession(null));
+
+        List<String> output = LttngSessionControl.viewSession(null);
+        assertNotNull(output);
+        assertEquals(10, output.size());
+
+        assertTrue(LttngSessionControl.destroySession(null));
+
+        ILttngHandler handler = getAgentHandler();
+        assertEquals(10, handler.getEventCount());
+    }
+
+    /**
+     * Get the singleton Log4j Handler currently managed by the LTTngAgent. It
+     * is not public, so we need reflection to access it.
+     *
+     * @return The agent's Log4j handler
+     */
+    private ILttngHandler getAgentHandler() {
+        try {
+            Field log4jAppenderField = LTTngAgent.class.getDeclaredField("log4jAppender");
+            log4jAppenderField.setAccessible(true);
+            return (ILttngHandler) log4jAppenderField.get(LTTngAgent.getLTTngAgent());
+        } catch (ReflectiveOperationException | SecurityException e) {
+            fail();
+            return null;
+        }
+    }
+
+}
+
This page took 0.036273 seconds and 4 git commands to generate.