From: Alexandre Montplaisir Date: Thu, 18 Feb 2016 23:09:46 +0000 (-0500) Subject: Put common setup code in the utils classes X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=eca27046b6f32c55dc7ceccb0821431c9be9f3af;p=lttng-ust-java-tests.git Put common setup code in the utils classes We now have a large amount of test classes, it's a bit simpler to put the common, API-specific @BeforeClass and @AfterClass code in the utils classes. At the same time we can give slightly more information in case of failure of these checks. Signed-off-by: Alexandre Montplaisir --- diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextIT.java index a6b3f68..844acef 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextIT.java @@ -18,8 +18,6 @@ package org.lttng.ust.agent.integration.context; -import static org.junit.Assert.assertTrue; - import java.io.IOException; import java.util.logging.Handler; import java.util.logging.Level; @@ -30,10 +28,8 @@ 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.jul.LttngLogHandler; import org.lttng.ust.agent.utils.JulTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; /** * Enabled app contexts test for the LTTng-UST JUL log handler. @@ -49,11 +45,7 @@ public class JulAppContextIT extends AppContextITBase { */ @BeforeClass public static void julClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(JulTestUtils.checkForJulLibrary()); - assertTrue(LttngUtils.checkForLttngTools(Domain.JUL)); - - LttngToolsHelper.destroyAllSessions(); + JulTestUtils.testClassSetup(); } /** @@ -61,7 +53,7 @@ public class JulAppContextIT extends AppContextITBase { */ @AfterClass public static void julClassCleanup() { - LttngToolsHelper.deleteAllTraces(); + JulTestUtils.testClassCleanup(); } /** diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextOrderingIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextOrderingIT.java index 5fbea4c..530efab 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextOrderingIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextOrderingIT.java @@ -18,7 +18,6 @@ package org.lttng.ust.agent.integration.context; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; @@ -27,12 +26,11 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.junit.After; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.lttng.tools.ILttngSession.Domain; -import org.lttng.tools.LttngToolsHelper; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.JulTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; /** * Implementation of {@link AppContextOrderingITBase} for the JUL API. @@ -46,11 +44,15 @@ public class JulAppContextOrderingIT extends AppContextOrderingITBase { */ @BeforeClass public static void julClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(JulTestUtils.checkForJulLibrary()); - assertTrue(LttngUtils.checkForLttngTools(Domain.JUL)); + JulTestUtils.testClassSetup(); + } - LttngToolsHelper.destroyAllSessions(); + /** + * Class cleanup + */ + @AfterClass + public static void julClassCleanup() { + JulTestUtils.testClassCleanup(); } /** diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulEnabledEventsIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulEnabledEventsIT.java index f5aaaac..0226f7d 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulEnabledEventsIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulEnabledEventsIT.java @@ -18,8 +18,6 @@ package org.lttng.ust.agent.integration.events; -import static org.junit.Assert.assertTrue; - import java.io.IOException; import java.util.logging.Handler; import java.util.logging.Level; @@ -30,10 +28,8 @@ 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.jul.LttngLogHandler; import org.lttng.ust.agent.utils.JulTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; /** * Enabled events test for the LTTng-UST JUL log handler. @@ -52,11 +48,7 @@ public class JulEnabledEventsIT extends EnabledEventsITBase { */ @BeforeClass public static void julClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(JulTestUtils.checkForJulLibrary()); - assertTrue(LttngUtils.checkForLttngTools(Domain.JUL)); - - LttngToolsHelper.destroyAllSessions(); + JulTestUtils.testClassSetup(); } /** @@ -64,7 +56,7 @@ public class JulEnabledEventsIT extends EnabledEventsITBase { */ @AfterClass public static void julClassCleanup() { - LttngToolsHelper.deleteAllTraces(); + JulTestUtils.testClassCleanup(); } /** diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiIT.java index 88ed2ab..f7c130a 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiIT.java @@ -36,11 +36,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.lttng.tools.ILttngSession; import org.lttng.tools.ILttngSession.Domain; -import org.lttng.tools.LttngToolsHelper; import org.lttng.ust.agent.ILttngHandler; import org.lttng.ust.agent.LTTngAgent; import org.lttng.ust.agent.utils.JulTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; import org.lttng.ust.agent.utils.TestPrintRunner; /** @@ -65,11 +63,7 @@ public class JulLegacyApiIT { */ @BeforeClass public static void julClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(JulTestUtils.checkForJulLibrary()); - assertTrue(LttngUtils.checkForLttngTools(Domain.JUL)); - - LttngToolsHelper.destroyAllSessions(); + JulTestUtils.testClassSetup(); } /** @@ -77,7 +71,7 @@ public class JulLegacyApiIT { */ @AfterClass public static void julClassCleanup() { - LttngToolsHelper.deleteAllTraces(); + JulTestUtils.testClassCleanup(); } /** diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulListEventsIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulListEventsIT.java index 3a4cef6..0c97d37 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulListEventsIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulListEventsIT.java @@ -18,22 +18,17 @@ package org.lttng.ust.agent.integration.events; -import static org.junit.Assert.assertTrue; - import java.io.IOException; import java.util.logging.Handler; 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.ILttngSession; -import org.lttng.tools.LttngToolsHelper; -import org.lttng.ust.agent.integration.events.ListEventsITBase; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.JulTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; /** * Test suite for the list events command for the JUL domain @@ -44,15 +39,19 @@ public class JulListEventsIT extends ListEventsITBase { private Handler[] handlers; /** - * Test class setup + * Class setup */ @BeforeClass - public static void testClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(JulTestUtils.checkForJulLibrary()); - assertTrue(LttngUtils.checkForLttngTools(Domain.JUL)); + public static void julClassSetup() { + JulTestUtils.testClassSetup(); + } - LttngToolsHelper.destroyAllSessions(); + /** + * Class cleanup + */ + @AfterClass + public static void julClassCleanup() { + JulTestUtils.testClassCleanup(); } /** diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulMultiSessionIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulMultiSessionIT.java index 4f34b1b..0c860bb 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulMultiSessionIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulMultiSessionIT.java @@ -18,8 +18,6 @@ package org.lttng.ust.agent.integration.events; -import static org.junit.Assert.assertTrue; - import java.io.IOException; import java.util.logging.Handler; import java.util.logging.Level; @@ -30,11 +28,8 @@ 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.JulTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; /** * JUL tests for multiple concurrent tracing sessions @@ -53,11 +48,7 @@ public class JulMultiSessionIT extends MultiSessionITBase { */ @BeforeClass public static void julClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(JulTestUtils.checkForJulLibrary()); - assertTrue(LttngUtils.checkForLttngTools(Domain.JUL)); - - LttngToolsHelper.destroyAllSessions(); + JulTestUtils.testClassSetup(); } /** @@ -65,7 +56,7 @@ public class JulMultiSessionIT extends MultiSessionITBase { */ @AfterClass public static void julClassCleanup() { - LttngToolsHelper.deleteAllTraces(); + JulTestUtils.testClassCleanup(); } /** diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerIT.java index 70390a4..ace61de 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerIT.java @@ -18,18 +18,15 @@ package org.lttng.ust.agent.integration.filter; -import static org.junit.Assert.assertTrue; - import java.io.IOException; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.lttng.tools.ILttngSession; -import org.lttng.tools.LttngToolsHelper; import org.lttng.ust.agent.ILttngHandler; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.ILogLevelStrings; import org.lttng.ust.agent.utils.JulTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; /** * Filter notifications tests using the JUL logging API. @@ -43,10 +40,15 @@ public class JulFilterListenerIT extends FilterListenerITBase { */ @BeforeClass public static void julClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(JulTestUtils.checkForJulLibrary()); - assertTrue(LttngUtils.checkForLttngTools(ILttngSession.Domain.JUL)); - LttngToolsHelper.destroyAllSessions(); + JulTestUtils.testClassSetup(); + } + + /** + * Class cleanup + */ + @AfterClass + public static void julClassCleanup() { + JulTestUtils.testClassCleanup(); } @Override diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerOrderingIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerOrderingIT.java index 4d599cd..e1145c9 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerOrderingIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerOrderingIT.java @@ -18,7 +18,6 @@ package org.lttng.ust.agent.integration.filter; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; @@ -26,12 +25,11 @@ import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.lttng.tools.ILttngSession.Domain; -import org.lttng.tools.LttngToolsHelper; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.JulTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; /** * Implementation of {@link FilterListenerOrderingITBase} for the JUL API. @@ -46,11 +44,15 @@ public class JulFilterListenerOrderingIT extends FilterListenerOrderingITBase { */ @BeforeClass public static void julClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(JulTestUtils.checkForJulLibrary()); - assertTrue(LttngUtils.checkForLttngTools(Domain.JUL)); + JulTestUtils.testClassSetup(); + } - LttngToolsHelper.destroyAllSessions(); + /** + * Class cleanup + */ + @AfterClass + public static void julClassCleanup() { + JulTestUtils.testClassCleanup(); } @Override diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/utils/JulTestUtils.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/utils/JulTestUtils.java index 4008815..af90383 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/utils/JulTestUtils.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/utils/JulTestUtils.java @@ -18,10 +18,15 @@ package org.lttng.ust.agent.utils; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; +import org.lttng.tools.LttngToolsHelper; +import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.jul.LttngLogHandler; /** @@ -32,20 +37,35 @@ public final class JulTestUtils { private JulTestUtils() { } + /** + * Setup method common to most JUL tests. To be called in a @BeforeClass. + */ + public static void testClassSetup() { + /* Make sure we can find the JNI library and lttng-tools */ + checkForJulLibrary(); + assertTrue("lttng-tools is not working properly.", LttngUtils.checkForLttngTools(Domain.JUL)); + + LttngToolsHelper.destroyAllSessions(); + } + + /** + * Teardown method common to most JUL tests. To be called in a @AfterClass. + */ + public static void testClassCleanup() { + LttngToolsHelper.deleteAllTraces(); + } + /** * Check the the JUL native library is available, effectively allowing LTTng * JUL handlers to be used. - * - * @return True if JUL works fine, false if it does not. */ - public static boolean checkForJulLibrary() { + private static void checkForJulLibrary() { try { LttngLogHandler testHandler = new LttngLogHandler(); testHandler.close(); } catch (SecurityException | IOException e) { - return false; + fail(e.getMessage()); } - return true; } /** diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextIT.java index 00e8b37..1eea96d 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextIT.java @@ -18,8 +18,6 @@ package org.lttng.ust.agent.integration.context; -import static org.junit.Assert.assertTrue; - import java.io.IOException; import org.apache.log4j.Appender; @@ -30,10 +28,8 @@ 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.log4j.LttngLogAppender; import org.lttng.ust.agent.utils.Log4jTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; /** * Enabled app contexts test for the LTTng-UST JUL log handler. @@ -48,20 +44,16 @@ public class Log4jAppContextIT extends AppContextITBase { * Class setup */ @BeforeClass - public static void julClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(Log4jTestUtils.checkForLog4jLibrary()); - assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J)); - - LttngToolsHelper.destroyAllSessions(); + public static void log4jClassSetup() { + Log4jTestUtils.testClassSetup(); } /** * Class cleanup */ @AfterClass - public static void julClassCleanup() { - LttngToolsHelper.deleteAllTraces(); + public static void log4jClassCleanup() { + Log4jTestUtils.testClassCleanup(); } /** diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextOrderingIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextOrderingIT.java index 59b7d1b..44a93a8 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextOrderingIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextOrderingIT.java @@ -18,7 +18,6 @@ package org.lttng.ust.agent.integration.context; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; @@ -27,12 +26,11 @@ 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.BeforeClass; import org.lttng.tools.ILttngSession.Domain; -import org.lttng.tools.LttngToolsHelper; import org.lttng.ust.agent.log4j.LttngLogAppender; import org.lttng.ust.agent.utils.Log4jTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; /** * Implementation of {@link AppContextOrderingITBase} for the log4j API. @@ -46,11 +44,15 @@ public class Log4jAppContextOrderingIT extends AppContextOrderingITBase { */ @BeforeClass public static void log4jClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(Log4jTestUtils.checkForLog4jLibrary()); - assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J)); + Log4jTestUtils.testClassSetup(); + } - LttngToolsHelper.destroyAllSessions(); + /** + * Class cleanup + */ + @AfterClass + public static void log4jClassCleanup() { + Log4jTestUtils.testClassCleanup(); } /** diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jEnabledEventsIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jEnabledEventsIT.java index dcca40d..2d73217 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jEnabledEventsIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jEnabledEventsIT.java @@ -18,8 +18,6 @@ package org.lttng.ust.agent.integration.events; -import static org.junit.Assert.assertTrue; - import java.io.IOException; import org.apache.log4j.Appender; @@ -31,10 +29,8 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.lttng.tools.ILttngSession.Domain; -import org.lttng.tools.LttngToolsHelper; import org.lttng.ust.agent.log4j.LttngLogAppender; import org.lttng.ust.agent.utils.Log4jTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; /** * Enabled events test for the LTTng-UST Log4j log handler. @@ -53,19 +49,15 @@ public class Log4jEnabledEventsIT extends EnabledEventsITBase { */ @BeforeClass public static void log4jClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(Log4jTestUtils.checkForLog4jLibrary()); - assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J)); - - LttngToolsHelper.destroyAllSessions(); + Log4jTestUtils.testClassSetup(); } /** - * Class teardown + * Class cleanup */ @AfterClass public static void log4jClassCleanup() { - LttngToolsHelper.deleteAllTraces(); + Log4jTestUtils.testClassCleanup(); } /** diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jLegacyApiIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jLegacyApiIT.java index af46cf4..4cfff7b 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jLegacyApiIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jLegacyApiIT.java @@ -36,11 +36,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.lttng.tools.ILttngSession; import org.lttng.tools.ILttngSession.Domain; -import org.lttng.tools.LttngToolsHelper; import org.lttng.ust.agent.ILttngHandler; import org.lttng.ust.agent.LTTngAgent; import org.lttng.ust.agent.utils.Log4jTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; import org.lttng.ust.agent.utils.TestPrintRunner; /** @@ -65,20 +63,16 @@ public class Log4jLegacyApiIT { * Class setup */ @BeforeClass - public static void classSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(Log4jTestUtils.checkForLog4jLibrary()); - assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J)); - - LttngToolsHelper.destroyAllSessions(); + public static void log4jClassSetup() { + Log4jTestUtils.testClassSetup(); } /** * Class cleanup */ @AfterClass - public static void classCleanup() { - LttngToolsHelper.deleteAllTraces(); + public static void log4jClassCleanup() { + Log4jTestUtils.testClassCleanup(); } /** diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jListEventsIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jListEventsIT.java index 885ba4b..c7be8c8 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jListEventsIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jListEventsIT.java @@ -18,22 +18,17 @@ package org.lttng.ust.agent.integration.events; -import static org.junit.Assert.assertTrue; - import java.io.IOException; import org.apache.log4j.Appender; 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.ILttngSession; -import org.lttng.tools.LttngToolsHelper; -import org.lttng.ust.agent.integration.events.ListEventsITBase; import org.lttng.ust.agent.log4j.LttngLogAppender; import org.lttng.ust.agent.utils.Log4jTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; /** * Test suite for the list events command for the log4j domain @@ -44,15 +39,19 @@ public class Log4jListEventsIT extends ListEventsITBase { private Appender[] appenders; /** - * Test class setup + * Class setup */ @BeforeClass - public static void testClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(Log4jTestUtils.checkForLog4jLibrary()); - assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J)); + public static void log4jClassSetup() { + Log4jTestUtils.testClassSetup(); + } - LttngToolsHelper.destroyAllSessions(); + /** + * Class cleanup + */ + @AfterClass + public static void log4jClassCleanup() { + Log4jTestUtils.testClassCleanup(); } /** diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jMultiSessionIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jMultiSessionIT.java index 00e7183..150260a 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jMultiSessionIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jMultiSessionIT.java @@ -18,8 +18,6 @@ package org.lttng.ust.agent.integration.events; -import static org.junit.Assert.assertTrue; - import java.io.IOException; import org.apache.log4j.Appender; @@ -30,11 +28,8 @@ 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.Log4jTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; /** * Log4j tests for multiple concurrent tracing sessions @@ -53,19 +48,15 @@ public class Log4jMultiSessionIT extends MultiSessionITBase { */ @BeforeClass public static void log4jClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(Log4jTestUtils.checkForLog4jLibrary()); - assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J)); - - LttngToolsHelper.destroyAllSessions(); + Log4jTestUtils.testClassSetup(); } /** - * Class teardown + * Class cleanup */ @AfterClass public static void log4jClassCleanup() { - LttngToolsHelper.deleteAllTraces(); + Log4jTestUtils.testClassCleanup(); } /** diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerIT.java index 3647963..abe591d 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerIT.java @@ -18,18 +18,15 @@ package org.lttng.ust.agent.integration.filter; -import static org.junit.Assert.assertTrue; - import java.io.IOException; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.lttng.tools.ILttngSession; -import org.lttng.tools.LttngToolsHelper; import org.lttng.ust.agent.ILttngHandler; import org.lttng.ust.agent.log4j.LttngLogAppender; import org.lttng.ust.agent.utils.ILogLevelStrings; import org.lttng.ust.agent.utils.Log4jTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; /** * Filter notifications tests using the log4j logging API. @@ -43,10 +40,15 @@ public class Log4jFilterListenerIT extends FilterListenerITBase { */ @BeforeClass public static void log4jClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(Log4jTestUtils.checkForLog4jLibrary()); - assertTrue(LttngUtils.checkForLttngTools(ILttngSession.Domain.LOG4J)); - LttngToolsHelper.destroyAllSessions(); + Log4jTestUtils.testClassSetup(); + } + + /** + * Class cleanup + */ + @AfterClass + public static void log4jClassCleanup() { + Log4jTestUtils.testClassCleanup(); } @Override diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerOrderingIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerOrderingIT.java index 0399b71..5c700db 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerOrderingIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerOrderingIT.java @@ -18,7 +18,6 @@ package org.lttng.ust.agent.integration.filter; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; @@ -26,12 +25,11 @@ import java.io.IOException; import org.apache.log4j.Appender; import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.lttng.tools.ILttngSession.Domain; -import org.lttng.tools.LttngToolsHelper; import org.lttng.ust.agent.log4j.LttngLogAppender; import org.lttng.ust.agent.utils.Log4jTestUtils; -import org.lttng.ust.agent.utils.LttngUtils; /** * Implementation of {@link FilterListenerOrderingITBase} for the log4j API. @@ -45,12 +43,16 @@ public class Log4jFilterListenerOrderingIT extends FilterListenerOrderingITBase * Class setup */ @BeforeClass - public static void julClassSetup() { - /* Make sure we can find the JNI library and lttng-tools */ - assertTrue(Log4jTestUtils.checkForLog4jLibrary()); - assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J)); + public static void log4jClassSetup() { + Log4jTestUtils.testClassSetup(); + } - LttngToolsHelper.destroyAllSessions(); + /** + * Class cleanup + */ + @AfterClass + public static void log4jClassCleanup() { + Log4jTestUtils.testClassCleanup(); } @Override diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/utils/Log4jTestUtils.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/utils/Log4jTestUtils.java index b356dbe..a258e92 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/utils/Log4jTestUtils.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/utils/Log4jTestUtils.java @@ -18,10 +18,15 @@ package org.lttng.ust.agent.utils; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.IOException; import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.lttng.tools.LttngToolsHelper; +import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.log4j.LttngLogAppender; /** @@ -32,21 +37,35 @@ public final class Log4jTestUtils { private Log4jTestUtils() { } + /** + * Setup method common to most log4j tests. To be called in a @BeforeClass. + */ + public static void testClassSetup() { + /* Make sure we can find the JNI library and lttng-tools */ + checkForLog4jLibrary(); + assertTrue("lttng-tools is not working properly.", LttngUtils.checkForLttngTools(Domain.LOG4J)); + + LttngToolsHelper.destroyAllSessions(); + } + + /** + * Teardown method common to most log4j tests. To be called in a @AfterClass. + */ + public static void testClassCleanup() { + LttngToolsHelper.deleteAllTraces(); + } + /** * Check the the Log4j native library is available, effectively allowing * LTTng Log4j appenders to be used. - * - * @return True if Log4j works fine, false if it does not. */ - public static boolean checkForLog4jLibrary() { + private static void checkForLog4jLibrary() { try { LttngLogAppender testAppender = new LttngLogAppender(); testAppender.close(); } catch (SecurityException | IOException e) { - e.printStackTrace(); - return false; + fail(e.getMessage()); } - return true; } /**