Skip to content
Permalink
Browse files
feat: add dubbo.{service}.version config support
  • Loading branch information
plusmancn committed Sep 15, 2021
1 parent 8a18989 commit f34b7779e2d091a3871824977ac33028535c1c75
Showing 4 changed files with 67 additions and 10 deletions.
@@ -19,5 +19,7 @@
# Supported component versions of the test case

# Spring app
dubbo.version=2.7*, 3.*
spring.version=4.*, 5.*
spring.version=4.*, 5.*

dubbo.dubbo-samples-migration-default.version=3.*
dubbo.dubbo-samples-migration-default-test.version=2.7.*
@@ -16,8 +16,8 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<dubbo.version>3.0.2.1</dubbo.version>
<!-- <dubbo.version>3.0.3-SNAPSHOT</dubbo.version>-->
<!-- <dubbo.version>3.0.2.1</dubbo.version>-->
<dubbo.version>3.0.3-SNAPSHOT</dubbo.version>
<!-- <dubbo.version>2.7.13</dubbo.version>-->
<junit.version>4.12</junit.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
@@ -17,12 +17,26 @@

package org.apache.dubbo.scenario.builder;

public class Constants {
import java.util.regex.Pattern;

public static final String ERROR_MSG_FLAG=":ErrorMsg:";
/**
* Constants in dubbo-scenario-builder
*/
public interface Constants {

String ERROR_MSG_FLAG=":ErrorMsg:";

int EXIT_FAILED = 1;
int EXIT_UNMATCHED = 100;
int EXIT_IGNORED = 120;

public static final int EXIT_FAILED = 1;
public static final int EXIT_UNMATCHED = 100;
public static final int EXIT_IGNORED = 120;
/**
* Used in case-versions.conf
*/
String DUBBO_VERSION_KEY = "dubbo.version";

/**
* The pattern used for searching target service name
*/
Pattern PATTERN_DUBBO_VERSION = Pattern.compile("^dubbo\\.(.+)\\.version$");
}
@@ -41,6 +41,10 @@
public class VersionMatcher {

private static final Logger logger = LoggerFactory.getLogger(VersionMatcher.class);

/**
* Java Property names
*/
public static final String CASE_VERSIONS_FILE = "caseVersionsFile";
public static final String CANDIDATE_VERSIONS = "candidateVersions";
public static final String OUTPUT_FILE = "outputFile";
@@ -85,6 +89,9 @@ private void doMatch(String caseVersionsFile, String candidateVersionListStr, St
// parse case version match rules
Map<String, List<MatchRule>> caseVersionMatchRules = parseCaseVersionMatchRules(caseVersionsFile);

// Filter caseVersionMatchRules
chooseActiveDubboVersionRule(caseVersionMatchRules);

Map<String, List<String>> matchedVersionMap = new LinkedHashMap<>();

candidateVersionMap.forEach((component, candidateVersionList) -> {
@@ -152,6 +159,33 @@ private void doMatch(String caseVersionsFile, String candidateVersionListStr, St
}
}

/**
* Choose only one final active Dubbo version rule from following case:
* <br>
* 1. dubbo.version - original usage
* <br>
* 2. dubbo.{service}.version - different services can have different dubbo version for supporting compatibility-test
* @param caseVersionMatchRules
*/
private static void chooseActiveDubboVersionRule(Map<String, List<MatchRule>> caseVersionMatchRules) {
for (String key : caseVersionMatchRules.keySet()) {
if (Constants.PATTERN_DUBBO_VERSION.matcher(key).matches() && caseVersionMatchRules.get(Constants.DUBBO_VERSION_KEY) != null) {
errorAndExit(Constants.EXIT_FAILED, "The config item dubbo.version and dubbo.{service}.version can't appear simultaneously");
}
}

for (String key : caseVersionMatchRules.keySet()) {
Matcher matcher = Constants.PATTERN_DUBBO_VERSION.matcher(key);
if (matcher.matches()) {
String service = matcher.group(1);
List<MatchRule> matchRules = caseVersionMatchRules.computeIfAbsent(
Constants.DUBBO_VERSION_KEY,
item -> new ArrayList<>()
);
}
}
}

private static boolean hasIncludeVersion(List<MatchRule> matchRules, String version) {
boolean included = false;
version = trimVersion(version);
@@ -298,11 +332,18 @@ private static void errorAndExit(int exitCode, String format, Object... argument
}

private interface MatchRule {

boolean isExcluded();

boolean match(String version);


/**
* Which service the MatchRule bind to
* @return
*/
default String getServiceName() {
return null;
}
}

private static abstract class ExcludableMatchRule implements MatchRule {

0 comments on commit f34b777

Please sign in to comment.