Skip to content

Commit

Permalink
GEODE-10257: Upgrade tests can upgrade Java (#7686)
Browse files Browse the repository at this point in the history
Currently, upgrade tests upgrade from an old version of Geode to the
current version, both running on the test JVM's version of Java.

This commit enhances most upgrade tests so that they also upgrade from
an old Java version to a newer one, both running the current version of
Geode.

The new `VmConfiguration` class represents a configuration for a Geode
JVM, specifying both the Java version and the Geode version.

The new `VmConfigurations` class offers two factory methods to produce
lists of candidate configurations:
- `VmConfigurations.upgrades()` produces a list of "upgrade"
  configurations useful for most upgrade tests. Each upgrade
  configuration specifies either and old version of Geode or an old
  version of Java, but not both.
- `VmConfigurations.all()` produces a list of upgrades plus a
  configuration representing the current version of Geode and the test
  JVM's version of Java.

`VmConfigurations` also includes factory methods to create predicates to
filter configurations.
  • Loading branch information
demery-pivotal committed May 16, 2022
1 parent 6ec2994 commit e835c8c
Show file tree
Hide file tree
Showing 77 changed files with 1,342 additions and 623 deletions.
12 changes: 12 additions & 0 deletions build-tools/scripts/src/main/groovy/multi-process-test.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ def multiProcessTestTasks = [acceptanceTest, repeatAcceptanceTest,
upgradeTest, repeatUpgradeTest,
uiTest, repeatUnitTest]

for (task in multiProcessTestTasks) {
if(project.hasProperty('testJava8Home')) {
task.environment "TEST_JAVA_8_HOME", "${project.testJava8Home}"
}
if(project.hasProperty('testJava11Home')) {
task.environment "TEST_JAVA_11_HOME", "${project.testJava11Home}"
}
if(project.hasProperty('testJava17Home')) {
task.environment "TEST_JAVA_17_HOME", "${project.testJava17Home}"
}
}

if (project.hasProperty('testJVM') && !testJVM.trim().isEmpty()) {
for (task in multiProcessTestTasks) {
task.environment "JAVA_HOME", "${project.testJVM}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

package org.apache.geode.management;

import static org.apache.geode.test.dunit.Host.getHost;
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;
Expand Down Expand Up @@ -65,7 +64,7 @@ public OperationManagementUpgradeTest(String version) {
oldGfsh = new GfshRule(oldVersion);
DUnitLauncher.launchIfNeeded(false);
// get the vm with the same version of the oldGfsh
vm = getHost(0).getVM(oldVersion, 0);
vm = VM.getVM(oldVersion, 0);
}

@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
*/
package org.apache.geode.rest.internal.web.controllers;

import static java.util.stream.Collectors.toList;
import static org.apache.geode.test.version.VmConfigurations.hasGeodeVersion;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -53,20 +54,22 @@
import org.apache.geode.test.junit.rules.GfshCommandRule;
import org.apache.geode.test.junit.rules.MemberStarterRule;
import org.apache.geode.test.version.TestVersion;
import org.apache.geode.test.version.VersionManager;
import org.apache.geode.test.version.TestVersions;
import org.apache.geode.test.version.VmConfiguration;
import org.apache.geode.test.version.VmConfigurations;
import org.apache.geode.util.internal.GeodeJsonMapper;

@Category({BackwardCompatibilityTest.class})
@RunWith(Parameterized.class)
public class RestAPICompatibilityTest {
private final String oldVersion;
private final VmConfiguration sourceVmConfiguration;
private static final ObjectMapper mapper = GeodeJsonMapper.getMapper();

@Parameterized.Parameters(name = "{0}")
public static Collection<String> data() {
List<String> result = VersionManager.getInstance().getVersionsWithoutCurrent();
result.removeIf(s -> TestVersion.compare(s, "1.11.0") < 0);
return result;
public static Collection<VmConfiguration> data() {
return VmConfigurations.upgrades().stream()
.filter(hasGeodeVersion(TestVersions.atLeast(TestVersion.valueOf("1.11.0"))))
.collect(toList());
}

@Rule
Expand All @@ -75,8 +78,9 @@ public static Collection<String> data() {
@Rule
public GfshCommandRule gfsh = new GfshCommandRule();

public RestAPICompatibilityTest(String oldVersion) throws JsonProcessingException {
this.oldVersion = oldVersion;
public RestAPICompatibilityTest(VmConfiguration sourceVmConfiguration)
throws JsonProcessingException {
this.sourceVmConfiguration = sourceVmConfiguration;
DiskStore diskStore = new DiskStore();
diskStore.setName("diskStore");
postRESTAPICalls = new HashMap<>();
Expand Down Expand Up @@ -104,15 +108,18 @@ public void restCommandExecutedOnLatestLocatorShouldBeBackwardsCompatible() thro
int locatorPort2 = locatorPorts[1];

// Initialize all cluster members with old versions
cluster.startLocatorVM(0, locatorPort1, oldVersion, MemberStarterRule::withHttpService);
cluster.startLocatorVM(1, locatorPort2, oldVersion,
cluster.startLocatorVM(0, locatorPort1, sourceVmConfiguration,
MemberStarterRule::withHttpService);
cluster.startLocatorVM(1, locatorPort2, sourceVmConfiguration,
x -> x.withConnectionToLocator(locatorPort1).withHttpService());
cluster
.startServerVM(2, oldVersion, s -> s.withRegion(RegionShortcut.PARTITION, "region")
.withConnectionToLocator(locatorPort1, locatorPort2));
.startServerVM(2, sourceVmConfiguration,
s -> s.withRegion(RegionShortcut.PARTITION, "region")
.withConnectionToLocator(locatorPort1, locatorPort2));
cluster
.startServerVM(3, oldVersion, s -> s.withRegion(RegionShortcut.PARTITION, "region")
.withConnectionToLocator(locatorPort1, locatorPort2));
.startServerVM(3, sourceVmConfiguration,
s -> s.withRegion(RegionShortcut.PARTITION, "region")
.withConnectionToLocator(locatorPort1, locatorPort2));

// Roll locators to the current version
cluster.stop(0);
Expand Down Expand Up @@ -143,7 +150,8 @@ void executeAndValidatePOSTRESTCalls(int locator) throws Exception {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
for (Map.Entry<String, String[]> entry : postRESTAPICalls.entrySet()) {
// Skip the test is the version is before the REST api was introduced.
if (TestVersion.compare(oldVersion, entry.getValue()[2]) < 0) {
TestVersion restApiMinimumGeodeVersion = TestVersion.valueOf(entry.getValue()[2]);
if (sourceVmConfiguration.geodeVersion().lessThan(restApiMinimumGeodeVersion)) {
continue;
}
HttpPost post =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
*/
package org.apache.geode.session.tests;

import static java.util.stream.Collectors.toList;
import static org.apache.geode.test.version.VmConfigurations.hasGeodeVersion;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.junit.Assert.assertEquals;

import java.io.File;
Expand All @@ -38,7 +41,10 @@
import org.apache.geode.test.junit.rules.GfshCommandRule;
import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
import org.apache.geode.test.version.TestVersion;
import org.apache.geode.test.version.TestVersions;
import org.apache.geode.test.version.VersionManager;
import org.apache.geode.test.version.VmConfiguration;
import org.apache.geode.test.version.VmConfigurations;

/**
* This test iterates through the versions of Geode and executes session client compatibility with
Expand All @@ -50,14 +56,20 @@
public abstract class TomcatSessionBackwardsCompatibilityTestBase {
private final UniquePortSupplier portSupplier = new UniquePortSupplier();

@Parameterized.Parameters
@Parameterized.Parameters(name = "{0}")
public static Collection<String> data() {
List<String> result = VersionManager.getInstance().getVersionsWithoutCurrent();
result.removeIf(s -> TestVersion.compare(s, "1.2.0") < 0);
if (result.size() < 1) {
throw new RuntimeException("No older versions of Geode were found to test against");
}
return result;
List<String> sourceVersions = VmConfigurations.upgrades().stream()
// Skip versions older than 1.2
.filter(hasGeodeVersion(TestVersions.atLeast(TestVersion.valueOf("1.2.0"))))
// Skip Java upgrades
.filter(hasGeodeVersion(TestVersions.lessThan(TestVersion.CURRENT_VERSION)))
.map(VmConfiguration::geodeVersion)
.map(String::valueOf)
.collect(toList());
assumeThat(sourceVersions)
.as("source versions")
.isNotEmpty();
return sourceVersions;
}

@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.apache.geode;

import static java.util.Comparator.comparing;
import static org.apache.geode.distributed.ConfigurationProperties.CONSERVE_SOCKETS;
import static org.apache.geode.distributed.ConfigurationProperties.DISABLE_TCP;
import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
Expand All @@ -38,7 +39,9 @@
import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM;
import static org.apache.geode.test.dunit.VM.getVM;
import static org.apache.geode.test.util.ResourceUtils.createTempFileFromResource;
import static org.apache.geode.test.version.VmConfigurations.hasGeodeVersion;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;

import java.io.DataInput;
import java.io.DataOutput;
Expand All @@ -48,7 +51,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -98,7 +101,11 @@
import org.apache.geode.test.junit.categories.MembershipTest;
import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
import org.apache.geode.test.version.TestVersion;
import org.apache.geode.test.version.TestVersions;
import org.apache.geode.test.version.VersionManager;
import org.apache.geode.test.version.VmConfiguration;
import org.apache.geode.test.version.VmConfigurations;

/**
* This class tests cluster tcp/ip communications both with and without SSL enabled
Expand Down Expand Up @@ -272,12 +279,18 @@ public void receiveBigResponse() {

@Test
public void performARollingUpgrade() {
List<String> testVersions = VersionManager.getInstance().getVersionsWithoutCurrent();
String testVersion = testVersions.get(testVersions.size() - 1);
Optional<VmConfiguration> sourceConfiguration = VmConfigurations.upgrades().stream()
// Skip the configurations with the current Geode
.filter(hasGeodeVersion(TestVersions.lessThan(TestVersion.CURRENT_VERSION)))
// Get the configuration with the latest Geode
.max(comparing(VmConfiguration::geodeVersion));
assumeThat(sourceConfiguration)
.as("newest old configuration")
.isNotEmpty();

// create a cluster with the previous version of Geode
VM locatorVM = Host.getHost(0).getVM(testVersion, 0);
VM server1VM = Host.getHost(0).getVM(testVersion, 1);
VM locatorVM = Host.getHost(0).getVM(sourceConfiguration.get(), 0);
VM server1VM = Host.getHost(0).getVM(sourceConfiguration.get(), 1);
int locatorPort = createLocator(locatorVM, true);
createCacheAndRegion(server1VM, locatorPort);
performCreate(getVM(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
*/
package org.apache.geode.internal.cache;


import static java.util.stream.Collectors.toList;
import static org.apache.geode.test.version.VmConfigurations.hasGeodeVersion;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.junit.Rule;
Expand All @@ -31,25 +34,25 @@
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
import org.apache.geode.test.version.TestVersion;
import org.apache.geode.test.version.VersionManager;
import org.apache.geode.test.version.TestVersions;
import org.apache.geode.test.version.VmConfiguration;
import org.apache.geode.test.version.VmConfigurations;

@RunWith(Parameterized.class)
public class GetClusterConfigurationFunctionCompatibilityTest {

private final String oldVersion;
private final VmConfiguration sourceConfiguration;

@Parameterized.Parameters(name = "Version: {0}")
public static Collection<String> data() {
final TestVersion OLDEST_VERSION_SUPPORTING_GET_CLUSTER_CONFIGURATION_FUNCTION =
TestVersion.valueOf("1.12.0");
List<String> result = VersionManager.getInstance().getVersionsWithoutCurrent();
result.removeIf(s -> TestVersion.valueOf(s)
.lessThan(OLDEST_VERSION_SUPPORTING_GET_CLUSTER_CONFIGURATION_FUNCTION));
return result;
@Parameterized.Parameters(name = "From {0}")
public static Collection<VmConfiguration> data() {
TestVersion minimumGeodeVersion = TestVersion.valueOf("1.12.0");
return VmConfigurations.upgrades().stream()
.filter(hasGeodeVersion(TestVersions.atLeast(minimumGeodeVersion)))
.collect(toList());
}

public GetClusterConfigurationFunctionCompatibilityTest(String oldVersion) {
this.oldVersion = oldVersion;
public GetClusterConfigurationFunctionCompatibilityTest(VmConfiguration sourceConfiguration) {
this.sourceConfiguration = sourceConfiguration;
}

@Rule
Expand All @@ -64,11 +67,11 @@ public GetClusterConfigurationFunctionCompatibilityTest(String oldVersion) {
@Test
public void newLocatorCanGetClusterConfigurationFromOldLocator() {
// Start locators in old version
MemberVM locator1 = clusterStartupRule.startLocatorVM(0, oldVersion);
MemberVM locator1 = clusterStartupRule.startLocatorVM(0, sourceConfiguration);
int locator1Port = locator1.getPort();
MemberVM locator2 =
clusterStartupRule.startLocatorVM(1, AvailablePortHelper.getRandomAvailableTCPPort(),
oldVersion, l -> l.withConnectionToLocator(locator1Port));
sourceConfiguration, l -> l.withConnectionToLocator(locator1Port));
// Roll one locator to the new version
locator2.stop(false);
locator2 = clusterStartupRule.startLocatorVM(1, l -> l.withConnectionToLocator(locator1Port));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.apache.geode.internal.cache;

import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPort;
import static org.assertj.core.api.Assertions.assertThat;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
Expand Down Expand Up @@ -50,7 +51,8 @@
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
import org.apache.geode.test.junit.categories.BackwardCompatibilityTest;
import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
import org.apache.geode.test.version.VersionManager;
import org.apache.geode.test.version.VmConfiguration;
import org.apache.geode.test.version.VmConfigurations;

/**
* This test class tests the communication pattern of a transaction for replicate and partition
Expand All @@ -70,17 +72,16 @@
@SuppressWarnings("serial")
public abstract class TxCommitMessageBCTestBase extends JUnit4DistributedTestCase {
@Parameterized.Parameter
public String testVersion;

@Parameterized.Parameters
public static Collection<String> data() {
List<String> result = VersionManager.getInstance().getVersionsWithoutCurrent();
if (result.size() < 1) {
throw new RuntimeException("No older versions of Geode were found to test against");
} else {
System.out.println("running against these versions: " + result);
}
return result;
public VmConfiguration sourceConfiguration;

@Parameterized.Parameters(name = "From {0}")
public static Collection<VmConfiguration> data() {
List<VmConfiguration> sourceConfigurations = VmConfigurations.upgrades();
assertThat(sourceConfigurations)
.as("upgrade configurations")
.isNotEmpty();
System.out.println("upgrading from configurations: " + sourceConfigurations);
return sourceConfigurations;
}

protected static VM server1 = null;
Expand All @@ -106,7 +107,7 @@ public final void postSetUp() throws Exception {
server1 = host.getVM(0); // server
server2 = host.getVM(1); // server
server3 = host.getVM(2); // server with pool
client = host.getVM(testVersion, 3); // client
client = host.getVM(sourceConfiguration, 3);
oldClient = host.getVM(4); // client old version

int port1 =
Expand Down
Loading

0 comments on commit e835c8c

Please sign in to comment.