Skip to content

Commit

Permalink
Merge branch '2.5.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	all/pom.xml
#	dubbo-admin/pom.xml
#	dubbo-admin/src/main/java/com/alibaba/dubbo/governance/web/governance/module/screen/Providers.java
#	dubbo-cluster/pom.xml
#	dubbo-common/pom.xml
#	dubbo-config/dubbo-config-api/pom.xml
#	dubbo-config/dubbo-config-spring/pom.xml
#	dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/ServiceBean.java
#	dubbo-config/pom.xml
#	dubbo-container/dubbo-container-api/pom.xml
#	dubbo-container/dubbo-container-jetty/pom.xml
#	dubbo-container/dubbo-container-log4j/pom.xml
#	dubbo-container/dubbo-container-logback/pom.xml
#	dubbo-container/dubbo-container-spring/pom.xml
#	dubbo-container/pom.xml
#	dubbo-demo/dubbo-demo-api/pom.xml
#	dubbo-demo/dubbo-demo-consumer/pom.xml
#	dubbo-demo/dubbo-demo-provider/pom.xml
#	dubbo-demo/pom.xml
#	dubbo-filter/dubbo-filter-cache/pom.xml
#	dubbo-filter/dubbo-filter-validation/pom.xml
#	dubbo-filter/pom.xml
#	dubbo-maven/pom.xml
#	dubbo-monitor/dubbo-monitor-api/pom.xml
#	dubbo-monitor/dubbo-monitor-default/pom.xml
#	dubbo-monitor/pom.xml
#	dubbo-plugin/dubbo-qos/pom.xml
#	dubbo-plugin/pom.xml
#	dubbo-registry/dubbo-registry-api/pom.xml
#	dubbo-registry/dubbo-registry-default/pom.xml
#	dubbo-registry/dubbo-registry-multicast/pom.xml
#	dubbo-registry/dubbo-registry-redis/pom.xml
#	dubbo-registry/dubbo-registry-zookeeper/pom.xml
#	dubbo-registry/pom.xml
#	dubbo-remoting/dubbo-remoting-api/pom.xml
#	dubbo-remoting/dubbo-remoting-grizzly/pom.xml
#	dubbo-remoting/dubbo-remoting-http/pom.xml
#	dubbo-remoting/dubbo-remoting-mina/pom.xml
#	dubbo-remoting/dubbo-remoting-netty/pom.xml
#	dubbo-remoting/dubbo-remoting-netty4/pom.xml
#	dubbo-remoting/dubbo-remoting-p2p/pom.xml
#	dubbo-remoting/dubbo-remoting-zookeeper/pom.xml
#	dubbo-remoting/pom.xml
#	dubbo-rpc/dubbo-rpc-api/pom.xml
#	dubbo-rpc/dubbo-rpc-default/pom.xml
#	dubbo-rpc/dubbo-rpc-default/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/DubboProtocol.java
#	dubbo-rpc/dubbo-rpc-hessian/pom.xml
#	dubbo-rpc/dubbo-rpc-http/pom.xml
#	dubbo-rpc/dubbo-rpc-injvm/pom.xml
#	dubbo-rpc/dubbo-rpc-memcached/pom.xml
#	dubbo-rpc/dubbo-rpc-redis/pom.xml
#	dubbo-rpc/dubbo-rpc-rmi/pom.xml
#	dubbo-rpc/dubbo-rpc-thrift/pom.xml
#	dubbo-rpc/dubbo-rpc-webservice/pom.xml
#	dubbo-rpc/pom.xml
#	dubbo-simple/dubbo-monitor-simple/pom.xml
#	dubbo-simple/dubbo-registry-simple/pom.xml
#	dubbo-simple/pom.xml
#	dubbo-test/dubbo-test-benchmark/pom.xml
#	dubbo-test/dubbo-test-compatibility/dubbo-test-spring3/pom.xml
#	dubbo-test/dubbo-test-compatibility/pom.xml
#	dubbo-test/dubbo-test-examples/pom.xml
#	dubbo-test/dubbo-test-integration/pom.xml
#	dubbo-test/pom.xml
#	hessian-lite/pom.xml
#	pom.xml
  • Loading branch information
chickenlj committed Jan 25, 2018
2 parents 5b0ab11 + 4f3017c commit a4632da
Show file tree
Hide file tree
Showing 71 changed files with 995 additions and 332 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ private boolean matchCondition(Map<String, MatchPair> condition, URL url, URL pa
sampleValue = invocation.getMethodName();
} else {
sampleValue = sample.get(key);
if (sampleValue == null) {
sampleValue = sample.get(Constants.DEFAULT_KEY_PREFIX + key);
}
}
if (sampleValue != null) {
if (!matchPair.getValue().isMatch(sampleValue, param)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public void testRoute_matchWhen() {
@Test
public void testRoute_matchFilter() {
List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService"));
Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf(
"dubbo://10.20.3.3:20880/com.foo.BarService?default.serialization=fastjson"));
Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost()
+ ":20880/com.foo.BarService"));
Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost()
Expand All @@ -122,6 +123,9 @@ public void testRoute_matchFilter() {
Router router5 = new ConditionRouterFactory().getRouter(getRouteUrl(
"host = " + NetUtils.getLocalHost() + " => " + " host != 10.20.3.3").addParameter(Constants.FORCE_KEY,
String.valueOf(true)));
Router router6 = new ConditionRouterFactory().getRouter(getRouteUrl(
"host = " + NetUtils.getLocalHost() + " => " + " serialization = fastjson").addParameter(
Constants.FORCE_KEY, String.valueOf(true)));

List<Invoker<String>> fileredInvokers1 = router1.route(invokers,
URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
Expand All @@ -133,11 +137,14 @@ public void testRoute_matchFilter() {
URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
List<Invoker<String>> fileredInvokers5 = router5.route(invokers,
URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
List<Invoker<String>> fileredInvokers6 = router6.route(invokers,
URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
Assert.assertEquals(1, fileredInvokers1.size());
Assert.assertEquals(0, fileredInvokers2.size());
Assert.assertEquals(0, fileredInvokers3.size());
Assert.assertEquals(1, fileredInvokers4.size());
Assert.assertEquals(2, fileredInvokers5.size());
Assert.assertEquals(1, fileredInvokers6.size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,12 @@ public class Constants {

public static final String REGISTER_IP_KEY = "register.ip";

public static final String QOS_ENABLE = "qos.enable";

public static final String QOS_PORT = "qos.port";

public static final String ACCEPT_FOREIGN_IP = "qos.accept.foreign.ip";

/*
* private Constants(){ }
*/
Expand Down
12 changes: 2 additions & 10 deletions dubbo-common/src/main/java/com/alibaba/dubbo/common/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
*/
public final class Version {

private static final String DEFAULT_DUBBO_VERSION = "2.0.0";
private static final Logger logger = LoggerFactory.getLogger(Version.class);
private static final String VERSION = getVersion(Version.class, "2.0.0");
private static final boolean INTERNAL = hasResource("com/alibaba/dubbo/registry/internal/RemoteRegistry.class");
private static final boolean COMPATIBLE = hasResource("com/taobao/remoting/impl/ConnectionRequest.class");
private static final String VERSION = getVersion(Version.class, DEFAULT_DUBBO_VERSION);

static {
// check if there's duplicated jar
Expand All @@ -48,13 +47,6 @@ public static String getVersion() {
return VERSION;
}

public static boolean isInternalVersion() {
return INTERNAL;
}

public static boolean isCompatibleVersion() {
return COMPATIBLE;
}

private static boolean hasResource(String path) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class ConcurrentHashSet<E> extends AbstractSet<E> implements Set<E>, java.io.Serializable {

private static final long serialVersionUID = -8672117787651310382L;

private static final Object PRESENT = new Object();

private final ConcurrentHashMap<E, Object> map;
private final ConcurrentMap<E, Object> map;

public ConcurrentHashSet() {
map = new ConcurrentHashMap<E, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,26 @@ public static int getPid() {
return PID;
}

@SuppressWarnings("deprecation")
public static int getServerShutdownTimeout() {
int timeout = Constants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT;
String value = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_KEY);
if (value != null && value.length() > 0) {
try {
timeout = Integer.parseInt(value);
} catch (Exception e) {
}
} else {
value = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY);
if (value != null && value.length() > 0) {
try {
timeout = Integer.parseInt(value) * 1000;
} catch (Exception e) {
}
}
}

return timeout;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static InetAddress getLocalAddress() {
}

public static String getLogHost() {
InetAddress address = LOCAL_ADDRESS;
InetAddress address = getLocalAddress();
return address == null ? LOCALHOST : address.getHostAddress();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public class ApplicationConfig extends AbstractConfig {
// directory for saving thread dump
private String dumpDirectory;

private Boolean qosEnable;

private Integer qosPort;

private Boolean qosAcceptForeignIp;

// customized parameters
private Map<String, String> parameters;

Expand Down Expand Up @@ -201,7 +207,7 @@ public void setDefault(Boolean isDefault) {
this.isDefault = isDefault;
}

@Parameter(key = "dump.directory")
@Parameter(key = Constants.DUMP_DIRECTORY)
public String getDumpDirectory() {
return dumpDirectory;
}
Expand All @@ -210,6 +216,33 @@ public void setDumpDirectory(String dumpDirectory) {
this.dumpDirectory = dumpDirectory;
}

@Parameter(key = Constants.QOS_ENABLE)
public Boolean getQosEnable() {
return qosEnable;
}

public void setQosEnable(Boolean qosEnable) {
this.qosEnable = qosEnable;
}

@Parameter(key = Constants.QOS_PORT)
public Integer getQosPort() {
return qosPort;
}

public void setQosPort(Integer qosPort) {
this.qosPort = qosPort;
}

@Parameter(key = Constants.ACCEPT_FOREIGN_IP)
public Boolean getQosAcceptForeignIp() {
return qosAcceptForeignIp;
}

public void setQosAcceptForeignIp(Boolean qosAcceptForeignIp) {
this.qosAcceptForeignIp = qosAcceptForeignIp;
}

public Map<String, String> getParameters() {
return parameters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.alibaba.dubbo.common.serialize.Serialization;
import com.alibaba.dubbo.common.status.StatusChecker;
import com.alibaba.dubbo.common.threadpool.ThreadPool;
import com.alibaba.dubbo.common.utils.ConfigUtils;
import com.alibaba.dubbo.config.support.Parameter;
import com.alibaba.dubbo.registry.support.AbstractRegistryFactory;
import com.alibaba.dubbo.remoting.Codec;
Expand Down Expand Up @@ -155,6 +156,14 @@ public static void destroyAll() {
return;
}
AbstractRegistryFactory.destroyAll();

// Wait for registry notification
try {
Thread.sleep(ConfigUtils.getServerShutdownTimeout());
} catch (InterruptedException e) {
logger.warn("Interrupted unexpectedly when waiting for registry notification during shutdown process!");
}

ExtensionLoader<Protocol> loader = ExtensionLoader.getExtensionLoader(Protocol.class);
for (String protocolName : loader.getLoadedExtensions()) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.service.GenericException;
import com.alibaba.dubbo.rpc.service.GenericService;

import org.junit.Assert;
Expand Down Expand Up @@ -74,8 +75,7 @@ public void testValidation() {
parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000));
validationService.save(parameter);
Assert.fail();
} catch (RpcException e) {
ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
} catch (ConstraintViolationException ve) {
Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
Assert.assertNotNull(violations);
}
Expand All @@ -89,8 +89,7 @@ public void testValidation() {
parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000));
validationService.save(parameter);
Assert.fail();
} catch (RpcException e) {
ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
} catch (ConstraintViolationException ve) {
Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
Assert.assertNotNull(violations);
}
Expand All @@ -105,8 +104,7 @@ public void testValidation() {
parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000));
validationService.relatedQuery(parameter);
Assert.fail();
} catch (RpcException e) {
ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
} catch (ConstraintViolationException ve) {
Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
Assert.assertEquals(violations.size(),2);
}
Expand All @@ -116,8 +114,7 @@ public void testValidation() {
parameter = new ValidationParameter();
validationService.save(parameter);
Assert.fail();
} catch (RpcException e) {
ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
} catch (ConstraintViolationException ve) {
Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
Assert.assertTrue(violations.size() == 3);
Assert.assertNotNull(violations);
Expand All @@ -130,8 +127,7 @@ public void testValidation() {
try {
validationService.delete(2, "a");
Assert.fail();
} catch (RpcException e) {
ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
} catch (ConstraintViolationException ve) {
Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
Assert.assertNotNull(violations);
Assert.assertEquals(1, violations.size());
Expand All @@ -141,26 +137,23 @@ public void testValidation() {
try {
validationService.delete(0, "abc");
Assert.fail();
} catch (RpcException e) {
ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
} catch (ConstraintViolationException ve) {
Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
Assert.assertNotNull(violations);
Assert.assertEquals(1, violations.size());
}
try {
validationService.delete(2, null);
Assert.fail();
} catch (RpcException e) {
ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
} catch (ConstraintViolationException ve) {
Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
Assert.assertNotNull(violations);
Assert.assertEquals(1, violations.size());
}
try {
validationService.delete(0, null);
Assert.fail();
} catch (RpcException e) {
ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
} catch (ConstraintViolationException ve) {
Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
Assert.assertNotNull(violations);
Assert.assertEquals(2, violations.size());
Expand Down Expand Up @@ -252,7 +245,7 @@ public void testGenericValidation() {
ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
reference.setApplication(new ApplicationConfig("validation-consumer"));
reference.setInterface(ValidationService.class.getName());
reference.setUrl("dubbo://127.0.0.1:29582?scope=remote&validation=true");
reference.setUrl("dubbo://127.0.0.1:29582?scope=remote&validation=true&timeout=9000000");
reference.setGeneric(true);
GenericService validationService = reference.get();
try {
Expand All @@ -270,8 +263,8 @@ public void testGenericValidation() {
parameter = new HashMap<String, Object>();
validationService.$invoke("save", new String[]{ValidationParameter.class.getName()}, new Object[]{parameter});
Assert.fail();
} catch (RpcException e) {
Assert.assertTrue(e.getMessage().contains("ConstraintViolation"));
} catch (GenericException e) {
Assert.assertTrue(e.getMessage().contains("Failed to validate service"));
}

// Delete OK
Expand All @@ -281,21 +274,23 @@ public void testGenericValidation() {
try {
validationService.$invoke("delete", new String[]{long.class.getName(), String.class.getName()}, new Object[]{0, "abc"});
Assert.fail();
} catch (RpcException e) {
Assert.assertTrue(e.getMessage().contains("ConstraintViolation"));
} catch (GenericException e) {
Assert.assertTrue(e.getMessage().contains("Failed to validate service"));
}
try {
validationService.$invoke("delete", new String[]{long.class.getName(), String.class.getName()}, new Object[]{2, null});
Assert.fail();
} catch (RpcException e) {
Assert.assertTrue(e.getMessage().contains("ConstraintViolation"));
} catch (GenericException e) {
Assert.assertTrue(e.getMessage().contains("Failed to validate service"));
}
try {
validationService.$invoke("delete", new String[]{long.class.getName(), String.class.getName()}, new Object[]{0, null});
Assert.fail();
} catch (RpcException e) {
Assert.assertTrue(e.getMessage().contains("ConstraintViolation"));
} catch (GenericException e) {
Assert.assertTrue(e.getMessage().contains("Failed to validate service"));
}
} catch (GenericException e) {
Assert.assertTrue(e.getMessage().contains("Failed to validate service"));
} finally {
reference.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@
*/
package com.alibaba.dubbo.config.spring;

import com.alibaba.dubbo.config.*;
import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ConsumerConfig;
import com.alibaba.dubbo.config.ModuleConfig;
import com.alibaba.dubbo.config.MonitorConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.spring.extension.SpringExtensionFactory;
import com.alibaba.dubbo.config.support.Parameter;

import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
Expand Down Expand Up @@ -167,4 +173,8 @@ public void afterPropertiesSet() throws Exception {
}
}

@Override
public void destroy() {
// do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ && getInterface() != null && getInterface().length() > 0
}

public void destroy() throws Exception {
unexport();
// This will only be called for singleton scope bean, and expected to be called by spring shutdown hook when BeanFactory/ApplicationContext destroys.
// We will guarantee dubbo related resources being released with dubbo shutdown hook.
//unexport();
}

// merged from dubbox
Expand Down
Loading

0 comments on commit a4632da

Please sign in to comment.