You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2018/12/20 19:02:59 UTC
[geode] 01/01: GEODE-6230 Add test start/stop logging to tests
using distributed test Rules
This is an automated email from the ASF dual-hosted git repository.
bschuchardt pushed a commit to branch feature/GEODE-6230
in repository https://gitbox.apache.org/repos/asf/geode.git
commit 103c83e8d98e8af1565342377dc8b7b050e4a7dc
Author: Bruce Schuchardt <bs...@pivotal.io>
AuthorDate: Thu Dec 20 11:00:29 2018 -0800
GEODE-6230 Add test start/stop logging to tests using distributed test Rules
Added logging to AbstractDistributedRule and moved history logging out
of JUnit4DistributedTestCase and into another class so it can be used by
Rules w/o referring to a deprecated class.
---
.../dunit/internal/JUnit4DistributedTestCase.java | 16 +----------
.../geode/test/dunit/internal/ProcessManager.java | 1 -
.../test/dunit/internal/TestHistoryLogger.java | 32 ++++++++++++++++++++++
.../test/dunit/rules/AbstractDistributedRule.java | 20 ++++++++++----
4 files changed, 47 insertions(+), 22 deletions(-)
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java b/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java
index 8c64555..1da7094 100644
--- a/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java
+++ b/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java
@@ -29,10 +29,8 @@ import static org.junit.Assert.assertNotNull;
import java.io.File;
import java.io.Serializable;
import java.util.Arrays;
-import java.util.LinkedHashSet;
import java.util.Map.Entry;
import java.util.Properties;
-import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.Logger;
@@ -67,8 +65,6 @@ import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
public abstract class JUnit4DistributedTestCase implements DistributedTestFixture, Serializable {
private static final Logger logger = LogService.getLogger();
- private static final Set<String> testHistory = new LinkedHashSet<>();
-
/** This VM's connection to the distributed system */
protected static InternalDistributedSystem system;
private static Class lastSystemCreatedInTest;
@@ -381,7 +377,7 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
final String className = getTestClass().getCanonicalName();
final String methodName = getName();
- logTestHistory();
+ TestHistoryLogger.logTestHistory(getTestClass().getSimpleName(), methodName);
setUpVM(methodName, getDefaultDiskStoreName(0, -1, className, methodName));
@@ -470,16 +466,6 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
}
/**
- * Write a message to the log about what tests have ran previously. This makes it easier to figure
- * out if a previous test may have caused problems
- */
- private final void logTestHistory() {
- String name = getTestClass().getSimpleName() + "." + getTestMethodName();
- testHistory.add(name);
- System.out.println("Previously run tests: " + testHistory);
- }
-
- /**
* Tears down the DistributedTestCase.
*
* <p>
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/ProcessManager.java b/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/ProcessManager.java
index 6b864e4..c4fa0b2 100755
--- a/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/ProcessManager.java
+++ b/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/ProcessManager.java
@@ -155,7 +155,6 @@ public class ProcessManager {
private void linkStreams(final String version, final int vmNum, final ProcessHolder holder,
final InputStream in, final PrintStream out) {
final String vmName = "[" + VM.getVMName(version, vmNum) + "] ";
- System.out.println("linking IO streams for " + vmName);
Thread ioTransport = new Thread() {
public void run() {
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/TestHistoryLogger.java b/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/TestHistoryLogger.java
new file mode 100644
index 0000000..d8beddb
--- /dev/null
+++ b/geode-dunit/src/main/java/org/apache/geode/test/dunit/internal/TestHistoryLogger.java
@@ -0,0 +1,32 @@
+/*
+ * 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.dunit.internal;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+public class TestHistoryLogger {
+ private static final Set<String> testHistory = new LinkedHashSet<>();
+
+ /**
+ * Write a message to the log about what tests have ran previously. This makes it easier to figure
+ * out if a previous test may have caused problems
+ */
+ public static final void logTestHistory(String className, String methodName) {
+ String name = className + "." + methodName;
+ testHistory.add(name);
+ System.out.println("Previously run tests: " + testHistory);
+ }
+}
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/AbstractDistributedRule.java b/geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/AbstractDistributedRule.java
index 46bd45d..44cb498 100644
--- a/geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/AbstractDistributedRule.java
+++ b/geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/AbstractDistributedRule.java
@@ -22,6 +22,7 @@ import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.apache.geode.test.dunit.internal.DUnitLauncher;
+import org.apache.geode.test.dunit.internal.TestHistoryLogger;
import org.apache.geode.test.junit.rules.serializable.SerializableStatement;
import org.apache.geode.test.junit.rules.serializable.SerializableTestRule;
@@ -45,33 +46,40 @@ class AbstractDistributedRule implements SerializableTestRule {
this.invoker = invoker;
}
+
@Override
public Statement apply(final Statement base, final Description description) {
- return statement(base);
+ return statement(base, description);
}
- private Statement statement(final Statement base) {
+ private Statement statement(final Statement base, Description testDescription) {
return new SerializableStatement() {
@Override
public void evaluate() throws Throwable {
- beforeDistributedTest();
+ beforeDistributedTest(testDescription);
before();
try {
base.evaluate();
} finally {
after();
- afterDistributedTest();
+ afterDistributedTest(testDescription);
}
}
};
}
- private void beforeDistributedTest() throws Throwable {
+ private void beforeDistributedTest(Description testDescription) throws Throwable {
+ TestHistoryLogger.logTestHistory(testDescription.getTestClass().getSimpleName(),
+ testDescription.getMethodName());
DUnitLauncher.launchIfNeeded(vmCount);
beforeVmCount = getVMCount();
+ System.out.println("\n\n[setup] START TEST " + testDescription.getClassName() + "."
+ + testDescription.getMethodName());
}
- private void afterDistributedTest() throws Throwable {
+ private void afterDistributedTest(Description testDescription) throws Throwable {
+ System.out.println("\n\n[setup] END TEST " + testDescription.getTestClass().getSimpleName()
+ + "." + testDescription.getMethodName());
int afterVmCount = getVMCount();
assertThat(afterVmCount).isEqualTo(beforeVmCount);
}