Skip to content

Commit

Permalink
Make code strong, version check compatibility. (#4488)
Browse files Browse the repository at this point in the history
* 2.6.x test

* version check compatibility

* add comment

* revert demo changes

* update ut

* add error log

* change log level to warn
  • Loading branch information
chickenlj authored and mercyblitz committed Jul 8, 2019
1 parent 374d41b commit 4054050
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 10 additions & 1 deletion dubbo-common/src/main/java/com/alibaba/dubbo/common/Version.java
Expand Up @@ -36,6 +36,8 @@ public final class Version {

// Dubbo RPC protocol version, for compatibility, it must not be between 2.0.10 ~ 2.6.2
public static final String DEFAULT_DUBBO_PROTOCOL_VERSION = "2.0.2";
// version 1.0.0 represents Dubbo rpc protocol before v2.6.2
public static final int LEGACY_DUBBO_PROTOCOL_VERSION = 10000; // 1.0.0
// Dubbo implementation version, usually is jar version.
private static final String VERSION = getVersion(Version.class, "");

Expand Down Expand Up @@ -78,7 +80,14 @@ public static boolean isSupportResponseAttatchment(String version) {
public static int getIntVersion(String version) {
Integer v = VERSION2INT.get(version);
if (v == null) {
v = parseInt(version);
try {
v = parseInt(version);
} catch (Exception e) {
logger.warn("Please make sure your version value has the right format: " +
"\n 1. only contains digital number: 2.0.0; \n 2. with string suffix: 2.6.7-stable. " +
"\nIf you are using Dubbo before v2.6.2, the version value is the same with the jar version.");
v = LEGACY_DUBBO_PROTOCOL_VERSION;
}
VERSION2INT.put(version, v);
}
return v;
Expand Down
Expand Up @@ -18,7 +18,6 @@


import com.alibaba.dubbo.common.Version;

import org.junit.Assert;
import org.junit.Test;

Expand All @@ -34,5 +33,11 @@ public void testSupportResponseAttatchment() {
Assert.assertTrue(Version.isSupportResponseAttatchment("2.0.2"));
Assert.assertTrue(Version.isSupportResponseAttatchment("2.0.3"));
Assert.assertFalse(Version.isSupportResponseAttatchment("2.0.0"));
Assert.assertFalse(Version.isSupportResponseAttatchment("1.0.0"));
Assert.assertTrue(Version.isSupportResponseAttatchment("2.6.6-stable"));

Assert.assertFalse(Version.isSupportResponseAttatchment("2.0.contains"));
Assert.assertFalse(Version.isSupportResponseAttatchment("version.string"));
Assert.assertFalse(Version.isSupportResponseAttatchment("prefix2.0"));
}
}

0 comments on commit 4054050

Please sign in to comment.