This is an automated email from the ASF dual-hosted git repository. jasonhuynh pushed a commit to branch support/1.13 in repository https://gitbox.apache.org/repos/asf/geode.git
commit 3149d9680e97351090c61f1ceb694bf8b7d6f182 Author: Jinmei Liao <jil...@pivotal.io> AuthorDate: Thu Jun 25 09:59:47 2020 -0700 GEODE-8200: enhance GfshRule to specify a working dir (#5299) * improve some backward compatibility test to cover more versions. (cherry picked from commit 561533c53cf44e53c42f26cd988eae6821af6769) --- .../DeploymentManagementUpgradeTest.java | 52 +++++++++++++++++----- .../RollingUpgradeWithGfshDUnitTest.java | 29 +++--------- .../geode/test/junit/rules/gfsh/GfshRule.java | 50 ++++++++++++++++++--- .../geode/test/junit/rules/gfsh/GfshScript.java | 8 ++++ 4 files changed, 101 insertions(+), 38 deletions(-) diff --git a/geode-assembly/src/upgradeTest/java/org/apache/geode/management/DeploymentManagementUpgradeTest.java b/geode-assembly/src/upgradeTest/java/org/apache/geode/management/DeploymentManagementUpgradeTest.java index 4fe3e42..1b98213 100644 --- a/geode-assembly/src/upgradeTest/java/org/apache/geode/management/DeploymentManagementUpgradeTest.java +++ b/geode-assembly/src/upgradeTest/java/org/apache/geode/management/DeploymentManagementUpgradeTest.java @@ -16,26 +16,55 @@ package org.apache.geode.management; import static org.apache.geode.test.junit.assertions.ClusterManagementListResultAssert.assertManagementListResult; +import static org.apache.geode.test.junit.rules.gfsh.GfshRule.startLocatorCommand; import java.io.File; import java.io.IOException; +import java.util.Collection; +import java.util.List; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.apache.geode.internal.AvailablePortHelper; import org.apache.geode.management.api.ClusterManagementService; import org.apache.geode.management.client.ClusterManagementServiceBuilder; import org.apache.geode.management.configuration.Deployment; import org.apache.geode.test.compiler.JarBuilder; +import org.apache.geode.test.junit.categories.BackwardCompatibilityTest; +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; +import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory; +import org.apache.geode.test.version.TestVersion; +import org.apache.geode.test.version.VersionManager; +@Category({BackwardCompatibilityTest.class}) +@RunWith(Parameterized.class) +@Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class) public class DeploymentManagementUpgradeTest { + private final String oldVersion; + + @Parameterized.Parameters(name = "{0}") + public static Collection<String> data() { + List<String> result = VersionManager.getInstance().getVersionsWithoutCurrent(); + result.removeIf(s -> TestVersion.compare(s, "1.10.0") < 0); + return result; + } + + public DeploymentManagementUpgradeTest(String version) { + oldVersion = version; + oldGfsh = new GfshRule(oldVersion); + } + @Rule - public GfshRule oldGfsh = new GfshRule("1.10.0"); + public GfshRule oldGfsh; @Rule public GfshRule gfsh = new GfshRule(); @@ -55,19 +84,22 @@ public class DeploymentManagementUpgradeTest { @Test public void newLocatorCanReadOldConfigurationData() throws IOException { - File workingDir = tempFolder.newFolder(); int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(3); - oldGfsh.execute("start locator --name=test --port=" + ports[0] + " --http-service-port=" - + ports[1] + " --dir=" + workingDir.getAbsolutePath() + " --J=-Dgemfire.jmx-manager-port=" - + ports[2], - "deploy --jar=" + clusterJar.getAbsolutePath(), - "shutdown --include-locators"); + int httpPort = ports[0]; + int locatorPort = ports[1]; + int jmxPort = ports[2]; + GfshExecution execute = + GfshScript.of(startLocatorCommand("test", locatorPort, jmxPort, httpPort, 0)) + .and("deploy --jar=" + clusterJar.getAbsolutePath()) + .and("shutdown --include-locators") + .execute(oldGfsh); - gfsh.execute("start locator --name=test --port=" + ports[0] + " --http-service-port=" + ports[1] - + " --dir=" + workingDir.getAbsolutePath() + " --J=-Dgemfire.jmx-manager-port=" + ports[2]); + // use the latest gfsh to start the locator in the same working dir + GfshScript.of(startLocatorCommand("test", locatorPort, jmxPort, httpPort, 0)) + .execute(gfsh, execute.getWorkingDir()); ClusterManagementService cms = new ClusterManagementServiceBuilder() - .setPort(ports[1]) + .setPort(httpPort) .build(); assertManagementListResult(cms.list(new Deployment())).isSuccessful() .hasConfigurations().hasSize(1); diff --git a/geode-core/src/upgradeTest/java/org/apache/geode/internal/cache/rollingupgrade/RollingUpgradeWithGfshDUnitTest.java b/geode-core/src/upgradeTest/java/org/apache/geode/internal/cache/rollingupgrade/RollingUpgradeWithGfshDUnitTest.java index d16650e..08a2c63 100644 --- a/geode-core/src/upgradeTest/java/org/apache/geode/internal/cache/rollingupgrade/RollingUpgradeWithGfshDUnitTest.java +++ b/geode-core/src/upgradeTest/java/org/apache/geode/internal/cache/rollingupgrade/RollingUpgradeWithGfshDUnitTest.java @@ -14,6 +14,8 @@ */ package org.apache.geode.internal.cache.rollingupgrade; +import static org.apache.geode.test.junit.rules.gfsh.GfshRule.startLocatorCommand; +import static org.apache.geode.test.junit.rules.gfsh.GfshRule.startServerCommand; import static org.assertj.core.api.Assertions.assertThat; import java.io.File; @@ -80,8 +82,8 @@ public class RollingUpgradeWithGfshDUnitTest { int server2Port = portSupplier.getAvailablePort(); GfshExecution startupExecution = - GfshScript.of(startLocatorCommand("loc1", locatorPort, locatorJmxPort, -1)) - .and(startLocatorCommand("loc2", locator2Port, locator2JmxPort, locatorPort)) + GfshScript.of(startLocatorCommand("loc1", locatorPort, locatorJmxPort, 0, -1)) + .and(startLocatorCommand("loc2", locator2Port, locator2JmxPort, 0, locatorPort)) .and(startServerCommand("server1", server1Port, locatorPort)) .and(startServerCommand("server2", server2Port, locatorPort)) .and(deployDirCommand()) @@ -89,12 +91,12 @@ public class RollingUpgradeWithGfshDUnitTest { // doing rolling upgrades oldGfsh.stopLocator(startupExecution, "loc1"); - GfshScript.of(startLocatorCommand("loc1", locatorPort, locatorJmxPort, locator2Port)) + GfshScript.of(startLocatorCommand("loc1", locatorPort, locatorJmxPort, 0, locator2Port)) .execute(currentGfsh); verifyListDeployed(locatorPort); oldGfsh.stopLocator(startupExecution, "loc2"); - GfshScript.of(startLocatorCommand("loc2", locator2Port, locator2JmxPort, locatorPort)) + GfshScript.of(startLocatorCommand("loc2", locator2Port, locator2JmxPort, 0, locatorPort)) .execute(currentGfsh); verifyListDeployed(locator2Port); @@ -123,23 +125,4 @@ public class RollingUpgradeWithGfshDUnitTest { classBuilder.writeJarFromName(class1, jar1); return "deploy --dir=" + jarsDir.getAbsolutePath(); } - - private String startServerCommand(String name, int port, int connectedLocatorPort) { - String command = "start server --name=" + name - + " --server-port=" + port - + " --locators=localhost[" + connectedLocatorPort + "]"; - return command; - } - - private String startLocatorCommand(String name, int port, int jmxPort, - int connectedLocatorPort) { - String command = "start locator --name=" + name - + " --port=" + port - + " --http-service-port=0"; - if (connectedLocatorPort > 0) { - command += " --locators=localhost[" + connectedLocatorPort + "]"; - } - command += " --J=-Dgemfire.jmx-manager-port=" + jmxPort; - return command; - } } diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/GfshRule.java b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/GfshRule.java index 9114cf6..e9981a8 100644 --- a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/GfshRule.java +++ b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/GfshRule.java @@ -114,15 +114,26 @@ public class GfshRule extends ExternalResource { return execute(GfshScript.of(commands)); } - public GfshExecution execute(GfshScript gfshScript) { + public GfshExecution execute(File workingDir, String... commands) { + return execute(GfshScript.of(commands), workingDir); + } + + /** + * this will allow you to specify a gfsh workingDir when executing the script + * this is usually helpful if: + * 1. you would start a different gfsh session but would + * like to remain in the same working dir as your previous one, (You can get your gfsh session's + * working dir by using GfshExecution.getWorkingDir) + * 2. you already prepared the workingdir with some initial setup. + * + * This way, this workingDir will be managed by the gfshRule and stop all the processes that + * exists in this working dir when tests finish + */ + public GfshExecution execute(GfshScript gfshScript, File workingDir) { System.out.println("Executing " + gfshScript); try { - File workingDir = new File(temporaryFolder.getRoot(), gfshScript.getName()); - workingDir.mkdirs(); - int debugPort = gfshScript.getDebugPort(); Process process = toProcessBuilder(gfshScript, gfsh, workingDir, debugPort).start(); - GfshExecution gfshExecution = new GfshExecution(process, workingDir); gfshExecutions.add(gfshExecution); gfshExecution.awaitTermination(gfshScript); @@ -132,6 +143,16 @@ public class GfshRule extends ExternalResource { } } + public GfshExecution execute(GfshScript gfshScript) { + try { + File workingDir = new File(temporaryFolder.getRoot(), gfshScript.getName()); + workingDir.mkdirs(); + return execute(gfshScript, workingDir); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + private ProcessBuilder toProcessBuilder(GfshScript gfshScript, Path gfshPath, File workingDir, int gfshDebugPort) { List<String> commandsToExecute = new ArrayList<>(); @@ -199,4 +220,23 @@ public class GfshRule extends ExternalResource { } execute(GfshScript.of(stopMemberScripts).withName("Stop-Members")); } + + public static String startServerCommand(String name, int port, int connectedLocatorPort) { + String command = "start server --name=" + name + + " --server-port=" + port + + " --locators=localhost[" + connectedLocatorPort + "]"; + return command; + } + + public static String startLocatorCommand(String name, int port, int jmxPort, int httpPort, + int connectedLocatorPort) { + String command = "start locator --name=" + name + + " --port=" + port + + " --http-service-port=" + httpPort; + if (connectedLocatorPort > 0) { + command += " --locators=localhost[" + connectedLocatorPort + "]"; + } + command += " --J=-Dgemfire.jmx-manager-port=" + jmxPort; + return command; + } } diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/GfshScript.java b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/GfshScript.java index 0d50990..7945012 100644 --- a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/GfshScript.java +++ b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/gfsh/GfshScript.java @@ -16,6 +16,7 @@ package org.apache.geode.test.junit.rules.gfsh; import static org.assertj.core.api.Assertions.assertThat; +import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -133,6 +134,13 @@ public class GfshScript { return gfshRule.execute(this); } + /** + * this will allow you to specify a gfsh workingDir when executing the script + */ + public GfshExecution execute(GfshRule gfshRule, File workingDir) { + return gfshRule.execute(this, workingDir); + } + public List<DebuggableCommand> getCommands() { return commands; }