Skip to content

Commit

Permalink
GEODE-7250 accomodate new versions greater than 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
bschuchardt committed Sep 27, 2019
1 parent 875294c commit 3c0174c
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
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;

/**
Expand All @@ -64,7 +65,7 @@ public static Collection<String> data() {
List<String> result = VersionManager.getInstance().getVersionsWithoutCurrent();
String minimumVersion =
SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_9) ? "1.8.0" : "1.7.0";
result.removeIf(s -> s.compareTo(minimumVersion) < 0);
result.removeIf(s -> TestVersion.compare(s, minimumVersion) < 0);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.geode.test.junit.categories.BackwardCompatibilityTest;
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.VersionManager;

/**
Expand All @@ -52,7 +53,7 @@ public abstract class TomcatSessionBackwardsCompatibilityTestBase {
@Parameterized.Parameters
public static Collection<String> data() {
List<String> result = VersionManager.getInstance().getVersionsWithoutCurrent();
result.removeIf(s -> Integer.parseInt(VersionManager.getInstance().versionWithNoDots(s)) < 120);
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");
}
Expand Down Expand Up @@ -87,7 +88,13 @@ public static Collection<String> data() {

protected TomcatSessionBackwardsCompatibilityTestBase(String version) {
VersionManager versionManager = VersionManager.getInstance();
String installLocation = versionManager.getInstall(version);
String installLocation = null;
try {
installLocation = versionManager.getInstall(version);
} finally {
System.out.println(
"BRUCE: for version " + version + " the installation directory is " + installLocation);
}
oldBuild = new File(installLocation);
oldModules = new File(installLocation + "/tools/Modules/");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
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.VersionManager;

/**
Expand Down Expand Up @@ -202,7 +203,7 @@ public void receiveBigResponse() {
@Test
public void performARollingUpgrade() {
List<String> testVersions = VersionManager.getInstance().getVersionsWithoutCurrent();
Collections.sort(testVersions);
Collections.sort(testVersions, (v1, v2) -> TestVersion.compare(v1, v2));
String testVersion = testVersions.get(testVersions.size() - 1);

// create a cluster with the previous version of Geode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.apache.geode.test.dunit.rules.MemberVM;
import org.apache.geode.test.junit.categories.SecurityTest;
import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
import org.apache.geode.test.version.TestVersion;
import org.apache.geode.test.version.VersionManager;

/**
Expand Down Expand Up @@ -98,8 +99,7 @@ public void setup() throws Exception {
// We want the cluster VMs to be super-users for ease of testing / remote invocation.
Properties clusterMemberProperties = getVMPropertiesWithPermission("cluster,data");

int version = Integer.parseInt(VersionManager.getInstance().versionWithNoDots(clientVersion));
if (version == 0 || version >= 140) {
if (TestVersion.compare(clientVersion, "1.4.0") >= 0) {
clusterMemberProperties.setProperty(ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER,
"org.apache.geode.security.templates.UsernamePrincipal");
}
Expand Down Expand Up @@ -145,8 +145,7 @@ public void dataWriteClientCanPut() throws Exception {
@Test
public void dataWriteCannotGet() throws Exception {
Properties props = getVMPropertiesWithPermission("dataWrite");
int version = Integer.parseInt(VersionManager.getInstance().versionWithNoDots(clientVersion));
if (version == 0 || version >= 140) {
if (TestVersion.compare(clientVersion, "1.4.0") >= 0) {
props.setProperty(ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER,
"org.apache.geode.security.templates.UsernamePrincipal");
}
Expand Down Expand Up @@ -206,8 +205,7 @@ public void dataReadClientCanGet() throws Exception {
@Test
public void dataReadCannotPut() throws Exception {
Properties props = getVMPropertiesWithPermission("dataRead");
int version = Integer.parseInt(VersionManager.getInstance().versionWithNoDots(clientVersion));
if (version == 0 || version >= 140) {
if (TestVersion.compare(clientVersion, "1.4.0") >= 0) {
props.setProperty(ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER,
"org.apache.geode.security.templates.UsernamePrincipal");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.apache.geode.test.dunit.rules.MemberVM;
import org.apache.geode.test.junit.categories.SecurityTest;
import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
import org.apache.geode.test.version.TestVersion;
import org.apache.geode.test.version.VersionManager;

/**
Expand Down Expand Up @@ -131,8 +132,7 @@ public static Collection<String> data() {
@Before
public void setup() throws Exception {
Properties clusterMemberProperties = getVMPropertiesWithPermission("cluster,data");
int version = Integer.parseInt(VersionManager.getInstance().versionWithNoDots(clientVersion));
if (version == 0 || version >= 140) {
if (TestVersion.compare(clientVersion, "1.4.0") >= 0) {
clusterMemberProperties.setProperty(ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER,
"org.apache.geode.security.templates.UsernamePrincipal");
}
Expand Down Expand Up @@ -317,8 +317,7 @@ public void dataReaderCanRegisterAndUnregisterAcrossFailover() throws Exception
@Test
public void dataWriterCannotRegisterInterestAcrossFailover() throws Exception {
Properties props = getVMPropertiesWithPermission("dataWrite");
int version = Integer.parseInt(VersionManager.getInstance().versionWithNoDots(clientVersion));
if (version == 0 || version >= 140) {
if (TestVersion.compare(clientVersion, "1.4.0") >= 0) {
props.setProperty(ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER,
"org.apache.geode.security.templates.UsernamePrincipal");
}
Expand Down Expand Up @@ -378,8 +377,7 @@ private ClientVM createAndInitializeClientAndCache(String withPermission) throws

Properties props = getVMPropertiesWithPermission(withPermission);

int version = Integer.parseInt(VersionManager.getInstance().versionWithNoDots(clientVersion));
if (version == 0 || version >= 140) {
if (TestVersion.compare(clientVersion, "1.4.0") >= 0) {
props.setProperty(ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER,
"org.apache.geode.security.templates.UsernamePrincipal");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,18 @@ private String removeModuleFromEclipsePath(String classpath, String module) {
return classpath;
}

private String removeModuleFromIntelliJPath(String classpath, String module) {
private String removeModuleFromIntelliJPath(String p_classpath, String module) {
String classpath = p_classpath;
String mainClasses = File.separator + "out" + File.separator + "production"
+ File.separator + "org.apache.geode." + module + ".main";

if (!classpath.contains(mainClasses)) {
return classpath;
if (classpath.contains(mainClasses)) {
classpath = removeFromPath(classpath, mainClasses);
}
mainClasses = File.separator + "out" + File.separator + "production"
+ File.separator + "geode." + module + ".main";
if (classpath.contains(mainClasses)) {
classpath = removeFromPath(classpath, mainClasses);
}

classpath = removeFromPath(classpath, mainClasses);
return classpath;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* 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.version;

import java.util.Objects;

public class TestVersion implements Comparable {
private final int major;
private final int minor;
private final int patch;

public TestVersion(String versionString) {
String[] split = versionString.split("\\.");
if (split.length != 3) {
throw new IllegalArgumentException("Expected a version string but received " + versionString);
}
major = Integer.parseInt(split[0]);
minor = Integer.parseInt(split[1]);
if (split[2].contains("-incubating")) {
split[2] = split[2].substring(0, split[2].length() - "-incubating".length());
}
patch = Integer.parseInt(split[2]);
}

/**
* Perform a comparison of the major, minor and patch versions of the two version strings.
* The version strings should be in dot notation.
*/
public static int compare(String version1, String version2) {
return new TestVersion(version1).compareTo(new TestVersion(version2));
}

@Override
public String toString() {
return "" + major + "." + minor + "." + patch;
}


@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof TestVersion)) {
return false;
}
TestVersion that = (TestVersion) o;
return major == that.major &&
minor == that.minor &&
patch == that.patch;
}

@Override
public int hashCode() {
return Objects.hash(major, minor, patch);
}

public TestVersion(int major, int minor, int patch) {
this.major = major;
this.minor = minor;
this.patch = patch;
}

@Override
public int compareTo(Object o) {
if (o == null) {
throw new NullPointerException("parameter may not be null");
}
TestVersion other = (TestVersion) o;
int comparison = Integer.compare(major, other.major);
if (comparison != 0) {
return comparison;
}
comparison = Integer.compare(minor, other.minor);
if (comparison != 0) {
return comparison;
}
return Integer.compare(patch, other.patch);
}

public int compareTo(int major, int minor, int patch) {
return compareTo(new TestVersion(major, minor, patch));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* see Host.getVM(String, int)
*/
public class VersionManager {
public static final String CURRENT_VERSION = "0.0.0";
public static final String CURRENT_VERSION = "10240.0.0";

private static VersionManager instance;

Expand Down Expand Up @@ -117,30 +117,15 @@ public String getClasspath(String version) {


public String getInstall(String version) {
return installs.get(version);
}

/**
* Remove the dots from a version string. "1.2.0" -> "120"
*/
public String versionWithNoDots(String s) {
StringBuilder b = new StringBuilder(10);
int length = s.length();
for (int i = 0; i < length; i++) {
char ch = s.charAt(i);
if (ch != '.') {
// leave off any trailing stuff like "-incubating"
if (!Character.isDigit(ch)) {
break;
}
b.append(ch);
}
if (!installs.containsKey(version) || (installs.get(version) == null)) {
throw new IllegalArgumentException("unable to locate installation directory for " + version);
}
return b.toString();
return installs.get(version);
}

/**
* Returns a list of older versions available for testing
* Returns a list of older versions available for testing.
* Note: if you need to compare version strings use TestVersion.compare()
*/
public List<String> getVersions() {
checkForLoadFailure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.apache.geode.test.dunit.internal.DUnitLauncher;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
import org.apache.geode.test.version.TestVersion;
import org.apache.geode.test.version.VersionManager;

@RunWith(Parameterized.class)
Expand All @@ -82,7 +83,7 @@ private static Collection<String> getLuceneVersions() {
List<String> result = VersionManager.getInstance().getVersionsWithoutCurrent();
// Lucene Compatibility checks start with Apache Geode v1.2.0
// Removing the versions older than v1.2.0
result.removeIf(s -> Integer.parseInt(VersionManager.getInstance().versionWithNoDots(s)) < 120);
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");
} else {
Expand Down
5 changes: 3 additions & 2 deletions geode-old-versions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ subprojects {

def oldGeodeVersion = project.name

boolean useTgz = (oldGeodeVersion >= "1.7.0")
boolean downloadInstall = (oldGeodeVersion >= "1.2.0")
boolean isIncubating = oldGeodeVersion.contains("incubating")
boolean useTgz = !isIncubating && ((oldGeodeVersion >= "1.7.0") || (oldGeodeVersion.length() > 5))
boolean downloadInstall = !isIncubating && ((oldGeodeVersion >= "1.2.0") || (oldGeodeVersion.length() > 5))

String archiveType = useTgz ? "tgz" : "zip"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.NetworkUtils;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.version.TestVersion;
import org.apache.geode.test.version.VersionManager;

public class WANRollingUpgradeMultipleReceiversDefinedInClusterConfiguration
Expand Down Expand Up @@ -95,7 +96,7 @@ private static List<String> getVersionsToTest() {
// saved in cluster configuration and multiple receivers are not supported starting in 140.
// Note: This comparison works because '130' < '140'.
List<String> result = VersionManager.getInstance().getVersionsWithoutCurrent();
result.removeIf(version -> (version.compareTo("1.4.0") >= 0));
result.removeIf(version -> (TestVersion.compare(version, "1.4.0") >= 0));
if (result.size() < 1) {
throw new RuntimeException("No older versions of Geode were found to test against");
}
Expand Down
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ include 'static-analysis:pmd-rules'
'1.7.0',
'1.8.0',
'1.9.0',
'1.9.1'].each {
'1.9.1',
'1.10.0'].each {
include 'geode-old-versions:'.concat(it)
}

Expand Down

0 comments on commit 3c0174c

Please sign in to comment.