From: Alexandre Montplaisir Date: Mon, 31 Aug 2015 22:10:08 +0000 (-0400) Subject: Move some tests to the "events" subpackage X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=0e77c728205cb09c2594e05d9d455e84c6a330ab;p=lttng-ust-java-tests.git Move some tests to the "events" subpackage Better clarify these now that we have "client" and "filter" tests too. Signed-off-by: Alexandre Montplaisir --- 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 deleted file mode 100644 index 0e8c9e6..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/EnabledEventsITBase.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 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/MultiSessionITBase.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/MultiSessionITBase.java deleted file mode 100644 index e467f0e..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/MultiSessionITBase.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 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/events/EnabledEventsITBase.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/EnabledEventsITBase.java new file mode 100644 index 0000000..5659493 --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/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.events; + +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/events/MultiSessionITBase.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/MultiSessionITBase.java new file mode 100644 index 0000000..6864292 --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/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.events; + +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/events/jul/JulEnabledEventsIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/jul/JulEnabledEventsIT.java new file mode 100644 index 0000000..3b292fe --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/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.events.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.events.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/events/jul/JulLegacyApiIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/jul/JulLegacyApiIT.java new file mode 100644 index 0000000..fc0353b --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/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.events.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/events/jul/JulMultiSessionIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/jul/JulMultiSessionIT.java new file mode 100644 index 0000000..59c8e39 --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/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.events.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.events.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/events/jul/JulTestUtils.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/jul/JulTestUtils.java new file mode 100644 index 0000000..2d98496 --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/jul/JulTestUtils.java @@ -0,0 +1,48 @@ +/* + * 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.events.jul; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Utility methods for JUL tests + */ +final class JulTestUtils { + + JulTestUtils() { + } + + static void send10EventsTo(Logger logger) { + String a = new String("a"); + Object[] params = { a, new String("b"), new Object() }; + + // Levels are FINE, FINER, FINEST, INFO, SEVERE, WARNING + logger.fine("A fine level message"); + logger.finer("A finer level message"); + logger.finest("A finest level message"); + logger.info("A info level message"); + logger.severe("A severe level message"); + logger.warning("A warning level message"); + logger.warning("Another warning level message"); + logger.log(Level.WARNING, "A warning message using Logger.log()"); + logger.log(Level.INFO, "A message with one parameter", a); + logger.log(Level.INFO, "A message with parameters", params); + } +} diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/log4j/Log4jEnabledEventsIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/log4j/Log4jEnabledEventsIT.java new file mode 100644 index 0000000..120143d --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/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.events.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.events.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/events/log4j/Log4jLegacyApiIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/log4j/Log4jLegacyApiIT.java new file mode 100644 index 0000000..d673cfa --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/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.events.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/events/log4j/Log4jMultiSessionIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/log4j/Log4jMultiSessionIT.java new file mode 100644 index 0000000..0821744 --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/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.events.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.events.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/events/log4j/Log4jTestUtils.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/log4j/Log4jTestUtils.java new file mode 100644 index 0000000..e7e645e --- /dev/null +++ b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/events/log4j/Log4jTestUtils.java @@ -0,0 +1,47 @@ +/* + * 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.events.log4j; + +import java.io.IOException; + +import org.apache.log4j.Level; +import org.apache.log4j.Logger; + +/** + * Utility methods for log4j tests + */ +final class Log4jTestUtils { + + private Log4jTestUtils() { + } + + 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/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 deleted file mode 100644 index d7a31f1..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulEnabledEventsIT.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.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/JulLegacyApiIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulLegacyApiIT.java deleted file mode 100644 index a7abe71..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulLegacyApiIT.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 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/JulMultiSessionIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulMultiSessionIT.java deleted file mode 100644 index 8d71c86..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulMultiSessionIT.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.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/JulTestUtils.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulTestUtils.java deleted file mode 100644 index 0a3e13c..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/jul/JulTestUtils.java +++ /dev/null @@ -1,48 +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 java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Utility methods for JUL tests - */ -final class JulTestUtils { - - JulTestUtils() { - } - - static void send10EventsTo(Logger logger) { - String a = new String("a"); - Object[] params = { a, new String("b"), new Object() }; - - // Levels are FINE, FINER, FINEST, INFO, SEVERE, WARNING - logger.fine("A fine level message"); - logger.finer("A finer level message"); - logger.finest("A finest level message"); - logger.info("A info level message"); - logger.severe("A severe level message"); - logger.warning("A warning level message"); - logger.warning("Another warning level message"); - logger.log(Level.WARNING, "A warning message using Logger.log()"); - logger.log(Level.INFO, "A message with one parameter", a); - logger.log(Level.INFO, "A message with parameters", params); - } -} 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 deleted file mode 100644 index 02bae94..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jEnabledEventsIT.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.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/Log4jLegacyApiIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jLegacyApiIT.java deleted file mode 100644 index 054fd94..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jLegacyApiIT.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 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/Log4jMultiSessionIT.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jMultiSessionIT.java deleted file mode 100644 index e9f9458..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jMultiSessionIT.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.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/Log4jTestUtils.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jTestUtils.java deleted file mode 100644 index c69f7bc..0000000 --- a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/log4j/Log4jTestUtils.java +++ /dev/null @@ -1,47 +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 java.io.IOException; - -import org.apache.log4j.Level; -import org.apache.log4j.Logger; - -/** - * Utility methods for log4j tests - */ -final class Log4jTestUtils { - - private Log4jTestUtils() { - } - - 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()"); - } -}