[ 
https://issues.apache.org/jira/browse/GEODE-4225?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16320981#comment-16320981
 ] 

ASF GitHub Bot commented on GEODE-4225:
---------------------------------------

PurelyApplied closed pull request #1250: GEODE-4225: Extend ClusterStartupRule 
to specify member / client version.
URL: https://github.com/apache/geode/pull/1250
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsOnServerManagerDUnit.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsOnServerManagerDUnit.java
index 6a6901e34a..626909f1d0 100644
--- 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsOnServerManagerDUnit.java
+++ 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsOnServerManagerDUnit.java
@@ -61,7 +61,7 @@ public void testExportWithOneServer() throws Exception {
 
   @Test
   public void testExportWithPeerLocator() throws Exception {
-    MemberVM server0 = lsRule.startServerAsEmbededLocator(0);
+    MemberVM server0 = lsRule.startServerAsEmbeddedLocator(0);
     lsRule.startServerVM(1, server0.getEmbeddedLocatorPort());
     gfshConnector.connect(server0.getEmbeddedLocatorPort(), 
GfshCommandRule.PortType.locator);
     gfshConnector.executeAndAssertThat("export logs").statusIsSuccess();
diff --git 
a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ClusterStartupRule.java
 
b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ClusterStartupRule.java
index 89029c65e6..dc79bea0bb 100644
--- 
a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ClusterStartupRule.java
+++ 
b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ClusterStartupRule.java
@@ -45,6 +45,7 @@
 import org.apache.geode.security.templates.UserPasswordAuthInit;
 import org.apache.geode.test.dunit.VM;
 import org.apache.geode.test.dunit.standalone.DUnitLauncher;
+import org.apache.geode.test.dunit.standalone.VersionManager;
 import org.apache.geode.test.junit.rules.ClientCacheRule;
 import org.apache.geode.test.junit.rules.Locator;
 import org.apache.geode.test.junit.rules.LocatorStarterRule;
@@ -140,7 +141,7 @@ protected void after() {
       MemberStarterRule.disconnectDSIfAny();
 
       // stop all the clientsVM before stop all the memberVM
-      occupiedVMs.values().stream().forEach(x -> x.stopVM(true));
+      occupiedVMs.values().forEach(x -> x.stopVM(true));
 
       if (useTempWorkingDir()) {
         tempWorkingDir.delete();
@@ -149,25 +150,14 @@ protected void after() {
     }
   }
 
-  public MemberVM startLocatorVM(int index) throws Exception {
-    return startLocatorVM(index, new Properties());
-  }
-
-  public MemberVM startLocatorVM(int index, int... locatorPort) throws 
Exception {
-    Properties properties = new Properties();
-    String locators = Arrays.stream(locatorPort).mapToObj(i -> "localhost[" + 
i + "]")
-        .collect(Collectors.joining(","));
-    properties.setProperty(LOCATORS, locators);
-    return startLocatorVM(index, properties);
-  }
-
   /**
    * Starts a locator instance with the given configuration properties inside
    * {@code getHost(0).getVM(index)}.
    *
    * @return VM locator vm
    */
-  public MemberVM startLocatorVM(int index, Properties specifiedProperties) 
throws Exception {
+  public MemberVM startLocatorVM(int index, Properties specifiedProperties, 
String version)
+      throws Exception {
     Properties properties = new Properties();
     properties.putAll(specifiedProperties);
 
@@ -175,7 +165,7 @@ public MemberVM startLocatorVM(int index, Properties 
specifiedProperties) throws
     properties.putIfAbsent(NAME, defaultName);
     String name = properties.getProperty(NAME);
 
-    VM locatorVM = getVM(index);
+    VM locatorVM = getVM(index, version);
     Locator locator = locatorVM.invoke(() -> {
       memberStarter = new LocatorStarterRule();
       LocatorStarterRule locatorStarter = (LocatorStarterRule) memberStarter;
@@ -195,29 +185,27 @@ public MemberVM startLocatorVM(int index, Properties 
specifiedProperties) throws
     return memberVM;
   }
 
-  public MemberVM startServerVM(int index) throws IOException {
-    return startServerVM(index, new Properties(), -1);
-  }
-
-  public MemberVM startServerVM(int index, int locatorPort) throws IOException 
{
-    return startServerVM(index, new Properties(), locatorPort);
+  public MemberVM startLocatorVM(int index, Properties specifiedProperties) 
throws Exception {
+    return startLocatorVM(index, specifiedProperties, 
VersionManager.CURRENT_VERSION);
   }
 
-  public MemberVM startServerVM(int index, String group, int locatorPort) 
throws IOException {
+  public MemberVM startLocatorVM(int index, int... locatorPort) throws 
Exception {
     Properties properties = new Properties();
-    properties.put(GROUPS, group);
-    return startServerVM(index, properties, locatorPort);
+    String locators = Arrays.stream(locatorPort).mapToObj(i -> "localhost[" + 
i + "]")
+        .collect(Collectors.joining(","));
+    properties.setProperty(LOCATORS, locators);
+    return startLocatorVM(index, properties);
   }
 
-  public MemberVM startServerVM(int index, Properties properties) throws 
IOException {
-    return startServerVM(index, properties, -1);
+  public MemberVM startLocatorVM(int index) throws Exception {
+    return startLocatorVM(index, new Properties());
   }
 
   /**
    * Starts a cache server with given properties
    */
-  public MemberVM startServerVM(int index, Properties specifiedProperties, int 
locatorPort)
-      throws IOException {
+  public MemberVM startServerVM(int index, Properties specifiedProperties, int 
locatorPort,
+      String version) throws IOException {
     Properties properties = new Properties();
     properties.putAll(specifiedProperties);
 
@@ -225,7 +213,7 @@ public MemberVM startServerVM(int index, Properties 
specifiedProperties, int loc
     properties.putIfAbsent(NAME, defaultName);
     String name = properties.getProperty(NAME);
 
-    VM serverVM = getVM(index);
+    VM serverVM = getVM(index, version);
     Server server = serverVM.invoke(() -> {
       memberStarter = new ServerStarterRule();
       ServerStarterRule serverStarter = (ServerStarterRule) memberStarter;
@@ -246,23 +234,55 @@ public MemberVM startServerVM(int index, Properties 
specifiedProperties, int loc
     return memberVM;
   }
 
-  public MemberVM startServerAsJmxManager(int index) throws IOException {
-    return startServerAsJmxManager(index, new Properties());
+  public MemberVM startServerVM(int index, Properties specifiedProperties, int 
locatorPort)
+      throws IOException {
+    return startServerVM(index, specifiedProperties, locatorPort, 
VersionManager.CURRENT_VERSION);
   }
 
+  public MemberVM startServerVM(int index, String group, int locatorPort) 
throws IOException {
+    Properties properties = new Properties();
+    properties.put(GROUPS, group);
+    return startServerVM(index, properties, locatorPort);
+  }
+
+  public MemberVM startServerVM(int index, int locatorPort) throws IOException 
{
+    return startServerVM(index, new Properties(), locatorPort);
+  }
+
+  public MemberVM startServerVM(int index, Properties properties) throws 
IOException {
+    return startServerVM(index, properties, -1);
+  }
+
+  public MemberVM startServerVM(int index) throws IOException {
+    return startServerVM(index, new Properties(), -1);
+  }
+
+  /**
+   * Starts a cache server with given properties, plus an available port for a 
JMX manager
+   */
   public MemberVM startServerAsJmxManager(int index, Properties properties) 
throws IOException {
     properties.setProperty(JMX_MANAGER_PORT, 
AvailablePortHelper.getRandomAvailableTCPPort() + "");
     return startServerVM(index, properties, -1);
   }
 
-  public MemberVM startServerAsEmbededLocator(int index) throws IOException {
-    return startServerAsEmbededLocator(index, new Properties());
+  public MemberVM startServerAsJmxManager(int index) throws IOException {
+    return startServerAsJmxManager(index, new Properties());
   }
 
-  public MemberVM startServerAsEmbededLocator(int index, Properties 
properties) throws IOException {
-    String name = "server-" + index;
+  /**
+   * Starts a cache server with given properties. Additionally, start the 
server with a JMX manager
+   * and embedded locator.
+   */
+  public MemberVM startServerAsEmbeddedLocator(int index, Properties 
specifiedProperties,
+      String version) throws IOException {
+    Properties properties = new Properties();
+    properties.putAll(specifiedProperties);
 
-    VM serverVM = getVM(index);
+    String defaultName = "server-" + index;
+    properties.putIfAbsent(NAME, defaultName);
+    String name = properties.getProperty(NAME);
+
+    VM serverVM = getVM(index, version);
     Server server = serverVM.invoke(() -> {
       memberStarter = new ServerStarterRule();
       ServerStarterRule serverStarter = (ServerStarterRule) memberStarter;
@@ -284,17 +304,43 @@ public MemberVM startServerAsEmbededLocator(int index, 
Properties properties) th
     return memberVM;
   }
 
-  public void stopVM(int index) {
-    stopVM(index, true);
+  public MemberVM startServerAsEmbeddedLocator(int index, Properties 
properties)
+      throws IOException {
+    return startServerAsEmbeddedLocator(index, properties, 
VersionManager.CURRENT_VERSION);
   }
 
-  public void stopVM(int index, boolean cleanWorkingDir) {
-    VMProvider member = occupiedVMs.get(index);
+  public MemberVM startServerAsEmbeddedLocator(int index) throws IOException {
+    return startServerAsEmbeddedLocator(index, new Properties());
+  }
 
-    if (member == null)
-      return;
+  /**
+   * Starts a client with the given properties, configuring the cacheFactory 
with the provided
+   * Consumer
+   */
+  public ClientVM startClientVM(int index, Properties properties,
+      Consumer<ClientCacheFactory> cacheFactorySetup, String clientVersion) 
throws Exception {
+    VM client = getVM(index, clientVersion);
+    Exception error = client.invoke(() -> {
+      clientCacheRule =
+          new 
ClientCacheRule().withProperties(properties).withCacheSetup(cacheFactorySetup);
+      try {
+        clientCacheRule.before();
+        return null;
+      } catch (Exception e) {
+        return e;
+      }
+    });
+    if (error != null) {
+      throw error;
+    }
+    ClientVM clientVM = new ClientVM(client);
+    occupiedVMs.put(index, clientVM);
+    return clientVM;
+  }
 
-    member.stopVM(cleanWorkingDir);
+  public ClientVM startClientVM(int index, Properties properties,
+      Consumer<ClientCacheFactory> cacheFactorySetup) throws Exception {
+    return startClientVM(index, properties, cacheFactorySetup, 
VersionManager.CURRENT_VERSION);
   }
 
   public ClientVM startClientVM(int index, String username, String password,
@@ -314,26 +360,6 @@ public ClientVM startClientVM(int index, String username, 
String password,
     return startClientVM(index, props, consumer);
   }
 
-  public ClientVM startClientVM(int index, Properties properties,
-      Consumer<ClientCacheFactory> cacheFactorySetup) throws Exception {
-    VM client = getVM(index);
-    Exception error = client.invoke(() -> {
-      clientCacheRule =
-          new 
ClientCacheRule().withProperties(properties).withCacheSetup(cacheFactorySetup);
-      try {
-        clientCacheRule.before();
-        return null;
-      } catch (Exception e) {
-        return e;
-      }
-    });
-    if (error != null) {
-      throw error;
-    }
-    ClientVM clientVM = new ClientVM(client);
-    occupiedVMs.put(index, clientVM);
-    return clientVM;
-  }
 
   /**
    * Returns the {@link Member} running inside the VM with the specified 
{@code index}
@@ -342,8 +368,25 @@ public MemberVM getMember(int index) {
     return (MemberVM) occupiedVMs.get(index);
   }
 
+  public VM getVM(int index, String version) {
+    return getHost(0).getVM(version, index);
+  }
+
   public VM getVM(int index) {
-    return getHost(0).getVM(index);
+    return getVM(index, VersionManager.CURRENT_VERSION);
+  }
+
+  public void stopVM(int index) {
+    stopVM(index, true);
+  }
+
+  public void stopVM(int index, boolean cleanWorkingDir) {
+    VMProvider member = occupiedVMs.get(index);
+
+    if (member == null)
+      return;
+
+    member.stopVM(cleanWorkingDir);
   }
 
   public TemporaryFolder getTempWorkingDir() {
diff --git 
a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/ClusterStartupRuleCanSpecifyOlderVersionsDUnitTest.java
 
b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/ClusterStartupRuleCanSpecifyOlderVersionsDUnitTest.java
new file mode 100644
index 0000000000..2354aa7cb8
--- /dev/null
+++ 
b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/ClusterStartupRuleCanSpecifyOlderVersionsDUnitTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.rules.tests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Properties;
+import java.util.function.Consumer;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.internal.GemFireVersion;
+import org.apache.geode.test.dunit.rules.ClientVM;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.dunit.standalone.VersionManager;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import 
org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
+
+@Category(DistributedTest.class)
+@RunWith(Parameterized.class)
[email protected](CategoryWithParameterizedRunnerFactory.class)
+public class ClusterStartupRuleCanSpecifyOlderVersionsDUnitTest {
+  @Parameterized.Parameter
+  public String version;
+
+  @Parameterized.Parameters(name = "version={0}")
+  public static List<String> versions() {
+    return VersionManager.getInstance().getVersionsWithoutCurrent();
+  }
+
+  @Rule
+  public ClusterStartupRule csRule = new ClusterStartupRule();
+
+  @Test
+  public void locatorVersioningTest() throws Exception {
+    MemberVM locator = csRule.startLocatorVM(0, new Properties(), version);
+    String locatorVMVersion = locator.getVM().getVersion();
+    String locatorActualVersion = 
locator.invoke(GemFireVersion::getGemFireVersion);
+    assertThat(locatorVMVersion).isEqualTo(version);
+    
assertThat(locatorActualVersion).isEqualTo(getDottedVersionString(version));
+  }
+
+  @Test
+  public void serverVersioningTest() throws Exception {
+    MemberVM locator = csRule.startLocatorVM(0, new Properties(), version);
+    String locatorVMVersion = locator.getVM().getVersion();
+    String locatorActualVersion = 
locator.invoke(GemFireVersion::getGemFireVersion);
+    assertThat(locatorVMVersion).isEqualTo(version);
+    
assertThat(locatorActualVersion).isEqualTo(getDottedVersionString(version));
+  }
+
+  @Test
+  public void serverWithEmbeddedLocatorVersioningTest() throws Exception {
+    MemberVM locator = csRule.startServerAsEmbeddedLocator(0, new 
Properties(), version);
+    String locatorVMVersion = locator.getVM().getVersion();
+    String locatorActualVersion = 
locator.invoke(GemFireVersion::getGemFireVersion);
+    assertThat(locatorVMVersion).isEqualTo(version);
+    
assertThat(locatorActualVersion).isEqualTo(getDottedVersionString(version));
+  }
+
+  @Test
+  public void clientVersioningTest() throws Exception {
+    Consumer<ClientCacheFactory> consumer = (Serializable & 
Consumer<ClientCacheFactory>) cf -> {
+    };
+    ClientVM locator = csRule.startClientVM(0, new Properties(), consumer, 
version);
+    String locatorVMVersion = locator.getVM().getVersion();
+    String locatorActualVersion = 
locator.invoke(GemFireVersion::getGemFireVersion);
+    assertThat(locatorVMVersion).isEqualTo(version);
+    
assertThat(locatorActualVersion).isEqualTo(getDottedVersionString(version));
+  }
+
+  private static String getDottedVersionString(String vmVersionShorthand) 
throws Exception {
+    if (vmVersionShorthand.equals("100")) {
+      return "1.0.0-incubating";
+    } else {
+      return vmVersionShorthand.charAt(0) + "." + vmVersionShorthand.charAt(1) 
+ "."
+          + vmVersionShorthand.charAt(2);
+    }
+  }
+}
diff --git 
a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ExportConfigCommandDUnitTest.java
 
b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ExportConfigCommandDUnitTest.java
index 7db2faf140..819624186d 100644
--- 
a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ExportConfigCommandDUnitTest.java
+++ 
b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ExportConfigCommandDUnitTest.java
@@ -56,7 +56,7 @@ public void testExportConfig(final boolean connectOverHttp) 
throws Exception {
     Properties props = new Properties();
     props.setProperty(GROUPS, "Group1");
 
-    MemberVM server0 = startupRule.startServerAsEmbededLocator(0, props);
+    MemberVM server0 = startupRule.startServerAsEmbeddedLocator(0, props);
 
     if (connectOverHttp) {
       gfsh.connectAndVerify(server0.getHttpPort(), 
GfshCommandRule.PortType.http);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Extend ClusterStartupRule to instantiate members and clients of a particular 
> version
> ------------------------------------------------------------------------------------
>
>                 Key: GEODE-4225
>                 URL: https://issues.apache.org/jira/browse/GEODE-4225
>             Project: Geode
>          Issue Type: Improvement
>            Reporter: Patrick Rhomberg
>            Assignee: Patrick Rhomberg
>
> Many tests, particularly those testing rolling upgrade, would benefit from 
> the consistency of the ClusterStartupRule but require clients of a specific 
> version.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to