diff options
author | gjoranv <gv@verizonmedia.com> | 2022-05-12 15:27:05 +0200 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2022-05-12 15:31:46 +0200 |
commit | 59840b8f1bb24e34a8b07e14cf721bba855566e9 (patch) | |
tree | 899407a37d7159d1e2ae2a7a0de3f1f720cd2d64 /jdisc_core_test | |
parent | 2f1beb1a191580fde26e1b855a1fb7426c789e30 (diff) |
Readd integration test for log frameworks.
- Test was deleted by accident instead of renamed
(old name: OsgiLogServiceIntegrationTest)
Diffstat (limited to 'jdisc_core_test')
-rw-r--r-- | jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/LogFrameworksIntegrationTest.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/LogFrameworksIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/LogFrameworksIntegrationTest.java new file mode 100644 index 00000000000..6297a9c4505 --- /dev/null +++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/LogFrameworksIntegrationTest.java @@ -0,0 +1,56 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.jdisc.core; + +import com.yahoo.io.IOUtils; +import com.yahoo.jdisc.test.TestDriver; +import com.yahoo.log.LogSetup; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.util.List; + +import static org.junit.Assert.assertTrue; + + +/** + * @author Simon Thoresen Hult + * @author gjoranv + */ +public class LogFrameworksIntegrationTest { + private static final String VESPA_LOG_TARGET = "vespa.log.target"; + + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); + + @Test + public void requireThatAllSupportedLogFrameworksAreConfigured() throws Exception { + File logFile = tempFolder.newFile(); + try { + System.setProperty(VESPA_LOG_TARGET, "file:" + logFile.getAbsolutePath()); + TestDriver driver = TestDriver.newApplicationBundleInstance("app-h-log.jar", false); + + List<String> logLines = IOUtils.getLines(logFile.getAbsolutePath()); + assertLogFileContains("[jdk14] hello world", logLines); + assertLogFileContains("[slf4j] hello world", logLines); + assertLogFileContains("[log4j] hello world", logLines); + assertLogFileContains("[jcl] hello world", logLines); + + assertTrue(driver.close()); + } finally { + System.clearProperty(VESPA_LOG_TARGET); + // Triggers a warning that can be ignored. Necessary to reset the log target for later tests. + LogSetup.initVespaLogging("jdisc_core_test"); + } + } + + private static void assertLogFileContains(String expected, List<String> logLines) { + for (var line : logLines) { + if (line.contains(expected)) return; + } + Assert.fail("Log did not contain : " + expected); + } + +} |