You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2018/09/28 18:43:01 UTC
[geode] branch develop updated: GEODE-2644: Cleanup logging tests
(#2519)
This is an automated email from the ASF dual-hosted git repository.
klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 65725eb GEODE-2644: Cleanup logging tests (#2519)
65725eb is described below
commit 65725eb7e466be85260b215cf3a0917f931a21c5
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Fri Sep 28 11:42:53 2018 -0700
GEODE-2644: Cleanup logging tests (#2519)
---
...java => GfshStartLocatorLogAcceptanceTest.java} | 7 +-
...scribeConfigAreFullyRedactedAcceptanceTest.java | 6 +-
geode-core/build.gradle | 3 +
...a => ChangeLogLevelCommandDistributedTest.java} | 8 +-
...nitTest.java => ExportLogsDistributedTest.java} | 9 +-
... ExportLogsOnServerManagerDistributedTest.java} | 7 +-
...st.java => ExportLogsStatsDistributedTest.java} | 9 +-
... ExportLogsWithMemberGroupDistributedTest.java} | 28 +-
.../cli/commands/ShowLogCommandDUnitTest.java | 2 +-
...UnitTest.java => MergeLogsDistributedTest.java} | 17 +-
...opClientExecutorWithLoggingIntegrationTest.java | 4 +-
...cherRemoteWithCustomLoggingIntegrationTest.java | 18 +-
...cherRemoteWithCustomLoggingIntegrationTest.java | 16 +-
.../logging/CacheLogRollingIntegrationTest.java | 109 ++++----
...> DistributedSystemLogFileIntegrationTest.java} | 94 ++++---
...est.java => LocatorLogFileIntegrationTest.java} | 30 +--
...nitTest.java => LogServiceIntegrationTest.java} | 33 ++-
...Test.java => MergeLogFilesIntegrationTest.java} | 44 ++--
.../logging/log4j/ConfigLocatorJUnitTest.java | 220 ----------------
...penderWithLoggerContextRuleIntegrationTest.java | 142 +++++++++++
...leAppenderWithSystemOutRuleIntegrationTest.java | 182 +++++++++++++
...nitTest.java => FastLoggerIntegrationTest.java} | 282 ++++++++++-----------
...astLoggerWithDefaultConfigIntegrationTest.java} | 20 +-
.../GeodeVerboseLogMarkerIntegrationTest.java | 84 +++---
.../log4j/LogWriterAppenderIntegrationTest.java} | 51 ++--
.../CustomConfigWithCacheIntegrationTest.java | 47 ++--
.../CustomConfigWithLogServiceIntegrationTest.java | 39 +--
.../internal/cli/GfshParserAutoCompletionTest.java | 23 +-
.../ExportLogsFunctionIntegrationTest.java | 48 ++--
...SizeExportLogsFunctionFileIntegrationTest.java} | 27 +-
... => SizeExportLogsFunctionIntegrationTest.java} | 25 +-
...st.java => LogExporterFileIntegrationTest.java} | 24 +-
.../cli/util/LogExporterIntegrationTest.java | 68 ++++-
...moteWithCustomLoggingIntegrationTest_log4j2.xml | 45 ++++
...moteWithCustomLoggingIntegrationTest_log4j2.xml | 45 ++++
...WithLoggerContextRuleIntegrationTest_log4j2.xml | 42 +++
...nderWithSystemOutRuleIntegrationTest_log4j2.xml | 40 +++
...CustomConfigWithCacheIntegrationTest_log4j2.xml | 45 ++++
...mConfigWithLogServiceIntegrationTest_log4j2.xml | 45 ++++
geode-core/src/main/resources/log4j2-cli.xml | 16 ++
geode-core/src/main/resources/log4j2.xml | 16 ++
.../logging/LogWriterDisabledPerformanceTest.java | 5 +-
.../internal/logging/LogWriterPerformanceTest.java | 13 +-
.../log4j/Log4J2DisabledPerformanceTest.java | 5 +-
.../logging/log4j/Log4J2PerformanceTest.java | 50 ++--
.../LogWriterLoggerDisabledPerformanceTest.java | 5 +-
.../log4j/LogWriterLoggerPerformanceTest.java | 52 ++--
...ogServiceJUnitTest.java => LogServiceTest.java} | 21 +-
...erImplJUnitTest.java => LogWriterImplTest.java} | 5 +-
...tLogFileJUnitTest.java => SortLogFileTest.java} | 33 +--
...astLoggerJUnitTest.java => FastLoggerTest.java} | 79 +++---
.../geode/internal/logging/log4j/LogLevelTest.java | 11 +-
.../logging/log4j/custom/CustomConfiguration.java | 60 -----
.../cli/commands/ExportLogsCommandTest.java | 71 ++----
...nitTest.java => ExportLogsInterceptorTest.java} | 10 +-
.../cli/commands/LogLevelInterceptorTest.java | 9 +-
.../cli/converters/LogLevelConverterTest.java | 10 +-
.../cli/functions/ExportLogsFunctionTest.java | 11 +-
...nitTest.java => ExportLogsCacheWriterTest.java} | 11 +-
.../internal/cli/util/LogFilterTest.java | 19 +-
.../internal/cli/util/LogLevelExtractorTest.java | 20 +-
.../management/internal/cli/util/LogSizerTest.java | 25 +-
.../logging/log4j/custom/log4j2-custom.xml | 29 ---
.../log4j/marker/log4j2-gemfire_verbose-accept.xml | 16 ++
.../log4j/marker/log4j2-gemfire_verbose-deny.xml | 16 ++
.../log4j/marker/log4j2-geode_verbose-accept.xml | 16 ++
.../log4j/marker/log4j2-geode_verbose-deny.xml | 16 ++
.../org/apache/geode/test/golden/log4j2-test.xml | 16 ++
... ChangeLogLevelCommandDistributedTestBase.java} | 5 +-
...ase.java => ExportLogsDistributedTestBase.java} | 13 +-
...ava => ExportLogsStatsDistributedTestBase.java} | 7 +-
...java => ShowLogCommandDistributedTestBase.java} | 4 +-
.../org/apache/geode/test/util/ResourceUtils.java | 87 +++++++
.../test/util/ResourceUtilsIntegrationTest.java | 58 +++++
.../apache/geode/test/util/ResourceUtilsTest.java | 67 +++++
.../geode/test/util/ResourceUtilsTest_resource.txt | 17 ++
...HandlerUnitTest.java => LogoutHandlerTest.java} | 21 +-
geode-web/build.gradle | 1 +
...ngeLogLevelCommandOverHttpDistributedTest.java} | 10 +-
.../ExportLogsOverHttpDistributedTest.java | 10 +-
...=> ExportLogsStatsOverHttpDistributedTest.java} | 7 +-
... => ShowLogCommandOverHttpDistributedTest.java} | 10 +-
...Test.java => LogNoPasswordIntegrationTest.java} | 18 +-
... LoginHandlerInterceptorRequestHeaderTest.java} | 14 +-
...tTest.java => LoginHandlerInterceptorTest.java} | 8 +-
85 files changed, 1872 insertions(+), 1139 deletions(-)
diff --git a/geode-assembly/src/acceptanceTest/java/org/apache/geode/management/internal/cli/commands/GfshStartLocatorLogTest.java b/geode-assembly/src/acceptanceTest/java/org/apache/geode/management/internal/cli/commands/GfshStartLocatorLogAcceptanceTest.java
similarity index 89%
rename from geode-assembly/src/acceptanceTest/java/org/apache/geode/management/internal/cli/commands/GfshStartLocatorLogTest.java
rename to geode-assembly/src/acceptanceTest/java/org/apache/geode/management/internal/cli/commands/GfshStartLocatorLogAcceptanceTest.java
index b7169f4..01a47c9 100644
--- a/geode-assembly/src/acceptanceTest/java/org/apache/geode/management/internal/cli/commands/GfshStartLocatorLogTest.java
+++ b/geode-assembly/src/acceptanceTest/java/org/apache/geode/management/internal/cli/commands/GfshStartLocatorLogAcceptanceTest.java
@@ -22,12 +22,17 @@ import java.nio.charset.StandardCharsets;
import com.google.common.io.Files;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.rules.gfsh.GfshExecution;
import org.apache.geode.test.junit.rules.gfsh.GfshRule;
import org.apache.geode.test.junit.rules.gfsh.GfshScript;
-public class GfshStartLocatorLogTest {
+@Category({GfshTest.class, LoggingTest.class})
+public class GfshStartLocatorLogAcceptanceTest {
+
@Rule
public GfshRule gfshRule = new GfshRule();
diff --git a/geode-assembly/src/acceptanceTest/java/org/apache/geode/management/internal/cli/commands/LogsAndDescribeConfigAreFullyRedactedAcceptanceTest.java b/geode-assembly/src/acceptanceTest/java/org/apache/geode/management/internal/cli/commands/LogsAndDescribeConfigAreFullyRedactedAcceptanceTest.java
index 9a860c6..4c9c1a2 100644
--- a/geode-assembly/src/acceptanceTest/java/org/apache/geode/management/internal/cli/commands/LogsAndDescribeConfigAreFullyRedactedAcceptanceTest.java
+++ b/geode-assembly/src/acceptanceTest/java/org/apache/geode/management/internal/cli/commands/LogsAndDescribeConfigAreFullyRedactedAcceptanceTest.java
@@ -12,7 +12,6 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.cli.commands;
import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
@@ -31,9 +30,12 @@ import org.assertj.core.api.SoftAssertions;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.apache.geode.examples.security.ExampleSecurityManager;
import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+import org.apache.geode.test.junit.categories.LoggingTest;
+import org.apache.geode.test.junit.categories.SecurityTest;
import org.apache.geode.test.junit.rules.gfsh.GfshExecution;
import org.apache.geode.test.junit.rules.gfsh.GfshRule;
import org.apache.geode.util.test.TestUtil;
@@ -46,7 +48,9 @@ import org.apache.geode.util.test.TestUtil;
*
* Each password shares the string below for easier log scanning.
*/
+@Category({SecurityTest.class, LoggingTest.class})
public class LogsAndDescribeConfigAreFullyRedactedAcceptanceTest {
+
private static String sharedPasswordString = "abcdefg";
private File propertyFile;
diff --git a/geode-core/build.gradle b/geode-core/build.gradle
index df0c9f8..3975797 100755
--- a/geode-core/build.gradle
+++ b/geode-core/build.gradle
@@ -90,6 +90,7 @@ dependencies {
compile 'org.apache.logging.log4j:log4j-api:' + project.'log4j.version'
compile 'org.apache.logging.log4j:log4j-core:' + project.'log4j.version'
+
runtimeOnly ('org.fusesource.jansi:jansi:' + project.'jansi.version') {
ext.optional = true
}
@@ -171,6 +172,8 @@ dependencies {
integrationTestCompile project(':geode-concurrency-test')
integrationTestCompile 'redis.clients:jedis:' + project.'jedis.version'
integrationTestCompile 'org.apache.bcel:bcel:' + project.'bcel.version'
+ integrationTestCompile 'org.apache.logging.log4j:log4j-core:' + project.'log4j.version' + ':tests'
+ integrationTestCompile 'org.apache.logging.log4j:log4j-core:' + project.'log4j.version' + ':test-sources'
integrationTestCompile 'org.springframework:spring-test:' + project.'springframework.version'
integrationTestCompile 'net.spy:spymemcached:' + project.'spymemcached.version'
integrationTestCompile 'pl.pragmatists:JUnitParams:' + project.'JUnitParams.version'
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandDistributedTest.java
similarity index 72%
rename from geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandDUnitTest.java
rename to geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandDistributedTest.java
index cd556df..455df6d 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandDistributedTest.java
@@ -14,5 +14,11 @@
*/
package org.apache.geode.management.internal.cli.commands;
-public class ChangeLogLevelCommandDUnitTest extends ChangeLogLevelCommandDUnitTestBase {
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+
+@Category({GfshTest.class, LoggingTest.class})
+public class ChangeLogLevelCommandDistributedTest extends ChangeLogLevelCommandDistributedTestBase {
}
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsDistributedTest.java
similarity index 74%
rename from geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java
rename to geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsDistributedTest.java
index 2e17429..6a943a5 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsDistributedTest.java
@@ -13,8 +13,13 @@
* the License.
*
*/
-
package org.apache.geode.management.internal.cli.commands;
-public class ExportLogsDUnitTest extends ExportLogsDUnitTestBase {
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+
+@Category({GfshTest.class, LoggingTest.class})
+public class ExportLogsDistributedTest extends ExportLogsDistributedTestBase {
}
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOnServerManagerDUnit.java b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOnServerManagerDistributedTest.java
similarity index 95%
rename from geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOnServerManagerDUnit.java
rename to geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOnServerManagerDistributedTest.java
index 7295447..7b68c51 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOnServerManagerDUnit.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOnServerManagerDistributedTest.java
@@ -12,7 +12,6 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.cli.commands;
import static org.assertj.core.api.Assertions.assertThat;
@@ -30,12 +29,12 @@ import org.junit.experimental.categories.Category;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.GfshTest;
import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.rules.GfshCommandRule;
-
-@Category({LoggingTest.class})
-public class ExportLogsOnServerManagerDUnit {
+@Category({GfshTest.class, LoggingTest.class})
+public class ExportLogsOnServerManagerDistributedTest {
@Rule
public ClusterStartupRule lsRule = new ClusterStartupRule().withLogFile();
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsDistributedTest.java
similarity index 73%
rename from geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsDUnitTest.java
rename to geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsDistributedTest.java
index f51ef3e..acc2f29 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsDistributedTest.java
@@ -12,8 +12,13 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.cli.commands;
-public class ExportLogsStatsDUnitTest extends ExportLogsStatsDUnitTestBase {
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+
+@Category({GfshTest.class, LoggingTest.class})
+public class ExportLogsStatsDistributedTest extends ExportLogsStatsDistributedTestBase {
}
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsWithMemberGroupDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsWithMemberGroupDistributedTest.java
similarity index 90%
rename from geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsWithMemberGroupDUnitTest.java
rename to geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsWithMemberGroupDistributedTest.java
index f6f8dd1..c52a2e3 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsWithMemberGroupDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsWithMemberGroupDistributedTest.java
@@ -12,7 +12,6 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.cli.commands;
import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
@@ -34,28 +33,33 @@ import com.google.common.collect.Sets;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.cli.result.CommandResult;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.rules.GfshCommandRule;
+@Category({GfshTest.class, LoggingTest.class})
+public class ExportLogsWithMemberGroupDistributedTest {
-public class ExportLogsWithMemberGroupDUnitTest {
@ClassRule
public static ClusterStartupRule lsRule = new ClusterStartupRule().withLogFile();
@ClassRule
public static GfshCommandRule connector = new GfshCommandRule();
- protected static int jmxPort, httpPort;
- protected static Set<String> expectedZipEntries = new HashSet<>();
protected static MemberVM locator;
+ protected static int jmxPort;
+ private static int httpPort;
+ private static Set<String> expectedZipEntries = new HashSet<>();
@BeforeClass
- public static void beforeClass() throws Exception {
+ public static void beforeClass() {
int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
httpPort = ports[0];
jmxPort = ports[1];
@@ -75,17 +79,10 @@ public class ExportLogsWithMemberGroupDUnitTest {
serverProperties.setProperty(GROUPS, "group2");
lsRule.startServerVM(3, serverProperties, locator.getPort());
-
expectedZipEntries = Sets.newHashSet("locator-0/locator-0.log", "server-1/server-1.log",
"server-1/statistics.gfs");
}
- protected void connectIfNeeded() throws Exception {
- if (!connector.isConnected()) {
- connector.connect(locator);
- }
- }
-
@Test
public void testExportLogsWithMemberName() throws Exception {
connectIfNeeded();
@@ -125,8 +122,13 @@ public class ExportLogsWithMemberGroupDUnitTest {
assertThat(connector.getGfshOutput()).contains("Can't specify both group and member");
}
+ private void connectIfNeeded() throws Exception {
+ if (!connector.isConnected()) {
+ connector.connect(locator);
+ }
+ }
- protected String getZipPathFromCommandResult(String message) {
+ private String getZipPathFromCommandResult(String message) {
return message.replaceAll("Logs exported to the connected member's file system: ", "").trim();
}
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ShowLogCommandDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ShowLogCommandDUnitTest.java
index 93496c3..bb93817 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ShowLogCommandDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ShowLogCommandDUnitTest.java
@@ -14,5 +14,5 @@
*/
package org.apache.geode.management.internal.cli.commands;
-public class ShowLogCommandDUnitTest extends ShowLogCommandDUnitTestBase {
+public class ShowLogCommandDUnitTest extends ShowLogCommandDistributedTestBase {
}
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/util/MergeLogsDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/util/MergeLogsDistributedTest.java
similarity index 94%
rename from geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/util/MergeLogsDUnitTest.java
rename to geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/util/MergeLogsDistributedTest.java
index 67b40d3..3639a80 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/util/MergeLogsDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/util/MergeLogsDistributedTest.java
@@ -13,7 +13,6 @@
* the License.
*
*/
-
package org.apache.geode.management.internal.cli.util;
import static java.util.stream.Collectors.joining;
@@ -33,17 +32,17 @@ import org.awaitility.Awaitility;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.internal.logging.LogService;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
-
-public class MergeLogsDUnitTest {
- @Rule
- public ClusterStartupRule lsRule = new ClusterStartupRule().withLogFile();
- private MemberVM locator;
+@Category({GfshTest.class, LoggingTest.class})
+public class MergeLogsDistributedTest {
private static final String MESSAGE_1 = "MergeLogsMessage1";
private static final String MESSAGE_2 = "MergeLogsMessage2";
@@ -52,11 +51,14 @@ public class MergeLogsDUnitTest {
private static final String MESSAGE_5 = "MergeLogsMessage5";
private static final String MESSAGE_6 = "MergeLogsMessage6";
+ @Rule
+ public ClusterStartupRule lsRule = new ClusterStartupRule().withLogFile();
+
@Before
public void setup() throws Exception {
Properties properties = new Properties();
properties.setProperty(DistributionConfig.LOG_LEVEL_NAME, "info");
- locator = lsRule.startLocatorVM(0, properties);
+ MemberVM locator = lsRule.startLocatorVM(0, properties);
MemberVM server = lsRule.startServerVM(1, properties, locator.getPort());
MemberVM server2 = lsRule.startServerVM(2, properties, locator.getPort());
@@ -103,7 +105,6 @@ public class MergeLogsDUnitTest {
throw new AssertionError("No merged log file found");
});
assertOnLogContents(result);
-
}
private void assertOnLogContents(File mergedLogFile) throws IOException {
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/SingleHopClientExecutorWithLoggingIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/SingleHopClientExecutorWithLoggingIntegrationTest.java
index 48aa2ae..88f70f1 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/SingleHopClientExecutorWithLoggingIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/SingleHopClientExecutorWithLoggingIntegrationTest.java
@@ -28,12 +28,13 @@ import org.junit.contrib.java.lang.system.SystemOutRule;
import org.junit.experimental.categories.Category;
import org.apache.geode.test.junit.categories.ClientServerTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Test if exceptions are logged when thread is submitted using
* {@code SingleHopClientExecutor#submitTask} method.
*/
-@Category(ClientServerTest.class)
+@Category({ClientServerTest.class, LoggingTest.class})
public class SingleHopClientExecutorWithLoggingIntegrationTest {
@Rule
@@ -62,5 +63,4 @@ public class SingleHopClientExecutorWithLoggingIntegrationTest {
await().atMost(2, MINUTES)
.untilAsserted(() -> assertThat(systemErrRule.getLog()).contains(message));
}
-
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherRemoteWithCustomLoggingIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherRemoteWithCustomLoggingIntegrationTest.java
index 136211c..3299bbb 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherRemoteWithCustomLoggingIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherRemoteWithCustomLoggingIntegrationTest.java
@@ -14,8 +14,8 @@
*/
package org.apache.geode.distributed;
-import static org.apache.geode.internal.logging.log4j.custom.CustomConfiguration.CONFIG_LAYOUT_PREFIX;
-import static org.apache.geode.internal.logging.log4j.custom.CustomConfiguration.createConfigFileIn;
+import static org.apache.geode.test.util.ResourceUtils.createFileFromResource;
+import static org.apache.geode.test.util.ResourceUtils.getResource;
import static org.apache.logging.log4j.core.config.ConfigurationFactory.CONFIGURATION_FILE_PROPERTY;
import static org.assertj.core.api.Assertions.assertThat;
@@ -27,17 +27,23 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemOutRule;
+import org.junit.experimental.categories.Category;
import org.apache.geode.distributed.LocatorLauncher.Command;
import org.apache.geode.internal.process.ProcessStreamReader.InputListener;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Integration tests for using {@code LocatorLauncher} as an application main in a forked JVM with
* custom logging configuration.
*/
+@Category({GfshTest.class, LoggingTest.class})
public class LocatorLauncherRemoteWithCustomLoggingIntegrationTest
extends LocatorLauncherRemoteIntegrationTestCase {
+ private static final String CONFIG_LAYOUT_PREFIX = "CUSTOM";
+
private File customLoggingConfigFile;
@Rule
@@ -45,17 +51,19 @@ public class LocatorLauncherRemoteWithCustomLoggingIntegrationTest
@Before
public void setUpLocatorLauncherRemoteWithCustomLoggingIntegrationTest() throws Exception {
- this.customLoggingConfigFile = createConfigFileIn(getWorkingDirectory());
+ String configFileName = getClass().getSimpleName() + "_log4j2.xml";
+ customLoggingConfigFile = createFileFromResource(getResource(configFileName),
+ getWorkingDirectory(), configFileName);
}
@Test
- public void startWithCustomLoggingConfiguration() throws Exception {
+ public void startWithCustomLoggingConfiguration() {
startLocator(new LocatorCommand(this)
.addJvmArgument("-D" + CONFIGURATION_FILE_PROPERTY + "=" + getCustomLoggingConfigFilePath())
.withCommand(Command.START), new ToSystemOut(), new ToSystemOut());
assertThat(systemOutRule.getLog()).contains(CONFIG_LAYOUT_PREFIX)
- .contains("log4j.configurationFile = " + getCustomLoggingConfigFilePath());
+ .contains(CONFIGURATION_FILE_PROPERTY + " = " + getCustomLoggingConfigFilePath());
}
private String getCustomLoggingConfigFilePath() {
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherRemoteWithCustomLoggingIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherRemoteWithCustomLoggingIntegrationTest.java
index 2794304..760f700 100755
--- a/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherRemoteWithCustomLoggingIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherRemoteWithCustomLoggingIntegrationTest.java
@@ -14,8 +14,8 @@
*/
package org.apache.geode.distributed;
-import static org.apache.geode.internal.logging.log4j.custom.CustomConfiguration.CONFIG_LAYOUT_PREFIX;
-import static org.apache.geode.internal.logging.log4j.custom.CustomConfiguration.createConfigFileIn;
+import static org.apache.geode.test.util.ResourceUtils.createFileFromResource;
+import static org.apache.geode.test.util.ResourceUtils.getResource;
import static org.apache.logging.log4j.core.config.ConfigurationFactory.CONFIGURATION_FILE_PROPERTY;
import static org.assertj.core.api.Assertions.assertThat;
@@ -27,16 +27,22 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemOutRule;
+import org.junit.experimental.categories.Category;
import org.apache.geode.distributed.ServerLauncher.Command;
import org.apache.geode.internal.process.ProcessStreamReader.InputListener;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Integration tests for launching a Server in a forked process with custom logging configuration
*/
+@Category({GfshTest.class, LoggingTest.class})
public class ServerLauncherRemoteWithCustomLoggingIntegrationTest
extends ServerLauncherRemoteIntegrationTestCase {
+ private static final String CONFIG_LAYOUT_PREFIX = "CUSTOM";
+
private File customLoggingConfigFile;
@Rule
@@ -44,7 +50,9 @@ public class ServerLauncherRemoteWithCustomLoggingIntegrationTest
@Before
public void setUpServerLauncherRemoteWithCustomLoggingIntegrationTest() throws Exception {
- this.customLoggingConfigFile = createConfigFileIn(getWorkingDirectory());
+ String configFileName = getClass().getSimpleName() + "_log4j2.xml";
+ customLoggingConfigFile = createFileFromResource(getResource(configFileName),
+ getWorkingDirectory(), configFileName);
}
@Test
@@ -55,7 +63,7 @@ public class ServerLauncherRemoteWithCustomLoggingIntegrationTest
new ToSystemOut(), new ToSystemOut());
assertThat(systemOutRule.getLog())
- .contains("log4j.configurationFile = " + getCustomLoggingConfigFilePath());
+ .contains(CONFIGURATION_FILE_PROPERTY + " = " + getCustomLoggingConfigFilePath());
assertThat(systemOutRule.getLog()).contains(CONFIG_LAYOUT_PREFIX);
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/CacheLogRollingIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/CacheLogRollingIntegrationTest.java
index 3728007..278a95f 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/CacheLogRollingIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/CacheLogRollingIntegrationTest.java
@@ -46,7 +46,7 @@ import org.apache.geode.test.junit.categories.LoggingTest;
*
* @since GemFire 6.5
*/
-@Category({LoggingTest.class})
+@Category(LoggingTest.class)
public class CacheLogRollingIntegrationTest {
private static final int MAX_LOG_STATEMENTS = 100000;
@@ -67,29 +67,29 @@ public class CacheLogRollingIntegrationTest {
@Before
public void before() throws Exception {
- this.baseName = this.testName.getMethodName();
- this.dir = this.temporaryFolder.getRoot();
- this.logFile = new File(this.dir, logFileName());
- this.securityLogFile = new File(this.dir, securityLogFileName());
- this.mainIdPattern = Pattern.compile("meta-" + this.baseName + "-\\d\\d.log");
+ baseName = testName.getMethodName();
+ dir = temporaryFolder.getRoot();
+ logFile = new File(dir, logFileName());
+ securityLogFile = new File(dir, securityLogFileName());
+ mainIdPattern = Pattern.compile("meta-" + baseName + "-\\d\\d.log");
}
@After
public void after() throws Exception {
- if (this.system != null) {
- this.system.disconnect();
+ if (system != null) {
+ system.disconnect();
}
}
@Test
public void testSimpleStartRestartWithRolling() throws Exception {
Properties config = createConfig();
- config.put(LOG_FILE, this.logFile.getAbsolutePath());
+ config.put(LOG_FILE, logFile.getAbsolutePath());
config.put(LOG_FILE_SIZE_LIMIT, "1");
config.put(LOG_DISK_SPACE_LIMIT, "200");
- this.system = DistributedSystem.connect(config);
- this.system.disconnect();
+ system = DistributedSystem.connect(config);
+ system.disconnect();
for (int mainInt = 2; mainInt <= 4; mainInt++) {
assertThat(metaFile(mainInt - 1)).exists();
@@ -100,49 +100,49 @@ public class CacheLogRollingIntegrationTest {
assertThat(newMetaFile).doesNotExist();
assertThat(newRolledLogFile).doesNotExist();
- this.system = DistributedSystem.connect(config);
+ system = DistributedSystem.connect(config);
assertThat(newMetaFile).exists();
assertThat(newRolledLogFile).exists();
- this.system.disconnect();
+ system.disconnect();
}
}
@Test
public void testStartWithRollingThenRestartWithRolling() throws Exception {
Properties config = createConfig();
- config.put(LOG_FILE, this.logFile.getAbsolutePath());
+ config.put(LOG_FILE, logFile.getAbsolutePath());
config.put(LOG_FILE_SIZE_LIMIT, "1");
- this.system = DistributedSystem.connect(config);
+ system = DistributedSystem.connect(config);
logAndRollAndVerify(1);
- DistributedSystem firstSystem = this.system;
+ DistributedSystem firstSystem = system;
- assertThat(this.logFile).exists();
+ assertThat(logFile).exists();
assertThat(childFile(1, 1)).exists();
assertThat(childFile(1, 2)).exists();
assertThat(childFile(1, 3)).doesNotExist();
assertThat(childFile(2, 1)).doesNotExist();
- this.system.disconnect();
+ system.disconnect();
config.put(LOG_DISK_SPACE_LIMIT, "200");
- this.system = DistributedSystem.connect(config);
+ system = DistributedSystem.connect(config);
- assertThat(this.system).isNotSameAs(firstSystem);
+ assertThat(system).isNotSameAs(firstSystem);
assertThat(childFile(1, 3)).exists();
}
@Test
public void testLogFileLayoutAndRolling() throws Exception {
Properties config = createConfig();
- config.put(LOG_FILE, this.logFile.getAbsolutePath());
+ config.put(LOG_FILE, logFile.getAbsolutePath());
config.put(LOG_FILE_SIZE_LIMIT, "1");
- this.system = DistributedSystem.connect(config);
+ system = DistributedSystem.connect(config);
logAndRollAndVerify(1);
}
@@ -150,11 +150,11 @@ public class CacheLogRollingIntegrationTest {
@Test
public void testSecurityLogFileLayoutAndRolling() throws Exception {
Properties config = createConfig();
- config.put(LOG_FILE, this.logFile.getAbsolutePath());
+ config.put(LOG_FILE, logFile.getAbsolutePath());
config.put(LOG_FILE_SIZE_LIMIT, "1");
- config.put(SECURITY_LOG_FILE, this.securityLogFile.getAbsolutePath());
+ config.put(SECURITY_LOG_FILE, securityLogFile.getAbsolutePath());
- this.system = DistributedSystem.connect(config);
+ system = DistributedSystem.connect(config);
securityLogAndRollAndVerify(1);
}
@@ -162,13 +162,13 @@ public class CacheLogRollingIntegrationTest {
@Test
public void with_logFileSizeLimit_should_createMetaLogFile() throws Exception {
Properties config = createConfig();
- config.put(LOG_FILE, this.logFile.getAbsolutePath());
+ config.put(LOG_FILE, logFile.getAbsolutePath());
config.put(LOG_FILE_SIZE_LIMIT, "1");
- this.system = DistributedSystem.connect(config);
+ system = DistributedSystem.connect(config);
File[] metaLogsMatched =
- this.dir.listFiles((dir, name) -> mainIdPattern.matcher(name).matches());
+ dir.listFiles((dir, name) -> mainIdPattern.matcher(name).matches());
assertThat(metaLogsMatched).hasSize(1);
File metaLogFile = metaFile(1);
@@ -178,12 +178,12 @@ public class CacheLogRollingIntegrationTest {
@Test
public void without_logFileSizeLimit_shouldNot_createMetaLogFile() throws Exception {
Properties config = createConfig();
- config.put(LOG_FILE, this.logFile.getAbsolutePath());
+ config.put(LOG_FILE, logFile.getAbsolutePath());
- this.system = DistributedSystem.connect(config);
+ system = DistributedSystem.connect(config);
File[] metaLogsMatched =
- this.dir.listFiles((dir, name) -> mainIdPattern.matcher(name).matches());
+ dir.listFiles((dir, name) -> mainIdPattern.matcher(name).matches());
assertThat(metaLogsMatched).hasSize(0);
File metaLogFile = metaFile(12);
@@ -227,23 +227,23 @@ public class CacheLogRollingIntegrationTest {
File childLogFile01 = childFile(mainId, 1);
File childLogFile02 = childFile(mainId, 2);
- String switchingToLog = "Switching to log " + this.logFile;
+ String switchingToLog = "Switching to log " + logFile;
String rollingCurrentLogTo01 = "Rolling current log to " + childLogFile01;
String rollingCurrentLogTo02 = "Rolling current log to " + childLogFile02;
String messageInChild = "hey im the first child";
String messagePrefix = "hey whatsup i can't believe it wow ";
- this.system.getLogWriter().info(messageInChild);
+ system.getLogWriter().info(messageInChild);
- assertThat(this.logFile).exists();
+ assertThat(logFile).exists();
assertThat(metaLogFile).exists();
assertThat(childLogFile01).doesNotExist();
assertThat(childLogFile02).doesNotExist();
assertThat(readContents(metaLogFile)).contains(switchingToLog);
- assertThat(readContents(this.logFile)).contains(messageInChild);
+ assertThat(readContents(logFile)).contains(messageInChild);
- logUntilFileExists(this.system.getLogWriter(), messagePrefix, childLogFile02);
+ logUntilFileExists(system.getLogWriter(), messagePrefix, childLogFile02);
assertThat(childLogFile01).exists();
assertThat(childLogFile02).exists();
@@ -253,7 +253,7 @@ public class CacheLogRollingIntegrationTest {
assertThat(metaLogContents).contains(rollingCurrentLogTo02);
assertThat(metaLogContents).doesNotContain(messagePrefix);
- assertThat(readContents(this.logFile)).contains(messagePrefix);
+ assertThat(readContents(logFile)).contains(messagePrefix);
assertThat(readContents(childLogFile01)).contains(messagePrefix);
assertThat(readContents(childLogFile02)).contains(messagePrefix);
}
@@ -273,7 +273,7 @@ public class CacheLogRollingIntegrationTest {
File childSecurityLogFile01 = childSecurityFile(mainId, 1);
File childSecurityLogFile02 = childSecurityFile(mainId, 2);
- String switchingToLog = "Switching to log " + this.logFile;
+ String switchingToLog = "Switching to log " + logFile;
String rollingCurrentLogTo01 = "Rolling current log to " + childLogFile01;
String rollingCurrentLogTo02 = "Rolling current log to " + childLogFile02;
@@ -281,12 +281,12 @@ public class CacheLogRollingIntegrationTest {
String messageInSecurityChild = "hey im the first security child";
String messagePrefix = "hey whatsup i can't believe it wow ";
- this.system.getLogWriter().info(messageInChild);
- this.system.getSecurityLogWriter().info(messageInSecurityChild);
+ system.getLogWriter().info(messageInChild);
+ system.getSecurityLogWriter().info(messageInSecurityChild);
- assertThat(readContents(this.logFile)).contains(messageInChild)
+ assertThat(readContents(logFile)).contains(messageInChild)
.doesNotContain(messageInSecurityChild);
- assertThat(readContents(this.securityLogFile)).contains(messageInSecurityChild)
+ assertThat(readContents(securityLogFile)).contains(messageInSecurityChild)
.doesNotContain(messageInChild);
assertThat(readContents(metaLogFile)).contains(switchingToLog);
@@ -296,11 +296,11 @@ public class CacheLogRollingIntegrationTest {
assertThat(childLogFile02).doesNotExist();
assertThat(childSecurityLogFile02).doesNotExist();
- logUntilFileExists(this.system.getLogWriter(), messagePrefix, childLogFile02);
- logUntilFileExists(this.system.getSecurityLogWriter(), messagePrefix, childSecurityLogFile02);
+ logUntilFileExists(system.getLogWriter(), messagePrefix, childLogFile02);
+ logUntilFileExists(system.getSecurityLogWriter(), messagePrefix, childSecurityLogFile02);
- assertThat(readContents(this.logFile)).contains(messagePrefix);
- assertThat(readContents(this.securityLogFile)).contains(messagePrefix);
+ assertThat(readContents(logFile)).contains(messagePrefix);
+ assertThat(readContents(securityLogFile)).contains(messagePrefix);
String metaLogContents = readContents(metaLogFile);
assertThat(metaLogContents).contains(rollingCurrentLogTo01);
@@ -326,36 +326,35 @@ public class CacheLogRollingIntegrationTest {
}
private String logFileName() {
- return this.baseName + ".log";
+ return baseName + ".log";
}
private String securityLogFileName() {
- return SECURITY_PREFIX + this.baseName + ".log";
+ return SECURITY_PREFIX + baseName + ".log";
}
private String metaFileName(int mainId) {
- return "meta-" + this.baseName + "-" + formatId(mainId) + ".log";
+ return "meta-" + baseName + "-" + formatId(mainId) + ".log";
}
private File metaFile(int mainId) {
- return new File(this.dir, metaFileName(mainId));
+ return new File(dir, metaFileName(mainId));
}
private String childFileName(int mainId, int childId) {
- return this.baseName + "-" + formatId(mainId) + "-" + formatId(childId) + ".log";
+ return baseName + "-" + formatId(mainId) + "-" + formatId(childId) + ".log";
}
private File childFile(int mainId, int childId) {
- return new File(this.dir, childFileName(mainId, childId));
+ return new File(dir, childFileName(mainId, childId));
}
private String childSecurityFileName(int mainId, int childId) {
- return SECURITY_PREFIX + this.baseName + "-" + formatId(mainId) + "-" + formatId(childId)
+ return SECURITY_PREFIX + baseName + "-" + formatId(mainId) + "-" + formatId(childId)
+ ".log";
}
private File childSecurityFile(int mainId, int childId) {
- return new File(this.dir, childSecurityFileName(mainId, childId));
+ return new File(dir, childSecurityFileName(mainId, childId));
}
-
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/DistributedSystemLogFileJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/DistributedSystemLogFileIntegrationTest.java
similarity index 97%
rename from geode-core/src/integrationTest/java/org/apache/geode/internal/logging/DistributedSystemLogFileJUnitTest.java
rename to geode-core/src/integrationTest/java/org/apache/geode/internal/logging/DistributedSystemLogFileIntegrationTest.java
index a1dbe41..07456ba 100755
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/DistributedSystemLogFileJUnitTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/DistributedSystemLogFileIntegrationTest.java
@@ -57,27 +57,26 @@ import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Connects DistributedSystem and tests logging behavior at a high level.
- *
*/
-@Category({LoggingTest.class})
-public class DistributedSystemLogFileJUnitTest {
- @Rule
- public TestName name = new TestName();
+@Category(LoggingTest.class)
+public class DistributedSystemLogFileIntegrationTest {
- protected static final int TIMEOUT_MILLISECONDS = 180 * 1000; // 2 minutes
- protected static final int INTERVAL_MILLISECONDS = 100; // 100 milliseconds
+ private static final int TIMEOUT_MILLISECONDS = 180 * 1000; // 2 minutes
+ private static final int INTERVAL_MILLISECONDS = 100; // 100 milliseconds
private DistributedSystem system;
+ @Rule
+ public TestName name = new TestName();
@Before
public void setUp() throws Exception {}
@After
public void tearDown() throws Exception {
- if (this.system != null) {
- this.system.disconnect();
- this.system = null;
+ if (system != null) {
+ system.disconnect();
+ system = null;
}
// We will want to remove this at some point but right now the log context
// does not clear out the security logconfig between tests
@@ -105,10 +104,10 @@ public class DistributedSystemLogFileJUnitTest {
}
assertFalse(logFile.exists());
- this.system = DistributedSystem.connect(properties);
- assertNotNull(this.system);
+ system = DistributedSystem.connect(properties);
+ assertNotNull(system);
- DistributionConfig config = ((InternalDistributedSystem) this.system).getConfig();
+ DistributionConfig config = ((InternalDistributedSystem) system).getConfig();
assertEquals(
"Expected " + LogWriterImpl.levelToString(InternalLogWriter.CONFIG_LEVEL) + " but was "
+ LogWriterImpl.levelToString(config.getLogLevel()),
@@ -500,8 +499,8 @@ public class DistributedSystemLogFileJUnitTest {
assertTrue(fileContainsString(logFile, FATAL_STRING_A));
}
- this.system.disconnect();
- this.system = null;
+ system.disconnect();
+ system = null;
}
@Test
@@ -525,10 +524,10 @@ public class DistributedSystemLogFileJUnitTest {
}
assertFalse(logFile.exists());
- this.system = DistributedSystem.connect(properties);
- assertNotNull(this.system);
+ system = DistributedSystem.connect(properties);
+ assertNotNull(system);
- DistributionConfig config = ((InternalDistributedSystem) this.system).getConfig();
+ DistributionConfig config = ((InternalDistributedSystem) system).getConfig();
assertEquals(
"Expected " + LogWriterImpl.levelToString(InternalLogWriter.FINE_LEVEL) + " but was "
+ LogWriterImpl.levelToString(config.getLogLevel()),
@@ -737,8 +736,8 @@ public class DistributedSystemLogFileJUnitTest {
assertTrue(fileContainsString(logFile, FATAL_STRING));
}
- this.system.disconnect();
- this.system = null;
+ system.disconnect();
+ system = null;
}
@Test
@@ -762,10 +761,10 @@ public class DistributedSystemLogFileJUnitTest {
}
assertFalse(logFile.exists());
- this.system = DistributedSystem.connect(properties);
- assertNotNull(this.system);
+ system = DistributedSystem.connect(properties);
+ assertNotNull(system);
- DistributionConfig config = ((InternalDistributedSystem) this.system).getConfig();
+ DistributionConfig config = ((InternalDistributedSystem) system).getConfig();
assertEquals(
"Expected " + LogWriterImpl.levelToString(InternalLogWriter.FINE_LEVEL) + " but was "
+ LogWriterImpl.levelToString(config.getLogLevel()),
@@ -974,8 +973,8 @@ public class DistributedSystemLogFileJUnitTest {
assertTrue(fileContainsString(logFile, FATAL_STRING));
}
- this.system.disconnect();
- this.system = null;
+ system.disconnect();
+ system = null;
}
@Test
@@ -1008,10 +1007,10 @@ public class DistributedSystemLogFileJUnitTest {
}
assertFalse(logFile.exists());
- this.system = DistributedSystem.connect(properties);
- assertNotNull(this.system);
+ system = DistributedSystem.connect(properties);
+ assertNotNull(system);
- DistributionConfig config = ((InternalDistributedSystem) this.system).getConfig();
+ DistributionConfig config = ((InternalDistributedSystem) system).getConfig();
assertEquals(
"Expected " + LogWriterImpl.levelToString(InternalLogWriter.CONFIG_LEVEL) + " but was "
+ LogWriterImpl.levelToString(config.getLogLevel()),
@@ -1021,7 +1020,6 @@ public class DistributedSystemLogFileJUnitTest {
+ LogWriterImpl.levelToString(config.getLogLevel()),
InternalLogWriter.FINE_LEVEL, config.getLogLevel());
-
InternalLogWriter securityLogWriter = (InternalLogWriter) system.getSecurityLogWriter();
InternalLogWriter logWriter = (InternalLogWriter) system.getLogWriter();
assertNotNull(securityLogWriter);
@@ -1049,7 +1047,6 @@ public class DistributedSystemLogFileJUnitTest {
assertTrue(((FastLogger) securityLogWriter).isDelegating());
assertTrue(((FastLogger) logWriter).isDelegating());
-
Wait.waitForCriterion(new WaitCriterion() {
@Override
public boolean done() {
@@ -1103,8 +1100,8 @@ public class DistributedSystemLogFileJUnitTest {
assertTrue(fileContainsString(logFile, FINE_STRING_FOR_LOGGER));
}
- this.system.disconnect();
- this.system = null;
+ system.disconnect();
+ system = null;
}
@Test
@@ -1138,10 +1135,10 @@ public class DistributedSystemLogFileJUnitTest {
}
assertFalse(logFile.exists());
- this.system = DistributedSystem.connect(properties);
- assertNotNull(this.system);
+ system = DistributedSystem.connect(properties);
+ assertNotNull(system);
- DistributionConfig config = ((InternalDistributedSystem) this.system).getConfig();
+ DistributionConfig config = ((InternalDistributedSystem) system).getConfig();
assertEquals(
"Expected " + LogWriterImpl.levelToString(InternalLogWriter.FINE_LEVEL) + " but was "
+ LogWriterImpl.levelToString(config.getLogLevel()),
@@ -1151,7 +1148,6 @@ public class DistributedSystemLogFileJUnitTest {
+ LogWriterImpl.levelToString(config.getLogLevel()),
InternalLogWriter.FINE_LEVEL, config.getLogLevel());
-
InternalLogWriter securityLogWriter = (InternalLogWriter) system.getSecurityLogWriter();
InternalLogWriter logWriter = (InternalLogWriter) system.getLogWriter();
assertNotNull(securityLogWriter);
@@ -1293,8 +1289,8 @@ public class DistributedSystemLogFileJUnitTest {
assertTrue(fileContainsString(logFile, FATAL_STRING));
}
- this.system.disconnect();
- this.system = null;
+ system.disconnect();
+ system = null;
}
/**
@@ -1325,10 +1321,10 @@ public class DistributedSystemLogFileJUnitTest {
}
assertFalse(logFile.exists());
- this.system = DistributedSystem.connect(properties);
- assertNotNull(this.system);
+ system = DistributedSystem.connect(properties);
+ assertNotNull(system);
- DistributionConfig config = ((InternalDistributedSystem) this.system).getConfig();
+ DistributionConfig config = ((InternalDistributedSystem) system).getConfig();
assertEquals(
"Expected " + LogWriterImpl.levelToString(InternalLogWriter.INFO_LEVEL) + " but was "
+ LogWriterImpl.levelToString(config.getLogLevel()),
@@ -1338,7 +1334,6 @@ public class DistributedSystemLogFileJUnitTest {
+ LogWriterImpl.levelToString(config.getLogLevel()),
InternalLogWriter.FINE_LEVEL, config.getLogLevel());
-
InternalLogWriter securityLogWriter = (InternalLogWriter) system.getSecurityLogWriter();
InternalLogWriter logWriter = (InternalLogWriter) system.getLogWriter();
assertNotNull(securityLogWriter);
@@ -1457,8 +1452,8 @@ public class DistributedSystemLogFileJUnitTest {
assertTrue(fileContainsString(logFile, FATAL_STRING));
}
- this.system.disconnect();
- this.system = null;
+ system.disconnect();
+ system = null;
}
/**
@@ -1489,10 +1484,10 @@ public class DistributedSystemLogFileJUnitTest {
}
assertFalse(logFile.exists());
- this.system = DistributedSystem.connect(properties);
- assertNotNull(this.system);
+ system = DistributedSystem.connect(properties);
+ assertNotNull(system);
- DistributionConfig config = ((InternalDistributedSystem) this.system).getConfig();
+ DistributionConfig config = ((InternalDistributedSystem) system).getConfig();
assertEquals(
"Expected " + LogWriterImpl.levelToString(InternalLogWriter.FINE_LEVEL) + " but was "
+ LogWriterImpl.levelToString(config.getLogLevel()),
@@ -1621,11 +1616,10 @@ public class DistributedSystemLogFileJUnitTest {
assertTrue(fileContainsString(logFile, FATAL_STRING));
}
- this.system.disconnect();
- this.system = null;
+ system.disconnect();
+ system = null;
}
-
private static boolean fileContainsString(final File file, final String string)
throws FileNotFoundException {
Scanner scanner = new Scanner(file);
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LocatorLogFileJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LocatorLogFileIntegrationTest.java
similarity index 87%
rename from geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LocatorLogFileJUnitTest.java
rename to geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LocatorLogFileIntegrationTest.java
index 557740f..e20db9c 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LocatorLogFileJUnitTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LocatorLogFileIntegrationTest.java
@@ -48,11 +48,11 @@ import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Creates Locator and tests logging behavior at a high level.
*/
-@Category({LoggingTest.class})
-public class LocatorLogFileJUnitTest {
+@Category(LoggingTest.class)
+public class LocatorLogFileIntegrationTest {
- protected static final int TIMEOUT_MILLISECONDS = 180 * 1000; // 2 minutes
- protected static final int INTERVAL_MILLISECONDS = 100; // 100 milliseconds
+ private static final int TIMEOUT_MILLISECONDS = 180 * 1000; // 2 minutes
+ private static final int INTERVAL_MILLISECONDS = 100; // 100 milliseconds
private Locator locator;
private FileInputStream fis;
@@ -62,9 +62,9 @@ public class LocatorLogFileJUnitTest {
@After
public void tearDown() throws Exception {
- if (this.locator != null) {
- this.locator.stop();
- this.locator = null;
+ if (locator != null) {
+ locator.stop();
+ locator = null;
}
if (fis != null) {
fis.close();
@@ -91,9 +91,9 @@ public class LocatorLogFileJUnitTest {
}
assertFalse(logFile.exists());
- this.locator = Locator.startLocatorAndDS(port, logFile, properties);
+ locator = Locator.startLocatorAndDS(port, logFile, properties);
- InternalDistributedSystem ds = (InternalDistributedSystem) this.locator.getDistributedSystem();
+ InternalDistributedSystem ds = (InternalDistributedSystem) locator.getDistributedSystem();
assertNotNull(ds);
DistributionConfig config = ds.getConfig();
assertNotNull(config);
@@ -111,7 +111,7 @@ public class LocatorLogFileJUnitTest {
+ LogWriterImpl.levelToString(logWriter.getLogWriterLevel()),
InternalLogWriter.INFO_LEVEL, logWriter.getLogWriterLevel());
- assertNotNull(this.locator);
+ assertNotNull(locator);
Wait.waitForCriterion(new WaitCriterion() {
@Override
public boolean done() {
@@ -125,11 +125,11 @@ public class LocatorLogFileJUnitTest {
}, TIMEOUT_MILLISECONDS, INTERVAL_MILLISECONDS, true);
assertTrue(logFile.exists());
// assert not empty
- this.fis = new FileInputStream(logFile);
+ fis = new FileInputStream(logFile);
assertTrue(fis.available() > 0);
- this.locator.stop();
- this.locator = null;
- this.fis.close();
- this.fis = null;
+ locator.stop();
+ locator = null;
+ fis.close();
+ fis = null;
}
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LogServiceIntegrationJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LogServiceIntegrationTest.java
similarity index 90%
rename from geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LogServiceIntegrationJUnitTest.java
rename to geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LogServiceIntegrationTest.java
index 3bb0359..2f94dc3 100755
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LogServiceIntegrationJUnitTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/LogServiceIntegrationTest.java
@@ -40,10 +40,9 @@ import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Integration tests for LogService and how it configures and uses log4j2
- *
*/
-@Category({LoggingTest.class})
-public class LogServiceIntegrationJUnitTest {
+@Category(LoggingTest.class)
+public class LogServiceIntegrationTest {
private static final String DEFAULT_CONFIG_FILE_NAME = "log4j2.xml";
private static final String CLI_CONFIG_FILE_NAME = "log4j2-cli.xml";
@@ -94,20 +93,20 @@ public class LogServiceIntegrationJUnitTest {
@Before
public void setUp() {
- this.defaultConfigUrl = LogService.class.getResource(LogService.DEFAULT_CONFIG);
- this.cliConfigUrl = LogService.class.getResource(LogService.CLI_CONFIG);
+ defaultConfigUrl = LogService.class.getResource(LogService.DEFAULT_CONFIG);
+ cliConfigUrl = LogService.class.getResource(LogService.CLI_CONFIG);
}
@After
public void after() {
// if either of these fail then log4j2 probably logged a failure to stdout
- assertThat(this.systemErrRule.getLog()).isEmpty();
- assertThat(this.systemOutRule.getLog()).isEmpty();
+ assertThat(systemErrRule.getLog()).isEmpty();
+ assertThat(systemOutRule.getLog()).isEmpty();
}
@Test
public void shouldPreferConfigurationFilePropertyIfSet() throws Exception {
- final File configFile = this.temporaryFolder.newFile(DEFAULT_CONFIG_FILE_NAME);
+ final File configFile = temporaryFolder.newFile(DEFAULT_CONFIG_FILE_NAME);
final String configFileName = configFile.toURI().toString();
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configFileName);
writeConfigFile(configFile, Level.DEBUG);
@@ -122,7 +121,7 @@ public class LogServiceIntegrationJUnitTest {
}
@Test
- public void shouldUseDefaultConfigIfNotConfigured() throws Exception {
+ public void shouldUseDefaultConfigIfNotConfigured() {
LogService.reconfigure();
assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigurationInfo())
@@ -192,23 +191,23 @@ public class LogServiceIntegrationJUnitTest {
}
@Test
- public void shouldNotUseDefaultConfigIfCliConfigSpecified() throws Exception {
+ public void shouldNotUseDefaultConfigIfCliConfigSpecified() {
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
- this.cliConfigUrl.toString());
+ cliConfigUrl.toString());
LogService.reconfigure();
assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigurationInfo())
.isFalse();
assertThat(System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY))
- .isEqualTo(this.cliConfigUrl.toString());
+ .isEqualTo(cliConfigUrl.toString());
assertThat(LogService.getLogger().getName()).isEqualTo(getClass().getName());
}
@Test
- public void isUsingGemFireDefaultConfigShouldBeTrueIfDefaultConfig() throws Exception {
+ public void isUsingGemFireDefaultConfigShouldBeTrueIfDefaultConfig() {
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
- this.defaultConfigUrl.toString());
+ defaultConfigUrl.toString());
assertThat(LogService.getConfiguration().getConfigurationSource().toString())
.contains(DEFAULT_CONFIG_FILE_NAME);
@@ -216,9 +215,9 @@ public class LogServiceIntegrationJUnitTest {
}
@Test
- public void isUsingGemFireDefaultConfigShouldBeFalseIfCliConfig() throws Exception {
+ public void isUsingGemFireDefaultConfigShouldBeFalseIfCliConfig() {
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
- this.cliConfigUrl.toString());
+ cliConfigUrl.toString());
assertThat(LogService.getConfiguration().getConfigurationSource().toString())
.doesNotContain(DEFAULT_CONFIG_FILE_NAME);
@@ -226,7 +225,7 @@ public class LogServiceIntegrationJUnitTest {
}
@Test
- public void shouldUseCliConfigIfCliConfigIsSpecifiedViaClasspath() throws Exception {
+ public void shouldUseCliConfigIfCliConfigIsSpecifiedViaClasspath() {
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
"classpath:" + CLI_CONFIG_FILE_NAME);
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/MergeLogFilesJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/MergeLogFilesIntegrationTest.java
similarity index 89%
rename from geode-core/src/integrationTest/java/org/apache/geode/internal/logging/MergeLogFilesJUnitTest.java
rename to geode-core/src/integrationTest/java/org/apache/geode/internal/logging/MergeLogFilesIntegrationTest.java
index bf99ea5..ba2a293 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/MergeLogFilesJUnitTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/MergeLogFilesIntegrationTest.java
@@ -21,7 +21,6 @@ import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
@@ -46,24 +45,19 @@ import org.apache.geode.test.junit.categories.LoggingTest;
/**
* This class tests the functionality of the (new multi-threaded) {@link MergeLogFiles} utility.
- *
- *
*/
-@Category({LoggingTest.class})
-public class MergeLogFilesJUnitTest {
-
- //////// Test Methods
+@Category(LoggingTest.class)
+public class MergeLogFilesIntegrationTest {
/** The next integer to be written to the log */
- protected int next = 0;
+ private int next;
/**
* A bunch of threads write a strictly increasing integer to log "files" stored in byte arrays.
* The files are merged and the order is verified.
*/
@Test
- public void testMultipleThreads() throws InterruptedException, IOException {
-
+ public void testMultipleThreads() throws Exception {
// Spawn a bunch of threads that write to a log
WorkerGroup group = new WorkerGroup("Workers");
List workers = new ArrayList();
@@ -118,7 +112,7 @@ public class MergeLogFilesJUnitTest {
/**
* A <code>ThreadGroup</code> for workers
*/
- static class WorkerGroup extends ThreadGroup {
+ private static class WorkerGroup extends ThreadGroup {
/**
* Did an uncaught exception occur in one of this group's threads?
*/
@@ -128,16 +122,17 @@ public class MergeLogFilesJUnitTest {
* A <code>StringBuffer</code> containing a description of the uncaught exceptions thrown by the
* worker threads.
*/
- private StringBuffer sb;
+ private final StringBuffer sb;
/**
* Creates a new <code>WorkerGroup</code> with the given name
*/
- public WorkerGroup(String name) {
+ WorkerGroup(String name) {
super(name);
sb = new StringBuffer();
}
+ @Override
public void uncaughtException(Thread t, Throwable e) {
if (e instanceof VirtualMachineError) {
SystemFailure.setFailure((VirtualMachineError) e); // don't throw
@@ -157,14 +152,14 @@ public class MergeLogFilesJUnitTest {
* Returns whether or not an uncaught exception occurred in one of the worker threads.
*/
public boolean exceptionOccurred() {
- return this.exceptionOccurred;
+ return exceptionOccurred;
}
/**
* Returns a string describing the uncaught exception(s) that occurred in the worker threads.
*/
- public String getExceptionString() {
- return this.sb.toString();
+ String getExceptionString() {
+ return sb.toString();
}
}
@@ -172,29 +167,30 @@ public class MergeLogFilesJUnitTest {
* Writes a strictly increasing number to a log "file" stored in a byte array. Waits a random
* amount of time between writing entries.
*/
- class Worker extends Thread {
+ private class Worker extends Thread {
/** The input stream for reading from the log file */
private InputStream in;
/** A random number generator */
- private Random random;
+ private final Random random;
/**
* Creates a new <code>Worker</code> with the given name
*/
public Worker(String name, ThreadGroup group) {
super(group, name);
- this.random = new Random();
+ random = new Random();
}
+ @Override
public void run() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
LogWriter logger =
new LocalLogWriter(InternalLogWriter.ALL_LEVEL, new PrintStream(baos, true));
for (int i = 0; i < 100; i++) {
int n;
- synchronized (MergeLogFilesJUnitTest.this) {
- n = MergeLogFilesJUnitTest.this.next++;
+ synchronized (MergeLogFilesIntegrationTest.this) {
+ n = next++;
// Have to log with the lock to guarantee ordering
logger.info("VALUE: " + n);
@@ -229,10 +225,8 @@ public class MergeLogFilesJUnitTest {
/**
* Returns an <code>InputStream</code> for reading from the log that this worker wrote.
*/
- public InputStream getInputStream() {
- return this.in;
+ InputStream getInputStream() {
+ return in;
}
-
}
-
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/ConfigLocatorJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/ConfigLocatorJUnitTest.java
deleted file mode 100755
index 184d8a3..0000000
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/ConfigLocatorJUnitTest.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.internal.logging.log4j;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
-
-import java.io.File;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.junit.AfterClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-
-/**
- * UnitTest for ConfigLocator which is used to find the Log4J 2 configuration file.
- *
- * @since GemFire 8.2
- */
-public class ConfigLocatorJUnitTest {
-
- private static Set<String> suffixesNotFoundTested = new HashSet<String>();
- private static Set<String> suffixesFoundTested = new HashSet<String>();
-
- @Rule
- public TemporaryFolder folder = new TemporaryFolder();
-
- @AfterClass
- public static void afterClass() {
- // ensure that every suffix was tested by Found and NotFound
- Set<String> suffixes = new HashSet<String>(Arrays.asList(ConfigLocator.SUFFIXES));
- try {
- assertEquals(suffixes, suffixesNotFoundTested);
- assertEquals(suffixes, suffixesFoundTested);
- } finally {
- suffixesNotFoundTested = null;
- suffixesFoundTested = null;
- }
- }
-
- @Test
- public void testYamlConfigIsNotFoundWhenNotInClasspath() throws Exception {
- configIsNotFoundWhenNotInClasspath(testingNotFoundSuffix(ConfigLocator.SUFFIX_TEST_YAML));
- }
-
- @Test
- public void testYamlConfigIsFoundWhenInClasspath() throws Exception {
- configIsFoundWhenInClasspath(testingFoundSuffix(ConfigLocator.SUFFIX_TEST_YAML));
- }
-
- @Test
- public void testYmlConfigIsNotFoundWhenNotInClasspath() throws Exception {
- configIsNotFoundWhenNotInClasspath(testingNotFoundSuffix(ConfigLocator.SUFFIX_TEST_YML));
- }
-
- @Test
- public void testYmlConfigIsFoundWhenInClasspath() throws Exception {
- configIsFoundWhenInClasspath(testingFoundSuffix(ConfigLocator.SUFFIX_TEST_YML));
- }
-
- @Test
- public void testJsonConfigIsNotFoundWhenNotInClasspath() throws Exception {
- configIsNotFoundWhenNotInClasspath(testingNotFoundSuffix(ConfigLocator.SUFFIX_TEST_JSON));
- }
-
- @Test
- public void testJsonConfigIsFoundWhenInClasspath() throws Exception {
- configIsFoundWhenInClasspath(testingFoundSuffix(ConfigLocator.SUFFIX_TEST_JSON));
- }
-
- @Test
- public void testJsnConfigIsNotFoundWhenNotInClasspath() throws Exception {
- configIsNotFoundWhenNotInClasspath(testingNotFoundSuffix(ConfigLocator.SUFFIX_TEST_JSN));
- }
-
- @Test
- public void testJsnConfigIsFoundWhenInClasspath() throws Exception {
- configIsFoundWhenInClasspath(testingFoundSuffix(ConfigLocator.SUFFIX_TEST_JSN));
- }
-
- @Test
- public void testXmlConfigIsNotFoundWhenNotInClasspath() throws Exception {
- configIsNotFoundWhenNotInClasspath(testingNotFoundSuffix(ConfigLocator.SUFFIX_TEST_XML));
- }
-
- @Test
- public void testXmlConfigIsFoundWhenInClasspath() throws Exception {
- configIsFoundWhenInClasspath(testingFoundSuffix(ConfigLocator.SUFFIX_TEST_XML));
- }
-
- @Test
- public void yamlConfigIsNotFoundWhenNotInClasspath() throws Exception {
- configIsNotFoundWhenNotInClasspath(testingNotFoundSuffix(ConfigLocator.SUFFIX_YAML));
- }
-
- @Test
- public void yamlConfigIsFoundWhenInClasspath() throws Exception {
- configIsFoundWhenInClasspath(testingFoundSuffix(ConfigLocator.SUFFIX_YAML));
- }
-
- @Test
- public void ymlConfigIsNotFoundWhenNotInClasspath() throws Exception {
- configIsNotFoundWhenNotInClasspath(testingNotFoundSuffix(ConfigLocator.SUFFIX_YML));
- }
-
- @Test
- public void ymlConfigIsFoundWhenInClasspath() throws Exception {
- configIsFoundWhenInClasspath(testingFoundSuffix(ConfigLocator.SUFFIX_YML));
- }
-
- @Test
- public void jsonConfigIsNotFoundWhenNotInClasspath() throws Exception {
- configIsNotFoundWhenNotInClasspath(testingNotFoundSuffix(ConfigLocator.SUFFIX_JSON));
- }
-
- @Test
- public void jsonConfigIsFoundWhenInClasspath() throws Exception {
- configIsFoundWhenInClasspath(testingFoundSuffix(ConfigLocator.SUFFIX_JSON));
- }
-
- @Test
- public void jsnConfigIsNotFoundWhenNotInClasspath() throws Exception {
- configIsNotFoundWhenNotInClasspath(testingNotFoundSuffix(ConfigLocator.SUFFIX_JSN));
- }
-
- @Test
- public void jsnConfigIsFoundWhenInClasspath() throws Exception {
- configIsFoundWhenInClasspath(testingFoundSuffix(ConfigLocator.SUFFIX_JSN));
- }
-
- @Test
- public void xmlConfigIsNotFoundWhenNotInClasspath() throws Exception {
- configIsNotFoundWhenNotInClasspath(testingNotFoundSuffix(ConfigLocator.SUFFIX_XML));
- }
-
- @Test
- public void xmlConfigIsFoundWhenInClasspath() throws Exception {
- configIsFoundWhenInClasspath(testingFoundSuffix(ConfigLocator.SUFFIX_XML));
- }
-
- private String testingNotFoundSuffix(final String suffix) {
- // ensure each suffix is only tested for NotFound once
- assertFalse(suffixesNotFoundTested.contains(suffix));
- suffixesNotFoundTested.add(suffix);
- return suffix;
- }
-
- private String testingFoundSuffix(final String suffix) {
- // ensure each suffix is only tested for Found once
- assertFalse(suffixesFoundTested.contains(suffix));
- suffixesFoundTested.add(suffix);
- return suffix;
- }
-
- private void configIsNotFoundWhenNotInClasspath(final String suffix) throws Exception {
- String fileName = ConfigLocator.PREFIX + suffix;
- assumeTrue(null == getClass().getClassLoader().getResource(fileName));
- assumeTrue(null == ConfigLocator.findConfigInClasspath());
-
- // create xml config file outside of classpath
- File configFile = folder.newFile(fileName);
- assertTrue(configFile.isFile());
-
- // make sure xml config file is not found
- assertNull(ConfigLocator.findConfigInClasspath());
- }
-
- private void configIsFoundWhenInClasspath(final String suffix) throws Exception {
- String fileName = ConfigLocator.PREFIX + suffix;
- assumeTrue(null == getClass().getClassLoader().getResource(fileName));
- assumeTrue(null == ConfigLocator.findConfigInClasspath());
-
- // create config file
- File configFile = folder.newFile(fileName);
- assertTrue(configFile.isFile());
-
- assertNull(ConfigLocator.findConfigInClasspath());
-
- // create class loader
- ClassLoader customLoader = new URLClassLoader(new URL[] {folder.getRoot().toURI().toURL()});
- assertNotNull(customLoader.getResource(fileName));
-
- // temporarily add class loader to the classpath searched by ConfigLocator
- ClassLoader tccl = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(customLoader);
-
- // verify config file can be found in classpath
- URL url = ConfigLocator.findConfigInClasspath();
- assertNotNull(url);
- assertEquals(configFile.toURI().toURL(), url);
- } finally {
- Thread.currentThread().setContextClassLoader(tccl);
- }
-
- assertNull(ConfigLocator.findConfigInClasspath());
- }
-}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/ConsoleAppenderWithLoggerContextRuleIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/ConsoleAppenderWithLoggerContextRuleIntegrationTest.java
new file mode 100644
index 0000000..2001d44
--- /dev/null
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/ConsoleAppenderWithLoggerContextRuleIntegrationTest.java
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geode.internal.logging.log4j;
+
+import static org.apache.geode.test.util.ResourceUtils.createFileFromResource;
+import static org.apache.geode.test.util.ResourceUtils.getResource;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.net.URL;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.LifeCycle;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.appender.DefaultErrorHandler;
+import org.apache.logging.log4j.core.appender.OutputStreamManager;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.SystemErrRule;
+import org.junit.contrib.java.lang.system.SystemOutRule;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+
+import org.apache.geode.test.junit.categories.LoggingTest;
+
+@Category(LoggingTest.class)
+public class ConsoleAppenderWithLoggerContextRuleIntegrationTest {
+
+ private static String configFilePath;
+
+ private Logger postConfigLogger;
+ private String logMessage;
+
+ @ClassRule
+ public static SystemOutRule systemOutRule = new SystemOutRule().enableLog();
+
+ @ClassRule
+ public static SystemErrRule systemErrRule = new SystemErrRule().enableLog();
+
+ @ClassRule
+ public static TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ @Rule
+ public LoggerContextRule loggerContextRule = new LoggerContextRule(configFilePath);
+
+ @BeforeClass
+ public static void setUpLogConfigFile() throws Exception {
+ String configFileName =
+ ConsoleAppenderWithLoggerContextRuleIntegrationTest.class.getSimpleName() + "_log4j2.xml";
+ URL resource = getResource(configFileName);
+ configFilePath = createFileFromResource(resource, temporaryFolder.getRoot(), configFileName)
+ .getAbsolutePath();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ postConfigLogger = LogManager.getLogger();
+ logMessage = "this is a log statement";
+
+ systemOutRule.clearLog();
+ systemErrRule.clearLog();
+ }
+
+ @Test
+ public void delegateConsoleAppenderIsConfigured() {
+ assertThat(loggerContextRule.getListAppender("LIST")).isNotNull();
+
+ ListAppender listAppender = findAppender(ListAppender.class);
+ assertThat(listAppender).isNotNull();
+
+ ConsoleAppender consoleAppender = findAppender(ConsoleAppender.class);
+ assertThat(consoleAppender).isNotNull();
+
+ assertThat(consoleAppender.getFilter()).isNull();
+ assertThat(consoleAppender.getHandler()).isInstanceOf(DefaultErrorHandler.class);
+ assertThat(consoleAppender.getImmediateFlush()).isTrue();
+ assertThat(consoleAppender.getLayout()).isNotNull();
+ assertThat(consoleAppender.getManager()).isInstanceOf(OutputStreamManager.class);
+ assertThat(consoleAppender.getName()).isEqualTo("STDOUT");
+ assertThat(consoleAppender.getState()).isSameAs(LifeCycle.State.STARTED);
+ assertThat(consoleAppender.getTarget()).isSameAs(ConsoleAppender.Target.SYSTEM_OUT);
+
+ OutputStreamManager outputStreamManager = consoleAppender.getManager();
+ assertThat(outputStreamManager.isOpen()).isTrue();
+ assertThat(outputStreamManager.getByteBuffer()).isInstanceOf(ByteBuffer.class);
+ assertThat(outputStreamManager.hasOutputStream()).isTrue();
+ assertThat(outputStreamManager.getContentFormat()).isEmpty();
+ assertThat(outputStreamManager.getLoggerContext()).isNull();
+ assertThat(outputStreamManager.getName()).isEqualTo("SYSTEM_OUT.false.false");
+ }
+
+ @Test
+ public void staticSystemOutRuleCapturesConsoleAppenderOutputFromPostConfigLogger() {
+ postConfigLogger.info(logMessage);
+
+ assertThat(systemOutRule.getLog()).contains(Level.INFO.name().toLowerCase());
+ assertThat(systemOutRule.getLog()).contains(logMessage);
+
+ assertThat(systemErrRule.getLog()).isEmpty();
+ }
+
+ private <T extends Appender> T findAppender(Class<T> appenderClass) {
+ LoggerContext loggerContext =
+ ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger()).getContext();
+ Map<String, Appender> appenders = loggerContext.getConfiguration().getAppenders();
+ List<Class<? extends Appender>> appenderClasses = new ArrayList<>();
+ for (Appender appender : appenders.values()) {
+ appenderClasses.add(appender.getClass());
+ if (appenderClass.isAssignableFrom(appender.getClass())) {
+ return appenderClass.cast(appender);
+ }
+ }
+ assertThat(appenderClasses).contains(appenderClass);
+ return null;
+ }
+}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/ConsoleAppenderWithSystemOutRuleIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/ConsoleAppenderWithSystemOutRuleIntegrationTest.java
new file mode 100644
index 0000000..cadd409
--- /dev/null
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/ConsoleAppenderWithSystemOutRuleIntegrationTest.java
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geode.internal.logging.log4j;
+
+import static org.apache.geode.test.util.ResourceUtils.createFileFromResource;
+import static org.apache.geode.test.util.ResourceUtils.getResource;
+import static org.apache.logging.log4j.core.config.ConfigurationFactory.CONFIGURATION_FILE_PROPERTY;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.LifeCycle;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.appender.DefaultErrorHandler;
+import org.apache.logging.log4j.core.appender.OutputStreamManager;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.SystemErrRule;
+import org.junit.contrib.java.lang.system.SystemOutRule;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+
+import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.test.junit.categories.LoggingTest;
+
+/**
+ * Verifies that we can capture output of {@code ConsoleAppender}. If this behavior changes, then
+ * Geode logging tests may also need to change.
+ */
+@Category(LoggingTest.class)
+public class ConsoleAppenderWithSystemOutRuleIntegrationTest {
+
+ private static final Logger classLoadedLogger = LogManager.getLogger();
+
+ private String beforeConfigFile;
+ private Level beforeLevel;
+
+ private Logger preConfigLogger;
+ private Logger postConfigLogger;
+ private String logMessage;
+
+ @ClassRule
+ public static SystemOutRule systemOutRule = new SystemOutRule().enableLog();
+
+ @ClassRule
+ public static SystemErrRule systemErrRule = new SystemErrRule().enableLog();
+
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ @Before
+ public void setUp() throws Exception {
+ preConfigLogger = LogManager.getLogger();
+
+ Configurator.shutdown();
+
+ beforeConfigFile = System.getProperty(CONFIGURATION_FILE_PROPERTY);
+ beforeLevel = StatusLogger.getLogger().getLevel();
+
+ String configFileName = getClass().getSimpleName() + "_log4j2.xml";
+ File configFile = createFileFromResource(getResource(configFileName),
+ temporaryFolder.getRoot(), configFileName);
+
+ System.setProperty(CONFIGURATION_FILE_PROPERTY, configFile.getAbsolutePath());
+ LogService.reconfigure();
+
+ assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation())
+ .isFalse();
+
+ systemOutRule.clearLog();
+ systemErrRule.clearLog();
+
+ postConfigLogger = LogManager.getLogger();
+ logMessage = "this is a log statement";
+ }
+
+ @After
+ public void tearDown() {
+ Configurator.shutdown();
+
+ System.clearProperty(CONFIGURATION_FILE_PROPERTY);
+ if (beforeConfigFile != null) {
+ System.setProperty(CONFIGURATION_FILE_PROPERTY, beforeConfigFile);
+ }
+ StatusLogger.getLogger().setLevel(beforeLevel);
+
+ LogService.reconfigure();
+ assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation())
+ .isTrue();
+ }
+
+ @Test
+ public void delegateConsoleAppenderIsConfigured() {
+ ConsoleAppender consoleAppender = findAppender(ConsoleAppender.class);
+ assertThat(consoleAppender).isNotNull();
+
+ assertThat(consoleAppender.getFilter()).isNull();
+ assertThat(consoleAppender.getHandler()).isInstanceOf(DefaultErrorHandler.class);
+ assertThat(consoleAppender.getImmediateFlush()).isTrue();
+ assertThat(consoleAppender.getLayout()).isNotNull();
+ assertThat(consoleAppender.getManager()).isInstanceOf(OutputStreamManager.class);
+ assertThat(consoleAppender.getName()).isEqualTo("STDOUT");
+ assertThat(consoleAppender.getState()).isSameAs(LifeCycle.State.STARTED);
+ assertThat(consoleAppender.getTarget()).isSameAs(ConsoleAppender.Target.SYSTEM_OUT);
+
+ OutputStreamManager outputStreamManager = consoleAppender.getManager();
+ assertThat(outputStreamManager.isOpen()).isTrue();
+ assertThat(outputStreamManager.getByteBuffer()).isInstanceOf(ByteBuffer.class);
+ assertThat(outputStreamManager.hasOutputStream()).isTrue();
+ assertThat(outputStreamManager.getContentFormat()).isEmpty();
+ assertThat(outputStreamManager.getLoggerContext()).isNull();
+ assertThat(outputStreamManager.getName()).isEqualTo("SYSTEM_OUT.false.false");
+ }
+
+ @Test
+ public void staticSystemOutRuleCapturesConsoleAppenderOutputFromPostConfigLogger() {
+ postConfigLogger.info(logMessage);
+
+ assertThat(systemOutRule.getLog()).contains(Level.INFO.name().toLowerCase());
+ assertThat(systemOutRule.getLog()).contains(logMessage);
+
+ assertThat(systemErrRule.getLog()).isEmpty();
+ }
+
+ @Test
+ public void staticSystemOutRuleFailsToCaptureConsoleAppenderOutputFromPreConfigLogger() {
+ preConfigLogger.info(logMessage);
+
+ assertThat(systemOutRule.getLog()).isEmpty();
+ assertThat(systemErrRule.getLog()).isEmpty();
+ }
+
+ @Test
+ public void staticSystemOutRuleFailsToCaptureConsoleAppenderOutputFromClassLoadedLogger() {
+ classLoadedLogger.info(logMessage);
+
+ assertThat(systemOutRule.getLog()).isEmpty();
+ assertThat(systemErrRule.getLog()).isEmpty();
+ }
+
+ private <T extends Appender> T findAppender(Class<T> appenderClass) {
+ LoggerContext loggerContext =
+ ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger()).getContext();
+ Map<String, Appender> appenders = loggerContext.getConfiguration().getAppenders();
+ List<Class<? extends Appender>> appenderClasses = new ArrayList<>();
+ for (Appender appender : appenders.values()) {
+ appenderClasses.add(appender.getClass());
+ if (appenderClass.isAssignableFrom(appender.getClass())) {
+ return appenderClass.cast(appender);
+ }
+ }
+ assertThat(appenderClasses).contains(appenderClass);
+ return null;
+ }
+}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/FastLoggerIntegrationJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/FastLoggerIntegrationTest.java
similarity index 67%
rename from geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/FastLoggerIntegrationJUnitTest.java
rename to geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/FastLoggerIntegrationTest.java
index 44782b8..1fcd650 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/FastLoggerIntegrationJUnitTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/FastLoggerIntegrationTest.java
@@ -34,28 +34,25 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Tests FastLogger isDebugEnabled and isTraceEnabled with various configurations.
*
+ * <p>
* For filters see https://logging.apache.org/log4j/2.0/manual/filters.html
- *
*/
-public class FastLoggerIntegrationJUnitTest {
+@Category(LoggingTest.class)
+public class FastLoggerIntegrationTest {
private static final String TEST_LOGGER_NAME = FastLogger.class.getPackage().getName();
private static final String ENABLED_MARKER_NAME = "ENABLED";
private static final String UNUSED_MARKER_NAME = "UNUSED";
- @Rule
- public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
-
- @Rule
- public final TemporaryFolder temporaryFolder = new TemporaryFolder();
-
private File configFile;
private String configFileLocation;
private Logger logger;
@@ -63,13 +60,19 @@ public class FastLoggerIntegrationJUnitTest {
private Marker enabledMarker;
private Marker unusedMarker;
+ @Rule
+ public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
@Before
public void setUp() throws Exception {
System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- this.configFile = new File(this.temporaryFolder.getRoot(), "log4j2-test.xml");
- this.configFileLocation = this.configFile.toURI().toURL().toString();
- this.enabledMarker = MarkerManager.getMarker(ENABLED_MARKER_NAME);
- this.unusedMarker = MarkerManager.getMarker(UNUSED_MARKER_NAME);
+ configFile = new File(temporaryFolder.getRoot(), "log4j2-test.xml");
+ configFileLocation = configFile.toURI().toURL().toString();
+ enabledMarker = MarkerManager.getMarker(ENABLED_MARKER_NAME);
+ unusedMarker = MarkerManager.getMarker(UNUSED_MARKER_NAME);
setUpLogService();
}
@@ -81,18 +84,18 @@ public class FastLoggerIntegrationJUnitTest {
private void setUpLogService() throws Exception {
// Load a base config and do some sanity checks
- writeSimpleConfigFile(this.configFile, Level.WARN);
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, this.configFileLocation);
+ writeSimpleConfigFile(configFile, Level.WARN);
+ System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configFileLocation);
LogService.reconfigure();
LogService.getLogger().getName(); // This causes the config file to be loaded
- this.logger = LogService.getLogger(TEST_LOGGER_NAME);
- this.appenderContext =
+ logger = LogService.getLogger(TEST_LOGGER_NAME);
+ appenderContext =
((org.apache.logging.log4j.core.Logger) LogService.getRootLogger()).getContext();
assertThat(LogService.getLogger(LogService.BASE_LOGGER_NAME).getLevel(), is(Level.FATAL));
- assertThat(this.logger, is(instanceOf(FastLogger.class)));
- assertThat(this.logger.getLevel(), is(Level.WARN));
+ assertThat(logger, is(instanceOf(FastLogger.class)));
+ assertThat(logger.getLevel(), is(Level.WARN));
}
@Test
@@ -293,32 +296,32 @@ public class FastLoggerIntegrationJUnitTest {
*/
private void verifyIsDelegatingForDebugOrLower(final Level level,
final boolean expectIsDelegating) throws Exception {
- writeSimpleConfigFile(this.configFile, level);
- this.appenderContext.reconfigure();
+ writeSimpleConfigFile(configFile, level);
+ appenderContext.reconfigure();
- assertThat(this.logger.getLevel(), is(level));
+ assertThat(logger.getLevel(), is(level));
- assertThat(this.logger.isTraceEnabled(), is(level.isLessSpecificThan(Level.TRACE)));
- assertThat(this.logger.isDebugEnabled(), is(level.isLessSpecificThan(Level.DEBUG)));
- assertThat(this.logger.isInfoEnabled(), is(level.isLessSpecificThan(Level.INFO)));
- assertThat(this.logger.isWarnEnabled(), is(level.isLessSpecificThan(Level.WARN)));
- assertThat(this.logger.isErrorEnabled(), is(level.isLessSpecificThan(Level.ERROR)));
- assertThat(this.logger.isFatalEnabled(), is(level.isLessSpecificThan(Level.FATAL)));
+ assertThat(logger.isTraceEnabled(), is(level.isLessSpecificThan(Level.TRACE)));
+ assertThat(logger.isDebugEnabled(), is(level.isLessSpecificThan(Level.DEBUG)));
+ assertThat(logger.isInfoEnabled(), is(level.isLessSpecificThan(Level.INFO)));
+ assertThat(logger.isWarnEnabled(), is(level.isLessSpecificThan(Level.WARN)));
+ assertThat(logger.isErrorEnabled(), is(level.isLessSpecificThan(Level.ERROR)));
+ assertThat(logger.isFatalEnabled(), is(level.isLessSpecificThan(Level.FATAL)));
- assertThat(this.logger.isTraceEnabled(this.unusedMarker),
+ assertThat(logger.isTraceEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.TRACE)));
- assertThat(this.logger.isDebugEnabled(this.unusedMarker),
+ assertThat(logger.isDebugEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.DEBUG)));
- assertThat(this.logger.isInfoEnabled(this.unusedMarker),
+ assertThat(logger.isInfoEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.INFO)));
- assertThat(this.logger.isWarnEnabled(this.unusedMarker),
+ assertThat(logger.isWarnEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.WARN)));
- assertThat(this.logger.isErrorEnabled(this.unusedMarker),
+ assertThat(logger.isErrorEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.ERROR)));
- assertThat(this.logger.isFatalEnabled(this.unusedMarker),
+ assertThat(logger.isFatalEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.FATAL)));
- final boolean delegating = ((FastLogger) this.logger).isDelegating();
+ final boolean delegating = ((FastLogger) logger).isDelegating();
assertThat(delegating, is(expectIsDelegating));
assertThat(delegating, is(level.isLessSpecificThan(Level.DEBUG)));
assertThat(delegating, is(expectIsDelegating));
@@ -334,45 +337,45 @@ public class FastLoggerIntegrationJUnitTest {
final boolean expectIsDelegating) throws Exception {
assertThat(expectIsDelegating, is(true)); // always true for Logger Filter
- writeLoggerFilterConfigFile(this.configFile, level);
- this.appenderContext.reconfigure();
+ writeLoggerFilterConfigFile(configFile, level);
+ appenderContext.reconfigure();
- assertThat(this.logger.getLevel(), is(level));
+ assertThat(logger.getLevel(), is(level));
- assertThat(this.logger.isTraceEnabled(), is(level.isLessSpecificThan(Level.TRACE)));
- assertThat(this.logger.isDebugEnabled(), is(level.isLessSpecificThan(Level.DEBUG)));
- assertThat(this.logger.isInfoEnabled(), is(level.isLessSpecificThan(Level.INFO)));
- assertThat(this.logger.isWarnEnabled(), is(level.isLessSpecificThan(Level.WARN)));
- assertThat(this.logger.isErrorEnabled(), is(level.isLessSpecificThan(Level.ERROR)));
- assertThat(this.logger.isFatalEnabled(), is(level.isLessSpecificThan(Level.FATAL)));
+ assertThat(logger.isTraceEnabled(), is(level.isLessSpecificThan(Level.TRACE)));
+ assertThat(logger.isDebugEnabled(), is(level.isLessSpecificThan(Level.DEBUG)));
+ assertThat(logger.isInfoEnabled(), is(level.isLessSpecificThan(Level.INFO)));
+ assertThat(logger.isWarnEnabled(), is(level.isLessSpecificThan(Level.WARN)));
+ assertThat(logger.isErrorEnabled(), is(level.isLessSpecificThan(Level.ERROR)));
+ assertThat(logger.isFatalEnabled(), is(level.isLessSpecificThan(Level.FATAL)));
- assertThat(this.logger.isTraceEnabled(this.enabledMarker),
+ assertThat(logger.isTraceEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.TRACE)));
- assertThat(this.logger.isDebugEnabled(this.enabledMarker),
+ assertThat(logger.isDebugEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.DEBUG)));
- assertThat(this.logger.isInfoEnabled(this.enabledMarker),
+ assertThat(logger.isInfoEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.INFO)));
- assertThat(this.logger.isWarnEnabled(this.enabledMarker),
+ assertThat(logger.isWarnEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.WARN)));
- assertThat(this.logger.isErrorEnabled(this.enabledMarker),
+ assertThat(logger.isErrorEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.ERROR)));
- assertThat(this.logger.isFatalEnabled(this.enabledMarker),
+ assertThat(logger.isFatalEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.FATAL)));
- assertThat(this.logger.isTraceEnabled(this.unusedMarker),
+ assertThat(logger.isTraceEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.TRACE)));
- assertThat(this.logger.isDebugEnabled(this.unusedMarker),
+ assertThat(logger.isDebugEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.DEBUG)));
- assertThat(this.logger.isInfoEnabled(this.unusedMarker),
+ assertThat(logger.isInfoEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.INFO)));
- assertThat(this.logger.isWarnEnabled(this.unusedMarker),
+ assertThat(logger.isWarnEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.WARN)));
- assertThat(this.logger.isErrorEnabled(this.unusedMarker),
+ assertThat(logger.isErrorEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.ERROR)));
- assertThat(this.logger.isFatalEnabled(this.unusedMarker),
+ assertThat(logger.isFatalEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.FATAL)));
- assertThat(((FastLogger) this.logger).isDelegating(), is(expectIsDelegating));
+ assertThat(((FastLogger) logger).isDelegating(), is(expectIsDelegating));
}
/**
@@ -385,35 +388,35 @@ public class FastLoggerIntegrationJUnitTest {
final boolean expectIsDelegating) throws Exception {
assertThat(expectIsDelegating, is(true)); // always true for Context-wide Filter
- writeContextWideFilterConfigFile(this.configFile, level);
- this.appenderContext.reconfigure();
+ writeContextWideFilterConfigFile(configFile, level);
+ appenderContext.reconfigure();
- assertThat(this.logger.getLevel(), is(level));
+ assertThat(logger.getLevel(), is(level));
// note: unlike other filters, Context-wide filters are processed BEFORE isEnabled checks
- assertThat(this.logger.isTraceEnabled(), is(false));
- assertThat(this.logger.isDebugEnabled(), is(false));
- assertThat(this.logger.isInfoEnabled(), is(false));
- assertThat(this.logger.isWarnEnabled(), is(false));
- assertThat(this.logger.isErrorEnabled(), is(false));
- assertThat(this.logger.isFatalEnabled(), is(false));
+ assertThat(logger.isTraceEnabled(), is(false));
+ assertThat(logger.isDebugEnabled(), is(false));
+ assertThat(logger.isInfoEnabled(), is(false));
+ assertThat(logger.isWarnEnabled(), is(false));
+ assertThat(logger.isErrorEnabled(), is(false));
+ assertThat(logger.isFatalEnabled(), is(false));
- assertThat(this.logger.isTraceEnabled(this.enabledMarker), is(true));
- assertThat(this.logger.isDebugEnabled(this.enabledMarker), is(true));
- assertThat(this.logger.isInfoEnabled(this.enabledMarker), is(true));
- assertThat(this.logger.isWarnEnabled(this.enabledMarker), is(true));
- assertThat(this.logger.isErrorEnabled(this.enabledMarker), is(true));
- assertThat(this.logger.isFatalEnabled(this.enabledMarker), is(true));
+ assertThat(logger.isTraceEnabled(enabledMarker), is(true));
+ assertThat(logger.isDebugEnabled(enabledMarker), is(true));
+ assertThat(logger.isInfoEnabled(enabledMarker), is(true));
+ assertThat(logger.isWarnEnabled(enabledMarker), is(true));
+ assertThat(logger.isErrorEnabled(enabledMarker), is(true));
+ assertThat(logger.isFatalEnabled(enabledMarker), is(true));
- assertThat(this.logger.isTraceEnabled(this.unusedMarker), is(false));
- assertThat(this.logger.isDebugEnabled(this.unusedMarker), is(false));
- assertThat(this.logger.isInfoEnabled(this.unusedMarker), is(false));
- assertThat(this.logger.isWarnEnabled(this.unusedMarker), is(false));
- assertThat(this.logger.isErrorEnabled(this.unusedMarker), is(false));
- assertThat(this.logger.isFatalEnabled(this.unusedMarker), is(false));
+ assertThat(logger.isTraceEnabled(unusedMarker), is(false));
+ assertThat(logger.isDebugEnabled(unusedMarker), is(false));
+ assertThat(logger.isInfoEnabled(unusedMarker), is(false));
+ assertThat(logger.isWarnEnabled(unusedMarker), is(false));
+ assertThat(logger.isErrorEnabled(unusedMarker), is(false));
+ assertThat(logger.isFatalEnabled(unusedMarker), is(false));
- assertThat(((FastLogger) this.logger).isDelegating(), is(expectIsDelegating));
+ assertThat(((FastLogger) logger).isDelegating(), is(expectIsDelegating));
}
/**
@@ -426,45 +429,45 @@ public class FastLoggerIntegrationJUnitTest {
final boolean expectIsDelegating) throws Exception {
assertThat(expectIsDelegating, is(true)); // always true for Appender Filter
- writeAppenderFilterConfigFile(this.configFile, level);
- this.appenderContext.reconfigure();
+ writeAppenderFilterConfigFile(configFile, level);
+ appenderContext.reconfigure();
- assertThat(this.logger.getLevel(), is(level));
+ assertThat(logger.getLevel(), is(level));
- assertThat(this.logger.isTraceEnabled(), is(level.isLessSpecificThan(Level.TRACE)));
- assertThat(this.logger.isDebugEnabled(), is(level.isLessSpecificThan(Level.DEBUG)));
- assertThat(this.logger.isInfoEnabled(), is(level.isLessSpecificThan(Level.INFO)));
- assertThat(this.logger.isWarnEnabled(), is(level.isLessSpecificThan(Level.WARN)));
- assertThat(this.logger.isErrorEnabled(), is(level.isLessSpecificThan(Level.ERROR)));
- assertThat(this.logger.isFatalEnabled(), is(level.isLessSpecificThan(Level.FATAL)));
+ assertThat(logger.isTraceEnabled(), is(level.isLessSpecificThan(Level.TRACE)));
+ assertThat(logger.isDebugEnabled(), is(level.isLessSpecificThan(Level.DEBUG)));
+ assertThat(logger.isInfoEnabled(), is(level.isLessSpecificThan(Level.INFO)));
+ assertThat(logger.isWarnEnabled(), is(level.isLessSpecificThan(Level.WARN)));
+ assertThat(logger.isErrorEnabled(), is(level.isLessSpecificThan(Level.ERROR)));
+ assertThat(logger.isFatalEnabled(), is(level.isLessSpecificThan(Level.FATAL)));
- assertThat(this.logger.isTraceEnabled(this.enabledMarker),
+ assertThat(logger.isTraceEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.TRACE)));
- assertThat(this.logger.isDebugEnabled(this.enabledMarker),
+ assertThat(logger.isDebugEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.DEBUG)));
- assertThat(this.logger.isInfoEnabled(this.enabledMarker),
+ assertThat(logger.isInfoEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.INFO)));
- assertThat(this.logger.isWarnEnabled(this.enabledMarker),
+ assertThat(logger.isWarnEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.WARN)));
- assertThat(this.logger.isErrorEnabled(this.enabledMarker),
+ assertThat(logger.isErrorEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.ERROR)));
- assertThat(this.logger.isFatalEnabled(this.enabledMarker),
+ assertThat(logger.isFatalEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.FATAL)));
- assertThat(this.logger.isTraceEnabled(this.unusedMarker),
+ assertThat(logger.isTraceEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.TRACE)));
- assertThat(this.logger.isDebugEnabled(this.unusedMarker),
+ assertThat(logger.isDebugEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.DEBUG)));
- assertThat(this.logger.isInfoEnabled(this.unusedMarker),
+ assertThat(logger.isInfoEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.INFO)));
- assertThat(this.logger.isWarnEnabled(this.unusedMarker),
+ assertThat(logger.isWarnEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.WARN)));
- assertThat(this.logger.isErrorEnabled(this.unusedMarker),
+ assertThat(logger.isErrorEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.ERROR)));
- assertThat(this.logger.isFatalEnabled(this.unusedMarker),
+ assertThat(logger.isFatalEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.FATAL)));
- assertThat(((FastLogger) this.logger).isDelegating(), is(expectIsDelegating));
+ assertThat(((FastLogger) logger).isDelegating(), is(expectIsDelegating));
}
/**
@@ -477,68 +480,67 @@ public class FastLoggerIntegrationJUnitTest {
final boolean expectIsDelegating) throws Exception {
assertThat(expectIsDelegating, is(true)); // always true for AppenderRef Filter
- writeAppenderRefFilterConfigFile(this.configFile, level);
- this.appenderContext.reconfigure();
+ writeAppenderRefFilterConfigFile(configFile, level);
+ appenderContext.reconfigure();
- assertThat(this.logger.getLevel(), is(level));
+ assertThat(logger.getLevel(), is(level));
- assertThat(this.logger.isTraceEnabled(), is(level.isLessSpecificThan(Level.TRACE)));
- assertThat(this.logger.isDebugEnabled(), is(level.isLessSpecificThan(Level.DEBUG)));
- assertThat(this.logger.isInfoEnabled(), is(level.isLessSpecificThan(Level.INFO)));
- assertThat(this.logger.isWarnEnabled(), is(level.isLessSpecificThan(Level.WARN)));
- assertThat(this.logger.isErrorEnabled(), is(level.isLessSpecificThan(Level.ERROR)));
- assertThat(this.logger.isFatalEnabled(), is(level.isLessSpecificThan(Level.FATAL)));
+ assertThat(logger.isTraceEnabled(), is(level.isLessSpecificThan(Level.TRACE)));
+ assertThat(logger.isDebugEnabled(), is(level.isLessSpecificThan(Level.DEBUG)));
+ assertThat(logger.isInfoEnabled(), is(level.isLessSpecificThan(Level.INFO)));
+ assertThat(logger.isWarnEnabled(), is(level.isLessSpecificThan(Level.WARN)));
+ assertThat(logger.isErrorEnabled(), is(level.isLessSpecificThan(Level.ERROR)));
+ assertThat(logger.isFatalEnabled(), is(level.isLessSpecificThan(Level.FATAL)));
- assertThat(this.logger.isTraceEnabled(this.enabledMarker),
+ assertThat(logger.isTraceEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.TRACE)));
- assertThat(this.logger.isDebugEnabled(this.enabledMarker),
+ assertThat(logger.isDebugEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.DEBUG)));
- assertThat(this.logger.isInfoEnabled(this.enabledMarker),
+ assertThat(logger.isInfoEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.INFO)));
- assertThat(this.logger.isWarnEnabled(this.enabledMarker),
+ assertThat(logger.isWarnEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.WARN)));
- assertThat(this.logger.isErrorEnabled(this.enabledMarker),
+ assertThat(logger.isErrorEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.ERROR)));
- assertThat(this.logger.isFatalEnabled(this.enabledMarker),
+ assertThat(logger.isFatalEnabled(enabledMarker),
is(level.isLessSpecificThan(Level.FATAL)));
- assertThat(this.logger.isTraceEnabled(this.unusedMarker),
+ assertThat(logger.isTraceEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.TRACE)));
- assertThat(this.logger.isDebugEnabled(this.unusedMarker),
+ assertThat(logger.isDebugEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.DEBUG)));
- assertThat(this.logger.isInfoEnabled(this.unusedMarker),
+ assertThat(logger.isInfoEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.INFO)));
- assertThat(this.logger.isWarnEnabled(this.unusedMarker),
+ assertThat(logger.isWarnEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.WARN)));
- assertThat(this.logger.isErrorEnabled(this.unusedMarker),
+ assertThat(logger.isErrorEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.ERROR)));
- assertThat(this.logger.isFatalEnabled(this.unusedMarker),
+ assertThat(logger.isFatalEnabled(unusedMarker),
is(level.isLessSpecificThan(Level.FATAL)));
- assertThat(((FastLogger) this.logger).isDelegating(), is(expectIsDelegating));
+ assertThat(((FastLogger) logger).isDelegating(), is(expectIsDelegating));
}
private boolean expectDelegating(final boolean value) {
return value;
}
- private static String writeSimpleConfigFile(final File configFile, final Level level)
+ private static void writeSimpleConfigFile(final File configFile, final Level level)
throws IOException {
- final String xml =
+ String xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Configuration monitorInterval=\"5\">"
+ "<Appenders><Console name=\"STDOUT\" target=\"SYSTEM_OUT\"/></Appenders>"
+ "<Loggers>" + "<Logger name=\"" + TEST_LOGGER_NAME + "\" level=\"" + level.name()
+ "\" additivity=\"true\">" + "<AppenderRef ref=\"STDOUT\"/>" + "</Logger>"
+ "<Root level=\"FATAL\"/>" + "</Loggers>" + "</Configuration>";
- final BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
+ BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
writer.write(xml);
writer.close();
- return xml;
}
- private static String writeLoggerFilterConfigFile(final File configFile, final Level level)
+ private static void writeLoggerFilterConfigFile(final File configFile, final Level level)
throws IOException {
- final String xml =
+ String xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Configuration monitorInterval=\"5\">"
+ "<Appenders><Console name=\"STDOUT\" target=\"SYSTEM_OUT\"/></Appenders>"
+ "<Loggers>" + "<Logger name=\"" + TEST_LOGGER_NAME + "\" level=\"" + level.name()
@@ -546,15 +548,14 @@ public class FastLoggerIntegrationJUnitTest {
+ ENABLED_MARKER_NAME + "\" onMatch=\"ACCEPT\" onMismatch=\"DENY\"/>" + "</filters>"
+ "<AppenderRef ref=\"STDOUT\"/>" + "</Logger>" + "<Root level=\"FATAL\"/>"
+ "</Loggers>" + "</Configuration>";
- final BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
+ BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
writer.write(xml);
writer.close();
- return xml;
}
- private static String writeContextWideFilterConfigFile(final File configFile, final Level level)
+ private static void writeContextWideFilterConfigFile(final File configFile, final Level level)
throws IOException {
- final String xml =
+ String xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Configuration monitorInterval=\"5\">"
+ "<Appenders><Console name=\"STDOUT\" target=\"SYSTEM_OUT\"/></Appenders>"
+ "<Loggers>" + "<Logger name=\"" + TEST_LOGGER_NAME + "\" level=\"" + level.name()
@@ -562,15 +563,14 @@ public class FastLoggerIntegrationJUnitTest {
+ "<AppenderRef ref=\"STDOUT\"/>" + "</Root>" + "</Loggers>" + "<filters>"
+ "<MarkerFilter marker=\"" + ENABLED_MARKER_NAME
+ "\" onMatch=\"ACCEPT\" onMismatch=\"DENY\"/>" + "</filters>" + "</Configuration>";
- final BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
+ BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
writer.write(xml);
writer.close();
- return xml;
}
- private static String writeAppenderFilterConfigFile(final File configFile, final Level level)
+ private static void writeAppenderFilterConfigFile(final File configFile, final Level level)
throws IOException {
- final String xml =
+ String xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Configuration monitorInterval=\"5\">"
+ "<Appenders>" + "<Console name=\"STDOUT\" target=\"SYSTEM_OUT\">" + "<filters>"
+ "<MarkerFilter marker=\"" + ENABLED_MARKER_NAME
@@ -578,15 +578,14 @@ public class FastLoggerIntegrationJUnitTest {
+ "</Appenders>" + "<Loggers>" + "<Logger name=\"" + TEST_LOGGER_NAME + "\" level=\""
+ level.name() + "\" additivity=\"true\">" + "</Logger>" + "<Root level=\"FATAL\">"
+ "<AppenderRef ref=\"STDOUT\"/>" + "</Root>" + "</Loggers>" + "</Configuration>";
- final BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
+ BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
writer.write(xml);
writer.close();
- return xml;
}
- private static String writeAppenderRefFilterConfigFile(final File configFile, final Level level)
+ private static void writeAppenderRefFilterConfigFile(final File configFile, final Level level)
throws IOException {
- final String xml =
+ String xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Configuration monitorInterval=\"5\">"
+ "<Appenders>" + "<Console name=\"STDOUT\" target=\"SYSTEM_OUT\">" + "</Console>"
+ "</Appenders>" + "<Loggers>" + "<Logger name=\"" + TEST_LOGGER_NAME + "\" level=\""
@@ -594,9 +593,8 @@ public class FastLoggerIntegrationJUnitTest {
+ "<AppenderRef ref=\"STDOUT\">" + "<filters>" + "<MarkerFilter marker=\""
+ ENABLED_MARKER_NAME + "\" onMatch=\"ACCEPT\" onMismatch=\"DENY\"/>" + "</filters>"
+ "</AppenderRef>" + "</Root>" + "</Loggers>" + "</Configuration>";
- final BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
+ BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
writer.write(xml);
writer.close();
- return xml;
}
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/FastLoggerWithDefaultConfigJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/FastLoggerWithDefaultConfigIntegrationTest.java
similarity index 82%
rename from geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/FastLoggerWithDefaultConfigJUnitTest.java
rename to geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/FastLoggerWithDefaultConfigIntegrationTest.java
index 47ceebe..99fdea2 100755
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/FastLoggerWithDefaultConfigJUnitTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/FastLoggerWithDefaultConfigIntegrationTest.java
@@ -25,22 +25,24 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.experimental.categories.Category;
import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Integration tests for FastLogger when using the default log4j2 config for GemFire.
- *
*/
-public class FastLoggerWithDefaultConfigJUnitTest {
+@Category(LoggingTest.class)
+public class FastLoggerWithDefaultConfigIntegrationTest {
private static final String TEST_LOGGER_NAME = FastLogger.class.getPackage().getName();
- @Rule
- public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
-
private Logger logger;
+ @Rule
+ public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
@Before
public void setUp() throws Exception {
System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
@@ -70,9 +72,9 @@ public class FastLoggerWithDefaultConfigJUnitTest {
*/
@Test
public void logServiceReturnsFastLoggers() {
- this.logger = LogService.getLogger(TEST_LOGGER_NAME);
+ logger = LogService.getLogger(TEST_LOGGER_NAME);
- assertThat(this.logger, is(instanceOf(FastLogger.class)));
+ assertThat(logger, is(instanceOf(FastLogger.class)));
}
/**
@@ -80,8 +82,8 @@ public class FastLoggerWithDefaultConfigJUnitTest {
*/
@Test
public void isDelegatingShouldBeFalse() {
- this.logger = LogService.getLogger(TEST_LOGGER_NAME);
+ logger = LogService.getLogger(TEST_LOGGER_NAME);
- assertThat(((FastLogger) this.logger).isDelegating(), is(false));
+ assertThat(((FastLogger) logger).isDelegating(), is(false));
}
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GeodeVerboseLogMarkerIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GeodeVerboseLogMarkerIntegrationTest.java
index a958be3..13d26b6 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GeodeVerboseLogMarkerIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GeodeVerboseLogMarkerIntegrationTest.java
@@ -14,6 +14,7 @@
*/
package org.apache.geode.internal.logging.log4j;
+import static org.apache.logging.log4j.core.config.ConfigurationFactory.CONFIGURATION_FILE_PROPERTY;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
@@ -22,7 +23,6 @@ import java.net.URISyntaxException;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.status.StatusLogger;
import org.junit.After;
import org.junit.Before;
@@ -30,15 +30,18 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemErrRule;
import org.junit.contrib.java.lang.system.SystemOutRule;
+import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;
import org.apache.geode.internal.logging.LogService;
import org.apache.geode.internal.logging.log4j.custom.BasicAppender;
+import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Integration tests with accept and deny of GEODE_VERBOSE and GEMFIRE_VERBOSE.
*/
+@Category(LoggingTest.class)
public class GeodeVerboseLogMarkerIntegrationTest {
private static final String RESOURCE_PACKAGE = "/org/apache/geode/internal/logging/log4j/marker/";
@@ -66,7 +69,7 @@ public class GeodeVerboseLogMarkerIntegrationTest {
public TestName testName = new TestName();
@Before
- public void preAssertions() throws Exception {
+ public void preAssertions() {
assertThat(getClass().getResource(RESOURCE_PACKAGE + FILE_NAME_GEMFIRE_VERBOSE_ACCEPT))
.isNotNull();
assertThat(getClass().getResource(RESOURCE_PACKAGE + FILE_NAME_GEMFIRE_VERBOSE_DENY))
@@ -81,26 +84,24 @@ public class GeodeVerboseLogMarkerIntegrationTest {
Configurator.shutdown();
BasicAppender.clearInstance();
- this.beforeConfigFileProp =
- System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- this.beforeLevel = StatusLogger.getLogger().getLevel();
+ beforeConfigFileProp = System.getProperty(CONFIGURATION_FILE_PROPERTY);
+ beforeLevel = StatusLogger.getLogger().getLevel();
- this.configFileGemfireVerboseAccept = createConfigFile(FILE_NAME_GEMFIRE_VERBOSE_ACCEPT);
- this.configFileGemfireVerboseDeny = createConfigFile(FILE_NAME_GEMFIRE_VERBOSE_DENY);
- this.configFileGeodeVerboseAccept = createConfigFile(FILE_NAME_GEODE_VERBOSE_ACCEPT);
- this.configFileGeodeVerboseDeny = createConfigFile(FILE_NAME_GEODE_VERBOSE_DENY);
+ configFileGemfireVerboseAccept = createConfigFile(FILE_NAME_GEMFIRE_VERBOSE_ACCEPT);
+ configFileGemfireVerboseDeny = createConfigFile(FILE_NAME_GEMFIRE_VERBOSE_DENY);
+ configFileGeodeVerboseAccept = createConfigFile(FILE_NAME_GEODE_VERBOSE_ACCEPT);
+ configFileGeodeVerboseDeny = createConfigFile(FILE_NAME_GEODE_VERBOSE_DENY);
}
@After
public void tearDown() throws Exception {
Configurator.shutdown();
- System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- if (this.beforeConfigFileProp != null) {
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
- this.beforeConfigFileProp);
+ System.clearProperty(CONFIGURATION_FILE_PROPERTY);
+ if (beforeConfigFileProp != null) {
+ System.setProperty(CONFIGURATION_FILE_PROPERTY, beforeConfigFileProp);
}
- StatusLogger.getLogger().setLevel(this.beforeLevel);
+ StatusLogger.getLogger().setLevel(beforeLevel);
LogService.reconfigure();
assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigurationInfo())
@@ -108,51 +109,51 @@ public class GeodeVerboseLogMarkerIntegrationTest {
BasicAppender.clearInstance();
- assertThat(this.systemErrRule.getLog()).isEmpty();
+ assertThat(systemErrRule.getLog()).isEmpty();
}
@Test
public void geodeVerboseShouldLogIfGeodeVerboseIsAccept() {
- configureLogging(this.configFileGeodeVerboseAccept);
+ configureLogging(configFileGeodeVerboseAccept);
Logger logger = LogService.getLogger();
- String msg = this.testName.getMethodName();
+ String msg = testName.getMethodName();
logger.info(LogMarker.GEODE_VERBOSE, msg);
- assertThat(this.systemOutRule.getLog()).contains(msg);
+ assertThat(systemOutRule.getLog()).contains(msg);
}
@Test
public void geodeVerboseShouldNotLogIfGeodeVerboseIsDeny() {
- configureLogging(this.configFileGeodeVerboseDeny);
+ configureLogging(configFileGeodeVerboseDeny);
Logger logger = LogService.getLogger();
- String msg = this.testName.getMethodName();
+ String msg = testName.getMethodName();
logger.info(LogMarker.GEODE_VERBOSE, msg);
- assertThat(this.systemOutRule.getLog()).doesNotContain(msg);
+ assertThat(systemOutRule.getLog()).doesNotContain(msg);
}
@Test
public void geodeVerboseShouldLogIfGemfireVerboseIsAccept() {
- configureLogging(this.configFileGemfireVerboseAccept);
+ configureLogging(configFileGemfireVerboseAccept);
Logger logger = LogService.getLogger();
- String msg = this.testName.getMethodName();
+ String msg = testName.getMethodName();
logger.info(LogMarker.GEODE_VERBOSE, msg);
- assertThat(this.systemOutRule.getLog()).contains(msg);
+ assertThat(systemOutRule.getLog()).contains(msg);
}
@Test
public void geodeVerboseShouldNotLogIfGemfireVerboseIsDeny() {
- configureLogging(this.configFileGemfireVerboseDeny);
+ configureLogging(configFileGemfireVerboseDeny);
Logger logger = LogService.getLogger();
- String msg = this.testName.getMethodName();
+ String msg = testName.getMethodName();
logger.info(LogMarker.GEODE_VERBOSE, msg);
- assertThat(this.systemOutRule.getLog()).doesNotContain(msg);
+ assertThat(systemOutRule.getLog()).doesNotContain(msg);
}
/**
@@ -161,13 +162,13 @@ public class GeodeVerboseLogMarkerIntegrationTest {
*/
@Test
public void gemfireVerboseShouldNotLogIfGeodeVerboseIsAccept() {
- configureLogging(this.configFileGeodeVerboseAccept);
+ configureLogging(configFileGeodeVerboseAccept);
Logger logger = LogService.getLogger();
- String msg = this.testName.getMethodName();
+ String msg = testName.getMethodName();
logger.info(LogMarker.GEMFIRE_VERBOSE, msg);
- assertThat(this.systemOutRule.getLog()).doesNotContain(msg);
+ assertThat(systemOutRule.getLog()).doesNotContain(msg);
}
/**
@@ -176,46 +177,45 @@ public class GeodeVerboseLogMarkerIntegrationTest {
*/
@Test
public void gemfireVerboseShouldLogIfGeodeVerboseIsDeny() {
- configureLogging(this.configFileGeodeVerboseDeny);
+ configureLogging(configFileGeodeVerboseDeny);
Logger logger = LogService.getLogger();
- String msg = this.testName.getMethodName();
+ String msg = testName.getMethodName();
logger.info(LogMarker.GEMFIRE_VERBOSE, msg);
- assertThat(this.systemOutRule.getLog()).contains(msg);
+ assertThat(systemOutRule.getLog()).contains(msg);
}
@Test
public void gemfireVerboseShouldLogIfGemfireVerboseIsAccept() {
- configureLogging(this.configFileGemfireVerboseAccept);
+ configureLogging(configFileGemfireVerboseAccept);
Logger logger = LogService.getLogger();
- String msg = this.testName.getMethodName();
+ String msg = testName.getMethodName();
logger.info(LogMarker.GEMFIRE_VERBOSE, msg);
- assertThat(this.systemOutRule.getLog()).contains(msg);
+ assertThat(systemOutRule.getLog()).contains(msg);
}
@Test
public void gemfireVerboseShouldNotLogIfGemfireVerboseIsDeny() {
- configureLogging(this.configFileGemfireVerboseDeny);
+ configureLogging(configFileGemfireVerboseDeny);
Logger logger = LogService.getLogger();
- String msg = this.testName.getMethodName();
+ String msg = testName.getMethodName();
logger.info(LogMarker.GEMFIRE_VERBOSE, msg);
- assertThat(this.systemOutRule.getLog()).doesNotContain(msg);
+ assertThat(systemOutRule.getLog()).doesNotContain(msg);
}
private File createConfigFile(final String name) throws IOException, URISyntaxException {
assertThat(getClass().getResource(RESOURCE_PACKAGE + name)).isNotNull();
return new Configuration(getClass().getResource(RESOURCE_PACKAGE + name), name)
- .createConfigFileIn(this.temporaryFolder.getRoot());
+ .createConfigFileIn(temporaryFolder.getRoot());
}
private void configureLogging(final File configFile) {
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
- configFile.getAbsolutePath());
+ System.setProperty(CONFIGURATION_FILE_PROPERTY, configFile.getAbsolutePath());
LogService.reconfigure();
}
}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogWriterAppenderJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/LogWriterAppenderIntegrationTest.java
similarity index 90%
rename from geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogWriterAppenderJUnitTest.java
rename to geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/LogWriterAppenderIntegrationTest.java
index 0bb4192..3106d80 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogWriterAppenderJUnitTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/LogWriterAppenderIntegrationTest.java
@@ -18,7 +18,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.regex.Pattern;
@@ -31,31 +30,34 @@ import org.apache.logging.log4j.message.ParameterizedMessage;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.apache.geode.internal.logging.InternalLogWriter;
import org.apache.geode.internal.logging.LogService;
import org.apache.geode.internal.logging.PureLogWriter;
+import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Tests the LogWriterAppender.
*/
-public class LogWriterAppenderJUnitTest {
+@Category(LoggingTest.class)
+public class LogWriterAppenderIntegrationTest {
private Level previousLogLevel;
private LogWriterAppender appender;
@Before
public void setUp() {
- this.previousLogLevel = LogService.getBaseLogLevel();
+ previousLogLevel = LogService.getBaseLogLevel();
}
@After
public void tearDown() {
- LogService.setBaseLogLevel(this.previousLogLevel);
- if (this.appender != null) {
- this.appender.stop();
+ LogService.setBaseLogLevel(previousLogLevel);
+ if (appender != null) {
+ appender.stop();
Configurator.getLoggerConfig(LogService.BASE_LOGGER_NAME).getAppenders()
- .remove(this.appender.getName());
+ .remove(appender.getName());
}
}
@@ -64,7 +66,7 @@ public class LogWriterAppenderJUnitTest {
* when the configuration is changed the appender is still there.
*/
@Test
- public void testAppenderToConfigHandling() throws IOException {
+ public void testAppenderToConfigHandling() {
LogService.setBaseLogLevel(Level.TRACE);
final AppenderContext rootContext = LogService.getAppenderContext();
@@ -85,31 +87,31 @@ public class LogWriterAppenderJUnitTest {
contexts[1] = LogService.getAppenderContext(LogService.BASE_LOGGER_NAME); // "org.apache"
// context
- this.appender =
+ appender =
LogWriterAppender.create(contexts, LogService.MAIN_LOGGER_NAME, logWriter, null);
assertEquals(rootContext.getLoggerConfig().getAppenders().values().toString(), startingSize + 1,
rootContext.getLoggerConfig().getAppenders().size());
- assertTrue(rootContext.getLoggerConfig().getAppenders().containsKey(this.appender.getName()));
+ assertTrue(rootContext.getLoggerConfig().getAppenders().containsKey(appender.getName()));
// Modify the config and verify that the appender still exists
assertEquals(Level.TRACE, LogService.getLogger(LogService.BASE_LOGGER_NAME).getLevel());
LogService.setBaseLogLevel(Level.DEBUG);
assertEquals(Level.DEBUG, LogService.getLogger(LogService.BASE_LOGGER_NAME).getLevel());
- assertTrue(rootContext.getLoggerConfig().getAppenders().containsKey(this.appender.getName()));
+ assertTrue(rootContext.getLoggerConfig().getAppenders().containsKey(appender.getName()));
// Destroy the appender and verify that it was removed from log4j
- this.appender.destroy();
+ appender.destroy();
assertEquals(rootContext.getLoggerConfig().getAppenders().values().toString(), startingSize,
rootContext.getLoggerConfig().getAppenders().size());
- assertFalse(rootContext.getLoggerConfig().getAppenders().containsKey(this.appender.getName()));
+ assertFalse(rootContext.getLoggerConfig().getAppenders().containsKey(appender.getName()));
}
/**
* Verifies that writing to a Log4j logger will end up in the LogWriter's output.
*/
@Test
- public void testLogOutput() throws IOException {
+ public void testLogOutput() {
// Create the appender
final StringWriter stringWriter = new StringWriter();
final PureLogWriter logWriter =
@@ -120,7 +122,7 @@ public class LogWriterAppenderJUnitTest {
contexts[1] = LogService.getAppenderContext(LogService.BASE_LOGGER_NAME); // "org.apache"
// context
- this.appender =
+ appender =
LogWriterAppender.create(contexts, LogService.MAIN_LOGGER_NAME, logWriter, null);
final Logger logger = LogService.getLogger();
@@ -168,16 +170,16 @@ public class LogWriterAppenderJUnitTest {
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
- this.appender.destroy();
+ appender.destroy();
assertFalse(Configurator.getLoggerConfig(LogService.BASE_LOGGER_NAME).getAppenders()
- .containsKey(this.appender.getName()));
+ .containsKey(appender.getName()));
}
/**
* Verifies that logging occurs at the levels set in the LogWriter
*/
@Test
- public void testLogWriterLevels() throws IOException {
+ public void testLogWriterLevels() {
final String loggerName = LogService.MAIN_LOGGER_NAME; // this.getClass().getName();
LogService.getLogger(); // Force logging to be initialized
@@ -191,11 +193,12 @@ public class LogWriterAppenderJUnitTest {
new PureLogWriter(InternalLogWriter.FINEST_LEVEL, new PrintWriter(stringWriter), "");
final AppenderContext[] contexts = new AppenderContext[2];
- contexts[0] = LogService.getAppenderContext(); // root context
- contexts[1] = LogService.getAppenderContext(LogService.BASE_LOGGER_NAME); // "org.apache"
- // context
+ // root context
+ contexts[0] = LogService.getAppenderContext();
+ // "org.apache" context
+ contexts[1] = LogService.getAppenderContext(LogService.BASE_LOGGER_NAME);
- this.appender = LogWriterAppender.create(contexts, loggerName, logWriter, null);
+ appender = LogWriterAppender.create(contexts, loggerName, logWriter, null);
logWriter.finest("DIRECT MESSAGE");
assertTrue(Pattern.compile(".*\\[finest .*DIRECT MESSAGE.*", Pattern.DOTALL)
@@ -204,7 +207,7 @@ public class LogWriterAppenderJUnitTest {
LogEvent event = Log4jLogEvent.newBuilder().setLevel(Level.INFO).setLoggerFqcn("NAME")
.setLoggerName("NAME").setMessage(new ParameterizedMessage("LOGEVENT MESSAGE")).build();
- this.appender.append(event);
+ appender.append(event);
assertTrue(Pattern.compile(".*\\[info .*LOGEVENT MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
@@ -243,6 +246,6 @@ public class LogWriterAppenderJUnitTest {
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
- this.appender.destroy();
+ appender.destroy();
}
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/custom/CustomConfigWithCacheIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/custom/CustomConfigWithCacheIntegrationTest.java
index f44156b..a98c68f 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/custom/CustomConfigWithCacheIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/custom/CustomConfigWithCacheIntegrationTest.java
@@ -17,13 +17,13 @@ package org.apache.geode.internal.logging.log4j.custom;
import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.apache.geode.internal.logging.log4j.custom.CustomConfiguration.CONFIG_LAYOUT_PREFIX;
-import static org.apache.geode.internal.logging.log4j.custom.CustomConfiguration.createConfigFileIn;
-import static org.apache.geode.internal.logging.log4j.custom.CustomConfiguration.defineLogStatementRegex;
+import static org.apache.geode.test.util.ResourceUtils.createFileFromResource;
+import static org.apache.geode.test.util.ResourceUtils.getResource;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.util.Properties;
+import java.util.regex.Pattern;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.LogEvent;
@@ -35,6 +35,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemErrRule;
import org.junit.contrib.java.lang.system.SystemOutRule;
+import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;
@@ -43,16 +44,22 @@ import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
import org.apache.geode.internal.logging.LogService;
import org.apache.geode.internal.logging.log4j.Configurator;
+import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Integration tests with custom log4j2 configuration.
*/
+@Category(LoggingTest.class)
public class CustomConfigWithCacheIntegrationTest {
+ private static final String CONFIG_LAYOUT_PREFIX = "CUSTOM";
+ private static final String CUSTOM_REGEX_STRING =
+ "CUSTOM: level=[A-Z]+ time=\\d{4}\\/\\d{2}\\/\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d{3} [^ ]{3} message=.*[\\n]+throwable=.*$";
+ private static final Pattern CUSTOM_REGEX = Pattern.compile(CUSTOM_REGEX_STRING, Pattern.DOTALL);
+
private String beforeConfigFileProp;
private Level beforeLevel;
- private File customConfigFile;
private Cache cache;
@Rule
@@ -69,39 +76,42 @@ public class CustomConfigWithCacheIntegrationTest {
@Before
public void setUp() throws Exception {
+
Configurator.shutdown();
BasicAppender.clearInstance();
- this.beforeConfigFileProp =
+ beforeConfigFileProp =
System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- this.beforeLevel = StatusLogger.getLogger().getLevel();
+ beforeLevel = StatusLogger.getLogger().getLevel();
- this.customConfigFile = createConfigFileIn(this.temporaryFolder.getRoot());
+ String configFileName = getClass().getSimpleName() + "_log4j2.xml";
+ File customConfigFile = createFileFromResource(getResource(configFileName),
+ temporaryFolder.getRoot(), configFileName);
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
- this.customConfigFile.getAbsolutePath());
+ customConfigFile.getAbsolutePath());
Properties gemfireProperties = new Properties();
gemfireProperties.put(LOCATORS, "");
gemfireProperties.put(MCAST_PORT, "0");
gemfireProperties.put(LOG_LEVEL, "info");
- this.cache = new CacheFactory(gemfireProperties).create();
+ cache = new CacheFactory(gemfireProperties).create();
}
@After
public void tearDown() throws Exception {
- if (this.cache != null) {
- this.cache.getDistributedSystem().disconnect();
+ if (cache != null) {
+ cache.getDistributedSystem().disconnect();
}
Configurator.shutdown();
System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- if (this.beforeConfigFileProp != null) {
+ if (beforeConfigFileProp != null) {
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
- this.beforeConfigFileProp);
+ beforeConfigFileProp);
}
- StatusLogger.getLogger().setLevel(this.beforeLevel);
+ StatusLogger.getLogger().setLevel(beforeLevel);
LogService.reconfigure();
assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigurationInfo())
@@ -109,16 +119,16 @@ public class CustomConfigWithCacheIntegrationTest {
BasicAppender.clearInstance();
- assertThat(this.systemErrRule.getLog()).isEmpty();
+ assertThat(systemErrRule.getLog()).isEmpty();
}
@Test
- public void cacheLogWriterMessageShouldMatchCustomConfig() throws Exception {
+ public void cacheLogWriterMessageShouldMatchCustomConfig() {
String logLogger = LogService.MAIN_LOGGER_NAME;
Level logLevel = Level.INFO;
String logMessage = "this is a log statement from " + testName.getMethodName();
- LogWriter logger = this.cache.getLogger();
+ LogWriter logger = cache.getLogger();
assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigurationInfo())
.isFalse();
@@ -147,7 +157,6 @@ public class CustomConfigWithCacheIntegrationTest {
assertThat(systemOutRule.getLog()).contains(logLevel.name());
assertThat(systemOutRule.getLog()).contains(logMessage);
assertThat(systemOutRule.getLog()).contains(CONFIG_LAYOUT_PREFIX);
- assertThat(systemOutRule.getLog())
- .containsPattern(defineLogStatementRegex(logLevel, logMessage));
+ assertThat(CUSTOM_REGEX.matcher(systemOutRule.getLog()).matches()).isTrue();
}
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/custom/CustomConfigWithLogServiceIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/custom/CustomConfigWithLogServiceIntegrationTest.java
index 8d80c34..b3d4d7b 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/custom/CustomConfigWithLogServiceIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/custom/CustomConfigWithLogServiceIntegrationTest.java
@@ -14,12 +14,12 @@
*/
package org.apache.geode.internal.logging.log4j.custom;
-import static org.apache.geode.internal.logging.log4j.custom.CustomConfiguration.CONFIG_LAYOUT_PREFIX;
-import static org.apache.geode.internal.logging.log4j.custom.CustomConfiguration.createConfigFileIn;
-import static org.apache.geode.internal.logging.log4j.custom.CustomConfiguration.defineLogStatementRegex;
+import static org.apache.geode.test.util.ResourceUtils.createFileFromResource;
+import static org.apache.geode.test.util.ResourceUtils.getResource;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
+import java.util.regex.Pattern;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
@@ -32,21 +32,27 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemErrRule;
import org.junit.contrib.java.lang.system.SystemOutRule;
+import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
import org.apache.geode.internal.logging.LogService;
import org.apache.geode.internal.logging.log4j.Configurator;
+import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Integration tests with custom log4j2 configuration.
*/
+@Category(LoggingTest.class)
public class CustomConfigWithLogServiceIntegrationTest {
+ private static final String CONFIG_LAYOUT_PREFIX = "CUSTOM";
+ private static final String CUSTOM_REGEX_STRING =
+ "CUSTOM: level=[A-Z]+ time=\\d{4}\\/\\d{2}\\/\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d{3} [^ ]{3} message=.*[\\n]+throwable=.*$";
+ private static final Pattern CUSTOM_REGEX = Pattern.compile(CUSTOM_REGEX_STRING, Pattern.DOTALL);
+
private String beforeConfigFileProp;
private Level beforeLevel;
- private File customConfigFile;
-
@Rule
public SystemErrRule systemErrRule = new SystemErrRule().enableLog();
@@ -61,14 +67,16 @@ public class CustomConfigWithLogServiceIntegrationTest {
Configurator.shutdown();
BasicAppender.clearInstance();
- this.beforeConfigFileProp =
+ beforeConfigFileProp =
System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- this.beforeLevel = StatusLogger.getLogger().getLevel();
+ beforeLevel = StatusLogger.getLogger().getLevel();
- this.customConfigFile = createConfigFileIn(this.temporaryFolder.getRoot());
+ String configFileName = getClass().getSimpleName() + "_log4j2.xml";
+ File customConfigFile = createFileFromResource(getResource(configFileName),
+ temporaryFolder.getRoot(), configFileName);
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
- this.customConfigFile.getAbsolutePath());
+ customConfigFile.getAbsolutePath());
LogService.reconfigure();
assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigurationInfo())
.isFalse();
@@ -79,11 +87,11 @@ public class CustomConfigWithLogServiceIntegrationTest {
Configurator.shutdown();
System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- if (this.beforeConfigFileProp != null) {
+ if (beforeConfigFileProp != null) {
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
- this.beforeConfigFileProp);
+ beforeConfigFileProp);
}
- StatusLogger.getLogger().setLevel(this.beforeLevel);
+ StatusLogger.getLogger().setLevel(beforeLevel);
LogService.reconfigure();
assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigurationInfo())
@@ -91,11 +99,11 @@ public class CustomConfigWithLogServiceIntegrationTest {
BasicAppender.clearInstance();
- assertThat(this.systemErrRule.getLog()).isEmpty();
+ assertThat(systemErrRule.getLog()).isEmpty();
}
@Test
- public void logEventShouldMatchCustomConfig() throws Exception {
+ public void logEventShouldMatchCustomConfig() {
String logLogger = getClass().getName();
Level logLevel = Level.DEBUG;
String logMessage = "this is a log statement";
@@ -115,7 +123,6 @@ public class CustomConfigWithLogServiceIntegrationTest {
assertThat(systemOutRule.getLog()).contains(logLevel.name());
assertThat(systemOutRule.getLog()).contains(logMessage);
assertThat(systemOutRule.getLog()).contains(CONFIG_LAYOUT_PREFIX);
- assertThat(systemOutRule.getLog()).matches(defineLogStatementRegex(logLevel, logMessage));
+ assertThat(CUSTOM_REGEX.matcher(systemOutRule.getLog()).matches()).isTrue();
}
-
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
index 4d82ef6..b3e3b08 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
@@ -17,6 +17,10 @@ package org.apache.geode.management.internal.cli;
import static org.apache.commons.lang.SystemUtils.LINE_SEPARATOR;
import static org.assertj.core.api.Assertions.assertThat;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -255,7 +259,7 @@ public class GfshParserAutoCompletionTest {
public void testCompleteLogLevel() {
buffer = "change loglevel --loglevel";
candidate = parser.complete(buffer);
- assertThat(candidate.getCandidates()).hasSize(8);
+ assertThat(removeExtendedLevels(candidate.getCandidates())).hasSize(8);
assertThat(candidate.getFirstCandidate()).isEqualTo(buffer + "=ALL");
}
@@ -263,7 +267,7 @@ public class GfshParserAutoCompletionTest {
public void testCompleteLogLevelWithEqualSign() {
buffer = "change loglevel --loglevel=";
candidate = parser.complete(buffer);
- assertThat(candidate.getCandidates()).hasSize(8);
+ assertThat(removeExtendedLevels(candidate.getCandidates())).hasSize(8);
assertThat(candidate.getFirstCandidate()).isEqualTo(buffer + "ALL");
}
@@ -289,4 +293,19 @@ public class GfshParserAutoCompletionTest {
assertThat(candidate.getCandidates()).hasSize(IndexType.values().length);
assertThat(candidate.getFirstCandidate()).isEqualTo(buffer + "hash");
}
+
+ /**
+ * The log4j-core:tests jar contains {@code ExtendedLevels} which adds 2 levels when that jar
+ * is on the classpath for integrationTest target.
+ */
+ private List<Completion> removeExtendedLevels(List<Completion> candidates) {
+ Collection<Completion> toRemove = new HashSet<>();
+ for (Completion completion : candidates) {
+ if (completion.getValue().contains("DETAIL") || completion.getValue().contains("NOTE")) {
+ toRemove.add(completion);
+ }
+ }
+ candidates.removeAll(toRemove);
+ return candidates;
+ }
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunctionIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunctionIntegrationTest.java
index 919b945..4b4df4e 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunctionIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunctionIntegrationTest.java
@@ -13,14 +13,11 @@
* the License.
*
*/
-
package org.apache.geode.management.internal.cli.functions;
-
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
-import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
@@ -34,15 +31,17 @@ import org.apache.geode.cache.execute.ResultSender;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.cache.execute.FunctionContextImpl;
import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.rules.ServerStarterRule;
-@Category({GfshTest.class})
+@Category({GfshTest.class, LoggingTest.class})
public class ExportLogsFunctionIntegrationTest {
+ private File serverWorkingDir;
+
@Rule
public ServerStarterRule serverStarterRule =
new ServerStarterRule().withWorkingDir().withAutoStart();
- private File serverWorkingDir;
@Before
public void setup() throws Exception {
@@ -65,21 +64,6 @@ public class ExportLogsFunctionIntegrationTest {
assertThat(cache.getRegion(ExportLogsFunction.EXPORT_LOGS_REGION)).isEmpty();
}
- public static void verifyExportLogsFunctionDoesNotBlowUp(Cache cache) throws Throwable {
- ExportLogsFunction.Args args =
- new ExportLogsFunction.Args(null, null, "info", false, false, false);
-
- CapturingResultSender resultSender = new CapturingResultSender();
-
- FunctionContext context = new FunctionContextImpl(cache, "functionId", args, resultSender);
-
- new ExportLogsFunction().execute(context);
-
- if (resultSender.getThrowable() != null) {
- throw resultSender.getThrowable();
- }
- }
-
@Test
public void createOrGetExistingExportLogsRegionDoesNotBlowUp() throws Exception {
GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
@@ -88,8 +72,7 @@ public class ExportLogsFunctionIntegrationTest {
}
@Test
- public void destroyExportLogsRegionWorksAsExpectedForInitiatingMember()
- throws IOException, ClassNotFoundException {
+ public void destroyExportLogsRegionWorksAsExpectedForInitiatingMember() throws Exception {
GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
ExportLogsFunction.createOrGetExistingExportLogsRegion(true, cache);
assertThat(cache.getRegion(ExportLogsFunction.EXPORT_LOGS_REGION)).isNotNull();
@@ -98,26 +81,37 @@ public class ExportLogsFunctionIntegrationTest {
assertThat(cache.getRegion(ExportLogsFunction.EXPORT_LOGS_REGION)).isNull();
}
+ private static void verifyExportLogsFunctionDoesNotBlowUp(Cache cache) throws Throwable {
+ ExportLogsFunction.Args args =
+ new ExportLogsFunction.Args(null, null, "info", false, false, false);
+ CapturingResultSender resultSender = new CapturingResultSender();
+ FunctionContext context = new FunctionContextImpl(cache, "functionId", args, resultSender);
+ new ExportLogsFunction().execute(context);
+ if (resultSender.getThrowable() != null) {
+ throw resultSender.getThrowable();
+ }
+ }
+
private static class CapturingResultSender implements ResultSender {
- private Throwable t;
+ private Throwable throwable;
public Throwable getThrowable() {
- return t;
+ return throwable;
}
@Override
public void sendResult(Object oneResult) {
-
+ // nothing
}
@Override
public void lastResult(Object lastResult) {
-
+ // nothing
}
@Override
public void sendException(Throwable t) {
- this.t = t;
+ throwable = t;
}
}
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionFileTest.java b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionFileIntegrationTest.java
similarity index 88%
rename from geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionFileTest.java
rename to geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionFileIntegrationTest.java
index 8f05aca..175d886 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionFileTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionFileIntegrationTest.java
@@ -32,18 +32,18 @@ import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;
-import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.management.internal.cli.functions.ExportLogsFunction.Args;
import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
-@Category({GfshTest.class})
-public class SizeExportLogsFunctionFileTest {
+@Category({GfshTest.class, LoggingTest.class})
+public class SizeExportLogsFunctionFileIntegrationTest {
private File dir;
private DistributedMember member;
private SizeExportLogsFunction.Args nonFilteringArgs;
- private FunctionContext functionContext;
+ private long expectedSize;
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -53,9 +53,9 @@ public class SizeExportLogsFunctionFileTest {
@Before
public void before() throws Exception {
- this.dir = this.temporaryFolder.getRoot();
- this.member = mock(DistributedMember.class);
- this.nonFilteringArgs = new Args(null, null, null, false, false, false);
+ dir = temporaryFolder.getRoot();
+ member = mock(DistributedMember.class);
+ nonFilteringArgs = new Args(null, null, null, false, false, false);
}
@After
@@ -76,12 +76,10 @@ public class SizeExportLogsFunctionFileTest {
long statFileSize = FileUtils.sizeOf(statArchive);
SizeExportLogsFunction function = new SizeExportLogsFunction();
- assertThat(function.estimateLogFileSize(this.member, logFile, statArchive, nonFilteringArgs))
+ assertThat(function.estimateLogFileSize(member, logFile, statArchive, nonFilteringArgs))
.isEqualTo(logFileSize + statFileSize);
}
- private long expectedSize;
-
@Test
public void manyFiles_returnsCombinedSize() throws Exception {
expectedSize = 0;
@@ -98,7 +96,7 @@ public class SizeExportLogsFunctionFileTest {
});
SizeExportLogsFunction function = new SizeExportLogsFunction();
- assertThat(function.estimateLogFileSize(this.member, logFiles.get(0), statFiles.get(0),
+ assertThat(function.estimateLogFileSize(member, logFiles.get(0), statFiles.get(0),
nonFilteringArgs)).isEqualTo(expectedSize);
}
@@ -110,7 +108,7 @@ public class SizeExportLogsFunctionFileTest {
List<File> statFiles =
createStatFiles(new File(dir.getName(), testName.getMethodName()), 1, 2, 0);
SizeExportLogsFunction function = new SizeExportLogsFunction();
- assertThat(function.estimateLogFileSize(this.member, logFiles.get(0), statFiles.get(0),
+ assertThat(function.estimateLogFileSize(member, logFiles.get(0), statFiles.get(0),
nonFilteringArgs)).isEqualTo(0);
}
@@ -120,7 +118,7 @@ public class SizeExportLogsFunctionFileTest {
File nullStatFile = new File(dir.getPath(), "nullStatFile");
SizeExportLogsFunction function = new SizeExportLogsFunction();
assertThat(
- function.estimateLogFileSize(this.member, nullLogFile, nullStatFile, nonFilteringArgs))
+ function.estimateLogFileSize(member, nullLogFile, nullStatFile, nonFilteringArgs))
.isEqualTo(0);
}
@@ -163,7 +161,7 @@ public class SizeExportLogsFunctionFileTest {
}
private File createFile(String name, long sizeInBytes, boolean lineFeed) throws IOException {
- File file = new File(this.dir, name);
+ File file = new File(dir, name);
fillUpFile(file, sizeInBytes, lineFeed);
return file;
}
@@ -178,5 +176,4 @@ public class SizeExportLogsFunctionFileTest {
}
writer.close();
}
-
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionTest.java b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionIntegrationTest.java
similarity index 92%
rename from geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionTest.java
rename to geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionIntegrationTest.java
index dea7cf9..d2d4b9e 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunctionIntegrationTest.java
@@ -43,11 +43,11 @@ import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.internal.cache.execute.FunctionContextImpl;
import org.apache.geode.management.ManagementException;
import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.rules.ServerStarterRule;
-@Category({GfshTest.class})
-public class SizeExportLogsFunctionTest {
-
+@Category({GfshTest.class, LoggingTest.class})
+public class SizeExportLogsFunctionIntegrationTest {
private SizeExportLogsFunction.Args nonFilteringArgs;
private File logFile;
@@ -65,18 +65,17 @@ public class SizeExportLogsFunctionTest {
public ServerStarterRule server = new ServerStarterRule();
@Before
- public void before() throws Throwable {
+ public void before() {
String name = testName.getMethodName();
config = new Properties();
config.setProperty(NAME, name);
- File dir = this.temporaryFolder.getRoot();
+ File dir = temporaryFolder.getRoot();
logFile = new File(dir, name + ".log");
statFile = new File(dir, name + ".gfs");
resultSender = new TestResultSender();
- this.nonFilteringArgs = new SizeExportLogsFunction.Args(null, null, null, false, false, false);
-
+ nonFilteringArgs = new SizeExportLogsFunction.Args(null, null, null, false, false, false);
}
@Test
@@ -110,7 +109,7 @@ public class SizeExportLogsFunctionTest {
}
@Test
- public void withFunctionError_shouldThrow() throws Throwable {
+ public void withFunctionError_shouldThrow() {
server.withProperties(config).startServer();
FunctionContext context =
@@ -120,7 +119,7 @@ public class SizeExportLogsFunctionTest {
}
@Test
- public void sizeGreaterThanDiskAvailable_sendsErrorResult() throws Throwable {
+ public void sizeGreaterThanDiskAvailable_sendsErrorResult() {
config.setProperty(LOG_FILE, logFile.getAbsolutePath());
config.setProperty(STATISTIC_ARCHIVE_FILE, statFile.getAbsolutePath());
server.withProperties(config).startServer();
@@ -162,11 +161,11 @@ public class SizeExportLogsFunctionTest {
private final List<Object> results = new LinkedList<>();
- private Throwable t;
+ private Throwable throwable;
List<Object> getResults() throws Throwable {
- if (t != null) {
- throw t;
+ if (throwable != null) {
+ throw throwable;
}
return Collections.unmodifiableList(results);
}
@@ -183,7 +182,7 @@ public class SizeExportLogsFunctionTest {
@Override
public void sendException(final Throwable t) {
- this.t = t;
+ throwable = t;
}
}
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/util/LogExporterTest.java b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/util/LogExporterFileIntegrationTest.java
similarity index 92%
rename from geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/util/LogExporterTest.java
rename to geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/util/LogExporterFileIntegrationTest.java
index 923d2cc..c1718a0 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/util/LogExporterTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/util/LogExporterFileIntegrationTest.java
@@ -13,44 +13,43 @@
* the License.
*
*/
-
package org.apache.geode.management.internal.cli.util;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
-import java.io.IOException;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
import org.apache.geode.management.internal.configuration.utils.ZipUtils;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
-public class LogExporterTest {
- @Rule
- public TemporaryFolder temporaryFolder = new TemporaryFolder();
+@Category({GfshTest.class, LoggingTest.class})
+public class LogExporterFileIntegrationTest {
private LogExporter logExporter;
private LogFilter logFilter;
private File workingDir;
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
@Before
public void setup() throws Exception {
logFilter = mock(LogFilter.class);
@@ -135,9 +134,4 @@ public class LogExporterTest {
assertThat(logExporter.findStatFiles(workingDir.toPath())).contains(statFile.toPath());
assertThat(logExporter.findStatFiles(workingDir.toPath())).doesNotContain(notALogFile.toPath());
}
-
- static Set<String> getZipEntries(String zipFilePath) throws IOException {
- return new ZipFile(zipFilePath).stream().map(ZipEntry::getName).collect(Collectors.toSet());
- }
-
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/util/LogExporterIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/util/LogExporterIntegrationTest.java
index 783dce0..cd02e88 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/util/LogExporterIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/util/LogExporterIntegrationTest.java
@@ -12,7 +12,6 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.cli.util;
import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE;
@@ -20,11 +19,15 @@ import static org.apache.geode.distributed.ConfigurationProperties.STATISTIC_ARC
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
+import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Properties;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
import com.google.common.collect.Sets;
import org.apache.logging.log4j.Level;
@@ -32,20 +35,27 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
-
-import org.apache.geode.management.internal.cli.functions.ExportLogsFunctionIntegrationTest;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.cache.execute.ResultSender;
+import org.apache.geode.internal.cache.execute.FunctionContextImpl;
+import org.apache.geode.management.internal.cli.functions.ExportLogsFunction;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.rules.ServerStarterRule;
+@Category({GfshTest.class, LoggingTest.class})
public class LogExporterIntegrationTest {
- @Rule
- public ServerStarterRule server = new ServerStarterRule().withWorkingDir();
+ private final LogFilter filter = new LogFilter(Level.INFO, null, null);
private LogExporter logExporter;
-
private Properties properties;
- private LogFilter filter = new LogFilter(Level.INFO, null, null);
+ @Rule
+ public ServerStarterRule server = new ServerStarterRule().withWorkingDir();
@Before
public void before() throws Exception {
@@ -110,7 +120,7 @@ public class LogExporterIntegrationTest {
properties.setProperty(LOG_FILE, logsFile.toString());
server.withProperties(properties).startServer();
- ExportLogsFunctionIntegrationTest.verifyExportLogsFunctionDoesNotBlowUp(server.getCache());
+ verifyExportLogsFunctionDoesNotBlowUp(server.getCache());
}
@Test
@@ -121,7 +131,7 @@ public class LogExporterIntegrationTest {
properties.setProperty(STATISTIC_ARCHIVE_FILE, "stats.gfs");
server.withProperties(properties).startServer();
- ExportLogsFunctionIntegrationTest.verifyExportLogsFunctionDoesNotBlowUp(server.getCache());
+ verifyExportLogsFunctionDoesNotBlowUp(server.getCache());
}
@Test
@@ -131,7 +141,7 @@ public class LogExporterIntegrationTest {
properties.setProperty(STATISTIC_ARCHIVE_FILE, statsFile.toString());
server.withProperties(properties).startServer();
- ExportLogsFunctionIntegrationTest.verifyExportLogsFunctionDoesNotBlowUp(server.getCache());
+ verifyExportLogsFunctionDoesNotBlowUp(server.getCache());
}
@Test
@@ -149,12 +159,48 @@ public class LogExporterIntegrationTest {
logExporter = new LogExporter(filter, logFile, statsFile);
Path exportedZip = logExporter.export();
- Set<String> actualFiles = LogExporterTest.getZipEntries(exportedZip.toString());
+ Set<String> actualFiles = getZipEntries(exportedZip.toString());
Set<String> expectedFiles = Sets.newHashSet("server.log", "stats.gfs");
assertThat(actualFiles).isEqualTo(expectedFiles);
+ }
+ private static void verifyExportLogsFunctionDoesNotBlowUp(Cache cache) throws Throwable {
+ ExportLogsFunction.Args args =
+ new ExportLogsFunction.Args(null, null, "info", false, false, false);
+ CapturingResultSender resultSender = new CapturingResultSender();
+ FunctionContext context = new FunctionContextImpl(cache, "functionId", args, resultSender);
+ new ExportLogsFunction().execute(context);
+ if (resultSender.getThrowable() != null) {
+ throw resultSender.getThrowable();
+ }
}
+ private static Set<String> getZipEntries(String zipFilePath) throws IOException {
+ return new ZipFile(zipFilePath).stream().map(ZipEntry::getName).collect(Collectors.toSet());
+ }
+
+ private static class CapturingResultSender implements ResultSender {
+
+ private Throwable throwable;
+
+ public Throwable getThrowable() {
+ return throwable;
+ }
+ @Override
+ public void sendResult(Object oneResult) {
+ // nothing
+ }
+
+ @Override
+ public void lastResult(Object lastResult) {
+ // nothing
+ }
+
+ @Override
+ public void sendException(Throwable t) {
+ throwable = t;
+ }
+ }
}
diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/distributed/LocatorLauncherRemoteWithCustomLoggingIntegrationTest_log4j2.xml b/geode-core/src/integrationTest/resources/org/apache/geode/distributed/LocatorLauncherRemoteWithCustomLoggingIntegrationTest_log4j2.xml
new file mode 100644
index 0000000..0190b9b
--- /dev/null
+++ b/geode-core/src/integrationTest/resources/org/apache/geode/distributed/LocatorLauncherRemoteWithCustomLoggingIntegrationTest_log4j2.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<Configuration status="FATAL" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j.custom">
+ <Properties>
+ <Property name="custom-pattern">CUSTOM: level=%level time=%date{yyyy/MM/dd HH:mm:ss.SSS z} message=%message%nthrowable=%throwable%n
+ </Property>
+ </Properties>
+ <Appenders>
+ <Console name="STDOUT" target="SYSTEM_OUT">
+ <PatternLayout pattern="${custom-pattern}"/>
+ </Console>
+ <Basic name="CUSTOM">
+ <PatternLayout pattern="${custom-pattern}"/>
+ </Basic>
+ </Appenders>
+ <Loggers>
+ <Logger name="com.gemstone" level="INFO" additivity="true"/>
+ <Logger name="org.apache.geode" level="INFO" additivity="true">
+ <filters>
+ <MarkerFilter marker="GEODE_VERBOSE" onMatch="DENY" onMismatch="NEUTRAL"/>
+ </filters>
+ </Logger>
+ <Logger name="org.apache.geode.internal.logging.log4j.custom" level="DEBUG" additivity="true"/>
+ <Logger name="org.jgroups" level="FATAL" additivity="true"/>
+ <Root level="INFO">
+ <AppenderRef ref="CUSTOM"/>
+ <AppenderRef ref="STDOUT"/>
+ </Root>
+ </Loggers>
+</Configuration>
diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/distributed/ServerLauncherRemoteWithCustomLoggingIntegrationTest_log4j2.xml b/geode-core/src/integrationTest/resources/org/apache/geode/distributed/ServerLauncherRemoteWithCustomLoggingIntegrationTest_log4j2.xml
new file mode 100644
index 0000000..0190b9b
--- /dev/null
+++ b/geode-core/src/integrationTest/resources/org/apache/geode/distributed/ServerLauncherRemoteWithCustomLoggingIntegrationTest_log4j2.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<Configuration status="FATAL" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j.custom">
+ <Properties>
+ <Property name="custom-pattern">CUSTOM: level=%level time=%date{yyyy/MM/dd HH:mm:ss.SSS z} message=%message%nthrowable=%throwable%n
+ </Property>
+ </Properties>
+ <Appenders>
+ <Console name="STDOUT" target="SYSTEM_OUT">
+ <PatternLayout pattern="${custom-pattern}"/>
+ </Console>
+ <Basic name="CUSTOM">
+ <PatternLayout pattern="${custom-pattern}"/>
+ </Basic>
+ </Appenders>
+ <Loggers>
+ <Logger name="com.gemstone" level="INFO" additivity="true"/>
+ <Logger name="org.apache.geode" level="INFO" additivity="true">
+ <filters>
+ <MarkerFilter marker="GEODE_VERBOSE" onMatch="DENY" onMismatch="NEUTRAL"/>
+ </filters>
+ </Logger>
+ <Logger name="org.apache.geode.internal.logging.log4j.custom" level="DEBUG" additivity="true"/>
+ <Logger name="org.jgroups" level="FATAL" additivity="true"/>
+ <Root level="INFO">
+ <AppenderRef ref="CUSTOM"/>
+ <AppenderRef ref="STDOUT"/>
+ </Root>
+ </Loggers>
+</Configuration>
diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/ConsoleAppenderWithLoggerContextRuleIntegrationTest_log4j2.xml b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/ConsoleAppenderWithLoggerContextRuleIntegrationTest_log4j2.xml
new file mode 100644
index 0000000..4321615
--- /dev/null
+++ b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/ConsoleAppenderWithLoggerContextRuleIntegrationTest_log4j2.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<Configuration status="WARN" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j,org.apache.logging.log4j.test.appender">
+ <Properties>
+ <Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%tid] %message%n%throwable%n</Property>
+ </Properties>
+ <Appenders>
+ <Console name="STDOUT" target="SYSTEM_OUT">
+ <PatternLayout pattern="${geode-pattern}"/>
+ </Console>
+ <List name="LIST"/>
+ </Appenders>
+ <Loggers>
+ <Logger name="com.gemstone" level="INFO" additivity="true"/>
+ <Logger name="org.apache.geode" level="INFO" additivity="true">
+ <filters>
+ <MarkerFilter marker="GEODE_VERBOSE" onMatch="DENY" onMismatch="NEUTRAL"/>
+ </filters>
+ </Logger>
+ <Logger name="org.jgroups" level="FATAL" additivity="true"/>
+ <Logger name="org.eclipse.jetty" level="FATAL" additivity="true"/>
+ <Root level="INFO">
+ <AppenderRef ref="STDOUT"/>
+ <AppenderRef ref="LIST"/>
+ </Root>
+ </Loggers>
+</Configuration>
diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/ConsoleAppenderWithSystemOutRuleIntegrationTest_log4j2.xml b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/ConsoleAppenderWithSystemOutRuleIntegrationTest_log4j2.xml
new file mode 100644
index 0000000..68d896e
--- /dev/null
+++ b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/ConsoleAppenderWithSystemOutRuleIntegrationTest_log4j2.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<Configuration status="ERROR" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j">
+ <Properties>
+ <Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%tid] %message%n%throwable%n</Property>
+ </Properties>
+ <Appenders>
+ <Console name="STDOUT" target="SYSTEM_OUT">
+ <PatternLayout pattern="${geode-pattern}"/>
+ </Console>
+ </Appenders>
+ <Loggers>
+ <Logger name="com.gemstone" level="INFO" additivity="true"/>
+ <Logger name="org.apache.geode" level="INFO" additivity="true">
+ <filters>
+ <MarkerFilter marker="GEODE_VERBOSE" onMatch="DENY" onMismatch="NEUTRAL"/>
+ </filters>
+ </Logger>
+ <Logger name="org.jgroups" level="FATAL" additivity="true"/>
+ <Logger name="org.eclipse.jetty" level="FATAL" additivity="true"/>
+ <Root level="INFO">
+ <AppenderRef ref="STDOUT"/>
+ </Root>
+ </Loggers>
+</Configuration>
diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/custom/CustomConfigWithCacheIntegrationTest_log4j2.xml b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/custom/CustomConfigWithCacheIntegrationTest_log4j2.xml
new file mode 100644
index 0000000..0190b9b
--- /dev/null
+++ b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/custom/CustomConfigWithCacheIntegrationTest_log4j2.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<Configuration status="FATAL" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j.custom">
+ <Properties>
+ <Property name="custom-pattern">CUSTOM: level=%level time=%date{yyyy/MM/dd HH:mm:ss.SSS z} message=%message%nthrowable=%throwable%n
+ </Property>
+ </Properties>
+ <Appenders>
+ <Console name="STDOUT" target="SYSTEM_OUT">
+ <PatternLayout pattern="${custom-pattern}"/>
+ </Console>
+ <Basic name="CUSTOM">
+ <PatternLayout pattern="${custom-pattern}"/>
+ </Basic>
+ </Appenders>
+ <Loggers>
+ <Logger name="com.gemstone" level="INFO" additivity="true"/>
+ <Logger name="org.apache.geode" level="INFO" additivity="true">
+ <filters>
+ <MarkerFilter marker="GEODE_VERBOSE" onMatch="DENY" onMismatch="NEUTRAL"/>
+ </filters>
+ </Logger>
+ <Logger name="org.apache.geode.internal.logging.log4j.custom" level="DEBUG" additivity="true"/>
+ <Logger name="org.jgroups" level="FATAL" additivity="true"/>
+ <Root level="INFO">
+ <AppenderRef ref="CUSTOM"/>
+ <AppenderRef ref="STDOUT"/>
+ </Root>
+ </Loggers>
+</Configuration>
diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/custom/CustomConfigWithLogServiceIntegrationTest_log4j2.xml b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/custom/CustomConfigWithLogServiceIntegrationTest_log4j2.xml
new file mode 100644
index 0000000..0190b9b
--- /dev/null
+++ b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/custom/CustomConfigWithLogServiceIntegrationTest_log4j2.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<Configuration status="FATAL" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j.custom">
+ <Properties>
+ <Property name="custom-pattern">CUSTOM: level=%level time=%date{yyyy/MM/dd HH:mm:ss.SSS z} message=%message%nthrowable=%throwable%n
+ </Property>
+ </Properties>
+ <Appenders>
+ <Console name="STDOUT" target="SYSTEM_OUT">
+ <PatternLayout pattern="${custom-pattern}"/>
+ </Console>
+ <Basic name="CUSTOM">
+ <PatternLayout pattern="${custom-pattern}"/>
+ </Basic>
+ </Appenders>
+ <Loggers>
+ <Logger name="com.gemstone" level="INFO" additivity="true"/>
+ <Logger name="org.apache.geode" level="INFO" additivity="true">
+ <filters>
+ <MarkerFilter marker="GEODE_VERBOSE" onMatch="DENY" onMismatch="NEUTRAL"/>
+ </filters>
+ </Logger>
+ <Logger name="org.apache.geode.internal.logging.log4j.custom" level="DEBUG" additivity="true"/>
+ <Logger name="org.jgroups" level="FATAL" additivity="true"/>
+ <Root level="INFO">
+ <AppenderRef ref="CUSTOM"/>
+ <AppenderRef ref="STDOUT"/>
+ </Root>
+ </Loggers>
+</Configuration>
diff --git a/geode-core/src/main/resources/log4j2-cli.xml b/geode-core/src/main/resources/log4j2-cli.xml
index fa05415..9597f99 100644
--- a/geode-core/src/main/resources/log4j2-cli.xml
+++ b/geode-core/src/main/resources/log4j2-cli.xml
@@ -1,4 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
<Configuration status="FATAL" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j">
<Properties>
<Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property>
diff --git a/geode-core/src/main/resources/log4j2.xml b/geode-core/src/main/resources/log4j2.xml
index 6f26752..e44c3e5 100755
--- a/geode-core/src/main/resources/log4j2.xml
+++ b/geode-core/src/main/resources/log4j2.xml
@@ -1,4 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
<Configuration status="FATAL" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j">
<Properties>
<Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property>
diff --git a/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/LogWriterDisabledPerformanceTest.java b/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/LogWriterDisabledPerformanceTest.java
index 47a16b6..5c084b9 100644
--- a/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/LogWriterDisabledPerformanceTest.java
+++ b/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/LogWriterDisabledPerformanceTest.java
@@ -18,10 +18,11 @@ import org.junit.Ignore;
import org.junit.experimental.categories.Category;
import org.apache.geode.LogWriter;
+import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.categories.PerformanceTest;
-@Category(PerformanceTest.class)
-@Ignore("Tests have no assertions")
+@Category({PerformanceTest.class, LoggingTest.class})
+@Ignore("TODO: repackage as jmh benchmark")
public class LogWriterDisabledPerformanceTest extends LogWriterPerformanceTest {
@Override
diff --git a/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/LogWriterPerformanceTest.java b/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/LogWriterPerformanceTest.java
index 3792c85..922d891 100644
--- a/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/LogWriterPerformanceTest.java
+++ b/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/LogWriterPerformanceTest.java
@@ -30,18 +30,19 @@ import org.apache.geode.LogWriter;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.distributed.internal.DistributionConfigImpl;
import org.apache.geode.internal.util.IOUtils;
+import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.categories.PerformanceTest;
/**
* Tests performance of logging when level is OFF.
*/
-@Category(PerformanceTest.class)
-@Ignore("Tests have no assertions")
+@Category({PerformanceTest.class, LoggingTest.class})
+@Ignore("TODO: repackage as jmh benchmark")
public class LogWriterPerformanceTest extends LoggingPerformanceTestCase {
- protected Properties createGemFireProperties() {
+ private Properties createGemFireProperties() {
final Properties props = new Properties();
- this.logFile = new File(this.configDirectory, DistributionConfig.GEMFIRE_PREFIX + "log");
+ logFile = new File(configDirectory, DistributionConfig.GEMFIRE_PREFIX + "log");
final String logFilePath = IOUtils.tryGetCanonicalPathElseGetAbsolutePath(logFile);
props.setProperty(LOG_FILE, logFilePath);
props.setProperty(LOG_LEVEL, "info");
@@ -63,8 +64,8 @@ public class LogWriterPerformanceTest extends LoggingPerformanceTestCase {
// create configuration with log-file and log-level
// this.configDirectory = new File(getUniqueName());
- this.configDirectory.mkdir();
- assertTrue(this.configDirectory.isDirectory() && this.configDirectory.canWrite());
+ configDirectory.mkdir();
+ assertTrue(configDirectory.isDirectory() && configDirectory.canWrite());
// this.gemfireProperties = new File(this.configDirectory, "gemfire.properties");
// writeProperties(props, this.gemfireProperties);
diff --git a/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/Log4J2DisabledPerformanceTest.java b/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/Log4J2DisabledPerformanceTest.java
index e50661e..f89ca87 100644
--- a/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/Log4J2DisabledPerformanceTest.java
+++ b/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/Log4J2DisabledPerformanceTest.java
@@ -21,10 +21,11 @@ import org.apache.logging.log4j.Logger;
import org.junit.Ignore;
import org.junit.experimental.categories.Category;
+import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.categories.PerformanceTest;
-@Category(PerformanceTest.class)
-@Ignore("Tests have no assertions")
+@Category({PerformanceTest.class, LoggingTest.class})
+@Ignore("TODO: repackage as jmh benchmark")
public class Log4J2DisabledPerformanceTest extends Log4J2PerformanceTest {
@Override
diff --git a/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/Log4J2PerformanceTest.java b/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/Log4J2PerformanceTest.java
index dfcff11..cd873ca 100644
--- a/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/Log4J2PerformanceTest.java
+++ b/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/Log4J2PerformanceTest.java
@@ -17,10 +17,7 @@ package org.apache.geode.internal.logging.log4j;
import static org.junit.Assert.assertTrue;
import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.PrintWriter;
import java.net.URL;
import org.apache.commons.io.FileUtils;
@@ -35,33 +32,28 @@ import org.junit.experimental.categories.Category;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.internal.logging.LoggingPerformanceTestCase;
import org.apache.geode.internal.util.IOUtils;
+import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.categories.PerformanceTest;
-@Category(PerformanceTest.class)
-@Ignore("Tests have no assertions")
+@Category({PerformanceTest.class, LoggingTest.class})
+@Ignore("TODO: repackage as jmh benchmark")
public class Log4J2PerformanceTest extends LoggingPerformanceTestCase {
- protected static final int DEFAULT_LOG_FILE_SIZE_LIMIT = Integer.MAX_VALUE;
- protected static final int DEFAULT_LOG_FILE_COUNT_LIMIT = 20;
+ private static final int DEFAULT_LOG_FILE_SIZE_LIMIT = Integer.MAX_VALUE;
+ private static final int DEFAULT_LOG_FILE_COUNT_LIMIT = 20;
- protected static final String SYS_LOG_FILE = "gemfire-log-file";
- protected static final String SYS_LOG_FILE_SIZE_LIMIT = "gemfire-log-file-size-limit";
- protected static final String SYS_LOG_FILE_COUNT_LIMIT = "gemfire-log-file-count-limit";
+ private static final String SYS_LOG_FILE = "gemfire-log-file";
+ private static final String SYS_LOG_FILE_SIZE_LIMIT = "gemfire-log-file-size-limit";
+ private static final String SYS_LOG_FILE_COUNT_LIMIT = "gemfire-log-file-count-limit";
- private File config = null;
+ private File config;
@After
- public void tearDownLog4J2PerformanceTest() throws Exception {
- this.config = null; // leave this file in place for now
+ public void tearDownLog4J2PerformanceTest() {
+ config = null; // leave this file in place for now
}
- protected void writeConfigFile(final File file) throws FileNotFoundException {
- final PrintWriter pw = new PrintWriter(new FileOutputStream(file));
- pw.println();
- pw.close();
- }
-
- protected void setPropertySubstitutionValues(final String logFile, final int logFileSizeLimitMB,
+ private void setPropertySubstitutionValues(final String logFile, final int logFileSizeLimitMB,
final int logFileCountLimit) {
if (logFileSizeLimitMB < 0) {
throw new IllegalArgumentException("logFileSizeLimitMB must be zero or positive integer");
@@ -83,22 +75,22 @@ public class Log4J2PerformanceTest extends LoggingPerformanceTestCase {
System.setProperty(SYS_LOG_FILE_COUNT_LIMIT, logFileCountLimitValue);
}
- protected Logger createLogger() throws IOException {
+ Logger createLogger() throws IOException {
// create configuration with log-file and log-level
- this.configDirectory = new File(getUniqueName());
- this.configDirectory.mkdir();
- assertTrue(this.configDirectory.isDirectory() && this.configDirectory.canWrite());
+ configDirectory = new File(getUniqueName());
+ configDirectory.mkdir();
+ assertTrue(configDirectory.isDirectory() && configDirectory.canWrite());
// copy the log4j2-test.xml to the configDirectory
// final URL srcURL =
// getClass().getResource("/org/apache/geode/internal/logging/log4j/log4j2-test.xml");
final URL srcURL = getClass().getResource("log4j2-test.xml");
final File src = new File(srcURL.getFile());
- FileUtils.copyFileToDirectory(src, this.configDirectory);
- this.config = new File(this.configDirectory, "log4j2-test.xml");
- assertTrue(this.config.exists());
+ FileUtils.copyFileToDirectory(src, configDirectory);
+ config = new File(configDirectory, "log4j2-test.xml");
+ assertTrue(config.exists());
- this.logFile = new File(this.configDirectory, DistributionConfig.GEMFIRE_PREFIX + "log");
+ logFile = new File(configDirectory, DistributionConfig.GEMFIRE_PREFIX + "log");
final String logFilePath = IOUtils.tryGetCanonicalPathElseGetAbsolutePath(logFile);
final String logFileName =
logFilePath.substring(0, logFilePath.lastIndexOf(File.separatorChar));
@@ -106,7 +98,7 @@ public class Log4J2PerformanceTest extends LoggingPerformanceTestCase {
DEFAULT_LOG_FILE_COUNT_LIMIT);
final String configPath =
- "file://" + IOUtils.tryGetCanonicalPathElseGetAbsolutePath(this.config);
+ "file://" + IOUtils.tryGetCanonicalPathElseGetAbsolutePath(config);
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configPath);
final Logger logger = LogManager.getLogger();
diff --git a/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/LogWriterLoggerDisabledPerformanceTest.java b/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/LogWriterLoggerDisabledPerformanceTest.java
index f8b4cf4..e432ed5 100644
--- a/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/LogWriterLoggerDisabledPerformanceTest.java
+++ b/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/LogWriterLoggerDisabledPerformanceTest.java
@@ -21,10 +21,11 @@ import org.apache.logging.log4j.Logger;
import org.junit.Ignore;
import org.junit.experimental.categories.Category;
+import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.categories.PerformanceTest;
-@Category(PerformanceTest.class)
-@Ignore("Tests have no assertions")
+@Category({PerformanceTest.class, LoggingTest.class})
+@Ignore("TODO: repackage as jmh benchmark")
public class LogWriterLoggerDisabledPerformanceTest extends LogWriterLoggerPerformanceTest {
@Override
diff --git a/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/LogWriterLoggerPerformanceTest.java b/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/LogWriterLoggerPerformanceTest.java
index f39eb23..3f94657 100644
--- a/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/LogWriterLoggerPerformanceTest.java
+++ b/geode-core/src/performanceTest/java/org/apache/geode/internal/logging/log4j/LogWriterLoggerPerformanceTest.java
@@ -17,10 +17,7 @@ package org.apache.geode.internal.logging.log4j;
import static org.junit.Assert.assertTrue;
import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.PrintWriter;
import java.net.URL;
import org.apache.commons.io.FileUtils;
@@ -34,33 +31,28 @@ import org.junit.experimental.categories.Category;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.internal.logging.LoggingPerformanceTestCase;
import org.apache.geode.internal.util.IOUtils;
+import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.categories.PerformanceTest;
-@Category(PerformanceTest.class)
-@Ignore("Tests have no assertions")
+@Category({PerformanceTest.class, LoggingTest.class})
+@Ignore("TODO: repackage as jmh benchmark")
public class LogWriterLoggerPerformanceTest extends LoggingPerformanceTestCase {
- protected static final int DEFAULT_LOG_FILE_SIZE_LIMIT = Integer.MAX_VALUE;
- protected static final int DEFAULT_LOG_FILE_COUNT_LIMIT = 20;
+ private static final int DEFAULT_LOG_FILE_SIZE_LIMIT = Integer.MAX_VALUE;
+ private static final int DEFAULT_LOG_FILE_COUNT_LIMIT = 20;
- protected static final String SYS_LOG_FILE = "gemfire-log-file";
- protected static final String SYS_LOG_FILE_SIZE_LIMIT = "gemfire-log-file-size-limit";
- protected static final String SYS_LOG_FILE_COUNT_LIMIT = "gemfire-log-file-count-limit";
+ private static final String SYS_LOG_FILE = "gemfire-log-file";
+ private static final String SYS_LOG_FILE_SIZE_LIMIT = "gemfire-log-file-size-limit";
+ private static final String SYS_LOG_FILE_COUNT_LIMIT = "gemfire-log-file-count-limit";
- private File config = null;
+ private File config;
@After
- public void tearDownLogWriterLoggerPerformanceTest() throws Exception {
- this.config = null; // leave this file in place for now
+ public void tearDownLogWriterLoggerPerformanceTest() {
+ config = null; // leave this file in place for now
}
- protected void writeConfigFile(final File file) throws FileNotFoundException {
- final PrintWriter pw = new PrintWriter(new FileOutputStream(file));
- pw.println();
- pw.close();
- }
-
- protected void setPropertySubstitutionValues(final String logFile, final int logFileSizeLimitMB,
+ private void setPropertySubstitutionValues(final String logFile, final int logFileSizeLimitMB,
final int logFileCountLimit) {
if (logFileSizeLimitMB < 0) {
throw new IllegalArgumentException("logFileSizeLimitMB must be zero or positive integer");
@@ -82,22 +74,22 @@ public class LogWriterLoggerPerformanceTest extends LoggingPerformanceTestCase {
System.setProperty(SYS_LOG_FILE_COUNT_LIMIT, logFileCountLimitValue);
}
- protected Logger createLogger() throws IOException {
+ Logger createLogger() throws IOException {
// create configuration with log-file and log-level
- this.configDirectory = new File(getUniqueName());
- this.configDirectory.mkdir();
- assertTrue(this.configDirectory.isDirectory() && this.configDirectory.canWrite());
+ configDirectory = new File(getUniqueName());
+ configDirectory.mkdir();
+ assertTrue(configDirectory.isDirectory() && configDirectory.canWrite());
// copy the log4j2-test.xml to the configDirectory
// final URL srcURL =
// getClass().getResource("/org/apache/geode/internal/logging/log4j/log4j2-test.xml");
final URL srcURL = getClass().getResource("log4j2-test.xml");
final File src = new File(srcURL.getFile());
- FileUtils.copyFileToDirectory(src, this.configDirectory);
- this.config = new File(this.configDirectory, "log4j2-test.xml");
- assertTrue(this.config.exists());
+ FileUtils.copyFileToDirectory(src, configDirectory);
+ config = new File(configDirectory, "log4j2-test.xml");
+ assertTrue(config.exists());
- this.logFile = new File(this.configDirectory, DistributionConfig.GEMFIRE_PREFIX + "log");
+ logFile = new File(configDirectory, DistributionConfig.GEMFIRE_PREFIX + "log");
final String logFilePath = IOUtils.tryGetCanonicalPathElseGetAbsolutePath(logFile);
final String logFileName =
logFilePath.substring(0, logFilePath.lastIndexOf(File.separatorChar));
@@ -105,10 +97,10 @@ public class LogWriterLoggerPerformanceTest extends LoggingPerformanceTestCase {
DEFAULT_LOG_FILE_COUNT_LIMIT);
final String configPath =
- "file://" + IOUtils.tryGetCanonicalPathElseGetAbsolutePath(this.config);
+ "file://" + IOUtils.tryGetCanonicalPathElseGetAbsolutePath(config);
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configPath);
- final Logger logger = LogWriterLogger.create(this.getClass().getName(), false);
+ final Logger logger = LogWriterLogger.create(getClass().getName(), false);
return logger;
}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/LogServiceJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/LogServiceTest.java
similarity index 83%
rename from geode-core/src/test/java/org/apache/geode/internal/logging/LogServiceJUnitTest.java
rename to geode-core/src/test/java/org/apache/geode/internal/logging/LogServiceTest.java
index 42cca54..1e7e8b0 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/logging/LogServiceJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/logging/LogServiceTest.java
@@ -26,16 +26,19 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.apache.geode.internal.ClassPathLoader;
import org.apache.geode.internal.logging.log4j.AppenderContext;
+import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Unit tests for LogService
*/
@RunWith(JUnitParamsRunner.class)
-public class LogServiceJUnitTest {
+@Category(LoggingTest.class)
+public class LogServiceTest {
private URL defaultConfigUrl;
private URL cliConfigUrl;
@@ -45,19 +48,19 @@ public class LogServiceJUnitTest {
@Before
public void setUp() {
- this.defaultConfigUrl = LogService.class.getResource(LogService.DEFAULT_CONFIG);
- this.cliConfigUrl = LogService.class.getResource(LogService.CLI_CONFIG);
+ defaultConfigUrl = LogService.class.getResource(LogService.DEFAULT_CONFIG);
+ cliConfigUrl = LogService.class.getResource(LogService.CLI_CONFIG);
}
@Test
- public void getAppenderContextShouldHaveEmptyName() throws Exception {
+ public void getAppenderContextShouldHaveEmptyName() {
final AppenderContext appenderContext = LogService.getAppenderContext();
assertThat(appenderContext.getName()).isEmpty();
}
@Test
- public void getAppenderContextWithNameShouldHaveName() throws Exception {
+ public void getAppenderContextWithNameShouldHaveName() {
final String name = "someName";
final AppenderContext appenderContext = LogService.getAppenderContext(name);
@@ -72,14 +75,14 @@ public class LogServiceJUnitTest {
@Test
public void cliConfigLoadsAsResource() {
- assertThat(this.cliConfigUrl).isNotNull();
- assertThat(this.cliConfigUrl.toString()).contains(LogService.CLI_CONFIG);
+ assertThat(cliConfigUrl).isNotNull();
+ assertThat(cliConfigUrl.toString()).contains(LogService.CLI_CONFIG);
}
@Test
public void defaultConfigLoadsAsResource() {
- assertThat(this.defaultConfigUrl).isNotNull();
- assertThat(this.defaultConfigUrl.toString()).contains(LogService.DEFAULT_CONFIG);
+ assertThat(defaultConfigUrl).isNotNull();
+ assertThat(defaultConfigUrl.toString()).contains(LogService.DEFAULT_CONFIG);
}
@Test
diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/LogWriterImplJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/LogWriterImplTest.java
similarity index 95%
rename from geode-core/src/test/java/org/apache/geode/internal/logging/LogWriterImplJUnitTest.java
rename to geode-core/src/test/java/org/apache/geode/internal/logging/LogWriterImplTest.java
index f899ae5..04ad2cc 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/logging/LogWriterImplJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/logging/LogWriterImplTest.java
@@ -17,9 +17,12 @@ package org.apache.geode.internal.logging;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.apache.geode.test.junit.categories.LoggingTest;
-public class LogWriterImplJUnitTest {
+@Category(LoggingTest.class)
+public class LogWriterImplTest {
@Test
public void testAllowedLogLevels() {
diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/SortLogFileJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/SortLogFileTest.java
similarity index 75%
rename from geode-core/src/test/java/org/apache/geode/internal/logging/SortLogFileJUnitTest.java
rename to geode-core/src/test/java/org/apache/geode/internal/logging/SortLogFileTest.java
index 3792f04..329908a 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/logging/SortLogFileJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/logging/SortLogFileTest.java
@@ -27,15 +27,18 @@ import java.util.Date;
import java.util.Random;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.apache.geode.LogWriter;
+import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Tests the functionality of the {@link SortLogFile} program.
*
* @since GemFire 3.0
*/
-public class SortLogFileJUnitTest {
+@Category(LoggingTest.class)
+public class SortLogFileTest {
/**
* Generates a "log file" whose entry timestamps are in a random order. Then it sorts the log file
@@ -44,28 +47,28 @@ public class SortLogFileJUnitTest {
@Test
public void testRandomLog() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintWriter pw = new PrintWriter(new OutputStreamWriter(baos), true);
- LogWriter logger = new RandomLogWriter(pw);
+ PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(baos), true);
+ LogWriter logger = new RandomLogWriter(printWriter);
for (int i = 0; i < 100; i++) {
logger.info(String.valueOf(i));
}
- pw.flush();
- pw.close();
+ printWriter.flush();
+ printWriter.close();
byte[] bytes = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- StringWriter sw = new StringWriter();
- pw = new PrintWriter(sw, true);
- SortLogFile.sortLogFile(bais, pw);
+ StringWriter stringWriter = new StringWriter();
+ printWriter = new PrintWriter(stringWriter, true);
+ SortLogFile.sortLogFile(bais, printWriter);
- String sorted = sw.toString();
+ String sorted = stringWriter.toString();
- BufferedReader br = new BufferedReader(new StringReader(sorted));
- LogFileParser parser = new LogFileParser(null, br);
+ BufferedReader reader = new BufferedReader(new StringReader(sorted));
+ LogFileParser parser = new LogFileParser(null, reader);
String prevTimestamp = null;
while (parser.hasMoreEntries()) {
LogFileParser.LogEntry entry = parser.getNextEntry();
@@ -84,13 +87,13 @@ public class SortLogFileJUnitTest {
private static class RandomLogWriter extends LocalLogWriter {
/** Used to generate a random date */
- private Random random = new Random();
+ private final Random random = new Random();
/**
* Creates a new <code>RandomLogWriter</code> that logs to the given <code>PrintWriter</code>.
*/
- public RandomLogWriter(PrintWriter pw) {
- super(ALL_LEVEL, pw);
+ RandomLogWriter(PrintWriter printWriter) {
+ super(ALL_LEVEL, printWriter);
}
/**
@@ -98,7 +101,7 @@ public class SortLogFileJUnitTest {
*/
@Override
protected String formatDate(Date date) {
- long time = date.getTime() + (random.nextInt(100000) * 1000);
+ long time = date.getTime() + random.nextInt(100000) * 1000;
date = new Date(time);
return super.formatDate(date);
}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/FastLoggerJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/FastLoggerTest.java
similarity index 61%
rename from geode-core/src/test/java/org/apache/geode/internal/logging/log4j/FastLoggerJUnitTest.java
rename to geode-core/src/test/java/org/apache/geode/internal/logging/log4j/FastLoggerTest.java
index 7ef021a..3ae40b8 100755
--- a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/FastLoggerJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/FastLoggerTest.java
@@ -31,13 +31,16 @@ import org.apache.logging.log4j.message.ParameterizedMessageFactory;
import org.apache.logging.log4j.spi.ExtendedLogger;
import org.junit.Before;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.apache.geode.test.junit.categories.LoggingTest;
/**
* Unit tests the FastLogger class which wraps and delegates to an actual Logger with optimizations
* for isDebugEnabled and isTraceEnabled.
*/
-public class FastLoggerJUnitTest {
+@Category(LoggingTest.class)
+public class FastLoggerTest {
private MessageFactory messageFactory;
private ExtendedLogger mockedLogger;
@@ -45,12 +48,12 @@ public class FastLoggerJUnitTest {
@Before
public void setUp() {
- this.messageFactory = new ParameterizedMessageFactory();
- this.mockedLogger = mock(ExtendedLogger.class);
- this.mockedMarker = mock(Marker.class);
+ messageFactory = new ParameterizedMessageFactory();
+ mockedLogger = mock(ExtendedLogger.class);
+ mockedMarker = mock(Marker.class);
- when(this.mockedLogger.getMessageFactory()).thenReturn(this.messageFactory);
- when(this.mockedMarker.getName()).thenReturn("MARKER");
+ when(mockedLogger.getMessageFactory()).thenReturn(messageFactory);
+ when(mockedMarker.getName()).thenReturn("MARKER");
}
/**
@@ -60,7 +63,7 @@ public class FastLoggerJUnitTest {
public void returnIsDelegatingAfterSetDelegating() {
FastLogger.setDelegating(true);
- FastLogger fastLogger = new FastLogger(this.mockedLogger);
+ FastLogger fastLogger = new FastLogger(mockedLogger);
assertThat(fastLogger.isDelegating(), is(true));
@@ -75,12 +78,12 @@ public class FastLoggerJUnitTest {
@Test
public void delegateGetLevel() {
FastLogger.setDelegating(true);
- when(this.mockedLogger.getLevel()).thenReturn(Level.DEBUG);
+ when(mockedLogger.getLevel()).thenReturn(Level.DEBUG);
- FastLogger fastLogger = new FastLogger(this.mockedLogger);
+ FastLogger fastLogger = new FastLogger(mockedLogger);
assertThat(fastLogger.getLevel(), is(Level.DEBUG));
- verify(this.mockedLogger, times(1)).getLevel();
+ verify(mockedLogger, times(1)).getLevel();
}
/**
@@ -89,19 +92,19 @@ public class FastLoggerJUnitTest {
@Test
public void delegateIsDebugEnabledWhenIsDelegating() {
FastLogger.setDelegating(true);
- when(this.mockedLogger.getLevel()).thenReturn(Level.DEBUG);
- when(this.mockedLogger.isEnabled(eq(Level.DEBUG), isNull(Marker.class), isNull(String.class)))
+ when(mockedLogger.getLevel()).thenReturn(Level.DEBUG);
+ when(mockedLogger.isEnabled(eq(Level.DEBUG), isNull(Marker.class), isNull(String.class)))
.thenReturn(true);
- when(this.mockedLogger.isEnabled(eq(Level.DEBUG), eq(this.mockedMarker), isNull(Object.class),
+ when(mockedLogger.isEnabled(eq(Level.DEBUG), eq(mockedMarker), isNull(Object.class),
isNull(Throwable.class))).thenReturn(true);
- FastLogger fastLogger = new FastLogger(this.mockedLogger);
+ FastLogger fastLogger = new FastLogger(mockedLogger);
assertThat(fastLogger.isDebugEnabled(), is(true));
- assertThat(fastLogger.isDebugEnabled(this.mockedMarker), is(true));
- verify(this.mockedLogger, times(1)).isEnabled(eq(Level.DEBUG), isNull(Marker.class),
+ assertThat(fastLogger.isDebugEnabled(mockedMarker), is(true));
+ verify(mockedLogger, times(1)).isEnabled(eq(Level.DEBUG), isNull(Marker.class),
isNull(String.class));
- verify(this.mockedLogger, times(1)).isEnabled(eq(Level.DEBUG), eq(this.mockedMarker),
+ verify(mockedLogger, times(1)).isEnabled(eq(Level.DEBUG), eq(mockedMarker),
isNull(Object.class), isNull(Throwable.class));
}
@@ -111,19 +114,19 @@ public class FastLoggerJUnitTest {
@Test
public void delegateIsTraceEnabledWhenIsDelegating() {
FastLogger.setDelegating(true);
- when(this.mockedLogger.getLevel()).thenReturn(Level.TRACE);
- when(this.mockedLogger.isEnabled(eq(Level.TRACE), isNull(Marker.class), isNull(Object.class),
+ when(mockedLogger.getLevel()).thenReturn(Level.TRACE);
+ when(mockedLogger.isEnabled(eq(Level.TRACE), isNull(Marker.class), isNull(Object.class),
isNull(Throwable.class))).thenReturn(true);
- when(this.mockedLogger.isEnabled(eq(Level.TRACE), eq(this.mockedMarker), isNull(Object.class),
+ when(mockedLogger.isEnabled(eq(Level.TRACE), eq(mockedMarker), isNull(Object.class),
isNull(Throwable.class))).thenReturn(true);
- FastLogger fastLogger = new FastLogger(this.mockedLogger);
+ FastLogger fastLogger = new FastLogger(mockedLogger);
assertThat(fastLogger.isTraceEnabled(), is(true));
- assertThat(fastLogger.isTraceEnabled(this.mockedMarker), is(true));
- verify(this.mockedLogger, times(1)).isEnabled(eq(Level.TRACE), isNull(Marker.class),
+ assertThat(fastLogger.isTraceEnabled(mockedMarker), is(true));
+ verify(mockedLogger, times(1)).isEnabled(eq(Level.TRACE), isNull(Marker.class),
isNull(Object.class), isNull(Throwable.class));
- verify(this.mockedLogger, times(1)).isEnabled(eq(Level.TRACE), eq(this.mockedMarker),
+ verify(mockedLogger, times(1)).isEnabled(eq(Level.TRACE), eq(mockedMarker),
isNull(Object.class), isNull(Throwable.class));
}
@@ -133,16 +136,16 @@ public class FastLoggerJUnitTest {
@Test
public void notDelegateIsDebugEnabledWhenNotIsDelegating() {
FastLogger.setDelegating(false);
- when(this.mockedLogger.getLevel()).thenReturn(Level.INFO);
+ when(mockedLogger.getLevel()).thenReturn(Level.INFO);
- FastLogger fastLogger = new FastLogger(this.mockedLogger);
+ FastLogger fastLogger = new FastLogger(mockedLogger);
assertThat(fastLogger.getLevel(), is(Level.INFO));
assertThat(fastLogger.isDebugEnabled(), is(false));
- assertThat(fastLogger.isDebugEnabled(this.mockedMarker), is(false));
- verify(this.mockedLogger, times(0)).isEnabled(eq(Level.DEBUG), isNull(Marker.class),
+ assertThat(fastLogger.isDebugEnabled(mockedMarker), is(false));
+ verify(mockedLogger, times(0)).isEnabled(eq(Level.DEBUG), isNull(Marker.class),
isNull(String.class));
- verify(this.mockedLogger, times(0)).isEnabled(eq(Level.DEBUG), eq(this.mockedMarker),
+ verify(mockedLogger, times(0)).isEnabled(eq(Level.DEBUG), eq(mockedMarker),
isNull(Object.class), isNull(Throwable.class));
}
@@ -154,14 +157,14 @@ public class FastLoggerJUnitTest {
FastLogger.setDelegating(false);
when(mockedLogger.getLevel()).thenReturn(Level.INFO);
- FastLogger fastLogger = new FastLogger(this.mockedLogger);
+ FastLogger fastLogger = new FastLogger(mockedLogger);
assertThat(fastLogger.getLevel(), is(Level.INFO));
assertThat(fastLogger.isTraceEnabled(), is(false));
- assertThat(fastLogger.isTraceEnabled(this.mockedMarker), is(false));
- verify(this.mockedLogger, times(0)).isEnabled(eq(Level.TRACE), isNull(Marker.class),
+ assertThat(fastLogger.isTraceEnabled(mockedMarker), is(false));
+ verify(mockedLogger, times(0)).isEnabled(eq(Level.TRACE), isNull(Marker.class),
isNull(String.class));
- verify(this.mockedLogger, times(0)).isEnabled(eq(Level.TRACE), eq(this.mockedMarker),
+ verify(mockedLogger, times(0)).isEnabled(eq(Level.TRACE), eq(mockedMarker),
isNull(Object.class), isNull(Throwable.class));
}
@@ -170,9 +173,9 @@ public class FastLoggerJUnitTest {
*/
@Test
public void wrapDelegateAndReturnFromGetExtendedLogger() {
- FastLogger fastLogger = new FastLogger(this.mockedLogger);
+ FastLogger fastLogger = new FastLogger(mockedLogger);
- assertThat(fastLogger.getExtendedLogger(), is(sameInstance(this.mockedLogger)));
+ assertThat(fastLogger.getExtendedLogger(), is(sameInstance(mockedLogger)));
}
/**
@@ -180,11 +183,11 @@ public class FastLoggerJUnitTest {
*/
@Test
public void delegateGetName() {
- when(this.mockedLogger.getName()).thenReturn("name");
+ when(mockedLogger.getName()).thenReturn("name");
- FastLogger fastLogger = new FastLogger(this.mockedLogger);
+ FastLogger fastLogger = new FastLogger(mockedLogger);
assertThat(fastLogger.getName(), is("name"));
- verify(this.mockedLogger, times(1)).getName();
+ verify(mockedLogger, times(1)).getName();
}
}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogLevelTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogLevelTest.java
index 85663d9..84b8054 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogLevelTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogLevelTest.java
@@ -12,7 +12,6 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.internal.logging.log4j;
import static org.assertj.core.api.Assertions.assertThat;
@@ -20,10 +19,14 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.apache.logging.log4j.Level;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.apache.geode.internal.logging.InternalLogWriter;
+import org.apache.geode.test.junit.categories.LoggingTest;
+@Category(LoggingTest.class)
public class LogLevelTest {
+
@Test
public void testGetLevel() {
assertThat(LogLevel.getLevel("all")).isEqualTo(Level.ALL);
@@ -67,7 +70,7 @@ public class LogLevelTest {
}
@Test
- public void testGetLog4jLevel() throws Exception {
+ public void testGetLog4jLevel() {
assertThat(LogLevel.getLog4jLevel(InternalLogWriter.SEVERE_LEVEL)).isEqualTo(Level.FATAL);
assertThat(LogLevel.getLog4jLevel(InternalLogWriter.ERROR_LEVEL)).isEqualTo(Level.ERROR);
assertThat(LogLevel.getLog4jLevel(InternalLogWriter.WARNING_LEVEL)).isEqualTo(Level.WARN);
@@ -83,7 +86,7 @@ public class LogLevelTest {
}
@Test
- public void testGetLogWriterLevel() throws Exception {
+ public void testGetLogWriterLevel() {
assertThat(LogLevel.getLogWriterLevel(Level.FATAL)).isEqualTo(InternalLogWriter.SEVERE_LEVEL);
assertThat(LogLevel.getLogWriterLevel(Level.ERROR)).isEqualTo(InternalLogWriter.ERROR_LEVEL);
assertThat(LogLevel.getLogWriterLevel(Level.WARN)).isEqualTo(InternalLogWriter.WARNING_LEVEL);
@@ -95,7 +98,7 @@ public class LogLevelTest {
}
@Test
- public void testGetLogWriterLevelWithString() throws Exception {
+ public void testGetLogWriterLevelWithString() {
assertThat(LogLevel.getLogWriterLevel("FATAL")).isEqualTo(InternalLogWriter.SEVERE_LEVEL);
assertThat(LogLevel.getLogWriterLevel("error")).isEqualTo(InternalLogWriter.ERROR_LEVEL);
assertThat(LogLevel.getLogWriterLevel("WARN")).isEqualTo(InternalLogWriter.WARNING_LEVEL);
diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/custom/CustomConfiguration.java b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/custom/CustomConfiguration.java
deleted file mode 100644
index b709300..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/custom/CustomConfiguration.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.internal.logging.log4j.custom;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.logging.log4j.Level;
-
-public class CustomConfiguration {
-
- public static final String CONFIG_FILE_NAME = "log4j2-custom.xml";
- public static final String CONFIG_LAYOUT_PREFIX = "CUSTOM";
-
- protected CustomConfiguration() {}
-
- public static URL openConfigResource() {
- return new CustomConfiguration().getClass().getResource(CONFIG_FILE_NAME);
- }
-
- public static File createConfigFileIn(final File targetFolder)
- throws IOException, URISyntaxException {
- URL resource = openConfigResource();
- File targetFile = new File(targetFolder, CONFIG_FILE_NAME);
- IOUtils.copy(resource.openStream(), new FileOutputStream(targetFile));
- assertThat(targetFile).hasSameContentAs(new File(resource.toURI()));
- return targetFile;
- }
-
- private static final String DATE =
- "((?:19|20)\\\\d\\\\d)/(0?[1-9]|1[012])/([12][0-9]|3[01]|0?[1-9])";
-
- private static final String TIME = "\\b(?<!')([xXzZ])(?!')\\b";
-
- public static String defineLogStatementRegex(final Level level, final String message) {
- // CUSTOM: level=%level time=%date{yyyy/MM/dd HH:mm:ss.SSS z}
- // message=%message%nthrowable=%throwable%n
- return CONFIG_LAYOUT_PREFIX + ": level=" + level.toString() + " time=" + ".*" + " message="
- + message + System.lineSeparator() + "throwable=" + System.lineSeparator();
- }
-
-}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommandTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommandTest.java
index f7ccb4c..ab21998 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommandTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommandTest.java
@@ -20,8 +20,8 @@ import static org.apache.geode.management.internal.cli.commands.ExportLogsComman
import static org.apache.geode.management.internal.cli.commands.ExportLogsCommand.TERABYTE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -32,10 +32,9 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.mockito.Matchers;
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.execute.Execution;
import org.apache.geode.cache.execute.FunctionException;
import org.apache.geode.cache.execute.ResultCollector;
import org.apache.geode.distributed.DistributedMember;
@@ -46,108 +45,111 @@ import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.cli.functions.SizeExportLogsFunction;
import org.apache.geode.management.internal.cli.result.CommandResult;
import org.apache.geode.management.internal.cli.util.BytesToString;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+@Category({GfshTest.class, LoggingTest.class})
public class ExportLogsCommandTest {
@Test
- public void parseSize_sizeWithUnit_shouldReturnSize() throws Exception {
+ public void parseSize_sizeWithUnit_shouldReturnSize() {
assertThat(ExportLogsCommand.parseSize("1000m")).isEqualTo(1000);
}
@Test
- public void parseSize_sizeWithoutUnit_shouldReturnSize() throws Exception {
+ public void parseSize_sizeWithoutUnit_shouldReturnSize() {
assertThat(ExportLogsCommand.parseSize("1000")).isEqualTo(1000);
}
@Test
- public void parseByteMultiplier_sizeWithoutUnit_shouldReturnDefaultUnit() throws Exception {
+ public void parseByteMultiplier_sizeWithoutUnit_shouldReturnDefaultUnit() {
assertThat(ExportLogsCommand.parseByteMultiplier("1000")).isEqualTo(MEGABYTE);
}
@Test
- public void parseByteMultiplier_sizeWith_k_shouldReturnUnit() throws Exception {
+ public void parseByteMultiplier_sizeWith_k_shouldReturnUnit() {
assertThat(ExportLogsCommand.parseByteMultiplier("1000k")).isEqualTo(KILOBYTE);
}
@Test
- public void parseByteMultiplier_sizeWith_m_shouldReturnUnit() throws Exception {
+ public void parseByteMultiplier_sizeWith_m_shouldReturnUnit() {
assertThat(ExportLogsCommand.parseByteMultiplier("1000m")).isEqualTo(MEGABYTE);
}
@Test
- public void parseByteMultiplier_sizeWith_g_shouldReturnUnit() throws Exception {
+ public void parseByteMultiplier_sizeWith_g_shouldReturnUnit() {
assertThat(ExportLogsCommand.parseByteMultiplier("1000g")).isEqualTo(GIGABYTE);
}
@Test
- public void parseByteMultiplier_sizeWith_t_shouldReturnUnit() throws Exception {
+ public void parseByteMultiplier_sizeWith_t_shouldReturnUnit() {
assertThat(ExportLogsCommand.parseByteMultiplier("1000t")).isEqualTo(TERABYTE);
}
@Test
- public void parseByteMultiplier_sizeWith_K_shouldReturnUnit() throws Exception {
+ public void parseByteMultiplier_sizeWith_K_shouldReturnUnit() {
assertThat(ExportLogsCommand.parseByteMultiplier("1000K")).isEqualTo(KILOBYTE);
}
@Test
- public void parseByteMultiplier_sizeWith_M_shouldReturnUnit() throws Exception {
+ public void parseByteMultiplier_sizeWith_M_shouldReturnUnit() {
assertThat(ExportLogsCommand.parseByteMultiplier("1000M")).isEqualTo(MEGABYTE);
}
@Test
- public void parseByteMultiplier_sizeWith_G_shouldReturnUnit() throws Exception {
+ public void parseByteMultiplier_sizeWith_G_shouldReturnUnit() {
assertThat(ExportLogsCommand.parseByteMultiplier("1000G")).isEqualTo(GIGABYTE);
}
@Test
- public void parseByteMultiplier_sizeWith_T_shouldReturnUnit() throws Exception {
+ public void parseByteMultiplier_sizeWith_T_shouldReturnUnit() {
assertThat(ExportLogsCommand.parseByteMultiplier("1000T")).isEqualTo(TERABYTE);
}
@Test
- public void parseByteMultiplier_illegalUnit_shouldThrow() throws Exception {
+ public void parseByteMultiplier_illegalUnit_shouldThrow() {
assertThatThrownBy(() -> ExportLogsCommand.parseByteMultiplier("1000q"))
.isInstanceOf(IllegalArgumentException.class);
}
@Test
- public void parseSize_garbage_shouldThrow() throws Exception {
+ public void parseSize_garbage_shouldThrow() {
assertThatThrownBy(() -> ExportLogsCommand.parseSize("bizbap"))
.isInstanceOf(IllegalArgumentException.class);
}
@Test
- public void parseByteMultiplier_garbage_shouldThrow() throws Exception {
+ public void parseByteMultiplier_garbage_shouldThrow() {
assertThatThrownBy(() -> ExportLogsCommand.parseByteMultiplier("bizbap"))
.isInstanceOf(IllegalArgumentException.class);
}
@Test
- public void parseSizeLimit_sizeWithoutUnit_shouldReturnMegabytesSize() throws Exception {
+ public void parseSizeLimit_sizeWithoutUnit_shouldReturnMegabytesSize() {
ExportLogsCommand exportCmd = new ExportLogsCommand();
assertThat(exportCmd.parseFileSizeLimit("1000")).isEqualTo(1000 * MEGABYTE);
}
@Test
- public void parseSizeLimit_sizeWith_K_shouldReturnKilobytesSize() throws Exception {
+ public void parseSizeLimit_sizeWith_K_shouldReturnKilobytesSize() {
ExportLogsCommand exportCmd = new ExportLogsCommand();
assertThat(exportCmd.parseFileSizeLimit("1000k")).isEqualTo(1000 * KILOBYTE);
}
@Test
- public void parseSizeLimit_sizeWith_M_shouldReturnMegabytesSize() throws Exception {
+ public void parseSizeLimit_sizeWith_M_shouldReturnMegabytesSize() {
ExportLogsCommand exportCmd = new ExportLogsCommand();
assertThat(exportCmd.parseFileSizeLimit("1000m")).isEqualTo(1000 * MEGABYTE);
}
@Test
- public void parseSizeLimit_sizeWith_G_shouldReturnMegabytesSize() throws Exception {
+ public void parseSizeLimit_sizeWith_G_shouldReturnMegabytesSize() {
ExportLogsCommand exportCmd = new ExportLogsCommand();
assertThat(exportCmd.parseFileSizeLimit("1000g")).isEqualTo(1000 * GIGABYTE);
}
@Test
- public void parseSizeLimit_sizeWith_T_shouldReturnMegabytesSize() throws Exception {
+ public void parseSizeLimit_sizeWith_T_shouldReturnMegabytesSize() {
ExportLogsCommand exportCmd = new ExportLogsCommand();
assertThat(exportCmd.parseFileSizeLimit("1000t")).isEqualTo(1000 * TERABYTE);
}
@@ -272,28 +274,9 @@ public class ExportLogsCommandTest {
"Estimated disk space required (1 GB) to consolidate logs on member member1 will exceed available disk space (500 MB)");
}
- private ExportLogsCommand createExportLogsCommand(final Cache cache,
- final DistributedMember distributedMember, final Execution functionExecutor) {
- return new TestExportLogsCommand(cache, distributedMember, functionExecutor);
- }
-
- private static class TestExportLogsCommand extends ExportLogsCommand {
-
- private final Cache cache;
- private final DistributedMember distributedMember;
- private final Execution functionExecutor;
-
- TestExportLogsCommand(final Cache cache, final DistributedMember distributedMember,
- final Execution functionExecutor) {
- assert cache != null;
- this.cache = cache;
- this.distributedMember = distributedMember;
- this.functionExecutor = functionExecutor;
- }
- }
+ private static class CustomCollector implements ResultCollector<Object, List<Object>> {
- public static class CustomCollector implements ResultCollector<Object, List<Object>> {
- private ArrayList<Object> results = new ArrayList<>();
+ private final ArrayList<Object> results = new ArrayList<>();
@Override
public List<Object> getResult() throws FunctionException {
@@ -302,7 +285,7 @@ public class ExportLogsCommandTest {
@Override
public List<Object> getResult(final long timeout, final TimeUnit unit)
- throws FunctionException, InterruptedException {
+ throws FunctionException {
return results;
}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsInterceptorJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsInterceptorTest.java
similarity index 92%
rename from geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsInterceptorJUnitTest.java
rename to geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsInterceptorTest.java
index dbcfdf3..b54e32d 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsInterceptorJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsInterceptorTest.java
@@ -12,7 +12,6 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.cli.commands;
import static org.assertj.core.api.Assertions.assertThat;
@@ -20,12 +19,17 @@ import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.mockito.Mockito;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.cli.GfshParseResult;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+
+@Category({GfshTest.class, LoggingTest.class})
+public class ExportLogsInterceptorTest {
-public class ExportLogsInterceptorJUnitTest {
private ExportLogsInterceptor interceptor;
private GfshParseResult parseResult;
private Result result;
@@ -47,7 +51,6 @@ public class ExportLogsInterceptorJUnitTest {
assertThat(result.nextLine()).contains("Can't specify both group and member");
}
-
@Test
public void testStartEnd() {
when(parseResult.getParamValueAsString("start-time")).thenReturn("2000/01/01");
@@ -72,6 +75,5 @@ public class ExportLogsInterceptorJUnitTest {
when(parseResult.getParamValue("stats-only")).thenReturn(true);
result = interceptor.preExecution(parseResult);
assertThat(result.nextLine()).contains("logs-only and stats-only can't both be true");
-
}
}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/LogLevelInterceptorTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/LogLevelInterceptorTest.java
index 6cd337c..2e583f2 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/LogLevelInterceptorTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/LogLevelInterceptorTest.java
@@ -12,7 +12,6 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.cli.commands;
import static org.assertj.core.api.Assertions.assertThat;
@@ -23,14 +22,19 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.mockito.Mockito;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.cli.AbstractCliAroundInterceptor;
import org.apache.geode.management.internal.cli.GfshParseResult;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+@Category({GfshTest.class, LoggingTest.class})
public class LogLevelInterceptorTest {
- private List<AbstractCliAroundInterceptor> interceptors = new ArrayList<>();
+
+ private final List<AbstractCliAroundInterceptor> interceptors = new ArrayList<>();
private GfshParseResult parseResult;
private Result result;
@@ -42,7 +46,6 @@ public class LogLevelInterceptorTest {
parseResult = Mockito.mock(GfshParseResult.class);
when(parseResult.getParamValue("logs-only")).thenReturn(true);
when(parseResult.getParamValue("stats-only")).thenReturn(false);
-
}
@Test
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/converters/LogLevelConverterTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/converters/LogLevelConverterTest.java
index 03ad5ac..f094519 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/converters/LogLevelConverterTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/converters/LogLevelConverterTest.java
@@ -12,10 +12,8 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.cli.converters;
-
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
@@ -23,15 +21,19 @@ import java.util.List;
import org.apache.logging.log4j.Level;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.springframework.shell.core.Completion;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+@Category({GfshTest.class, LoggingTest.class})
public class LogLevelConverterTest {
@Test
- public void testCompletionContainsOnlyLog4jLevels() throws Exception {
+ public void testCompletionContainsOnlyLog4jLevels() {
LogLevelConverter converter = new LogLevelConverter();
- List<Completion> completions = new ArrayList();
+ List<Completion> completions = new ArrayList<>();
converter.getAllPossibleValues(completions, null, null, null, null);
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunctionTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunctionTest.java
index 721dbe3..00d02d3 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunctionTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunctionTest.java
@@ -13,7 +13,6 @@
* the License.
*
*/
-
package org.apache.geode.management.internal.cli.functions;
import static org.assertj.core.api.Assertions.assertThat;
@@ -22,19 +21,24 @@ import static org.junit.Assert.assertTrue;
import org.apache.logging.log4j.Level;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.apache.geode.internal.logging.log4j.LogLevel;
import org.apache.geode.management.internal.cli.commands.ExportLogsCommand;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+@Category({GfshTest.class, LoggingTest.class})
public class ExportLogsFunctionTest {
+
@Test
- public void defaultExportLogLevelShouldBeAll() throws Exception {
+ public void defaultExportLogLevelShouldBeAll() {
assertTrue(ExportLogsCommand.DEFAULT_EXPORT_LOG_LEVEL.equals("ALL"));
assertEquals(LogLevel.getLevel(ExportLogsCommand.DEFAULT_EXPORT_LOG_LEVEL), Level.ALL);
}
@Test
- public void defaultExportLogLevelShouldBeAllViaArgs() throws Exception {
+ public void defaultExportLogLevelShouldBeAllViaArgs() {
ExportLogsFunction.Args args = new ExportLogsFunction.Args("", "", "", false, false, false);
assertEquals(args.getLogLevel(), Level.ALL);
ExportLogsFunction.Args args2 = new ExportLogsFunction.Args("", "", null, false, false, false);
@@ -70,5 +74,4 @@ public class ExportLogsFunctionTest {
assertThat(args.isIncludeLogs()).isTrue();
assertThat(args.isIncludeStats()).isFalse();
}
-
}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ExportLogsCacheWriterUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ExportLogsCacheWriterTest.java
similarity index 81%
rename from geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ExportLogsCacheWriterUnitTest.java
rename to geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ExportLogsCacheWriterTest.java
index ad51dbf..f61f978 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ExportLogsCacheWriterUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ExportLogsCacheWriterTest.java
@@ -12,7 +12,6 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.cli.util;
import static org.assertj.core.api.Assertions.assertThat;
@@ -20,11 +19,16 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.apache.geode.cache.EntryEvent;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+
+@Category({GfshTest.class, LoggingTest.class})
+public class ExportLogsCacheWriterTest {
-public class ExportLogsCacheWriterUnitTest {
- private ExportLogsCacheWriter writer = new ExportLogsCacheWriter();
+ private final ExportLogsCacheWriter writer = new ExportLogsCacheWriter();
@Test
public void writerReturnNullIfNoWrite() throws Exception {
@@ -40,5 +44,4 @@ public class ExportLogsCacheWriterUnitTest {
writer.beforeCreate(event);
assertThat(writer.endFile()).isNotNull();
}
-
}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogFilterTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogFilterTest.java
index fee27db..659bdeb 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogFilterTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogFilterTest.java
@@ -13,7 +13,6 @@
* the License.
*
*/
-
package org.apache.geode.management.internal.cli.util;
import static org.apache.geode.management.internal.cli.util.LogFilter.LineFilterResult.LINE_ACCEPTED;
@@ -32,11 +31,16 @@ import java.time.LocalDateTime;
import org.apache.logging.log4j.Level;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+@Category({GfshTest.class, LoggingTest.class})
public class LogFilterTest {
+
@Test
- public void permittedLogLevelsCanFilterLines() throws Exception {
+ public void permittedLogLevelsCanFilterLines() {
LogFilter logFilter = new LogFilter(Level.INFO, null, null);
LocalDateTime now = LocalDateTime.now();
@@ -47,7 +51,7 @@ public class LogFilterTest {
}
@Test
- public void permittedOnlyLogLevels() throws Exception {
+ public void permittedOnlyLogLevels() {
LogFilter logFilter = new LogFilter(Level.INFO, true, null, null);
LocalDateTime now = LocalDateTime.now();
@@ -58,7 +62,7 @@ public class LogFilterTest {
}
@Test
- public void permittedLogLevelsALL() throws Exception {
+ public void permittedLogLevelsALL() {
LogFilter logFilter = new LogFilter(Level.ALL, null, null);
LocalDateTime now = LocalDateTime.now();
@@ -68,7 +72,6 @@ public class LogFilterTest {
assertThat(logFilter.acceptsLogEntry(Level.TRACE, now)).isEqualTo(LINE_ACCEPTED);
}
-
@Test
public void startDateCanFilterLines() {
LocalDateTime startDate = LocalDateTime.now().minusDays(2);
@@ -113,7 +116,6 @@ public class LogFilterTest {
assertThat(logFilter.acceptsLogEntry(null)).isEqualTo(LINE_REJECTED);
-
assertThat(logFilter.acceptsLogEntry(Level.ERROR, LocalDateTime.now().minusDays(6)))
.isEqualTo(LINE_REJECTED);
assertThat(logFilter.acceptsLogEntry(null)).isEqualTo(LINE_REJECTED);
@@ -122,8 +124,6 @@ public class LogFilterTest {
.isEqualTo(LINE_ACCEPTED);
assertThat(logFilter.acceptsLogEntry(null)).isEqualTo(LINE_ACCEPTED);
-
-
assertThat(logFilter.acceptsLogEntry(Level.ERROR, LocalDateTime.now().minusDays(1)))
.isEqualTo(REMAINDER_OF_FILE_REJECTED);
assertThat(logFilter.acceptsLogEntry(null)).isEqualTo(REMAINDER_OF_FILE_REJECTED);
@@ -145,7 +145,7 @@ public class LogFilterTest {
}
@Test
- public void testAcceptFileWithCreateTimeNotAvailale() throws Exception {
+ public void testAcceptFileWithCreateTimeNotAvailale() {
Path path = mock(Path.class);
when(path.toFile()).thenReturn(mock(File.class));
when(path.toFile().lastModified()).thenReturn(System.currentTimeMillis());
@@ -176,7 +176,6 @@ public class LogFilterTest {
@Test
public void testAcceptFileWithCreateTimeAvailable() throws Exception {
- long now = System.currentTimeMillis();
Path path = mock(Path.class);
when(path.toFile()).thenReturn(mock(File.class));
when(path.toFile().lastModified()).thenReturn(System.currentTimeMillis());
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogLevelExtractorTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogLevelExtractorTest.java
index 04bc6c8..28230c3 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogLevelExtractorTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogLevelExtractorTest.java
@@ -11,21 +11,23 @@
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
- *
*/
-
package org.apache.geode.management.internal.cli.util;
-
import static org.assertj.core.api.Assertions.assertThat;
import org.apache.logging.log4j.Level;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+@Category({GfshTest.class, LoggingTest.class})
public class LogLevelExtractorTest {
+
@Test
- public void extractWorksCorrectlyForLineFromLogFile() throws Exception {
+ public void extractWorksCorrectlyForLineFromLogFile() {
String logLine =
"[info 2017/02/07 11:16:36.694 PST locator1 <locator request thread[1]> tid=0x27] Mapped \"{[/v1/async-event-queues],methods=[GET]}\" onto public java.lang.String";
@@ -38,7 +40,7 @@ public class LogLevelExtractorTest {
}
@Test
- public void extractWorksForFine() throws Exception {
+ public void extractWorksForFine() {
String logLine =
"[fine 2017/02/07 11:16:36.694 PST locator1 <locator request thread[1]> tid=0x27] Mapped \"{[/v1/async-event-queues],methods=[GET]}\" onto public java.lang.String";
@@ -51,7 +53,7 @@ public class LogLevelExtractorTest {
}
@Test
- public void extractWorksForFiner() throws Exception {
+ public void extractWorksForFiner() {
String logLine =
"[finer 2017/02/07 11:16:36.694 PST locator1 <locator request thread[1]> tid=0x27] Mapped \"{[/v1/async-event-queues],methods=[GET]}\" onto public java.lang.String";
@@ -63,7 +65,7 @@ public class LogLevelExtractorTest {
}
@Test
- public void extractWorksForFinest() throws Exception {
+ public void extractWorksForFinest() {
String logLine =
"[finest 2017/02/07 11:16:36.694 PST locator1 <locator request thread[1]> tid=0x27] Mapped \"{[/v1/async-event-queues],methods=[GET]}\" onto public java.lang.String";
@@ -75,7 +77,7 @@ public class LogLevelExtractorTest {
}
@Test
- public void extractReturnsNullIfNoTimestamp() throws Exception {
+ public void extractReturnsNullIfNoTimestamp() {
String logLine = "[info (this line is not a valid log statement since it has no timestamp)";
LogLevelExtractor.Result result = LogLevelExtractor.extract(logLine);
@@ -84,7 +86,7 @@ public class LogLevelExtractorTest {
}
@Test
- public void extractReturnsNullIfLineDoesNotMatchPattern() throws Exception {
+ public void extractReturnsNullIfLineDoesNotMatchPattern() {
String logLine = "some line containing a date like 2017/02/07 11:16:36.694 PST ";
LogLevelExtractor.Result result = LogLevelExtractor.extract(logLine);
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogSizerTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogSizerTest.java
index 9668c01..81eff54 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogSizerTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogSizerTest.java
@@ -20,26 +20,25 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.File;
-import java.io.IOException;
-import java.text.ParseException;
-import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.apache.geode.management.internal.cli.functions.ExportLogsFunction;
import org.apache.geode.management.internal.cli.functions.SizeExportLogsFunction;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+@Category({GfshTest.class, LoggingTest.class})
public class LogSizerTest {
+
private LogFilter logFilter;
private SizeExportLogsFunction.Args nonFilteringArgs;
@Rule
- public TemporaryFolder temporaryFolder = new TemporaryFolder();
- @Rule
public TestName testName = new TestName();
@Before
@@ -48,20 +47,14 @@ public class LogSizerTest {
nonFilteringArgs = new ExportLogsFunction.Args(null, null, null, false, false, false);
}
- @After
- public void tearDown() throws Exception {
-
- }
-
@Test
- public void nullFileArgs_returnsZeroSize() throws ParseException, IOException {
+ public void nullFileArgs_returnsZeroSize() throws Exception {
LogExporter sizer = new LogExporter(logFilter, null, null);
assertThat(sizer.estimateFilteredSize()).isEqualTo(0L);
}
@Test
- public void noFiles_returnsZeroSize() throws ParseException, IOException {
-
+ public void noFiles_returnsZeroSize() throws Exception {
File mockStatFile = mock(File.class);
File mockLogFile = mock(File.class);
when(mockLogFile.toPath()).thenReturn(
@@ -73,8 +66,7 @@ public class LogSizerTest {
}
@Test
- public void emptyFiles_returnsZeroSize() throws ParseException, IOException {
-
+ public void emptyFiles_returnsZeroSize() throws Exception {
File mockStatFile = mock(File.class);
File mockLogFile = mock(File.class);
when(mockLogFile.toPath()).thenReturn(
@@ -88,5 +80,4 @@ public class LogSizerTest {
LogExporter sizer = new LogExporter(logFilter, mockLogFile, mockStatFile);
assertThat(sizer.estimateFilteredSize()).isEqualTo(0L);
}
-
}
diff --git a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/custom/log4j2-custom.xml b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/custom/log4j2-custom.xml
deleted file mode 100644
index 574e969..0000000
--- a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/custom/log4j2-custom.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<Configuration status="FATAL" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j.custom">
- <Properties>
- <Property name="custom-pattern">CUSTOM: level=%level time=%date{yyyy/MM/dd HH:mm:ss.SSS z} message=%message%nthrowable=%throwable%n
- </Property>
- </Properties>
- <Appenders>
- <Console name="STDOUT" target="SYSTEM_OUT">
- <PatternLayout pattern="${custom-pattern}"/>
- </Console>
- <Basic name="CUSTOM">
- <PatternLayout pattern="${custom-pattern}"/>
- </Basic>
- </Appenders>
- <Loggers>
- <Logger name="com.gemstone" level="INFO" additivity="true"/>
- <Logger name="org.apache.geode" level="INFO" additivity="true">
- <filters>
- <MarkerFilter marker="GEODE_VERBOSE" onMatch="DENY" onMismatch="NEUTRAL"/>
- </filters>
- </Logger>
- <Logger name="org.apache.geode.internal.logging.log4j.custom" level="DEBUG" additivity="true"/>
- <Logger name="org.jgroups" level="FATAL" additivity="true"/>
- <Root level="INFO">
- <AppenderRef ref="CUSTOM"/>
- <AppenderRef ref="STDOUT"/>
- </Root>
- </Loggers>
-</Configuration>
diff --git a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-accept.xml b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-accept.xml
index 70f1531..37aff64 100644
--- a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-accept.xml
+++ b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-accept.xml
@@ -1,4 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
<Configuration status="FATAL" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j">
<Properties>
<Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property>
diff --git a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-deny.xml b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-deny.xml
index ca2416a..10281cb 100644
--- a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-deny.xml
+++ b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-deny.xml
@@ -1,4 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
<Configuration status="FATAL" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j">
<Properties>
<Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property>
diff --git a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-accept.xml b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-accept.xml
index 0f088db..d9d68dc 100644
--- a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-accept.xml
+++ b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-accept.xml
@@ -1,4 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
<Configuration status="FATAL" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j">
<Properties>
<Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property>
diff --git a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-deny.xml b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-deny.xml
index 9e8f90d..ec19f80 100644
--- a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-deny.xml
+++ b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-deny.xml
@@ -1,4 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
<Configuration status="FATAL" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j">
<Properties>
<Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property>
diff --git a/geode-core/src/test/resources/org/apache/geode/test/golden/log4j2-test.xml b/geode-core/src/test/resources/org/apache/geode/test/golden/log4j2-test.xml
index ba0b3b6..e5b3e4e 100755
--- a/geode-core/src/test/resources/org/apache/geode/test/golden/log4j2-test.xml
+++ b/geode-core/src/test/resources/org/apache/geode/test/golden/log4j2-test.xml
@@ -1,4 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
<Configuration status="ERROR" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j">
<Properties>
<Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property>
diff --git a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandDUnitTestBase.java b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandDistributedTestBase.java
similarity index 97%
rename from geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandDUnitTestBase.java
rename to geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandDistributedTestBase.java
index 27d98bd..11ea790 100644
--- a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandDUnitTestBase.java
+++ b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandDistributedTestBase.java
@@ -30,8 +30,8 @@ import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
import org.apache.geode.test.junit.rules.GfshCommandRule;
+public class ChangeLogLevelCommandDistributedTestBase {
-public class ChangeLogLevelCommandDUnitTestBase {
private static final String MANAGER_NAME = "Manager";
private static final String SERVER1_NAME = "Server1";
private static final String SERVER2_NAME = "Server2";
@@ -48,7 +48,7 @@ public class ChangeLogLevelCommandDUnitTestBase {
public static GfshCommandRule gfsh = new GfshCommandRule();
@BeforeClass
- public static void setup() throws Exception {
+ public static void setup() {
Properties managerProps = new Properties();
managerProps.setProperty(NAME, MANAGER_NAME);
managerProps.setProperty(GROUPS, GROUP0);
@@ -76,7 +76,6 @@ public class ChangeLogLevelCommandDUnitTestBase {
gfsh.disconnect();
}
-
@Test
public void testChangeLogLevelForGroups() {
String commandString = "change loglevel --loglevel=finer --groups=" + GROUP1 + "," + GROUP2;
diff --git a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTestBase.java b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsDistributedTestBase.java
similarity index 97%
rename from geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTestBase.java
rename to geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsDistributedTestBase.java
index 9381903..d4a9f29 100644
--- a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTestBase.java
+++ b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsDistributedTestBase.java
@@ -13,7 +13,6 @@
* the License.
*
*/
-
package org.apache.geode.management.internal.cli.commands;
import static java.util.stream.Collectors.joining;
@@ -49,7 +48,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
import org.apache.geode.cache.Cache;
@@ -62,12 +60,11 @@ import org.apache.geode.management.internal.configuration.utils.ZipUtils;
import org.apache.geode.test.dunit.IgnoredException;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
-import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.rules.GfshCommandRule;
import org.apache.geode.test.junit.rules.Member;
-@Category({LoggingTest.class})
-public class ExportLogsDUnitTestBase {
+public class ExportLogsDistributedTestBase {
+
private static final String ERROR_LOG_PREFIX = "[IGNORE]";
@Rule
@@ -247,9 +244,9 @@ public class ExportLogsDUnitTestBase {
verifyZipFileContents(acceptedLogLevels);
// Ensure export logs region gets cleaned up
- server1.invoke(ExportLogsDUnitTestBase::verifyExportLogsRegionWasDestroyed);
- server2.invoke(ExportLogsDUnitTestBase::verifyExportLogsRegionWasDestroyed);
- locator.invoke(ExportLogsDUnitTestBase::verifyExportLogsRegionWasDestroyed);
+ server1.invoke(ExportLogsDistributedTestBase::verifyExportLogsRegionWasDestroyed);
+ server2.invoke(ExportLogsDistributedTestBase::verifyExportLogsRegionWasDestroyed);
+ locator.invoke(ExportLogsDistributedTestBase::verifyExportLogsRegionWasDestroyed);
}
@Test
diff --git a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsDUnitTestBase.java b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsDistributedTestBase.java
similarity index 97%
rename from geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsDUnitTestBase.java
rename to geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsDistributedTestBase.java
index 17c1092..bf5a71e 100644
--- a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsDUnitTestBase.java
+++ b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsDistributedTestBase.java
@@ -12,7 +12,6 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.cli.commands;
import static java.util.stream.Collectors.toSet;
@@ -37,7 +36,6 @@ import com.google.common.collect.Sets;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
-import org.junit.experimental.categories.Category;
import org.apache.geode.distributed.ConfigurationProperties;
import org.apache.geode.management.cli.Result;
@@ -45,11 +43,10 @@ import org.apache.geode.management.internal.cli.result.CommandResult;
import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
-import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.rules.GfshCommandRule;
-@Category({LoggingTest.class})
-public class ExportLogsStatsDUnitTestBase {
+public class ExportLogsStatsDistributedTestBase {
+
@ClassRule
public static ClusterStartupRule lsRule = new ClusterStartupRule().withLogFile();
diff --git a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ShowLogCommandDUnitTestBase.java b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ShowLogCommandDistributedTestBase.java
similarity index 97%
rename from geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ShowLogCommandDUnitTestBase.java
rename to geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ShowLogCommandDistributedTestBase.java
index 7445ff3..68a8174 100644
--- a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ShowLogCommandDUnitTestBase.java
+++ b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/ShowLogCommandDistributedTestBase.java
@@ -42,7 +42,7 @@ import org.apache.geode.test.dunit.rules.MemberVM;
import org.apache.geode.test.junit.rules.GfshCommandRule;
-public class ShowLogCommandDUnitTestBase implements Serializable {
+public class ShowLogCommandDistributedTestBase implements Serializable {
private static final String MANAGER_NAME = "Manager";
private static final String SERVER1_NAME = "Server1";
private static final String SERVER2_NAME = "Server2";
@@ -94,7 +94,7 @@ public class ShowLogCommandDUnitTestBase implements Serializable {
gfsh.connectAndVerify(locator.getJmxPort(), jmxManager);
Awaitility.await().atMost(2, TimeUnit.MINUTES)
- .until(ShowLogCommandDUnitTestBase::allMembersAreConnected);
+ .until(ShowLogCommandDistributedTestBase::allMembersAreConnected);
}
@After
diff --git a/geode-junit/src/main/java/org/apache/geode/test/util/ResourceUtils.java b/geode-junit/src/main/java/org/apache/geode/test/util/ResourceUtils.java
new file mode 100644
index 0000000..58f78ca
--- /dev/null
+++ b/geode-junit/src/main/java/org/apache/geode/test/util/ResourceUtils.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geode.test.util;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import com.google.common.io.Resources;
+import org.apache.commons.io.IOUtils;
+
+/**
+ * {@code ResourceUtils} is a utility class for tests that use resources and copy them to
+ * directories such as {@code TemporaryFolder}.
+ *
+ * <p>
+ * See also {@link Resources#getResource(String)} and {@link Resources#getResource(Class, String)}.
+ */
+public class ResourceUtils {
+
+ /**
+ * Returns the class identified by {@code depth} element of the call stack.
+ */
+ public static Class<?> getCallerClass(final int depth) throws ClassNotFoundException {
+ return Class.forName(getCallerClassName(depth + 1));
+ }
+
+ /**
+ * Returns the name of the class identified by {@code depth} element of the call stack.
+ */
+ public static String getCallerClassName(final int depth) {
+ return new Throwable().getStackTrace()[depth].getClassName();
+ }
+
+ /**
+ * Finds {@code resourceName} using the {@code ClassLoader} of the caller class.
+ *
+ * @return the URL of the resource
+ */
+ public static URL getResource(final String resourceName) throws ClassNotFoundException {
+ URL configResource = getCallerClass(2).getResource(resourceName);
+ assertThat(configResource).as(resourceName).isNotNull();
+ return configResource;
+ }
+
+ /**
+ * Finds {@code resourceName} using the {@code ClassLoader} of {@code classInSamePackage}.
+ *
+ * @return the URL of the resource
+ */
+ public static URL getResource(final Class<?> classInSamePackage, final String resourceName) {
+ URL configResource = classInSamePackage.getResource(resourceName);
+ assertThat(configResource).as(resourceName).isNotNull();
+ return configResource;
+ }
+
+ /**
+ * Copies a {@code resource} to a {@code file} in {@code targetFolder}.
+ *
+ * @return the newly created file
+ */
+ public static File createFileFromResource(final URL resource, final File targetFolder,
+ final String fileName) throws IOException, URISyntaxException {
+ File targetFile = new File(targetFolder, fileName);
+ IOUtils.copy(resource.openStream(), new FileOutputStream(targetFile));
+ assertThat(targetFile).hasSameContentAs(new File(resource.toURI()));
+ return targetFile;
+ }
+}
diff --git a/geode-junit/src/test/java/org/apache/geode/test/util/ResourceUtilsIntegrationTest.java b/geode-junit/src/test/java/org/apache/geode/test/util/ResourceUtilsIntegrationTest.java
new file mode 100644
index 0000000..9c00e7d
--- /dev/null
+++ b/geode-junit/src/test/java/org/apache/geode/test/util/ResourceUtilsIntegrationTest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geode.test.util;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class ResourceUtilsIntegrationTest {
+
+ private static final String RESOURCE_SUFFIX = "_resource.txt";
+ private static final String RESOURCE_CONTENT = "simple string line";
+
+ private String resourceName;
+ private URL resource;
+
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ @Before
+ public void setUp() throws Exception {
+ resourceName = ResourceUtilsTest.class.getSimpleName() + RESOURCE_SUFFIX;
+ resource = ResourceUtils.getResource(ResourceUtilsTest.class, resourceName);
+ }
+
+ @Test
+ public void createFileFromResource() throws Exception {
+ File file =
+ ResourceUtils.createFileFromResource(resource, temporaryFolder.getRoot(), resourceName);
+ assertThat(file).isNotNull().exists();
+
+ List<String> content = FileUtils.readLines(file, Charset.defaultCharset());
+ assertThat(content).contains(RESOURCE_CONTENT);
+ }
+}
diff --git a/geode-junit/src/test/java/org/apache/geode/test/util/ResourceUtilsTest.java b/geode-junit/src/test/java/org/apache/geode/test/util/ResourceUtilsTest.java
new file mode 100644
index 0000000..24c3c7a
--- /dev/null
+++ b/geode-junit/src/test/java/org/apache/geode/test/util/ResourceUtilsTest.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geode.test.util;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.net.URL;
+import java.nio.charset.Charset;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ResourceUtilsTest {
+
+ private static final String RESOURCE_SUFFIX = "_resource.txt";
+ private static final String RESOURCE_CONTENT = "simple string line";
+
+ private String className;
+ private String resourceName;
+
+ @Before
+ public void setUp() throws Exception {
+ className = getClass().getName();
+ resourceName = getClass().getSimpleName() + RESOURCE_SUFFIX;
+ }
+
+ @Test
+ public void getCallerClassName() {
+ assertThat(ResourceUtils.getCallerClassName(1)).isEqualTo(className);
+ }
+
+ @Test
+ public void getCallerClass() throws Exception {
+ assertThat(ResourceUtils.getCallerClass(1)).isEqualTo(getClass());
+ }
+
+ @Test
+ public void getResource() throws Exception {
+ URL resource = ResourceUtils.getResource(resourceName);
+
+ assertThat(resource).isNotNull();
+ assertThat(IOUtils.toString(resource, Charset.defaultCharset())).contains(RESOURCE_CONTENT);
+ }
+
+ @Test
+ public void getResourceWithClass() throws Exception {
+ URL resource = ResourceUtils.getResource(getClass(), resourceName);
+
+ assertThat(resource).isNotNull();
+ assertThat(IOUtils.toString(resource, Charset.defaultCharset())).contains(RESOURCE_CONTENT);
+ }
+}
diff --git a/geode-junit/src/test/resources/org/apache/geode/test/util/ResourceUtilsTest_resource.txt b/geode-junit/src/test/resources/org/apache/geode/test/util/ResourceUtilsTest_resource.txt
new file mode 100644
index 0000000..894cb29
--- /dev/null
+++ b/geode-junit/src/test/resources/org/apache/geode/test/util/ResourceUtilsTest_resource.txt
@@ -0,0 +1,17 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+simple string line
\ No newline at end of file
diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/internal/security/LogoutHandlerUnitTest.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/internal/security/LogoutHandlerTest.java
similarity index 85%
rename from geode-pulse/src/test/java/org/apache/geode/tools/pulse/internal/security/LogoutHandlerUnitTest.java
rename to geode-pulse/src/test/java/org/apache/geode/tools/pulse/internal/security/LogoutHandlerTest.java
index 00291f5..424fc57 100644
--- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/internal/security/LogoutHandlerUnitTest.java
+++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/internal/security/LogoutHandlerTest.java
@@ -14,7 +14,6 @@
*/
package org.apache.geode.tools.pulse.internal.security;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -27,8 +26,12 @@ import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+import org.junit.runners.Parameterized.UseParametersRunnerFactory;
import org.mockito.Mockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
@@ -38,6 +41,9 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.security.core.Authentication;
+import org.apache.geode.test.junit.categories.LoggingTest;
+import org.apache.geode.test.junit.categories.PulseTest;
+import org.apache.geode.test.junit.categories.SecurityTest;
import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
import org.apache.geode.tools.pulse.internal.data.Cluster;
import org.apache.geode.tools.pulse.internal.data.Repository;
@@ -46,16 +52,19 @@ import org.apache.geode.tools.pulse.internal.data.Repository;
@PrepareForTest(Repository.class)
@PowerMockRunnerDelegate(Parameterized.class)
@PowerMockIgnore({"javax.management.*", "javax.security.*", "*.UnitTest"})
-@Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
-public class LogoutHandlerUnitTest {
+@UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
+@Category({PulseTest.class, SecurityTest.class, LoggingTest.class})
+public class LogoutHandlerTest {
+
+ private static final String mockUser = "admin";
+
private Repository repository;
private LogoutHandler handler;
- private static String mockUser = "admin";
- @Parameterized.Parameter
+ @Parameter
public static Authentication authentication;
- @Parameterized.Parameters(name = "{0}")
+ @Parameters(name = "{0}")
public static Collection<Authentication> authentications() throws Exception {
Authentication defaultAuthentication = mock(Authentication.class, "Default Authentication");
when(defaultAuthentication.getName()).thenReturn(mockUser);
diff --git a/geode-web/build.gradle b/geode-web/build.gradle
index 731d780..84003a3 100755
--- a/geode-web/build.gradle
+++ b/geode-web/build.gradle
@@ -44,6 +44,7 @@ dependencies {
testCompile project(':geode-junit')
// have to use output since we exclude the dependent classes from jar :(
testCompile project(path: ':geode-core', configuration: 'classesOutput')
+ testCompile project(':geode-junit')
testCompile 'org.springframework:spring-test:' + project.'springframework.version'
testCompile ('org.springframework:spring-webmvc:' + project.'springframework.version') {
exclude module: 'aopalliance'
diff --git a/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandOverHttpDUnitTest.java b/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandOverHttpDistributedTest.java
similarity index 75%
rename from geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandOverHttpDUnitTest.java
rename to geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandOverHttpDistributedTest.java
index c9ea7a4..61ee362 100644
--- a/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandOverHttpDUnitTest.java
+++ b/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommandOverHttpDistributedTest.java
@@ -16,7 +16,15 @@ package org.apache.geode.management.internal.cli.commands;
import static org.apache.geode.test.junit.rules.GfshCommandRule.PortType.http;
-public class ChangeLogLevelCommandOverHttpDUnitTest extends ChangeLogLevelCommandDUnitTestBase {
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+
+@Category({GfshTest.class, LoggingTest.class})
+public class ChangeLogLevelCommandOverHttpDistributedTest extends
+ ChangeLogLevelCommandDistributedTestBase {
+
@Override
public void before() throws Exception {
gfsh.connect(locator.getHttpPort(), http);
diff --git a/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpDistributedTest.java b/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpDistributedTest.java
index 6096781..b27fab7 100644
--- a/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpDistributedTest.java
+++ b/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpDistributedTest.java
@@ -12,7 +12,6 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.cli.commands;
import java.io.File;
@@ -20,10 +19,11 @@ import java.io.File;
import org.junit.experimental.categories.Category;
import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.rules.GfshCommandRule;
-@Category({GfshTest.class})
-public class ExportLogsOverHttpDistributedTest extends ExportLogsDUnitTestBase {
+@Category({GfshTest.class, LoggingTest.class})
+public class ExportLogsOverHttpDistributedTest extends ExportLogsDistributedTestBase {
@Override
public void connect() throws Exception {
@@ -32,8 +32,8 @@ public class ExportLogsOverHttpDistributedTest extends ExportLogsDUnitTestBase {
}
}
- public File getWorkingDirectory() throws Exception {
+ @Override
+ public File getWorkingDirectory() {
return new File(System.getProperty("user.dir"));
}
-
}
diff --git a/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsOverHttpDUnitTest.java b/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsOverHttpDistributedTest.java
similarity index 92%
rename from geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsOverHttpDUnitTest.java
rename to geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsOverHttpDistributedTest.java
index 3aa3b20..48c6ed5 100644
--- a/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsOverHttpDUnitTest.java
+++ b/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ExportLogsStatsOverHttpDistributedTest.java
@@ -12,7 +12,6 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.cli.commands;
import static org.assertj.core.api.Assertions.assertThat;
@@ -30,10 +29,11 @@ import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.rules.GfshCommandRule;
-@Category({GfshTest.class})
-public class ExportLogsStatsOverHttpDUnitTest extends ExportLogsStatsDUnitTestBase {
+@Category({GfshTest.class, LoggingTest.class})
+public class ExportLogsStatsOverHttpDistributedTest extends ExportLogsStatsDistributedTestBase {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -66,6 +66,7 @@ public class ExportLogsStatsOverHttpDUnitTest extends ExportLogsStatsDUnitTestBa
.filter(file -> file.getName().endsWith(".zip")).collect(Collectors.toSet())).isEmpty();
}
+ @Override
protected String getZipPathFromCommandResult(String message) {
return message.replaceAll("Logs exported to: ", "").trim();
}
diff --git a/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ShowLogComandOverHttpDUnitTest.java b/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ShowLogCommandOverHttpDistributedTest.java
similarity index 75%
rename from geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ShowLogComandOverHttpDUnitTest.java
rename to geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ShowLogCommandOverHttpDistributedTest.java
index 01c5cc1..a02768e 100644
--- a/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ShowLogComandOverHttpDUnitTest.java
+++ b/geode-web/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ShowLogCommandOverHttpDistributedTest.java
@@ -17,15 +17,19 @@ package org.apache.geode.management.internal.cli.commands;
import java.util.concurrent.TimeUnit;
import org.awaitility.Awaitility;
+import org.junit.experimental.categories.Category;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
import org.apache.geode.test.junit.rules.GfshCommandRule;
-public class ShowLogComandOverHttpDUnitTest extends ShowLogCommandDUnitTestBase {
+@Category({GfshTest.class, LoggingTest.class})
+public class ShowLogCommandOverHttpDistributedTest extends ShowLogCommandDistributedTestBase {
+
@Override
public void before() throws Exception {
gfsh.connectAndVerify(locator.getHttpPort(), GfshCommandRule.PortType.http);
Awaitility.await().atMost(2, TimeUnit.MINUTES)
- .until(ShowLogCommandDUnitTestBase::allMembersAreConnected);
+ .until(ShowLogCommandDistributedTestBase::allMembersAreConnected);
}
-
}
diff --git a/geode-web/src/integrationTest/java/org/apache/geode/management/internal/security/LogNoPasswordTest.java b/geode-web/src/integrationTest/java/org/apache/geode/management/internal/security/LogNoPasswordIntegrationTest.java
similarity index 83%
rename from geode-web/src/integrationTest/java/org/apache/geode/management/internal/security/LogNoPasswordTest.java
rename to geode-web/src/integrationTest/java/org/apache/geode/management/internal/security/LogNoPasswordIntegrationTest.java
index fffe591..4df04b9 100644
--- a/geode-web/src/integrationTest/java/org/apache/geode/management/internal/security/LogNoPasswordTest.java
+++ b/geode-web/src/integrationTest/java/org/apache/geode/management/internal/security/LogNoPasswordIntegrationTest.java
@@ -12,7 +12,6 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.security;
import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
@@ -26,16 +25,22 @@ import java.util.Scanner;
import org.apache.commons.lang.ArrayUtils;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.apache.geode.security.AuthenticationFailedException;
import org.apache.geode.security.SecurityManager;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+import org.apache.geode.test.junit.categories.SecurityTest;
import org.apache.geode.test.junit.rules.GfshCommandRule;
-public class LogNoPasswordTest {
+@Category({GfshTest.class, SecurityTest.class, LoggingTest.class})
+public class LogNoPasswordIntegrationTest {
+
+ private static final String PASSWORD = "abcdefghijklmn";
- private static String PASSWORD = "abcdefghijklmn";
@Rule
public ClusterStartupRule lsRule = new ClusterStartupRule().withLogFile();
@@ -71,10 +76,11 @@ public class LogNoPasswordTest {
}
public static class MySecurityManager implements SecurityManager {
+
@Override
- public Object authenticate(Properties credentials) throws AuthenticationFailedException {
- String user = credentials.getProperty("security-username");
- String password = credentials.getProperty("security-password");
+ public Object authenticate(Properties properties) throws AuthenticationFailedException {
+ String user = properties.getProperty("security-username");
+ String password = properties.getProperty("security-password");
if (PASSWORD.equals(password)) {
return user;
}
diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptorRequestHeaderJUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptorRequestHeaderTest.java
similarity index 84%
rename from geode-web/src/test/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptorRequestHeaderJUnitTest.java
rename to geode-web/src/test/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptorRequestHeaderTest.java
index 7317ce3..7b2d735 100644
--- a/geode-web/src/test/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptorRequestHeaderJUnitTest.java
+++ b/geode-web/src/test/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptorRequestHeaderTest.java
@@ -14,7 +14,6 @@
*/
package org.apache.geode.management.internal.web.controllers.support;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
@@ -24,16 +23,21 @@ import java.util.Properties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.springframework.mock.web.MockHttpServletRequest;
import org.apache.geode.internal.security.SecurityService;
+import org.apache.geode.test.junit.categories.GfshTest;
+import org.apache.geode.test.junit.categories.LoggingTest;
+import org.apache.geode.test.junit.categories.SecurityTest;
-public class LoginHandlerInterceptorRequestHeaderJUnitTest {
+@Category({GfshTest.class, SecurityTest.class, LoggingTest.class})
+public class LoginHandlerInterceptorRequestHeaderTest {
- SecurityService securityService;
- LoginHandlerInterceptor interceptor;
+ private SecurityService securityService;
+ private LoginHandlerInterceptor interceptor;
@Before
public void before() {
@@ -55,7 +59,6 @@ public class LoginHandlerInterceptorRequestHeaderJUnitTest {
mockRequest.addHeader("security-something", "anything");
mockRequest.addHeader("Content-Type", "application/json");
-
interceptor.preHandle(mockRequest, null, null);
ArgumentCaptor<Properties> props = ArgumentCaptor.forClass(Properties.class);
@@ -67,5 +70,4 @@ public class LoginHandlerInterceptorRequestHeaderJUnitTest {
// make sure security-* are not put in the environment variable
assertThat(env).hasSize(0);
}
-
}
diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptorJUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptorTest.java
similarity index 96%
rename from geode-web/src/test/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptorJUnitTest.java
rename to geode-web/src/test/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptorTest.java
index f35356c..d28ba5b 100644
--- a/geode-web/src/test/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptorJUnitTest.java
+++ b/geode-web/src/test/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptorTest.java
@@ -44,10 +44,10 @@ import org.mockito.Mock;
import org.springframework.web.servlet.HandlerInterceptor;
import org.apache.geode.internal.security.SecurityService;
-import org.apache.geode.management.internal.security.ResourceConstants;
import org.apache.geode.test.junit.rules.ConcurrencyRule;
-public class LoginHandlerInterceptorJUnitTest {
+public class LoginHandlerInterceptorTest {
+
@Mock
private SecurityService securityService;
private HandlerInterceptor interceptor;
@@ -230,8 +230,8 @@ public class LoginHandlerInterceptorJUnitTest {
parameters.keySet()
.forEach(name -> when(request.getParameter(name)).thenReturn(parameters.get(name)));
- when(request.getHeader(ResourceConstants.USER_NAME)).thenReturn(taskName + " admin");
- when(request.getHeader(ResourceConstants.PASSWORD)).thenReturn(taskName + " password");
+ when(request.getHeader(USER_NAME)).thenReturn(taskName + " admin");
+ when(request.getHeader(PASSWORD)).thenReturn(taskName + " password");
return request;
}