GEODE-127: Improve test reliability and execution speed. Recategorize tests involving spawned processes and file system I/O as IntegrationTests.
Improve reliability and shorten execution time. Fix up asynchronous waits, correct JUnit 4 syntax and misc code tidying. Add new TestSuite classes for targeted testing of test.golden and test.process packages. Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/94939c1f Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/94939c1f Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/94939c1f Branch: refs/heads/feature/GEODE-77 Commit: 94939c1f9cc3e09c4beee1155404dd82b9aca13f Parents: ea8ce3f Author: Kirk Lund <kl...@pivotal.io> Authored: Mon Jul 27 16:35:33 2015 -0700 Committer: Kirk Lund <kl...@pivotal.io> Committed: Wed Jul 29 09:33:03 2015 -0700 ---------------------------------------------------------------------- .../ServerLauncherRemoteJUnitTest.java | 2 +- .../gemfire/test/golden/ExecutableProcess.java | 8 + .../gemfire/test/golden/FailOutputTestCase.java | 22 +- .../golden/FailWithErrorInOutputJUnitTest.java | 18 +- .../FailWithExtraLineInOutputJUnitTest.java | 41 +-- ...WithLineMissingFromEndOfOutputJUnitTest.java | 39 ++- ...hLineMissingFromMiddleOfOutputJUnitTest.java | 39 ++- .../FailWithLoggerErrorInOutputJUnitTest.java | 18 +- .../FailWithLoggerFatalInOutputJUnitTest.java | 18 +- .../FailWithLoggerWarnInOutputJUnitTest.java | 18 +- .../golden/FailWithProblemInOutputTestCase.java | 30 ++- .../golden/FailWithSevereInOutputJUnitTest.java | 18 +- ...hTimeoutOfWaitForOutputToMatchJUnitTest.java | 43 ++-- .../FailWithWarningInOutputJUnitTest.java | 18 +- .../gemfire/test/golden/GoldenComparator.java | 64 +++-- .../test/golden/GoldenStringComparator.java | 5 +- .../gemfire/test/golden/GoldenTestCase.java | 108 +++----- .../golden/GoldenTestFrameworkTestSuite.java | 27 ++ .../gemfire/test/golden/PassJUnitTest.java | 50 ++-- .../golden/PassWithExpectedErrorJUnitTest.java | 18 +- .../golden/PassWithExpectedProblemTestCase.java | 58 +++-- .../golden/PassWithExpectedSevereJUnitTest.java | 18 +- .../PassWithExpectedWarningJUnitTest.java | 18 +- .../test/golden/RegexGoldenComparator.java | 10 +- .../test/golden/StringGoldenComparator.java | 4 +- .../process/ProcessTestFrameworkTestSuite.java | 12 + .../gemfire/test/process/ProcessWrapper.java | 251 +++++++++---------- .../test/process/ProcessWrapperJUnitTest.java | 19 +- .../gemfire/test/golden/log4j2-test.xml | 18 ++ 29 files changed, 486 insertions(+), 526 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherRemoteJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherRemoteJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherRemoteJUnitTest.java index fb0df63..1ba1189 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherRemoteJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherRemoteJUnitTest.java @@ -122,7 +122,7 @@ public class ServerLauncherRemoteJUnitTest extends AbstractServerLauncherJUnitTe File file = new File(this.temporaryFolder.getRoot(), ServerLauncherForkingProcess.class.getSimpleName().concat(".log")); //-logger.info("KIRK: log file is " + file); - final ProcessWrapper pw = new ProcessWrapper.Builder().main(ServerLauncherForkingProcess.class).build(); + final ProcessWrapper pw = new ProcessWrapper.Builder().mainClass(ServerLauncherForkingProcess.class).build(); pw.execute(null, this.temporaryFolder.getRoot()).waitFor(true); //logger.info("[testRunningServerOutlivesForkingProcess] ServerLauncherForkingProcess output is:\n\n"+pw.getOutput()); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/ExecutableProcess.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/ExecutableProcess.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/ExecutableProcess.java new file mode 100755 index 0000000..bc6d1e3 --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/ExecutableProcess.java @@ -0,0 +1,8 @@ +package com.gemstone.gemfire.test.golden; + +/** + * Defines the work that is executed within a remote process. + */ +public interface ExecutableProcess { + public void executeInProcess() throws Exception; +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailOutputTestCase.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailOutputTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailOutputTestCase.java index a3995f8..d460706 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailOutputTestCase.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailOutputTestCase.java @@ -10,11 +10,7 @@ import java.io.InputStreamReader; * * @author Kirk Lund */ -public abstract class FailOutputTestCase extends GoldenTestCase { - - FailOutputTestCase(String name) { - super(name); - } +public abstract class FailOutputTestCase extends GoldenTestCase implements ExecutableProcess { @Override protected GoldenComparator createGoldenComparator() { @@ -27,14 +23,14 @@ public abstract class FailOutputTestCase extends GoldenTestCase { abstract String problem(); - abstract void outputProblem(String message); + abstract void outputProblemInProcess(String message); - void execute() throws IOException { - System.out.println("Begin " + name() + ".main"); - System.out.println("Press Enter to continue."); - BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); - inputReader.readLine(); - outputProblem(problem()); - System.out.println("End " + name() + ".main"); + @Override + public final void executeInProcess() throws IOException { + outputLine("Begin " + name() + ".main"); + outputLine("Press Enter to continue."); + new BufferedReader(new InputStreamReader(System.in)).readLine(); + outputProblemInProcess(problem()); + outputLine("End " + name() + ".main"); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithErrorInOutputJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithErrorInOutputJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithErrorInOutputJUnitTest.java index b3ca93e..d8763b7 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithErrorInOutputJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithErrorInOutputJUnitTest.java @@ -2,10 +2,9 @@ package com.gemstone.gemfire.test.golden; import org.junit.experimental.categories.Category; -import com.gemstone.gemfire.LogWriter; import com.gemstone.gemfire.internal.logging.LocalLogWriter; import com.gemstone.gemfire.internal.logging.LogWriterImpl; -import com.gemstone.gemfire.test.junit.categories.UnitTest; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Verifies that test output containing an unexpected error message @@ -13,25 +12,20 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest; * * @author Kirk Lund */ -@Category(UnitTest.class) +@Category(IntegrationTest.class) public class FailWithErrorInOutputJUnitTest extends FailWithProblemInOutputTestCase { - public FailWithErrorInOutputJUnitTest() { - super(FailWithErrorInOutputJUnitTest.class.getSimpleName()); - } - @Override String problem() { return "ExpectedStrings: Description of a problem."; } @Override - void outputProblem(String message) { - LogWriter logWriter = new LocalLogWriter(LogWriterImpl.INFO_LEVEL); - logWriter.error(message); + void outputProblemInProcess(final String message) { + new LocalLogWriter(LogWriterImpl.INFO_LEVEL).error(message); } - public static void main(String[] args) throws Exception { - new FailWithErrorInOutputJUnitTest().execute(); + public static void main(final String[] args) throws Exception { + new FailWithErrorInOutputJUnitTest().executeInProcess(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithExtraLineInOutputJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithExtraLineInOutputJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithExtraLineInOutputJUnitTest.java index 1c49749..6fb674f 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithExtraLineInOutputJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithExtraLineInOutputJUnitTest.java @@ -1,13 +1,12 @@ package com.gemstone.gemfire.test.golden; -import java.io.IOException; +import static org.junit.Assert.*; +import org.junit.Test; import org.junit.experimental.categories.Category; import com.gemstone.gemfire.test.process.ProcessWrapper; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -import junit.framework.AssertionFailedError; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Verifies that test output containing an unexpected extra line @@ -15,45 +14,47 @@ import junit.framework.AssertionFailedError; * * @author Kirk Lund */ -@Category(UnitTest.class) +@Category(IntegrationTest.class) public class FailWithExtraLineInOutputJUnitTest extends FailOutputTestCase { - public FailWithExtraLineInOutputJUnitTest() { - super("FailWithExtraLineInOutputJUnitTest"); - } - @Override String problem() { return "This is an extra line"; } @Override - void outputProblem(String message) { + void outputProblemInProcess(final String message) { System.out.println(message); } - public void testFailWithExtraLineInOutput() throws InterruptedException, IOException { - // output has an extra line and should fail - final ProcessWrapper process = createProcessWrapper(getClass()); + /** + * Process output has an extra line and should fail + */ + @Test + public void testFailWithExtraLineInOutput() throws Exception { + final String goldenString = + "Begin " + name() + ".main" + "\n" + + "Press Enter to continue." + "\n" + + "End " + name() + ".main" + "\n"; + debug(goldenString, "GOLDEN"); + + final ProcessWrapper process = createProcessWrapper(new ProcessWrapper.Builder(), getClass()); process.execute(createProperties()); process.waitForOutputToMatch("Begin " + name() + "\\.main"); process.waitForOutputToMatch("Press Enter to continue\\."); process.sendInput(); process.waitForOutputToMatch("End " + name() + "\\.main"); process.waitFor(); - String goldenString = "Begin " + name() + ".main" + "\n" - + "Press Enter to continue." + "\n" - + "End " + name() + ".main" + "\n"; - innerPrintOutput(goldenString, "GOLDEN"); + try { assertOutputMatchesGoldenFile(process.getOutput(), goldenString); fail("assertOutputMatchesGoldenFile should have failed due to " + problem()); - } catch (AssertionFailedError expected) { + } catch (AssertionError expected) { assertTrue(expected.getMessage().contains(problem())); } } - public static void main(String[] args) throws Exception { - new FailWithExtraLineInOutputJUnitTest().execute(); + public static void main(final String[] args) throws Exception { + new FailWithExtraLineInOutputJUnitTest().executeInProcess(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLineMissingFromEndOfOutputJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLineMissingFromEndOfOutputJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLineMissingFromEndOfOutputJUnitTest.java index 877f671..a1802c5 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLineMissingFromEndOfOutputJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLineMissingFromEndOfOutputJUnitTest.java @@ -1,13 +1,12 @@ package com.gemstone.gemfire.test.golden; -import java.io.IOException; +import static org.junit.Assert.*; +import org.junit.Test; import org.junit.experimental.categories.Category; import com.gemstone.gemfire.test.process.ProcessWrapper; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -import junit.framework.AssertionFailedError; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Verifies that test output missing an expected line (at the end of @@ -15,46 +14,46 @@ import junit.framework.AssertionFailedError; * * @author Kirk Lund */ -@Category(UnitTest.class) +@Category(IntegrationTest.class) public class FailWithLineMissingFromEndOfOutputJUnitTest extends FailOutputTestCase { - public FailWithLineMissingFromEndOfOutputJUnitTest() { - super("FailWithLineMissingFromOutputJUnitTest"); - } - @Override String problem() { return "This line is missing in actual output."; } @Override - void outputProblem(String message) { + void outputProblemInProcess(final String message) { // this tests that the message is missing from output } - public void testFailWithLineMissingFromEndOfOutput() throws InterruptedException, IOException { - final ProcessWrapper process = createProcessWrapper(getClass()); + @Test + public void testFailWithLineMissingFromEndOfOutput() throws Exception { + final String goldenString = + "Begin " + name() + ".main" + "\n" + + "Press Enter to continue." + "\n" + + "End " + name() + ".main" + "\n" + + problem() + "\n"; + debug(goldenString, "GOLDEN"); + + final ProcessWrapper process = createProcessWrapper(new ProcessWrapper.Builder(), getClass()); process.execute(createProperties()); process.waitForOutputToMatch("Begin " + name() + "\\.main"); process.waitForOutputToMatch("Press Enter to continue\\."); process.sendInput(); process.waitForOutputToMatch("End " + name() + "\\.main"); process.waitFor(); - String goldenString = "Begin " + name() + ".main" + "\n" - + "Press Enter to continue." + "\n" - + "End " + name() + ".main" + "\n" - + problem() + "\n"; - innerPrintOutput(goldenString, "GOLDEN"); + try { assertOutputMatchesGoldenFile(process.getOutput(), goldenString); fail("assertOutputMatchesGoldenFile should have failed due to " + problem()); - } catch (AssertionFailedError expected) { + } catch (AssertionError expected) { assertTrue("AssertionFailedError message should contain \"" + problem() + "\"", expected.getMessage().contains(problem())); } } - public static void main(String[] args) throws Exception { - new FailWithLineMissingFromEndOfOutputJUnitTest().execute(); + public static void main(final String[] args) throws Exception { + new FailWithLineMissingFromEndOfOutputJUnitTest().executeInProcess(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLineMissingFromMiddleOfOutputJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLineMissingFromMiddleOfOutputJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLineMissingFromMiddleOfOutputJUnitTest.java index 629eb7f..91095ec 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLineMissingFromMiddleOfOutputJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLineMissingFromMiddleOfOutputJUnitTest.java @@ -1,13 +1,12 @@ package com.gemstone.gemfire.test.golden; -import java.io.IOException; +import static org.junit.Assert.*; +import org.junit.Test; import org.junit.experimental.categories.Category; import com.gemstone.gemfire.test.process.ProcessWrapper; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -import junit.framework.AssertionFailedError; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Verifies that test output missing an expected line (at the middle @@ -15,45 +14,45 @@ import junit.framework.AssertionFailedError; * * @author Kirk Lund */ -@Category(UnitTest.class) +@Category(IntegrationTest.class) public class FailWithLineMissingFromMiddleOfOutputJUnitTest extends FailOutputTestCase { - public FailWithLineMissingFromMiddleOfOutputJUnitTest() { - super("FailWithLineMissingFromMiddleOfOutputJUnitTest"); - } - @Override String problem() { return "This line is missing in actual output."; } @Override - void outputProblem(String message) { + void outputProblemInProcess(final String message) { // this tests that the message is missing from output } - public void testFailWithLineMissingFromEndOfOutput() throws InterruptedException, IOException { - final ProcessWrapper process = createProcessWrapper(getClass()); + @Test + public void testFailWithLineMissingFromEndOfOutput() throws Exception { + final String goldenString = + "Begin " + name() + ".main" + "\n" + + "Press Enter to continue." + "\n" + + problem() + "\n" + + "End " + name() + ".main" + "\n"; + debug(goldenString, "GOLDEN"); + + final ProcessWrapper process = createProcessWrapper(new ProcessWrapper.Builder(), getClass()); process.execute(createProperties()); process.waitForOutputToMatch("Begin " + name() + "\\.main"); process.waitForOutputToMatch("Press Enter to continue\\."); process.sendInput(); process.waitFor(); - String goldenString = "Begin " + name() + ".main" + "\n" - + "Press Enter to continue." + "\n" - + problem() + "\n" - + "End " + name() + ".main" + "\n"; - innerPrintOutput(goldenString, "GOLDEN"); + try { assertOutputMatchesGoldenFile(process.getOutput(), goldenString); fail("assertOutputMatchesGoldenFile should have failed due to " + problem()); - } catch (AssertionFailedError expected) { + } catch (AssertionError expected) { assertTrue("AssertionFailedError message should contain \"" + problem() + "\"", expected.getMessage().contains(problem())); } } - public static void main(String[] args) throws Exception { - new FailWithLineMissingFromMiddleOfOutputJUnitTest().execute(); + public static void main(final String[] args) throws Exception { + new FailWithLineMissingFromMiddleOfOutputJUnitTest().executeInProcess(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerErrorInOutputJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerErrorInOutputJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerErrorInOutputJUnitTest.java index b485ba4..5a2c49a 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerErrorInOutputJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerErrorInOutputJUnitTest.java @@ -1,10 +1,9 @@ package com.gemstone.gemfire.test.golden; -import org.apache.logging.log4j.Logger; import org.junit.experimental.categories.Category; import com.gemstone.gemfire.internal.logging.LogService; -import com.gemstone.gemfire.test.junit.categories.UnitTest; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Verifies that test output containing an unexpected ERROR message @@ -12,25 +11,20 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest; * * @author Kirk Lund */ -@Category(UnitTest.class) +@Category(IntegrationTest.class) public class FailWithLoggerErrorInOutputJUnitTest extends FailWithProblemInOutputTestCase { - public FailWithLoggerErrorInOutputJUnitTest() { - super(FailWithLoggerErrorInOutputJUnitTest.class.getSimpleName()); - } - @Override String problem() { return "ExpectedStrings: Description of a problem."; } @Override - void outputProblem(String message) { - Logger logger = LogService.getLogger(); - logger.error(message); + void outputProblemInProcess(final String message) { + LogService.getLogger().error(message); } - public static void main(String[] args) throws Exception { - new FailWithLoggerErrorInOutputJUnitTest().execute(); + public static void main(final String[] args) throws Exception { + new FailWithLoggerErrorInOutputJUnitTest().executeInProcess(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerFatalInOutputJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerFatalInOutputJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerFatalInOutputJUnitTest.java index a71ce18..a0c681a 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerFatalInOutputJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerFatalInOutputJUnitTest.java @@ -1,10 +1,9 @@ package com.gemstone.gemfire.test.golden; -import org.apache.logging.log4j.Logger; import org.junit.experimental.categories.Category; import com.gemstone.gemfire.internal.logging.LogService; -import com.gemstone.gemfire.test.junit.categories.UnitTest; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Verifies that test output containing an unexpected FATAL message @@ -12,25 +11,20 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest; * * @author Kirk Lund */ -@Category(UnitTest.class) +@Category(IntegrationTest.class) public class FailWithLoggerFatalInOutputJUnitTest extends FailWithProblemInOutputTestCase { - public FailWithLoggerFatalInOutputJUnitTest() { - super(FailWithLoggerFatalInOutputJUnitTest.class.getSimpleName()); - } - @Override String problem() { return "ExpectedStrings: Description of a problem."; } @Override - void outputProblem(String message) { - Logger logger = LogService.getLogger(); - logger.fatal(message); + void outputProblemInProcess(final String message) { + LogService.getLogger().fatal(message); } - public static void main(String[] args) throws Exception { - new FailWithLoggerFatalInOutputJUnitTest().execute(); + public static void main(final String[] args) throws Exception { + new FailWithLoggerFatalInOutputJUnitTest().executeInProcess(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerWarnInOutputJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerWarnInOutputJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerWarnInOutputJUnitTest.java index 211008a..5717f67 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerWarnInOutputJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithLoggerWarnInOutputJUnitTest.java @@ -1,10 +1,9 @@ package com.gemstone.gemfire.test.golden; -import org.apache.logging.log4j.Logger; import org.junit.experimental.categories.Category; import com.gemstone.gemfire.internal.logging.LogService; -import com.gemstone.gemfire.test.junit.categories.UnitTest; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Verifies that test output containing an unexpected WARN message @@ -12,25 +11,20 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest; * * @author Kirk Lund */ -@Category(UnitTest.class) +@Category(IntegrationTest.class) public class FailWithLoggerWarnInOutputJUnitTest extends FailWithProblemInOutputTestCase { - public FailWithLoggerWarnInOutputJUnitTest() { - super(FailWithLoggerWarnInOutputJUnitTest.class.getSimpleName()); - } - @Override String problem() { return "ExpectedStrings: Description of a problem."; } @Override - void outputProblem(String message) { - Logger logger = LogService.getLogger(); - logger.warn(message); + void outputProblemInProcess(final String message) { + LogService.getLogger().warn(message); } - public static void main(String[] args) throws Exception { - new FailWithLoggerWarnInOutputJUnitTest().execute(); + public static void main(final String[] args) throws Exception { + new FailWithLoggerWarnInOutputJUnitTest().executeInProcess(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithProblemInOutputTestCase.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithProblemInOutputTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithProblemInOutputTestCase.java index 5e1552f..7a68e02 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithProblemInOutputTestCase.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithProblemInOutputTestCase.java @@ -1,10 +1,10 @@ package com.gemstone.gemfire.test.golden; -import java.io.IOException; +import static org.junit.Assert.*; -import com.gemstone.gemfire.test.process.ProcessWrapper; +import org.junit.Test; -import junit.framework.AssertionFailedError; +import com.gemstone.gemfire.test.process.ProcessWrapper; /** * Abstract test case for tests verifying that test output with a @@ -14,33 +14,31 @@ import junit.framework.AssertionFailedError; */ public abstract class FailWithProblemInOutputTestCase extends FailOutputTestCase { - FailWithProblemInOutputTestCase(String name) { - super(name); - } - @Override protected String[] expectedProblemLines() { return new String[] { ".*" + name() + ".*" }; } - public void testFailWithProblemLogMessageInOutput() throws InterruptedException, IOException { - final ProcessWrapper process = createProcessWrapper(getClass()); + @Test + public void testFailWithProblemLogMessageInOutput() throws Exception { + final String goldenString = + "Begin " + name() + ".main" + "\n" + + "Press Enter to continue." + "\n" + + "End " + name() + ".main" + "\n"; + debug(goldenString, "GOLDEN"); + + final ProcessWrapper process = createProcessWrapper(new ProcessWrapper.Builder(), getClass()); process.execute(createProperties()); process.waitForOutputToMatch("Begin " + name() + "\\.main"); process.waitForOutputToMatch("Press Enter to continue\\."); process.sendInput(); process.waitForOutputToMatch("End " + name() + "\\.main"); process.waitFor(); - String goldenString = "Begin " + name() + ".main" + "\n" - + "Press Enter to continue." + "\n" - + "End " + name() + ".main" + "\n"; - innerPrintOutput(goldenString, "GOLDEN"); + try { assertOutputMatchesGoldenFile(process.getOutput(), goldenString); fail("assertOutputMatchesGoldenFile should have failed due to " + problem()); - } catch (AssertionFailedError expected) { -// System.out.println("Problem: " + problem()); -// System.out.println("AssertionFailedError message: " + expected.getMessage()); + } catch (AssertionError expected) { assertTrue(expected.getMessage().contains(problem())); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithSevereInOutputJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithSevereInOutputJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithSevereInOutputJUnitTest.java index 9089545..457c7cc 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithSevereInOutputJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithSevereInOutputJUnitTest.java @@ -2,10 +2,9 @@ package com.gemstone.gemfire.test.golden; import org.junit.experimental.categories.Category; -import com.gemstone.gemfire.LogWriter; import com.gemstone.gemfire.internal.logging.LocalLogWriter; import com.gemstone.gemfire.internal.logging.LogWriterImpl; -import com.gemstone.gemfire.test.junit.categories.UnitTest; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Verifies that test output containing an unexpected severe message @@ -13,25 +12,20 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest; * * @author Kirk Lund */ -@Category(UnitTest.class) +@Category(IntegrationTest.class) public class FailWithSevereInOutputJUnitTest extends FailWithProblemInOutputTestCase { - public FailWithSevereInOutputJUnitTest() { - super(FailWithSevereInOutputJUnitTest.class.getSimpleName()); - } - @Override String problem() { return "ExpectedStrings: Description of a problem."; } @Override - void outputProblem(String message) { - LogWriter logWriter = new LocalLogWriter(LogWriterImpl.INFO_LEVEL); - logWriter.severe(message); + void outputProblemInProcess(final String message) { + new LocalLogWriter(LogWriterImpl.INFO_LEVEL).severe(message); } - public static void main(String[] args) throws Exception { - new FailWithSevereInOutputJUnitTest().execute(); + public static void main(final String[] args) throws Exception { + new FailWithSevereInOutputJUnitTest().executeInProcess(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithTimeoutOfWaitForOutputToMatchJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithTimeoutOfWaitForOutputToMatchJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithTimeoutOfWaitForOutputToMatchJUnitTest.java index 2417f3d..1b8a312 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithTimeoutOfWaitForOutputToMatchJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithTimeoutOfWaitForOutputToMatchJUnitTest.java @@ -1,17 +1,23 @@ package com.gemstone.gemfire.test.golden; +import static org.junit.Assert.*; + +import org.junit.Test; import org.junit.experimental.categories.Category; import com.gemstone.gemfire.test.process.ProcessWrapper; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -import junit.framework.AssertionFailedError; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; -@Category(UnitTest.class) +@Category(IntegrationTest.class) public class FailWithTimeoutOfWaitForOutputToMatchJUnitTest extends FailOutputTestCase { - public FailWithTimeoutOfWaitForOutputToMatchJUnitTest() { - super("FailWithTimeoutOfWaitForOutputToMatchJUnitTest"); + private static final long timeoutMillis = 1000; + + private ProcessWrapper process; + + public void subTearDown() throws Exception { + this.process.waitFor(); + assertFalse(this.process.isAlive()); } @Override @@ -20,29 +26,28 @@ public class FailWithTimeoutOfWaitForOutputToMatchJUnitTest extends FailOutputTe } @Override - void outputProblem(String message) { + void outputProblemInProcess(final String message) { System.out.println(message); } + /** + * Process output has an extra line and should fail + */ + @Test public void testFailWithTimeoutOfWaitForOutputToMatch() throws Exception { - // output has an extra line and should fail - final ProcessWrapper process = createProcessWrapper(getClass()); - process.execute(createProperties()); - process.waitForOutputToMatch("Begin " + name() + "\\.main"); + this.process = createProcessWrapper(new ProcessWrapper.Builder().timeoutMillis(timeoutMillis), getClass()); + this.process.execute(createProperties()); + this.process.waitForOutputToMatch("Begin " + name() + "\\.main"); + try { - process.waitForOutputToMatch(problem()); + this.process.waitForOutputToMatch(problem()); fail("assertOutputMatchesGoldenFile should have failed due to " + problem()); - } catch (AssertionFailedError expected) { + } catch (AssertionError expected) { assertTrue(expected.getMessage().contains(problem())); } - // the following should generate no failures if timeout and tearDown are all working properly - assertNotNull(process); - assertTrue(process.isAlive()); - tearDown(); - process.waitFor(); } public static void main(String[] args) throws Exception { - new FailWithTimeoutOfWaitForOutputToMatchJUnitTest().execute(); + new FailWithTimeoutOfWaitForOutputToMatchJUnitTest().executeInProcess(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithWarningInOutputJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithWarningInOutputJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithWarningInOutputJUnitTest.java index 89cc7dc..c54ff85 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithWarningInOutputJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/FailWithWarningInOutputJUnitTest.java @@ -2,10 +2,9 @@ package com.gemstone.gemfire.test.golden; import org.junit.experimental.categories.Category; -import com.gemstone.gemfire.LogWriter; import com.gemstone.gemfire.internal.logging.LocalLogWriter; import com.gemstone.gemfire.internal.logging.LogWriterImpl; -import com.gemstone.gemfire.test.junit.categories.UnitTest; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Verifies that test output containing an unexpected warning message @@ -13,25 +12,20 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest; * * @author Kirk Lund */ -@Category(UnitTest.class) +@Category(IntegrationTest.class) public class FailWithWarningInOutputJUnitTest extends FailWithProblemInOutputTestCase { - public FailWithWarningInOutputJUnitTest() { - super(FailWithWarningInOutputJUnitTest.class.getSimpleName()); - } - @Override String problem() { return "ExpectedStrings: Description of a problem."; } @Override - void outputProblem(String message) { - LogWriter logWriter = new LocalLogWriter(LogWriterImpl.INFO_LEVEL); - logWriter.warning(message); + void outputProblemInProcess(final String message) { + new LocalLogWriter(LogWriterImpl.INFO_LEVEL).warning(message); } - public static void main(String[] args) throws Exception { - new FailWithWarningInOutputJUnitTest().execute(); + public static void main(final String[] args) throws Exception { + new FailWithWarningInOutputJUnitTest().executeInProcess(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenComparator.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenComparator.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenComparator.java index 34c1ce7..6244237 100644 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenComparator.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenComparator.java @@ -1,5 +1,7 @@ package com.gemstone.gemfire.test.golden; +import static org.junit.Assert.*; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -9,44 +11,37 @@ import java.io.StringReader; import java.util.ArrayList; import java.util.List; -import org.apache.logging.log4j.Logger; - -import com.gemstone.gemfire.internal.logging.LogService; import com.gemstone.gemfire.test.process.OutputFormatter; -import junit.framework.Assert; - /** * Compares test output to golden text file. * * @author Kirk Lund * @since 4.1.1 */ -public abstract class GoldenComparator extends Assert { +public abstract class GoldenComparator { - //private static final boolean ALLOW_EXTRA_WHITESPACE = true; - - protected final Logger logger = LogService.getLogger(); + //TODO: private static final boolean ALLOW_EXTRA_WHITESPACE = true; private String[] expectedProblemLines; - protected GoldenComparator(String[] expectedProblemLines) { + protected GoldenComparator(final String[] expectedProblemLines) { this.expectedProblemLines = expectedProblemLines; } - protected Reader readGoldenFile(String goldenFileName) throws IOException { - InputStream goldenStream = ClassLoader.getSystemResourceAsStream(goldenFileName); + protected Reader readGoldenFile(final String goldenFileName) throws IOException { + final InputStream goldenStream = ClassLoader.getSystemResourceAsStream(goldenFileName); assertNotNull("Golden file " + goldenFileName + " not found.", goldenStream); return new InputStreamReader(goldenStream); } - public void assertOutputMatchesGoldenFile(String actualOutput, String goldenFileName) throws IOException { - logger.debug(GoldenTestCase.GOLDEN_TEST, "GoldenComparator:assertOutputMatchesGoldenFile"); - BufferedReader goldenReader = new BufferedReader(readGoldenFile(goldenFileName)); - BufferedReader actualReader = new BufferedReader(new StringReader(actualOutput)); + public void assertOutputMatchesGoldenFile(final String actualOutput, final String goldenFileName) throws IOException { + debug("GoldenComparator:assertOutputMatchesGoldenFile"); + final BufferedReader goldenReader = new BufferedReader(readGoldenFile(goldenFileName)); + final BufferedReader actualReader = new BufferedReader(new StringReader(actualOutput)); - List<String> goldenStrings = readLines(goldenReader); - List<String> actualStrings = readLines(actualReader); + final List<String> goldenStrings = readLines(goldenReader); + final List<String> actualStrings = readLines(actualReader); scanForProblems(actualStrings); @@ -56,12 +51,11 @@ public abstract class GoldenComparator extends Assert { int lineCount = 0; do { lineCount++; - logger.debug(GoldenTestCase.GOLDEN_TEST, "GoldenComparator comparing line {}", lineCount); + debug("GoldenComparator comparing line " + lineCount); actualLine = actualStrings.get(lineCount - 1); goldenLine = goldenStrings.get(lineCount - 1); - //checkForProblem(lineCount, actualLine); if (actualLine == null && goldenLine != null) { fail("EOF reached in actual output but golden file, " + goldenFileName + ", continues at line " + lineCount + ": " + goldenLine + new OutputFormatter(actualStrings)); @@ -69,11 +63,7 @@ public abstract class GoldenComparator extends Assert { fail("EOF reached in golden file, " + goldenFileName + ", but actual output continues at line " + lineCount + ": " + actualLine + new OutputFormatter(actualStrings)); } else if (actualLine != null && goldenLine != null) { - assertTrue("Actual output \"" + actualLine - + "\" did not match expected pattern \"" + goldenLine - + "\" at line " + lineCount + " in " + goldenFileName - + ": " + new OutputFormatter(actualStrings), - compareLines(actualLine, goldenLine)); + assertTrue("Actual output \"" + actualLine + "\" did not match expected pattern \"" + goldenLine + "\" at line " + lineCount + " in " + goldenFileName + ": " + new OutputFormatter(actualStrings), compareLines(actualLine, goldenLine)); } } while (actualLine != null && goldenLine != null); } @@ -81,10 +71,10 @@ public abstract class GoldenComparator extends Assert { /** * Returns true if the line matches and is ok. Otherwise returns false. */ - protected abstract boolean compareLines(String actualLine, String goldenLine); + protected abstract boolean compareLines(final String actualLine, final String goldenLine); - private List<String> readLines(BufferedReader reader) throws IOException { - List<String> listOfLines = new ArrayList<String>(); + private List<String> readLines(final BufferedReader reader) throws IOException { + final List<String> listOfLines = new ArrayList<String>(); String line = null; do { line = reader.readLine(); @@ -93,17 +83,17 @@ public abstract class GoldenComparator extends Assert { return listOfLines; } - private void scanForProblems(List<String> lines) throws IOException { - logger.debug(GoldenTestCase.GOLDEN_TEST, "GoldenComparator:scanForProblems"); + private void scanForProblems(final List<String> lines) throws IOException { + debug("GoldenComparator:scanForProblems"); int lineCount = 0; for (String line : lines) { lineCount++; - logger.debug(GoldenTestCase.GOLDEN_TEST, "GoldenComparator:scanForProblems scanning line {}", lineCount); + debug("GoldenComparator:scanForProblems scanning line " + lineCount); checkForProblem(lineCount, line); } } - private void checkForProblem(int lineCount, String line) { + private void checkForProblem(final int lineCount, final String line) { if (line == null) { return; } @@ -114,19 +104,23 @@ public abstract class GoldenComparator extends Assert { checkLineFor(lineCount, line, "severe"); } - private void checkLineFor(int lineCount, String line, String problem) { + private void checkLineFor(final int lineCount, final String line, final String problem) { if (line != null && line.toLowerCase().contains(problem)) { if (this.expectedProblemLines != null && this.expectedProblemLines.length > 0) { for (int i = 0; i < this.expectedProblemLines.length; i++) { - logger.debug(GoldenTestCase.GOLDEN_TEST, "Comparing \"{}\" against expected \"{}\"", line, this.expectedProblemLines[i]); + debug("Comparing \" + line + \" against expected \" + this.expectedProblemLines[i] + \""); if (compareLines(line, this.expectedProblemLines[i])) { return; } } } // TODO: collect up entire stack trace if there is one (might span multiple lines) - logger.debug(GoldenTestCase.GOLDEN_TEST, "About to fail because of {}", line); + debug("About to fail because of " + line); fail("Actual output contains a problem (warning/error/severe) on line " + lineCount + ": " + line); } } + + protected static void debug(final String string) { + GoldenTestCase.debug(string); + } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenStringComparator.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenStringComparator.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenStringComparator.java index 75a3398..8b9fac1 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenStringComparator.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenStringComparator.java @@ -12,11 +12,12 @@ import java.io.StringReader; */ public class GoldenStringComparator extends RegexGoldenComparator { - protected GoldenStringComparator(String[] expectedProblemLines) { + protected GoldenStringComparator(final String[] expectedProblemLines) { super(expectedProblemLines); } - protected Reader readGoldenFile(String goldenFileName) throws IOException { + @Override + protected Reader readGoldenFile(final String goldenFileName) throws IOException { return new StringReader(goldenFileName); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenTestCase.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenTestCase.java index 37b4e48..cac6748 100644 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenTestCase.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenTestCase.java @@ -1,62 +1,43 @@ package com.gemstone.gemfire.test.golden; import java.io.IOException; -import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Properties; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.MarkerManager; import org.apache.logging.log4j.core.config.ConfigurationFactory; +import org.junit.After; +import org.junit.Before; -import com.gemstone.gemfire.internal.AvailablePort; -import com.gemstone.gemfire.internal.ClassPathLoader; -import com.gemstone.gemfire.internal.logging.LogService; import com.gemstone.gemfire.test.process.ProcessWrapper; -import junit.framework.TestCase; - /** - * The abstract superclass of tests that need to process output from the - * quickstart examples. + * Test framework for launching processes and comparing output to expected golden output. * * @author Kirk Lund * @since 4.1.1 */ -public abstract class GoldenTestCase extends TestCase { - protected static final Marker GOLDEN_TEST = MarkerManager.getMarker("GOLDEN_TEST"); +public abstract class GoldenTestCase { - protected final Logger logger = LogService.getLogger(); - - private final int mcastPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS); - private final List<ProcessWrapper> processes = new ArrayList<ProcessWrapper>(); + /** Use to enable debug output in the JUnit process */ + protected static final String DEBUG_PROPERTY = "golden.test.DEBUG"; + protected static final boolean DEBUG = Boolean.getBoolean(DEBUG_PROPERTY); - static { - final URL configUrl = GoldenTestCase.class.getResource("log4j2-test.xml"); - if (configUrl != null) { - System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configUrl.toString()); - } - } + /** The log4j2 config used within the spawned process */ + private static final String LOG4J2_CONFIG_URL_STRING = GoldenTestCase.class.getResource("log4j2-test.xml").toString(); + private static final String[] JVM_ARGS = new String[] { + "-D"+ConfigurationFactory.CONFIGURATION_FILE_PROPERTY+"="+LOG4J2_CONFIG_URL_STRING + }; - private final static String[] jvmArgs = new String[] { - "-D"+ConfigurationFactory.CONFIGURATION_FILE_PROPERTY+"="+System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY) - }; + private final List<ProcessWrapper> processes = new ArrayList<ProcessWrapper>(); - public GoldenTestCase(String name) { - super(name); - } - - @Override - public final void setUp() throws Exception { - super.setUp(); + @Before + public final void setUpGoldenTest() throws Exception { subSetUp(); } - @Override - public final void tearDown() throws Exception { - super.tearDown(); + @After + public final void tearDownGoldenTest() throws Exception { try { for (ProcessWrapper process : this.processes) { process.destroy(); @@ -86,25 +67,13 @@ public abstract class GoldenTestCase extends TestCase { public void subTearDown() throws Exception { // override me } - - protected final ProcessWrapper createProcessWrapper(Class<?> main) { - final ProcessWrapper processWrapper = new ProcessWrapper.Builder().jvmArgs(jvmArgs).main(main).build(); - this.processes.add(processWrapper); - return processWrapper; - } - - protected final ProcessWrapper createProcessWrapper(Class<?> main, String[] mainArgs) { - final ProcessWrapper processWrapper = new ProcessWrapper.Builder().jvmArgs(jvmArgs).main(main).mainArgs(mainArgs).build(); + + protected final ProcessWrapper createProcessWrapper(final ProcessWrapper.Builder processWrapperBuilder, final Class<?> main) { + final ProcessWrapper processWrapper = processWrapperBuilder.jvmArguments(JVM_ARGS).mainClass(main).build(); this.processes.add(processWrapper); return processWrapper; } - protected final ProcessWrapper createProcessWrapper(Class<?> main, String[] mainArgs, boolean useMainLauncher) { - final ProcessWrapper processWrapper = new ProcessWrapper.Builder().jvmArgs(jvmArgs).main(main).mainArgs(mainArgs).useMainLauncher(useMainLauncher).build(); - this.processes.add(processWrapper); - return processWrapper; - } - /** * Creates and returns a new GoldenComparator instance. Default implementation * is RegexGoldenComparator. Override if you need a different implementation @@ -125,19 +94,19 @@ public abstract class GoldenTestCase extends TestCase { return null; } - protected void assertOutputMatchesGoldenFile(String actualOutput, String goldenFileName) throws IOException { + protected void assertOutputMatchesGoldenFile(final String actualOutput, final String goldenFileName) throws IOException { GoldenComparator comparator = createGoldenComparator(); comparator.assertOutputMatchesGoldenFile(actualOutput, goldenFileName); } - protected final void assertOutputMatchesGoldenFile(ProcessWrapper process, String goldenFileName) throws IOException { + protected final void assertOutputMatchesGoldenFile(final ProcessWrapper process, final String goldenFileName) throws IOException { GoldenComparator comparator = createGoldenComparator(); comparator.assertOutputMatchesGoldenFile(process.getOutput(), goldenFileName); } protected final Properties createProperties() { Properties properties = new Properties(); - properties.setProperty("gemfire.mcast-port", String.valueOf(this.mcastPort)); + properties.setProperty("gemfire.mcast-port", "0"); properties.setProperty("gemfire.log-level", "warning"); properties.setProperty("file.encoding", "UTF-8"); return editProperties(properties); @@ -150,30 +119,23 @@ public abstract class GoldenTestCase extends TestCase { return properties; } - protected final int getMcastPort() { - return this.mcastPort; + protected final void outputLine(final String string) { + System.out.println(string); } - // TODO: get rid of this to tighten up tests - protected final void sleep(long millis) throws InterruptedException { - Thread.sleep(millis); + protected final void printProcessOutput(final ProcessWrapper process, final boolean ignoreStopped) { + debug(process.getOutput(ignoreStopped), "OUTPUT"); } - protected final void printProcessOutput(ProcessWrapper process) { - innerPrintOutput(process.getOutput(), "OUTPUT"); + protected static void debug(final String output, final String title) { + debug("------------------ BEGIN " + title + " ------------------"); + debug(output); + debug("------------------- END " + title + " -------------------"); } - protected final void printProcessOutput(ProcessWrapper process, boolean ignoreStopped) { - innerPrintOutput(process.getOutput(ignoreStopped), "OUTPUT"); - } - - protected final void printProcessOutput(ProcessWrapper process, String banner) { - innerPrintOutput(process.getOutput(), banner); - } - - protected final void innerPrintOutput(String output, String title) { - System.out.println("------------------ BEGIN " + title + " ------------------"); - System.out.println(output); - System.out.println("------------------- END " + title + " -------------------"); + protected static void debug(final String string) { + if (DEBUG) { + System.out.println(string); + } } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenTestFrameworkTestSuite.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenTestFrameworkTestSuite.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenTestFrameworkTestSuite.java new file mode 100755 index 0000000..ed540be --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/GoldenTestFrameworkTestSuite.java @@ -0,0 +1,27 @@ +package com.gemstone.gemfire.test.golden; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + FailWithErrorInOutputJUnitTest.class, + FailWithExtraLineInOutputJUnitTest.class, + FailWithLineMissingFromEndOfOutputJUnitTest.class, + FailWithLineMissingFromMiddleOfOutputJUnitTest.class, + FailWithLoggerErrorInOutputJUnitTest.class, + FailWithLoggerFatalInOutputJUnitTest.class, + FailWithLoggerWarnInOutputJUnitTest.class, + FailWithSevereInOutputJUnitTest.class, + FailWithTimeoutOfWaitForOutputToMatchJUnitTest.class, + FailWithWarningInOutputJUnitTest.class, + PassJUnitTest.class, + PassWithExpectedErrorJUnitTest.class, + PassWithExpectedSevereJUnitTest.class, + PassWithExpectedWarningJUnitTest.class, +}) +/** + * Suite of tests for the test.golden Golden Test framework classes. + */ +public class GoldenTestFrameworkTestSuite { +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassJUnitTest.java index 886fc94..5959291 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassJUnitTest.java @@ -1,13 +1,16 @@ package com.gemstone.gemfire.test.golden; +import static org.junit.Assert.*; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import org.junit.Test; import org.junit.experimental.categories.Category; import com.gemstone.gemfire.test.process.ProcessWrapper; -import com.gemstone.gemfire.test.junit.categories.UnitTest; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Basic unit testing of the golden testing framework. This tests an @@ -15,13 +18,9 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest; * * @author Kirk Lund */ -@Category(UnitTest.class) -public class PassJUnitTest extends GoldenTestCase { +@Category(IntegrationTest.class) +public class PassJUnitTest extends GoldenTestCase implements ExecutableProcess { - public PassJUnitTest() { - super("PassJUnitTest"); - } - @Override protected GoldenComparator createGoldenComparator() { return new GoldenStringComparator(expectedProblemLines()); @@ -31,36 +30,41 @@ public class PassJUnitTest extends GoldenTestCase { return getClass().getSimpleName(); } - public void testPass() throws InterruptedException, IOException { - // output has no problems and should pass - final ProcessWrapper process = createProcessWrapper(getClass()); + /** + * Process output has no problems and should pass + */ + @Test + public void testPass() throws Exception { + final String goldenString = + "Begin " + name() + ".main" + "\n" + + "Press Enter to continue." + "\n" + + "End " + name() + ".main" + "\n"; + + final ProcessWrapper process = createProcessWrapper(new ProcessWrapper.Builder(), getClass()); process.execute(createProperties()); assertTrue(process.isAlive()); + process.waitForOutputToMatch("Begin " + name() + "\\.main"); process.waitForOutputToMatch("Press Enter to continue\\."); process.sendInput(); process.waitForOutputToMatch("End " + name() + "\\.main"); process.waitFor(); - String goldenString = "Begin " + name() + ".main" + "\n" - + "Press Enter to continue." + "\n" - + "End " + name() + ".main" + "\n"; + assertOutputMatchesGoldenFile(process, goldenString); - assertFalse(process.isAlive()); - //assertFalse(process.getOutputReader()); assertFalse(process.getStandardOutReader().isAlive()); assertFalse(process.getStandardErrorReader().isAlive()); } - void execute() throws IOException { - System.out.println("Begin " + name() + ".main"); - System.out.println("Press Enter to continue."); - BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); - inputReader.readLine(); - System.out.println("End " + name() + ".main"); + @Override + public final void executeInProcess() throws IOException { + outputLine("Begin " + name() + ".main"); + outputLine("Press Enter to continue."); + new BufferedReader(new InputStreamReader(System.in)).readLine(); + outputLine("End " + name() + ".main"); } - public static void main(String[] args) throws Exception { - new PassJUnitTest().execute(); + public static void main(final String[] args) throws Exception { + new PassJUnitTest().executeInProcess(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedErrorJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedErrorJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedErrorJUnitTest.java index 39267e9..35f8173 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedErrorJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedErrorJUnitTest.java @@ -2,10 +2,9 @@ package com.gemstone.gemfire.test.golden; import org.junit.experimental.categories.Category; -import com.gemstone.gemfire.LogWriter; import com.gemstone.gemfire.internal.logging.LocalLogWriter; import com.gemstone.gemfire.internal.logging.LogWriterImpl; -import com.gemstone.gemfire.test.junit.categories.UnitTest; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Verifies that an example test should always pass even if the output contains @@ -13,25 +12,20 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest; * * @author Kirk Lund */ -@Category(UnitTest.class) +@Category(IntegrationTest.class) public class PassWithExpectedErrorJUnitTest extends PassWithExpectedProblemTestCase { - public PassWithExpectedErrorJUnitTest() { - super("PassWithExpectedErrorJUnitTest"); - } - @Override String problem() { return "error"; } @Override - void outputProblem(String message) { - LogWriter logWriter = new LocalLogWriter(LogWriterImpl.INFO_LEVEL); - logWriter.error(message); + void outputProblemInProcess(final String message) { + new LocalLogWriter(LogWriterImpl.INFO_LEVEL).error(message); } - public static void main(String[] args) throws Exception { - new PassWithExpectedErrorJUnitTest().execute(); + public static void main(final String[] args) throws Exception { + new PassWithExpectedErrorJUnitTest().executeInProcess(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedProblemTestCase.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedProblemTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedProblemTestCase.java index 2958007..edae866 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedProblemTestCase.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedProblemTestCase.java @@ -4,6 +4,8 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import org.junit.Test; + import com.gemstone.gemfire.test.process.ProcessWrapper; /** @@ -12,11 +14,9 @@ import com.gemstone.gemfire.test.process.ProcessWrapper; * * @author Kirk Lund */ -public abstract class PassWithExpectedProblemTestCase extends GoldenTestCase { +public abstract class PassWithExpectedProblemTestCase extends GoldenTestCase implements ExecutableProcess { - PassWithExpectedProblemTestCase(String name) { - super(name); - } + private int problemLine; @Override protected GoldenComparator createGoldenComparator() { @@ -25,7 +25,11 @@ public abstract class PassWithExpectedProblemTestCase extends GoldenTestCase { @Override protected String[] expectedProblemLines() { - return new String[] { ".*" + name() + ".*", "^\\[" + problem() + ".*\\] ExpectedStrings: This is an expected problem in the output" }; + this.problemLine = 1; + return new String[] { + ".*" + name() + ".*", + "^\\[" + problem() + ".*\\] ExpectedStrings: This is an expected problem in the output" + }; } String name() { @@ -34,36 +38,38 @@ public abstract class PassWithExpectedProblemTestCase extends GoldenTestCase { abstract String problem(); - abstract void outputProblem(String message); + abstract void outputProblemInProcess(String message); - public void testPassWithExpectedProblem() throws InterruptedException, IOException { - // output has an expected warning/error/severe message and should pass - final ProcessWrapper process = createProcessWrapper(getClass()); + /** + * Process output has an expected warning/error/severe message and should pass + */ + @Test + public void testPassWithExpectedProblem() throws Exception { + final String goldenString = + "Begin " + name() + ".main" + "\n" + + "Press Enter to continue." + "\n" + + "\n" + + expectedProblemLines()[this.problemLine] + "\n" + + "End " + name() + ".main" + "\n"; + debug(goldenString, "GOLDEN"); + + final ProcessWrapper process = createProcessWrapper(new ProcessWrapper.Builder(), getClass()); process.execute(createProperties()); process.waitForOutputToMatch("Begin " + name() + "\\.main"); process.waitForOutputToMatch("Press Enter to continue\\."); process.sendInput(); process.waitForOutputToMatch("End " + name() + "\\.main"); process.waitFor(); - String goldenString = "Begin " + name() + ".main" + "\n" - + "Press Enter to continue." + "\n" - + "\n" - + "^\\[" + problem() + ".*\\] ExpectedStrings: This is an expected problem in the output" + "\n" - + "End " + name() + ".main" + "\n"; - innerPrintOutput(goldenString, "GOLDEN"); - String[] printMe = expectedProblemLines(); - for (String str : printMe) { - System.out.println(str); - } + assertOutputMatchesGoldenFile(process.getOutput(), goldenString); } - void execute() throws IOException { - System.out.println("Begin " + name() + ".main"); - System.out.println("Press Enter to continue."); - BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); - inputReader.readLine(); - outputProblem("ExpectedStrings: This is an expected problem in the output"); - System.out.println("End " + name() + ".main"); + @Override + public final void executeInProcess() throws IOException { + outputLine("Begin " + name() + ".main"); + outputLine("Press Enter to continue."); + new BufferedReader(new InputStreamReader(System.in)).readLine(); + outputProblemInProcess("ExpectedStrings: This is an expected problem in the output"); + outputLine("End " + name() + ".main"); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedSevereJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedSevereJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedSevereJUnitTest.java index 659e807..225d55b 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedSevereJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedSevereJUnitTest.java @@ -2,10 +2,9 @@ package com.gemstone.gemfire.test.golden; import org.junit.experimental.categories.Category; -import com.gemstone.gemfire.LogWriter; import com.gemstone.gemfire.internal.logging.LocalLogWriter; import com.gemstone.gemfire.internal.logging.LogWriterImpl; -import com.gemstone.gemfire.test.junit.categories.UnitTest; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Verifies that an example test should always pass even if the output contains @@ -13,25 +12,20 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest; * * @author Kirk Lund */ -@Category(UnitTest.class) +@Category(IntegrationTest.class) public class PassWithExpectedSevereJUnitTest extends PassWithExpectedProblemTestCase { - public PassWithExpectedSevereJUnitTest() { - super("PassWithExpectedSevereJUnitTest"); - } - @Override String problem() { return "severe"; } @Override - void outputProblem(String message) { - LogWriter logWriter = new LocalLogWriter(LogWriterImpl.INFO_LEVEL); - logWriter.severe(message); + void outputProblemInProcess(final String message) { + new LocalLogWriter(LogWriterImpl.INFO_LEVEL).severe(message); } - public static void main(String[] args) throws Exception { - new PassWithExpectedSevereJUnitTest().execute(); + public static void main(final String[] args) throws Exception { + new PassWithExpectedSevereJUnitTest().executeInProcess(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedWarningJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedWarningJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedWarningJUnitTest.java index 866e8b2..215f5ca 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedWarningJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/PassWithExpectedWarningJUnitTest.java @@ -2,10 +2,9 @@ package com.gemstone.gemfire.test.golden; import org.junit.experimental.categories.Category; -import com.gemstone.gemfire.LogWriter; import com.gemstone.gemfire.internal.logging.LocalLogWriter; import com.gemstone.gemfire.internal.logging.LogWriterImpl; -import com.gemstone.gemfire.test.junit.categories.UnitTest; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Verifies that an example test should always pass even if the output contains @@ -13,25 +12,20 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest; * * @author Kirk Lund */ -@Category(UnitTest.class) +@Category(IntegrationTest.class) public class PassWithExpectedWarningJUnitTest extends PassWithExpectedProblemTestCase { - public PassWithExpectedWarningJUnitTest() { - super("PassWithExpectedWarningJUnitTest"); - } - @Override String problem() { return "warning"; } @Override - void outputProblem(String message) { - LogWriter logWriter = new LocalLogWriter(LogWriterImpl.INFO_LEVEL); - logWriter.warning(message); + void outputProblemInProcess(final String message) { + new LocalLogWriter(LogWriterImpl.INFO_LEVEL).warning(message); } - public static void main(String[] args) throws Exception { - new PassWithExpectedWarningJUnitTest().execute(); + public static void main(final String[] args) throws Exception { + new PassWithExpectedWarningJUnitTest().executeInProcess(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/RegexGoldenComparator.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/RegexGoldenComparator.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/RegexGoldenComparator.java index bc80b3a..759e3a3 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/RegexGoldenComparator.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/RegexGoldenComparator.java @@ -1,6 +1,5 @@ package com.gemstone.gemfire.test.golden; -import java.util.regex.Matcher; import java.util.regex.Pattern; /** @@ -10,14 +9,13 @@ import java.util.regex.Pattern; */ public class RegexGoldenComparator extends GoldenComparator { - protected RegexGoldenComparator(String[] expectedProblemLines) { + protected RegexGoldenComparator(final String[] expectedProblemLines) { super(expectedProblemLines); } @Override - protected boolean compareLines(String actualLine, String goldenLine) { - logger.debug(GoldenTestCase.GOLDEN_TEST, "RegexGoldenComparator:compareLines comparing \"{}\" to \"{}\"", actualLine, goldenLine); - Matcher matcher = Pattern.compile(goldenLine).matcher(actualLine); - return matcher.matches(); + protected boolean compareLines(final String actualLine, final String goldenLine) { + debug("RegexGoldenComparator:compareLines comparing \" + actualLine + \" to \" + goldenLine + \""); + return Pattern.compile(goldenLine).matcher(actualLine).matches(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/StringGoldenComparator.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/StringGoldenComparator.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/StringGoldenComparator.java index 5547a9e..48f645a 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/StringGoldenComparator.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/golden/StringGoldenComparator.java @@ -7,12 +7,12 @@ package com.gemstone.gemfire.test.golden; */ public class StringGoldenComparator extends GoldenComparator { - protected StringGoldenComparator(String[] expectedProblemLines) { + protected StringGoldenComparator(final String[] expectedProblemLines) { super(expectedProblemLines); } @Override - protected boolean compareLines(String actualLine, String goldenLine) { + protected boolean compareLines(final String actualLine, final String goldenLine) { if (actualLine == null) { return goldenLine == null; } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/94939c1f/gemfire-core/src/test/java/com/gemstone/gemfire/test/process/ProcessTestFrameworkTestSuite.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/process/ProcessTestFrameworkTestSuite.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/process/ProcessTestFrameworkTestSuite.java new file mode 100755 index 0000000..011a62e --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/process/ProcessTestFrameworkTestSuite.java @@ -0,0 +1,12 @@ +package com.gemstone.gemfire.test.process; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + MainLauncherJUnitTest.class, + ProcessWrapperJUnitTest.class, +}) +public class ProcessTestFrameworkTestSuite { +}