From: Alexandre Montplaisir Date: Fri, 31 Jul 2015 20:45:27 +0000 (-0400) Subject: Use maven-failsafe-plugin instead of surefire to run integration tests X-Git-Url: http://git.liburcu.org/?a=commitdiff_plain;h=7b82be365510ed64ba6c21d67b51be33211a4ab4;p=lttng-ust-java-tests.git Use maven-failsafe-plugin instead of surefire to run integration tests Failsafe is slightly more geared towards integration tests: it runs in the "verify" phase instead of the "test" one, and will not fail the build if a test fails, but will report it at the end. Signed-off-by: Alexandre Montplaisir --- diff --git a/README.md b/README.md index c44a5db..c30e7f3 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,8 @@ so make sure the output mentions succesful tests and not skipped ones. Please make sure you have no `lttng` session active prior to or during the tests, or it might interfere with the test runs! -Detailed JUnit test reports will be available as usual under -`target/surefire-reports/` +Detailed JUnit test reports will be available under +`lttng-ust-java-tests/target/failsafe-reports/` Running the benchmarks diff --git a/lttng-ust-java-tests/pom.xml b/lttng-ust-java-tests/pom.xml index f706c56..c5fecc7 100644 --- a/lttng-ust-java-tests/pom.xml +++ b/lttng-ust-java-tests/pom.xml @@ -34,7 +34,6 @@ LTTng-UST Java Agent Integration Tests - UTF-8 /usr/local/share/java/lttng-ust-agent-common-1.0.0.jar @@ -86,6 +85,24 @@ + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.18.1 + + + + integration-test + verify + + + + + + + benchmark @@ -93,7 +110,7 @@ org.apache.maven.plugins - maven-surefire-plugin + maven-failsafe-plugin 2.18.1 diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/EnabledEventsITBase.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/EnabledEventsITBase.java new file mode 100644 index 0000000..0e8c9e6 --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/EnabledEventsITBase.java @@ -0,0 +1,264 @@ +/* + * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.lttng.ust.agent.integration; + +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.junit.runner.RunWith; +import org.lttng.tools.ILttngSession; +import org.lttng.tools.ILttngSession.Domain; +import org.lttng.ust.agent.ILttngHandler; +import org.lttng.ust.agent.utils.TestPrintRunner; + +/** + * Base abstract class to implement all sorts of integration tests verifying the + * presence of enabled events in resulting traces. + */ +@RunWith(TestPrintRunner.class) +public abstract class EnabledEventsITBase { + + 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"; + + private ILttngSession session; + + /* Fields defined by the sub-class */ + protected ILttngHandler handlerA; + protected ILttngHandler handlerB; + protected ILttngHandler handlerC; + + protected abstract Domain getDomain(); + + protected abstract void sendEventsToLoggers(); + + /** + * Base test setup + */ + @Before + public void testSetup() { + session = ILttngSession.createSession(null, getDomain()); + } + + /** + * Base test teardown + */ + @After + public void testTeardown() { + session.close(); + + 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(session.start()); + + sendEventsToLoggers(); + + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertTrue(output.isEmpty()); + + 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(session.enableAllEvents()); + assertTrue(session.start()); + + sendEventsToLoggers(); + + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertEquals(30, output.size()); // loggerD has no handler attached + + 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(session.enableEvents(EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D)); + assertTrue(session.start()); + + sendEventsToLoggers(); + + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertEquals(20, output.size()); + + 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(session.enableAllEvents()); + assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_B)); + assertTrue(session.start()); + + sendEventsToLoggers(); + + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertEquals(30, output.size()); + + 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(session.enableEvents(EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D)); + assertTrue(session.disableEvents(EVENT_NAME_C)); + assertTrue(session.start()); + + sendEventsToLoggers(); + + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertEquals(10, output.size()); + + 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() { + // should match event/loggers B and C, but not A. + assertTrue(session.enableEvents("EventAB*")); + assertTrue(session.start()); + + sendEventsToLoggers(); + + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertEquals(20, output.size()); + + 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() { + // should still match B and C + assertTrue(session.enableEvents("EventAB*", "EventABC*")); + assertTrue(session.start()); + + sendEventsToLoggers(); + + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertEquals(20, output.size()); + + 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(session.enableAllEvents()); + assertTrue(session.enableEvents("EventAB*")); + assertTrue(session.start()); + + sendEventsToLoggers(); + + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertEquals(30, output.size()); + + assertEquals(10, handlerA.getEventCount()); + assertEquals(10, handlerB.getEventCount()); + assertEquals(10, handlerC.getEventCount()); + } +} diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/EnabledEventsTestBase.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/EnabledEventsTestBase.java deleted file mode 100644 index fd72279..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/EnabledEventsTestBase.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.lttng.ust.agent.integration; - -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.junit.runner.RunWith; -import org.lttng.tools.ILttngSession; -import org.lttng.tools.ILttngSession.Domain; -import org.lttng.ust.agent.ILttngHandler; -import org.lttng.ust.agent.utils.TestPrintRunner; - -/** - * Base abstract class to implement all sorts of integration tests verifying the - * presence of enabled events in resulting traces. - */ -@RunWith(TestPrintRunner.class) -public abstract class EnabledEventsTestBase { - - 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"; - - private ILttngSession session; - - /* Fields defined by the sub-class */ - protected ILttngHandler handlerA; - protected ILttngHandler handlerB; - protected ILttngHandler handlerC; - - protected abstract Domain getDomain(); - - protected abstract void sendEventsToLoggers(); - - /** - * Base test setup - */ - @Before - public void testSetup() { - session = ILttngSession.createSession(null, getDomain()); - } - - /** - * Base test teardown - */ - @After - public void testTeardown() { - session.close(); - - 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(session.start()); - - sendEventsToLoggers(); - - assertTrue(session.stop()); - - List output = session.view(); - assertNotNull(output); - assertTrue(output.isEmpty()); - - 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(session.enableAllEvents()); - assertTrue(session.start()); - - sendEventsToLoggers(); - - assertTrue(session.stop()); - - List output = session.view(); - assertNotNull(output); - assertEquals(30, output.size()); // loggerD has no handler attached - - 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(session.enableEvents(EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D)); - assertTrue(session.start()); - - sendEventsToLoggers(); - - assertTrue(session.stop()); - - List output = session.view(); - assertNotNull(output); - assertEquals(20, output.size()); - - 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(session.enableAllEvents()); - assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_B)); - assertTrue(session.start()); - - sendEventsToLoggers(); - - assertTrue(session.stop()); - - List output = session.view(); - assertNotNull(output); - assertEquals(30, output.size()); - - 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(session.enableEvents(EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D)); - assertTrue(session.disableEvents(EVENT_NAME_C)); - assertTrue(session.start()); - - sendEventsToLoggers(); - - assertTrue(session.stop()); - - List output = session.view(); - assertNotNull(output); - assertEquals(10, output.size()); - - 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() { - // should match event/loggers B and C, but not A. - assertTrue(session.enableEvents("EventAB*")); - assertTrue(session.start()); - - sendEventsToLoggers(); - - assertTrue(session.stop()); - - List output = session.view(); - assertNotNull(output); - assertEquals(20, output.size()); - - 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() { - // should still match B and C - assertTrue(session.enableEvents("EventAB*", "EventABC*")); - assertTrue(session.start()); - - sendEventsToLoggers(); - - assertTrue(session.stop()); - - List output = session.view(); - assertNotNull(output); - assertEquals(20, output.size()); - - 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(session.enableAllEvents()); - assertTrue(session.enableEvents("EventAB*")); - assertTrue(session.start()); - - sendEventsToLoggers(); - - assertTrue(session.stop()); - - List output = session.view(); - assertNotNull(output); - assertEquals(30, output.size()); - - assertEquals(10, handlerA.getEventCount()); - assertEquals(10, handlerB.getEventCount()); - assertEquals(10, handlerC.getEventCount()); - } -} diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/MultiSessionITBase.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/MultiSessionITBase.java new file mode 100644 index 0000000..e467f0e --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/MultiSessionITBase.java @@ -0,0 +1,363 @@ +/* + * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.lttng.ust.agent.integration; + +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.junit.runner.RunWith; +import org.lttng.tools.ILttngSession; +import org.lttng.tools.ILttngSession.Domain; +import org.lttng.ust.agent.ILttngHandler; +import org.lttng.ust.agent.utils.TestPrintRunner; + +/** + * Base abstract class for tests with multiple concurrent tracing sessions + */ +@RunWith(TestPrintRunner.class) +public abstract class MultiSessionITBase { + + 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"; + + private ILttngSession session1; + private ILttngSession session2; + private ILttngSession session3; + + /* Fields defined by the sub-class */ + protected ILttngHandler handlerA; + protected ILttngHandler handlerB; + protected ILttngHandler handlerC; + protected ILttngHandler handlerD; + + protected abstract Domain getDomain(); + + protected abstract void sendEventsToLoggers(); + + /** + * Base test setup + */ + @Before + public void testSetup() { + session1 = ILttngSession.createSession(null, getDomain()); + session2 = ILttngSession.createSession(null, getDomain()); + session3 = ILttngSession.createSession(null, getDomain()); + } + + /** + * Base test teardown + */ + @After + public void testTeardown() { + session1.close(); + session2.close(); + session3.close(); + + handlerA.close(); + handlerB.close(); + handlerC.close(); + handlerD.close(); + + handlerA = null; + handlerB = null; + handlerC = null; + handlerD = null; + } + + /** + * Test with no events in any session. + */ + @Test + public void testNoEvents() { + assertTrue(session1.start()); + assertTrue(session2.start()); + assertTrue(session3.start()); + + sendEventsToLoggers(); + + assertTrue(session1.stop()); + assertTrue(session2.stop()); + assertTrue(session3.stop()); + + List output1 = session1.view(); + List output2 = session2.view(); + List output3 = session3.view(); + assertNotNull(output1); + assertNotNull(output2); + assertNotNull(output3); + assertTrue(output1.isEmpty()); + assertTrue(output2.isEmpty()); + assertTrue(output3.isEmpty()); + + assertEquals(0, handlerA.getEventCount()); + assertEquals(0, handlerB.getEventCount()); + assertEquals(0, handlerC.getEventCount()); + assertEquals(0, handlerD.getEventCount()); + } + + /** + * Test with all events enabled in one session only. Everything should be + * sent through JNI, but only that session should keep the trace events. + */ + @Test + public void testAllEventsOneSession() { + assertTrue(session1.enableAllEvents()); + assertTrue(session1.start()); + assertTrue(session2.start()); + assertTrue(session3.start()); + + sendEventsToLoggers(); + + assertTrue(session1.stop()); + assertTrue(session2.stop()); + assertTrue(session3.stop()); + + List output1 = session1.view(); + List output2 = session2.view(); + List output3 = session3.view(); + assertNotNull(output1); + assertNotNull(output2); + assertNotNull(output3); + assertEquals(40, output1.size()); + assertTrue(output2.isEmpty()); + assertTrue(output3.isEmpty()); + + assertEquals(10, handlerA.getEventCount()); + assertEquals(10, handlerB.getEventCount()); + assertEquals(10, handlerC.getEventCount()); + assertEquals(10, handlerD.getEventCount()); + } + + /** + * Test with all events enabled in all sessions. All traces and handlers + * should see every event that was logged. + */ + @Test + public void testAllEventsAllSessions() { + assertTrue(session1.enableAllEvents()); + assertTrue(session2.enableAllEvents()); + assertTrue(session3.enableAllEvents()); + assertTrue(session1.start()); + assertTrue(session2.start()); + assertTrue(session3.start()); + + sendEventsToLoggers(); + + assertTrue(session1.stop()); + assertTrue(session2.stop()); + assertTrue(session3.stop()); + + List output1 = session1.view(); + List output2 = session2.view(); + List output3 = session3.view(); + assertNotNull(output1); + assertNotNull(output2); + assertNotNull(output3); + assertEquals(40, output1.size()); + assertEquals(40, output2.size()); + assertEquals(40, output3.size()); + + assertEquals(10, handlerA.getEventCount()); + assertEquals(10, handlerB.getEventCount()); + assertEquals(10, handlerC.getEventCount()); + assertEquals(10, handlerD.getEventCount()); + } + + /** + * Test enabling some events in some sessions only. + */ + @Test + public void testSomeEvents() { + assertTrue(session1.enableEvents(EVENT_NAME_A)); + assertTrue(session2.enableEvents(EVENT_NAME_B)); + assertTrue(session1.start()); + assertTrue(session2.start()); + assertTrue(session3.start()); + + sendEventsToLoggers(); + + assertTrue(session1.stop()); + assertTrue(session2.stop()); + assertTrue(session3.stop()); + + List output1 = session1.view(); + List output2 = session2.view(); + List output3 = session3.view(); + assertNotNull(output1); + assertNotNull(output2); + assertNotNull(output3); + assertEquals(10, output1.size()); + assertEquals(10, output2.size()); + assertEquals(0, output3.size()); + + assertEquals(10, handlerA.getEventCount()); + assertEquals(10, handlerB.getEventCount()); + assertEquals(0, handlerC.getEventCount()); + assertEquals(0, handlerD.getEventCount()); + } + + /** + * Test with all events enabled in one session, and some others in another. + * All events should arrive where expected, with no duplicates. + */ + @Test + public void testAllEventsAndSome() { + assertTrue(session1.enableAllEvents()); + assertTrue(session2.enableEvents(EVENT_NAME_D)); + assertTrue(session1.start()); + assertTrue(session2.start()); + assertTrue(session3.start()); + + sendEventsToLoggers(); + + assertTrue(session1.stop()); + assertTrue(session2.stop()); + assertTrue(session3.stop()); + + List output1 = session1.view(); + List output2 = session2.view(); + List output3 = session3.view(); + assertNotNull(output1); + assertNotNull(output2); + assertNotNull(output3); + assertEquals(40, output1.size()); + assertEquals(10, output2.size()); + assertEquals(0, output3.size()); + + assertEquals(10, handlerA.getEventCount()); + assertEquals(10, handlerB.getEventCount()); + assertEquals(10, handlerC.getEventCount()); + assertEquals(10, handlerD.getEventCount()); + } + + /** + * Test with enabling then disabling some events. Makes sure the refcounting + * works properly. + */ + @Test + public void testSomeEventsAfterDisabling() { + assertTrue(session1.enableEvents(EVENT_NAME_A, EVENT_NAME_B, EVENT_NAME_C)); + assertTrue(session2.enableEvents(EVENT_NAME_B, EVENT_NAME_C, EVENT_NAME_D)); + assertTrue(session3.enableEvents(EVENT_NAME_A)); + + assertTrue(session1.disableEvents(EVENT_NAME_C)); + assertTrue(session2.disableEvents(EVENT_NAME_B, EVENT_NAME_C)); + assertTrue(session3.disableEvents(EVENT_NAME_A)); + + assertTrue(session1.start()); + assertTrue(session2.start()); + assertTrue(session3.start()); + + sendEventsToLoggers(); + + assertTrue(session1.stop()); + assertTrue(session2.stop()); + assertTrue(session3.stop()); + + List output1 = session1.view(); + List output2 = session2.view(); + List output3 = session3.view(); + assertNotNull(output1); + assertNotNull(output2); + assertNotNull(output3); + assertEquals(20, output1.size()); + assertEquals(10, output2.size()); + assertEquals(0, output3.size()); + + assertEquals(10, handlerA.getEventCount()); + assertEquals(10, handlerB.getEventCount()); + assertEquals(0, handlerC.getEventCount()); + assertEquals(10, handlerD.getEventCount()); + } + + /** + * Test with a prefix in one session and a standard event in another. + */ + @Test + public void testPrefixAndEvent() { + assertTrue(session1.enableEvents("EventAB*")); + assertTrue(session3.enableEvents(EVENT_NAME_A)); + assertTrue(session1.start()); + assertTrue(session2.start()); + assertTrue(session3.start()); + + sendEventsToLoggers(); + + assertTrue(session1.stop()); + assertTrue(session2.stop()); + assertTrue(session3.stop()); + + List output1 = session1.view(); + List output2 = session2.view(); + List output3 = session3.view(); + assertNotNull(output1); + assertNotNull(output2); + assertNotNull(output3); + assertEquals(30, output1.size()); + assertEquals(0, output2.size()); + assertEquals(10, output3.size()); + + assertEquals(10, handlerA.getEventCount()); + assertEquals(10, handlerB.getEventCount()); + assertEquals(10, handlerC.getEventCount()); + assertEquals(10, handlerD.getEventCount()); + } + + /** + * Test with all events enabled in one session, and an event prefix in + * another. Once again, there should be no duplicates. + */ + @Test + public void testAllEventsAndPrefix() { + assertTrue(session1.enableAllEvents()); + assertTrue(session2.enableEvents("EventABC*")); + assertTrue(session1.start()); + assertTrue(session2.start()); + assertTrue(session3.start()); + + sendEventsToLoggers(); + + assertTrue(session1.stop()); + assertTrue(session2.stop()); + assertTrue(session3.stop()); + + List output1 = session1.view(); + List output2 = session2.view(); + List output3 = session3.view(); + assertNotNull(output1); + assertNotNull(output2); + assertNotNull(output3); + assertEquals(40, output1.size()); + assertEquals(20, output2.size()); + assertEquals(0, output3.size()); + + assertEquals(10, handlerA.getEventCount()); + assertEquals(10, handlerB.getEventCount()); + assertEquals(10, handlerC.getEventCount()); + assertEquals(10, handlerD.getEventCount()); + } +} diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/MultiSessionTestBase.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/MultiSessionTestBase.java deleted file mode 100644 index 1efa3a6..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/MultiSessionTestBase.java +++ /dev/null @@ -1,363 +0,0 @@ -/* - * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.lttng.ust.agent.integration; - -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.junit.runner.RunWith; -import org.lttng.tools.ILttngSession; -import org.lttng.tools.ILttngSession.Domain; -import org.lttng.ust.agent.ILttngHandler; -import org.lttng.ust.agent.utils.TestPrintRunner; - -/** - * Base abstract class for tests with multiple concurrent tracing sessions - */ -@RunWith(TestPrintRunner.class) -public abstract class MultiSessionTestBase { - - 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"; - - private ILttngSession session1; - private ILttngSession session2; - private ILttngSession session3; - - /* Fields defined by the sub-class */ - protected ILttngHandler handlerA; - protected ILttngHandler handlerB; - protected ILttngHandler handlerC; - protected ILttngHandler handlerD; - - protected abstract Domain getDomain(); - - protected abstract void sendEventsToLoggers(); - - /** - * Base test setup - */ - @Before - public void testSetup() { - session1 = ILttngSession.createSession(null, getDomain()); - session2 = ILttngSession.createSession(null, getDomain()); - session3 = ILttngSession.createSession(null, getDomain()); - } - - /** - * Base test teardown - */ - @After - public void testTeardown() { - session1.close(); - session2.close(); - session3.close(); - - handlerA.close(); - handlerB.close(); - handlerC.close(); - handlerD.close(); - - handlerA = null; - handlerB = null; - handlerC = null; - handlerD = null; - } - - /** - * Test with no events in any session. - */ - @Test - public void testNoEvents() { - assertTrue(session1.start()); - assertTrue(session2.start()); - assertTrue(session3.start()); - - sendEventsToLoggers(); - - assertTrue(session1.stop()); - assertTrue(session2.stop()); - assertTrue(session3.stop()); - - List output1 = session1.view(); - List output2 = session2.view(); - List output3 = session3.view(); - assertNotNull(output1); - assertNotNull(output2); - assertNotNull(output3); - assertTrue(output1.isEmpty()); - assertTrue(output2.isEmpty()); - assertTrue(output3.isEmpty()); - - assertEquals(0, handlerA.getEventCount()); - assertEquals(0, handlerB.getEventCount()); - assertEquals(0, handlerC.getEventCount()); - assertEquals(0, handlerD.getEventCount()); - } - - /** - * Test with all events enabled in one session only. Everything should be - * sent through JNI, but only that session should keep the trace events. - */ - @Test - public void testAllEventsOneSession() { - assertTrue(session1.enableAllEvents()); - assertTrue(session1.start()); - assertTrue(session2.start()); - assertTrue(session3.start()); - - sendEventsToLoggers(); - - assertTrue(session1.stop()); - assertTrue(session2.stop()); - assertTrue(session3.stop()); - - List output1 = session1.view(); - List output2 = session2.view(); - List output3 = session3.view(); - assertNotNull(output1); - assertNotNull(output2); - assertNotNull(output3); - assertEquals(40, output1.size()); - assertTrue(output2.isEmpty()); - assertTrue(output3.isEmpty()); - - assertEquals(10, handlerA.getEventCount()); - assertEquals(10, handlerB.getEventCount()); - assertEquals(10, handlerC.getEventCount()); - assertEquals(10, handlerD.getEventCount()); - } - - /** - * Test with all events enabled in all sessions. All traces and handlers - * should see every event that was logged. - */ - @Test - public void testAllEventsAllSessions() { - assertTrue(session1.enableAllEvents()); - assertTrue(session2.enableAllEvents()); - assertTrue(session3.enableAllEvents()); - assertTrue(session1.start()); - assertTrue(session2.start()); - assertTrue(session3.start()); - - sendEventsToLoggers(); - - assertTrue(session1.stop()); - assertTrue(session2.stop()); - assertTrue(session3.stop()); - - List output1 = session1.view(); - List output2 = session2.view(); - List output3 = session3.view(); - assertNotNull(output1); - assertNotNull(output2); - assertNotNull(output3); - assertEquals(40, output1.size()); - assertEquals(40, output2.size()); - assertEquals(40, output3.size()); - - assertEquals(10, handlerA.getEventCount()); - assertEquals(10, handlerB.getEventCount()); - assertEquals(10, handlerC.getEventCount()); - assertEquals(10, handlerD.getEventCount()); - } - - /** - * Test enabling some events in some sessions only. - */ - @Test - public void testSomeEvents() { - assertTrue(session1.enableEvents(EVENT_NAME_A)); - assertTrue(session2.enableEvents(EVENT_NAME_B)); - assertTrue(session1.start()); - assertTrue(session2.start()); - assertTrue(session3.start()); - - sendEventsToLoggers(); - - assertTrue(session1.stop()); - assertTrue(session2.stop()); - assertTrue(session3.stop()); - - List output1 = session1.view(); - List output2 = session2.view(); - List output3 = session3.view(); - assertNotNull(output1); - assertNotNull(output2); - assertNotNull(output3); - assertEquals(10, output1.size()); - assertEquals(10, output2.size()); - assertEquals(0, output3.size()); - - assertEquals(10, handlerA.getEventCount()); - assertEquals(10, handlerB.getEventCount()); - assertEquals(0, handlerC.getEventCount()); - assertEquals(0, handlerD.getEventCount()); - } - - /** - * Test with all events enabled in one session, and some others in another. - * All events should arrive where expected, with no duplicates. - */ - @Test - public void testAllEventsAndSome() { - assertTrue(session1.enableAllEvents()); - assertTrue(session2.enableEvents(EVENT_NAME_D)); - assertTrue(session1.start()); - assertTrue(session2.start()); - assertTrue(session3.start()); - - sendEventsToLoggers(); - - assertTrue(session1.stop()); - assertTrue(session2.stop()); - assertTrue(session3.stop()); - - List output1 = session1.view(); - List output2 = session2.view(); - List output3 = session3.view(); - assertNotNull(output1); - assertNotNull(output2); - assertNotNull(output3); - assertEquals(40, output1.size()); - assertEquals(10, output2.size()); - assertEquals(0, output3.size()); - - assertEquals(10, handlerA.getEventCount()); - assertEquals(10, handlerB.getEventCount()); - assertEquals(10, handlerC.getEventCount()); - assertEquals(10, handlerD.getEventCount()); - } - - /** - * Test with enabling then disabling some events. Makes sure the refcounting - * works properly. - */ - @Test - public void testSomeEventsAfterDisabling() { - assertTrue(session1.enableEvents(EVENT_NAME_A, EVENT_NAME_B, EVENT_NAME_C)); - assertTrue(session2.enableEvents(EVENT_NAME_B, EVENT_NAME_C, EVENT_NAME_D)); - assertTrue(session3.enableEvents(EVENT_NAME_A)); - - assertTrue(session1.disableEvents(EVENT_NAME_C)); - assertTrue(session2.disableEvents(EVENT_NAME_B, EVENT_NAME_C)); - assertTrue(session3.disableEvents(EVENT_NAME_A)); - - assertTrue(session1.start()); - assertTrue(session2.start()); - assertTrue(session3.start()); - - sendEventsToLoggers(); - - assertTrue(session1.stop()); - assertTrue(session2.stop()); - assertTrue(session3.stop()); - - List output1 = session1.view(); - List output2 = session2.view(); - List output3 = session3.view(); - assertNotNull(output1); - assertNotNull(output2); - assertNotNull(output3); - assertEquals(20, output1.size()); - assertEquals(10, output2.size()); - assertEquals(0, output3.size()); - - assertEquals(10, handlerA.getEventCount()); - assertEquals(10, handlerB.getEventCount()); - assertEquals(0, handlerC.getEventCount()); - assertEquals(10, handlerD.getEventCount()); - } - - /** - * Test with a prefix in one session and a standard event in another. - */ - @Test - public void testPrefixAndEvent() { - assertTrue(session1.enableEvents("EventAB*")); - assertTrue(session3.enableEvents(EVENT_NAME_A)); - assertTrue(session1.start()); - assertTrue(session2.start()); - assertTrue(session3.start()); - - sendEventsToLoggers(); - - assertTrue(session1.stop()); - assertTrue(session2.stop()); - assertTrue(session3.stop()); - - List output1 = session1.view(); - List output2 = session2.view(); - List output3 = session3.view(); - assertNotNull(output1); - assertNotNull(output2); - assertNotNull(output3); - assertEquals(30, output1.size()); - assertEquals(0, output2.size()); - assertEquals(10, output3.size()); - - assertEquals(10, handlerA.getEventCount()); - assertEquals(10, handlerB.getEventCount()); - assertEquals(10, handlerC.getEventCount()); - assertEquals(10, handlerD.getEventCount()); - } - - /** - * Test with all events enabled in one session, and an event prefix in - * another. Once again, there should be no duplicates. - */ - @Test - public void testAllEventsAndPrefix() { - assertTrue(session1.enableAllEvents()); - assertTrue(session2.enableEvents("EventABC*")); - assertTrue(session1.start()); - assertTrue(session2.start()); - assertTrue(session3.start()); - - sendEventsToLoggers(); - - assertTrue(session1.stop()); - assertTrue(session2.stop()); - assertTrue(session3.stop()); - - List output1 = session1.view(); - List output2 = session2.view(); - List output3 = session3.view(); - assertNotNull(output1); - assertNotNull(output2); - assertNotNull(output3); - assertEquals(40, output1.size()); - assertEquals(20, output2.size()); - assertEquals(0, output3.size()); - - assertEquals(10, handlerA.getEventCount()); - assertEquals(10, handlerB.getEventCount()); - assertEquals(10, handlerC.getEventCount()); - assertEquals(10, handlerD.getEventCount()); - } -} diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulEnabledEventsIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulEnabledEventsIT.java new file mode 100644 index 0000000..d7a31f1 --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulEnabledEventsIT.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.lttng.ust.agent.integration.jul; + +import static org.junit.Assume.assumeTrue; + +import java.io.IOException; +import java.util.logging.Handler; +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.lttng.tools.ILttngSession.Domain; +import org.lttng.tools.LttngToolsHelper; +import org.lttng.ust.agent.integration.EnabledEventsITBase; +import org.lttng.ust.agent.jul.LttngLogHandler; +import org.lttng.ust.agent.utils.LttngUtils; + +/** + * Enabled events test for the LTTng-UST JUL log handler. + */ +public class JulEnabledEventsIT extends EnabledEventsITBase { + + private static final Domain DOMAIN = Domain.JUL; + + private Logger loggerA; + private Logger loggerB; + private Logger loggerC; + private Logger loggerD; + + /** + * Class setup + */ + @BeforeClass + public static void julClassSetup() { + /* Skip tests if we can't find the JNI library or lttng-tools */ + assumeTrue(LttngUtils.checkForJulLibrary()); + assumeTrue(LttngUtils.checkForLttngTools(Domain.JUL)); + + LttngToolsHelper.destroyAllSessions(); + } + + /** + * Class cleanup + */ + @AfterClass + public static void julClassCleanup() { + LttngToolsHelper.deleteAllTraces(); + } + + /** + * Test setup + * + * @throws SecurityException + * @throws IOException + */ + @Before + public void julSetup() throws SecurityException, IOException { + 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 LttngLogHandler(); + handlerB = new LttngLogHandler(); + handlerC = new LttngLogHandler(); + + loggerA.addHandler((Handler) handlerA); + loggerB.addHandler((Handler) handlerB); + loggerC.addHandler((Handler) handlerC); + } + + /** + * Test teardown + */ + @After + public void julTeardown() { + loggerA.removeHandler((Handler) handlerA); + loggerB.removeHandler((Handler) handlerB); + loggerC.removeHandler((Handler) handlerC); + + loggerA = null; + loggerB = null; + loggerC = null; + loggerD = null; + } + + @Override + protected Domain getDomain() { + return DOMAIN; + } + + @Override + protected void sendEventsToLoggers() { + JulTestUtils.send10EventsTo(loggerA); + JulTestUtils.send10EventsTo(loggerB); + JulTestUtils.send10EventsTo(loggerC); + JulTestUtils.send10EventsTo(loggerD); + } +} diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulEnabledEventsTest.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulEnabledEventsTest.java deleted file mode 100644 index 1e9a07f..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulEnabledEventsTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.lttng.ust.agent.integration.jul; - -import static org.junit.Assume.assumeTrue; - -import java.io.IOException; -import java.util.logging.Handler; -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.lttng.tools.ILttngSession.Domain; -import org.lttng.tools.LttngToolsHelper; -import org.lttng.ust.agent.integration.EnabledEventsTestBase; -import org.lttng.ust.agent.jul.LttngLogHandler; -import org.lttng.ust.agent.utils.LttngUtils; - -/** - * Enabled events test for the LTTng-UST JUL log handler. - */ -public class JulEnabledEventsTest extends EnabledEventsTestBase { - - private static final Domain DOMAIN = Domain.JUL; - - private Logger loggerA; - private Logger loggerB; - private Logger loggerC; - private Logger loggerD; - - /** - * Class setup - */ - @BeforeClass - public static void julClassSetup() { - /* Skip tests if we can't find the JNI library or lttng-tools */ - assumeTrue(LttngUtils.checkForJulLibrary()); - assumeTrue(LttngUtils.checkForLttngTools(Domain.JUL)); - - LttngToolsHelper.destroyAllSessions(); - } - - /** - * Class cleanup - */ - @AfterClass - public static void julClassCleanup() { - LttngToolsHelper.deleteAllTraces(); - } - - /** - * Test setup - * - * @throws SecurityException - * @throws IOException - */ - @Before - public void julSetup() throws SecurityException, IOException { - 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 LttngLogHandler(); - handlerB = new LttngLogHandler(); - handlerC = new LttngLogHandler(); - - loggerA.addHandler((Handler) handlerA); - loggerB.addHandler((Handler) handlerB); - loggerC.addHandler((Handler) handlerC); - } - - /** - * Test teardown - */ - @After - public void julTeardown() { - loggerA.removeHandler((Handler) handlerA); - loggerB.removeHandler((Handler) handlerB); - loggerC.removeHandler((Handler) handlerC); - - loggerA = null; - loggerB = null; - loggerC = null; - loggerD = null; - } - - @Override - protected Domain getDomain() { - return DOMAIN; - } - - @Override - protected void sendEventsToLoggers() { - JulTestUtils.send10EventsTo(loggerA); - JulTestUtils.send10EventsTo(loggerB); - JulTestUtils.send10EventsTo(loggerC); - JulTestUtils.send10EventsTo(loggerD); - } -} diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulLegacyApiIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulLegacyApiIT.java new file mode 100644 index 0000000..a7abe71 --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulLegacyApiIT.java @@ -0,0 +1,191 @@ +/* + * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +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.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.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.LttngUtils; +import org.lttng.ust.agent.utils.TestPrintRunner; + +/** + * Enabled events test for the LTTng-UST JUL log handler, using the legacy API. + */ +@RunWith(TestPrintRunner.class) +@SuppressWarnings("deprecation") +public class JulLegacyApiIT { + + private static final Domain DOMAIN = Domain.JUL; + + private static final String EVENT_NAME_A = "EventA"; + private static final String EVENT_NAME_B = "EventB"; + + private ILttngSession session; + + private Logger loggerA; + private Logger loggerB; + + /** + * Class setup + */ + @BeforeClass + public static void julClassSetup() { + /* Skip tests if we can't find the JNI library or lttng-tools */ + assumeTrue(LttngUtils.checkForJulLibrary()); + assumeTrue(LttngUtils.checkForLttngTools(Domain.JUL)); + + LttngToolsHelper.destroyAllSessions(); + } + + /** + * Class cleanup + */ + @AfterClass + public static void julClassCleanup() { + LttngToolsHelper.deleteAllTraces(); + } + + /** + * Test setup + */ + @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); + + session = ILttngSession.createSession(null, DOMAIN); + } + + /** + * Test cleanup + */ + @After + public void tearDown() { + session.close(); + + LTTngAgent.dispose(); + + loggerA = null; + loggerB = null; + } + + /** + * Test tracing with no events enabled in the tracing session. + */ + @Test + public void testNoEvents() { + assertTrue(session.start()); + + JulTestUtils.send10EventsTo(loggerA); + JulTestUtils.send10EventsTo(loggerB); + + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertTrue(output.isEmpty()); + + ILttngHandler handler = getAgentHandler(); + assertEquals(0, handler.getEventCount()); + } + + /** + * Test tracing with all events enabled (-j -a) in the tracing session. + */ + @Test + public void testAllEvents() { + assertTrue(session.enableAllEvents()); + assertTrue(session.start()); + + JulTestUtils.send10EventsTo(loggerA); + JulTestUtils.send10EventsTo(loggerB); + + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertEquals(20, output.size()); + + ILttngHandler handler = getAgentHandler(); + assertEquals(20, handler.getEventCount()); + } + + /** + * Test tracing with a subset of events enabled in the tracing session. + */ + @Test + public void testSomeEvents() { + assertTrue(session.enableEvents(EVENT_NAME_A)); + assertTrue(session.start()); + + JulTestUtils.send10EventsTo(loggerA); + JulTestUtils.send10EventsTo(loggerB); + + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertEquals(10, output.size()); + + 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 static 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/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulLegacyApiTest.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulLegacyApiTest.java deleted file mode 100644 index d053d58..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulLegacyApiTest.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -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.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.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.LttngUtils; -import org.lttng.ust.agent.utils.TestPrintRunner; - -/** - * Enabled events test for the LTTng-UST JUL log handler, using the legacy API. - */ -@RunWith(TestPrintRunner.class) -@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 ILttngSession session; - - private Logger loggerA; - private Logger loggerB; - - /** - * Class setup - */ - @BeforeClass - public static void julClassSetup() { - /* Skip tests if we can't find the JNI library or lttng-tools */ - assumeTrue(LttngUtils.checkForJulLibrary()); - assumeTrue(LttngUtils.checkForLttngTools(Domain.JUL)); - - LttngToolsHelper.destroyAllSessions(); - } - - /** - * Class cleanup - */ - @AfterClass - public static void julClassCleanup() { - LttngToolsHelper.deleteAllTraces(); - } - - /** - * Test setup - */ - @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); - - session = ILttngSession.createSession(null, DOMAIN); - } - - /** - * Test cleanup - */ - @After - public void tearDown() { - session.close(); - - LTTngAgent.dispose(); - - loggerA = null; - loggerB = null; - } - - /** - * Test tracing with no events enabled in the tracing session. - */ - @Test - public void testNoEvents() { - assertTrue(session.start()); - - JulTestUtils.send10EventsTo(loggerA); - JulTestUtils.send10EventsTo(loggerB); - - assertTrue(session.stop()); - - List output = session.view(); - assertNotNull(output); - assertTrue(output.isEmpty()); - - ILttngHandler handler = getAgentHandler(); - assertEquals(0, handler.getEventCount()); - } - - /** - * Test tracing with all events enabled (-j -a) in the tracing session. - */ - @Test - public void testAllEvents() { - assertTrue(session.enableAllEvents()); - assertTrue(session.start()); - - JulTestUtils.send10EventsTo(loggerA); - JulTestUtils.send10EventsTo(loggerB); - - assertTrue(session.stop()); - - List output = session.view(); - assertNotNull(output); - assertEquals(20, output.size()); - - ILttngHandler handler = getAgentHandler(); - assertEquals(20, handler.getEventCount()); - } - - /** - * Test tracing with a subset of events enabled in the tracing session. - */ - @Test - public void testSomeEvents() { - assertTrue(session.enableEvents(EVENT_NAME_A)); - assertTrue(session.start()); - - JulTestUtils.send10EventsTo(loggerA); - JulTestUtils.send10EventsTo(loggerB); - - assertTrue(session.stop()); - - List output = session.view(); - assertNotNull(output); - assertEquals(10, output.size()); - - 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 static 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/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulMultiSessionIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulMultiSessionIT.java new file mode 100644 index 0000000..8d71c86 --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulMultiSessionIT.java @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.lttng.ust.agent.integration.jul; + +import static org.junit.Assume.assumeTrue; + +import java.io.IOException; +import java.util.logging.Handler; +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.lttng.tools.ILttngSession.Domain; +import org.lttng.tools.LttngToolsHelper; +import org.lttng.ust.agent.integration.MultiSessionITBase; +import org.lttng.ust.agent.jul.LttngLogHandler; +import org.lttng.ust.agent.utils.LttngUtils; + +/** + * JUL tests for multiple concurrent tracing sessions + */ +public class JulMultiSessionIT extends MultiSessionITBase { + + private static final Domain DOMAIN = Domain.JUL; + + private Logger loggerA; + private Logger loggerB; + private Logger loggerC; + private Logger loggerD; + + /** + * Class setup + */ + @BeforeClass + public static void julClassSetup() { + /* Skip tests if we can't find the JNI library or lttng-tools */ + assumeTrue(LttngUtils.checkForJulLibrary()); + assumeTrue(LttngUtils.checkForLttngTools(Domain.JUL)); + + LttngToolsHelper.destroyAllSessions(); + } + + /** + * Class cleanup + */ + @AfterClass + public static void julClassCleanup() { + LttngToolsHelper.deleteAllTraces(); + } + + /** + * Test setup + * + * @throws SecurityException + * @throws IOException + */ + @Before + public void julSetup() throws SecurityException, IOException { + 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 LttngLogHandler(); + handlerB = new LttngLogHandler(); + handlerC = new LttngLogHandler(); + handlerD = new LttngLogHandler(); + + loggerA.addHandler((Handler) handlerA); + loggerB.addHandler((Handler) handlerB); + loggerC.addHandler((Handler) handlerC); + loggerD.addHandler((Handler) handlerD); + } + + /** + * Test teardown + */ + @After + public void julTeardown() { + loggerA.removeHandler((Handler) handlerA); + loggerB.removeHandler((Handler) handlerB); + loggerC.removeHandler((Handler) handlerC); + loggerD.removeHandler((Handler) handlerD); + + loggerA = null; + loggerB = null; + loggerC = null; + loggerD = null; + } + + @Override + protected Domain getDomain() { + return DOMAIN; + } + + @Override + protected void sendEventsToLoggers() { + JulTestUtils.send10EventsTo(loggerA); + JulTestUtils.send10EventsTo(loggerB); + JulTestUtils.send10EventsTo(loggerC); + JulTestUtils.send10EventsTo(loggerD); + } +} diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulMultiSessionTest.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulMultiSessionTest.java deleted file mode 100644 index f377d91..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulMultiSessionTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.lttng.ust.agent.integration.jul; - -import static org.junit.Assume.assumeTrue; - -import java.io.IOException; -import java.util.logging.Handler; -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.lttng.tools.ILttngSession.Domain; -import org.lttng.tools.LttngToolsHelper; -import org.lttng.ust.agent.integration.MultiSessionTestBase; -import org.lttng.ust.agent.jul.LttngLogHandler; -import org.lttng.ust.agent.utils.LttngUtils; - -/** - * JUL tests for multiple concurrent tracing sessions - */ -public class JulMultiSessionTest extends MultiSessionTestBase { - - private static final Domain DOMAIN = Domain.JUL; - - private Logger loggerA; - private Logger loggerB; - private Logger loggerC; - private Logger loggerD; - - /** - * Class setup - */ - @BeforeClass - public static void julClassSetup() { - /* Skip tests if we can't find the JNI library or lttng-tools */ - assumeTrue(LttngUtils.checkForJulLibrary()); - assumeTrue(LttngUtils.checkForLttngTools(Domain.JUL)); - - LttngToolsHelper.destroyAllSessions(); - } - - /** - * Class cleanup - */ - @AfterClass - public static void julClassCleanup() { - LttngToolsHelper.deleteAllTraces(); - } - - /** - * Test setup - * - * @throws SecurityException - * @throws IOException - */ - @Before - public void julSetup() throws SecurityException, IOException { - 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 LttngLogHandler(); - handlerB = new LttngLogHandler(); - handlerC = new LttngLogHandler(); - handlerD = new LttngLogHandler(); - - loggerA.addHandler((Handler) handlerA); - loggerB.addHandler((Handler) handlerB); - loggerC.addHandler((Handler) handlerC); - loggerD.addHandler((Handler) handlerD); - } - - /** - * Test teardown - */ - @After - public void julTeardown() { - loggerA.removeHandler((Handler) handlerA); - loggerB.removeHandler((Handler) handlerB); - loggerC.removeHandler((Handler) handlerC); - loggerD.removeHandler((Handler) handlerD); - - loggerA = null; - loggerB = null; - loggerC = null; - loggerD = null; - } - - @Override - protected Domain getDomain() { - return DOMAIN; - } - - @Override - protected void sendEventsToLoggers() { - JulTestUtils.send10EventsTo(loggerA); - JulTestUtils.send10EventsTo(loggerB); - JulTestUtils.send10EventsTo(loggerC); - JulTestUtils.send10EventsTo(loggerD); - } -} diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jEnabledEventsIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jEnabledEventsIT.java new file mode 100644 index 0000000..02bae94 --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jEnabledEventsIT.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.lttng.ust.agent.integration.log4j; + +import static org.junit.Assume.assumeTrue; + +import java.io.IOException; + +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.tools.ILttngSession.Domain; +import org.lttng.tools.LttngToolsHelper; +import org.lttng.ust.agent.integration.EnabledEventsITBase; +import org.lttng.ust.agent.log4j.LttngLogAppender; +import org.lttng.ust.agent.utils.LttngUtils; + +/** + * Enabled events test for the LTTng-UST Log4j log handler. + */ +public class Log4jEnabledEventsIT extends EnabledEventsITBase { + + private static final Domain DOMAIN = Domain.LOG4J; + + private Logger loggerA; + private Logger loggerB; + private Logger loggerC; + private Logger loggerD; + + /** + * Class setup + */ + @BeforeClass + public static void log4jClassSetup() { + /* Skip tests if we can't find the JNI library or lttng-tools */ + assumeTrue(LttngUtils.checkForLog4jLibrary()); + assumeTrue(LttngUtils.checkForLttngTools(Domain.LOG4J)); + + LttngToolsHelper.destroyAllSessions(); + } + + /** + * Class teardown + */ + @AfterClass + public static void log4jClassCleanup() { + LttngToolsHelper.deleteAllTraces(); + } + + /** + * Test setup + * + * @throws SecurityException + * @throws IOException + */ + @Before + public void log4jSetup() throws SecurityException, IOException { + 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); + } + + /** + * Test teardown + */ + @After + public void log4jTeardown() { + 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() { + Log4jTestUtils.send10Events(loggerA); + Log4jTestUtils.send10Events(loggerB); + Log4jTestUtils.send10Events(loggerC); + Log4jTestUtils.send10Events(loggerD); + } +} diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jEnabledEventsTest.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jEnabledEventsTest.java deleted file mode 100644 index 0a18b17..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jEnabledEventsTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.lttng.ust.agent.integration.log4j; - -import static org.junit.Assume.assumeTrue; - -import java.io.IOException; - -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.tools.ILttngSession.Domain; -import org.lttng.tools.LttngToolsHelper; -import org.lttng.ust.agent.integration.EnabledEventsTestBase; -import org.lttng.ust.agent.log4j.LttngLogAppender; -import org.lttng.ust.agent.utils.LttngUtils; - -/** - * Enabled events test for the LTTng-UST Log4j log handler. - */ -public class Log4jEnabledEventsTest extends EnabledEventsTestBase { - - private static final Domain DOMAIN = Domain.LOG4J; - - private Logger loggerA; - private Logger loggerB; - private Logger loggerC; - private Logger loggerD; - - /** - * Class setup - */ - @BeforeClass - public static void log4jClassSetup() { - /* Skip tests if we can't find the JNI library or lttng-tools */ - assumeTrue(LttngUtils.checkForLog4jLibrary()); - assumeTrue(LttngUtils.checkForLttngTools(Domain.LOG4J)); - - LttngToolsHelper.destroyAllSessions(); - } - - /** - * Class teardown - */ - @AfterClass - public static void log4jClassCleanup() { - LttngToolsHelper.deleteAllTraces(); - } - - /** - * Test setup - * - * @throws SecurityException - * @throws IOException - */ - @Before - public void log4jSetup() throws SecurityException, IOException { - 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); - } - - /** - * Test teardown - */ - @After - public void log4jTeardown() { - 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() { - Log4jTestUtils.send10Events(loggerA); - Log4jTestUtils.send10Events(loggerB); - Log4jTestUtils.send10Events(loggerC); - Log4jTestUtils.send10Events(loggerD); - } -} diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jLegacyApiIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jLegacyApiIT.java new file mode 100644 index 0000000..054fd94 --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jLegacyApiIT.java @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +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.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.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.LttngUtils; +import org.lttng.ust.agent.utils.TestPrintRunner; + +/** + * Enabled events test for the LTTng-UST Log4j log handler, using the legacy + * API. + */ +@RunWith(TestPrintRunner.class) +@SuppressWarnings("deprecation") +public class Log4jLegacyApiIT { + + private static final Domain DOMAIN = Domain.LOG4J; + + private static final String EVENT_NAME_A = "EventA"; + private static final String EVENT_NAME_B = "EventB"; + + private ILttngSession session; + + private Logger loggerA; + private Logger loggerB; + + /** + * Class setup + */ + @BeforeClass + public static void classSetup() { + /* Skip tests if we can't find the JNI library or lttng-tools */ + assumeTrue(LttngUtils.checkForLog4jLibrary()); + assumeTrue(LttngUtils.checkForLttngTools(Domain.LOG4J)); + + LttngToolsHelper.destroyAllSessions(); + } + + /** + * Class cleanup + */ + @AfterClass + public static void classCleanup() { + LttngToolsHelper.deleteAllTraces(); + } + + /** + * Test setup + */ + @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); + + session = ILttngSession.createSession(null, DOMAIN); + } + + /** + * Test cleanup + */ + @After + public void tearDown() { + session.close(); + + LTTngAgent.dispose(); + + loggerA = null; + loggerB = null; + } + + /** + * Test tracing with no events enabled in the tracing session. + */ + @Test + public void testNoEvents() { + assertTrue(session.start()); + + Log4jTestUtils.send10Events(loggerA); + Log4jTestUtils.send10Events(loggerB); + + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertTrue(output.isEmpty()); + + ILttngHandler handler = getAgentHandler(); + assertEquals(0, handler.getEventCount()); + } + + /** + * Test tracing with all events enabled (-l -a) in the tracing session. + */ + @Test + public void testAllEvents() { + assertTrue(session.enableAllEvents()); + assertTrue(session.start()); + + Log4jTestUtils.send10Events(loggerA); + Log4jTestUtils.send10Events(loggerB); + + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertEquals(20, output.size()); + + ILttngHandler handler = getAgentHandler(); + assertEquals(20, handler.getEventCount()); + } + + /** + * Test tracing with a subset of events enabled in the tracing session. + */ + @Test + public void testSomeEvents() { + assertTrue(session.enableEvents(EVENT_NAME_A)); + assertTrue(session.start()); + + Log4jTestUtils.send10Events(loggerA); + Log4jTestUtils.send10Events(loggerB); + + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertEquals(10, output.size()); + + 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 static 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; + } + } + +} + diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jLegacyApiTest.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jLegacyApiTest.java deleted file mode 100644 index b0784ce..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jLegacyApiTest.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -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.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.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.LttngUtils; -import org.lttng.ust.agent.utils.TestPrintRunner; - -/** - * Enabled events test for the LTTng-UST Log4j log handler, using the legacy - * API. - */ -@RunWith(TestPrintRunner.class) -@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 ILttngSession session; - - private Logger loggerA; - private Logger loggerB; - - /** - * Class setup - */ - @BeforeClass - public static void classSetup() { - /* Skip tests if we can't find the JNI library or lttng-tools */ - assumeTrue(LttngUtils.checkForLog4jLibrary()); - assumeTrue(LttngUtils.checkForLttngTools(Domain.LOG4J)); - - LttngToolsHelper.destroyAllSessions(); - } - - /** - * Class cleanup - */ - @AfterClass - public static void classCleanup() { - LttngToolsHelper.deleteAllTraces(); - } - - /** - * Test setup - */ - @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); - - session = ILttngSession.createSession(null, DOMAIN); - } - - /** - * Test cleanup - */ - @After - public void tearDown() { - session.close(); - - LTTngAgent.dispose(); - - loggerA = null; - loggerB = null; - } - - /** - * Test tracing with no events enabled in the tracing session. - */ - @Test - public void testNoEvents() { - assertTrue(session.start()); - - Log4jTestUtils.send10Events(loggerA); - Log4jTestUtils.send10Events(loggerB); - - assertTrue(session.stop()); - - List output = session.view(); - assertNotNull(output); - assertTrue(output.isEmpty()); - - ILttngHandler handler = getAgentHandler(); - assertEquals(0, handler.getEventCount()); - } - - /** - * Test tracing with all events enabled (-l -a) in the tracing session. - */ - @Test - public void testAllEvents() { - assertTrue(session.enableAllEvents()); - assertTrue(session.start()); - - Log4jTestUtils.send10Events(loggerA); - Log4jTestUtils.send10Events(loggerB); - - assertTrue(session.stop()); - - List output = session.view(); - assertNotNull(output); - assertEquals(20, output.size()); - - ILttngHandler handler = getAgentHandler(); - assertEquals(20, handler.getEventCount()); - } - - /** - * Test tracing with a subset of events enabled in the tracing session. - */ - @Test - public void testSomeEvents() { - assertTrue(session.enableEvents(EVENT_NAME_A)); - assertTrue(session.start()); - - Log4jTestUtils.send10Events(loggerA); - Log4jTestUtils.send10Events(loggerB); - - assertTrue(session.stop()); - - List output = session.view(); - assertNotNull(output); - assertEquals(10, output.size()); - - 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 static 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; - } - } - -} - diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jMultiSessionIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jMultiSessionIT.java new file mode 100644 index 0000000..e9f9458 --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jMultiSessionIT.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.lttng.ust.agent.integration.log4j; + +import static org.junit.Assume.assumeTrue; + +import java.io.IOException; + +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.tools.ILttngSession.Domain; +import org.lttng.tools.LttngToolsHelper; +import org.lttng.ust.agent.integration.MultiSessionITBase; +import org.lttng.ust.agent.log4j.LttngLogAppender; +import org.lttng.ust.agent.utils.LttngUtils; + +/** + * Log4j tests for multiple concurrent tracing sessions + */ +public class Log4jMultiSessionIT extends MultiSessionITBase { + + private static final Domain DOMAIN = Domain.LOG4J; + + private Logger loggerA; + private Logger loggerB; + private Logger loggerC; + private Logger loggerD; + + /** + * Class setup + */ + @BeforeClass + public static void log4jClassSetup() { + /* Skip tests if we can't find the JNI library or lttng-tools */ + assumeTrue(LttngUtils.checkForLog4jLibrary()); + assumeTrue(LttngUtils.checkForLttngTools(Domain.LOG4J)); + + LttngToolsHelper.destroyAllSessions(); + } + + /** + * Class teardown + */ + @AfterClass + public static void log4jClassCleanup() { + LttngToolsHelper.deleteAllTraces(); + } + + /** + * Test setup + * + * @throws SecurityException + * @throws IOException + */ + @Before + public void log4jSetup() 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(); + handlerD = new LttngLogAppender(); + + loggerA.addAppender((Appender) handlerA); + loggerB.addAppender((Appender) handlerB); + loggerC.addAppender((Appender) handlerC); + loggerD.addAppender((Appender) handlerD); + } + + /** + * Test teardown + */ + @After + public void log4jTeardown() { + loggerA.removeAppender((Appender) handlerA); + loggerB.removeAppender((Appender) handlerB); + loggerC.removeAppender((Appender) handlerC); + loggerD.removeAppender((Appender) handlerD); + + loggerA = null; + loggerB = null; + loggerC = null; + loggerD = null; + } + + @Override + protected Domain getDomain() { + return DOMAIN; + } + + @Override + protected void sendEventsToLoggers() { + Log4jTestUtils.send10Events(loggerA); + Log4jTestUtils.send10Events(loggerB); + Log4jTestUtils.send10Events(loggerC); + Log4jTestUtils.send10Events(loggerD); + } +} diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jMultiSessionTest.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jMultiSessionTest.java deleted file mode 100644 index d573ba1..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jMultiSessionTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.lttng.ust.agent.integration.log4j; - -import static org.junit.Assume.assumeTrue; - -import java.io.IOException; - -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.tools.ILttngSession.Domain; -import org.lttng.tools.LttngToolsHelper; -import org.lttng.ust.agent.integration.MultiSessionTestBase; -import org.lttng.ust.agent.log4j.LttngLogAppender; -import org.lttng.ust.agent.utils.LttngUtils; - -/** - * Log4j tests for multiple concurrent tracing sessions - */ -public class Log4jMultiSessionTest extends MultiSessionTestBase { - - private static final Domain DOMAIN = Domain.LOG4J; - - private Logger loggerA; - private Logger loggerB; - private Logger loggerC; - private Logger loggerD; - - /** - * Class setup - */ - @BeforeClass - public static void log4jClassSetup() { - /* Skip tests if we can't find the JNI library or lttng-tools */ - assumeTrue(LttngUtils.checkForLog4jLibrary()); - assumeTrue(LttngUtils.checkForLttngTools(Domain.LOG4J)); - - LttngToolsHelper.destroyAllSessions(); - } - - /** - * Class teardown - */ - @AfterClass - public static void log4jClassCleanup() { - LttngToolsHelper.deleteAllTraces(); - } - - /** - * Test setup - * - * @throws SecurityException - * @throws IOException - */ - @Before - public void log4jSetup() 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(); - handlerD = new LttngLogAppender(); - - loggerA.addAppender((Appender) handlerA); - loggerB.addAppender((Appender) handlerB); - loggerC.addAppender((Appender) handlerC); - loggerD.addAppender((Appender) handlerD); - } - - /** - * Test teardown - */ - @After - public void log4jTeardown() { - loggerA.removeAppender((Appender) handlerA); - loggerB.removeAppender((Appender) handlerB); - loggerC.removeAppender((Appender) handlerC); - loggerD.removeAppender((Appender) handlerD); - - loggerA = null; - loggerB = null; - loggerC = null; - loggerD = null; - } - - @Override - protected Domain getDomain() { - return DOMAIN; - } - - @Override - protected void sendEventsToLoggers() { - Log4jTestUtils.send10Events(loggerA); - Log4jTestUtils.send10Events(loggerB); - Log4jTestUtils.send10Events(loggerC); - Log4jTestUtils.send10Events(loggerD); - } -} diff --git a/pom.xml b/pom.xml index 8dc1781..2c09828 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,7 @@ UTF-8 + UTF-8