X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=lttng-ust-java-tests-jul%2Fsrc%2Ftest%2Fjava%2Forg%2Flttng%2Fust%2Fagent%2Fintegration%2Fevents%2FJulLegacyApiLoggerHierarchyListIT.java;fp=lttng-ust-java-tests-jul%2Fsrc%2Ftest%2Fjava%2Forg%2Flttng%2Fust%2Fagent%2Fintegration%2Fevents%2FJulLegacyApiLoggerHierarchyListIT.java;h=a9ecf8c403b812bbeab59a11546794a9fa961e72;hb=fe6a3925eb9ae4514ff89db93c743e030f7afa99;hp=0000000000000000000000000000000000000000;hpb=bda25414d38806ccd992e072acd30221654faa38;p=lttng-ust-java-tests.git diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiLoggerHierarchyListIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiLoggerHierarchyListIT.java new file mode 100644 index 0000000..a9ecf8c --- /dev/null +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiLoggerHierarchyListIT.java @@ -0,0 +1,184 @@ +/* + * Copyright (C) 2016, 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 java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.logging.LogManager; +import java.util.logging.Logger; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.lttng.tools.ILttngSession.Domain; +import org.lttng.ust.agent.LTTngAgent; +import org.lttng.ust.agent.utils.JulTestUtils; + +/** + * Implementation of {@link LoggerHierachyListITBase} for the JUL part of the + * legacy LTTngAgent API. + * + * @author Alexandre Montplaisir + */ +@SuppressWarnings("deprecation") +@RunWith(Parameterized.class) +public class JulLegacyApiLoggerHierarchyListIT extends LoggerHierachyListITBase { + + private LTTngAgent agent; + private Logger parentLogger; + private Logger childLogger; + + /** + * Test constructor + * + * @param parentLoggerActive + * Parent logger has been instantiated + * @param parentLoggerHasHandler + * Parent logger has a LTTng handler attached to it + * @param childLoggerActive + * Child logger has been instantiated + * @param childLoggerHasHandler + * Child logger has a LTTng handler attached to it + */ + public JulLegacyApiLoggerHierarchyListIT(boolean parentLoggerActive, + boolean parentLoggerHasHandler, + boolean childLoggerActive, + boolean childLoggerHasHandler) { + /* Set by parameters defined in the base class */ + super(parentLoggerActive, + parentLoggerHasHandler, + childLoggerActive, + childLoggerHasHandler); + } + + // ------------------------------------------------------------------------ + // Maintenance + // ------------------------------------------------------------------------ + + /** + * Class setup + */ + @BeforeClass + public static void julClassSetup() { + JulTestUtils.testClassSetup(); + } + + /** + * Class cleanup + */ + @AfterClass + public static void julClassCleanup() { + JulTestUtils.testClassCleanup(); + } + + /** + * Test setup + */ + @SuppressWarnings("static-method") + @Before + public void setup() { + LogManager.getLogManager().reset(); + System.gc(); + } + + /** + * Test cleanup + */ + @After + public void cleanup() { + agent.dispose(); + + if (parentLogger != null) { + parentLogger = null; + } + + if (childLogger != null) { + childLogger = null; + } + + LogManager.getLogManager().reset(); + System.gc(); + } + + // ------------------------------------------------------------------------ + // Abstract methods + // ------------------------------------------------------------------------ + + @Override + protected Domain getDomain() { + return Domain.JUL; + } + + @Override + protected void activateLoggers() throws IOException { + agent = LTTngAgent.getLTTngAgent(); + + /* + * There is no notion of "hasHandler" for the legacy API: there is only + * one log handler attached to the root logger, so there are no handlers + * to specific events/loggers. + */ + + if (parentLoggerActive) { + parentLogger = Logger.getLogger(PARENT_LOGGER); + } + + if (childLoggerActive) { + childLogger = Logger.getLogger(CHILD_LOGGER); + } + } + + // ------------------------------------------------------------------------ + // Overridden tests + // ------------------------------------------------------------------------ + + /** + * Due to how the legacy agent works, there is no notion of "hasHandler". If + * the logger exists, it will be visible in "lttng list" because the single + * log handler is attached to the root logger. + */ + @Override + @Test + public void testList() throws IOException { + activateLoggers(); + + List enabledEvents = getSession().listEvents(); + List expectedEvents = new ArrayList<>(); + + if (parentLoggerActive) { + expectedEvents.add(PARENT_LOGGER); + } + if (childLoggerActive) { + expectedEvents.add(CHILD_LOGGER); + } + + Collections.sort(enabledEvents); + Collections.sort(expectedEvents); + assertEquals(expectedEvents, enabledEvents); + } + +}