Merge branch 'apache-3.0' into apache-3.1

This commit is contained in:
Albumen Kevin 2022-09-02 11:07:47 +08:00
commit 12f67868a9
37 changed files with 404 additions and 259 deletions

View File

@ -43,7 +43,7 @@ import static org.apache.dubbo.rpc.cluster.Constants.CONFIG_VERSION_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.OVERRIDE_PROVIDERS_KEY;
/**
* AbstractOverrideConfigurator
* AbstractConfigurator
*/
public abstract class AbstractConfigurator implements Configurator {

View File

@ -21,7 +21,6 @@ import org.apache.dubbo.rpc.cluster.configurator.AbstractConfigurator;
/**
* AbsentConfigurator
*
*/
public class AbsentConfigurator extends AbstractConfigurator {

View File

@ -21,7 +21,6 @@ import org.apache.dubbo.rpc.cluster.configurator.AbstractConfigurator;
/**
* OverrideConfigurator
*
*/
public class OverrideConfigurator extends AbstractConfigurator {

View File

@ -19,9 +19,8 @@ package org.apache.dubbo.rpc.cluster.governance;
import org.apache.dubbo.common.config.configcenter.ConfigurationListener;
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.apache.dubbo.rpc.model.ScopeModelAware;
public class DefaultGovernanceRuleRepositoryImpl implements GovernanceRuleRepository, ScopeModelAware {
public class DefaultGovernanceRuleRepositoryImpl implements GovernanceRuleRepository {
private ModuleModel moduleModel;

View File

@ -0,0 +1,53 @@
/*
* 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.dubbo.rpc.cluster;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.cluster.configurator.absent.AbsentConfigurator;
import org.apache.dubbo.rpc.cluster.configurator.override.OverrideConfigurator;
import org.apache.dubbo.rpc.cluster.configurator.parser.ConfigParser;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
/**
* {@link Configurator}
*/
public class ConfiguratorTest {
@Test
public void test() throws Exception {
Optional<List<Configurator>> emptyOptional = Configurator.toConfigurators(Collections.emptyList());
Assertions.assertEquals(Optional.empty(), emptyOptional);
String configData = "[\"override://0.0.0.0/com.xx.Service?category=configurators&timeout=6666&disabled=true&dynamic=false&enabled=true&group=dubbo&priority=2&version=1.0\"" +
", \"absent://0.0.0.0/com.xx.Service?category=configurators&timeout=6666&disabled=true&dynamic=false&enabled=true&group=dubbo&priority=1&version=1.0\" ]";
List<URL> urls = ConfigParser.parseConfigurators(configData);
Optional<List<Configurator>> optionalList = Configurator.toConfigurators(urls);
Assertions.assertTrue(optionalList.isPresent());
List<Configurator> configurators = optionalList.get();
Assertions.assertEquals(configurators.size(), 2);
// The hosts of AbsentConfigurator and OverrideConfigurator are equal, but the priority of OverrideConfigurator is higher
Assertions.assertTrue(configurators.get(0) instanceof AbsentConfigurator);
Assertions.assertTrue(configurators.get(1) instanceof OverrideConfigurator);
}
}

View File

@ -51,7 +51,7 @@ public final class ClassGenerator {
private static final AtomicLong CLASS_NAME_COUNTER = new AtomicLong(0);
private static final String SIMPLE_NAME_TAG = "<init>";
private static final Map<ClassLoader, ClassPool> POOL_MAP = new ConcurrentHashMap<ClassLoader, ClassPool>(); //ClassLoader - ClassPool
private static final Map<ClassLoader, ClassPool> POOL_MAP = new ConcurrentHashMap<>(); //ClassLoader - ClassPool
private ClassPool mPool;
private CtClass mCtc;
private String mClassName;
@ -131,7 +131,7 @@ public final class ClassGenerator {
public ClassGenerator addInterface(String cn) {
if (mInterfaces == null) {
mInterfaces = new HashSet<String>();
mInterfaces = new HashSet<>();
}
mInterfaces.add(cn);
return this;
@ -153,7 +153,7 @@ public final class ClassGenerator {
public ClassGenerator addField(String code) {
if (mFields == null) {
mFields = new ArrayList<String>();
mFields = new ArrayList<>();
}
mFields.add(code);
return this;
@ -177,7 +177,7 @@ public final class ClassGenerator {
public ClassGenerator addMethod(String code) {
if (mMethods == null) {
mMethods = new ArrayList<String>();
mMethods = new ArrayList<>();
}
mMethods.add(code);
return this;
@ -192,12 +192,14 @@ public final class ClassGenerator {
StringBuilder sb = new StringBuilder();
sb.append(modifier(mod)).append(' ').append(ReflectUtils.getName(rt)).append(' ').append(name);
sb.append('(');
for (int i = 0; i < pts.length; i++) {
if (i > 0) {
sb.append(',');
if (ArrayUtils.isNotEmpty(pts)) {
for (int i = 0; i < pts.length; i++) {
if (i > 0) {
sb.append(',');
}
sb.append(ReflectUtils.getName(pts[i]));
sb.append(" arg").append(i);
}
sb.append(ReflectUtils.getName(pts[i]));
sb.append(" arg").append(i);
}
sb.append(')');
if (ArrayUtils.isNotEmpty(ets)) {
@ -222,7 +224,7 @@ public final class ClassGenerator {
String desc = name + ReflectUtils.getDescWithoutMethodName(m);
addMethod(':' + desc);
if (mCopyMethods == null) {
mCopyMethods = new ConcurrentHashMap<String, Method>(8);
mCopyMethods = new ConcurrentHashMap<>(8);
}
mCopyMethods.put(desc, m);
return this;
@ -230,7 +232,7 @@ public final class ClassGenerator {
public ClassGenerator addConstructor(String code) {
if (mConstructors == null) {
mConstructors = new LinkedList<String>();
mConstructors = new LinkedList<>();
}
mConstructors.add(code);
return this;
@ -269,7 +271,7 @@ public final class ClassGenerator {
String desc = ReflectUtils.getDesc(c);
addConstructor(":" + desc);
if (mCopyConstructors == null) {
mCopyConstructors = new ConcurrentHashMap<String, Constructor<?>>(4);
mCopyConstructors = new ConcurrentHashMap<>(4);
}
mCopyConstructors.put(desc, c);
return this;

View File

@ -37,7 +37,6 @@ import static org.apache.dubbo.common.constants.CommonConstants.MAX_PROXY_COUNT;
/**
* Proxy.
*/
public class Proxy {
public static final InvocationHandler THROW_UNSUPPORTED_INVOKER = new InvocationHandler() {
@Override

View File

@ -293,6 +293,7 @@ public abstract class Wrapper {
throw new RuntimeException(e.getMessage(), e);
} finally {
cc.release();
pts.clear();
ms.clear();
mns.clear();
dmns.clear();

View File

@ -88,10 +88,11 @@ public class CallableSafeInitializer<T> {
public T remove(Consumer<? super T> action) {
// release
T value = reference.getAndSet(null);
if (value != null && action != null) {
if (value != null) {
if (action != null) {
action.accept(value);
} else if (value instanceof Disposable) {
}
if (value instanceof Disposable) {
((Disposable) value).destroy();
}
}

View File

@ -55,7 +55,7 @@ public interface Configuration {
}
default int getInt(String key) {
Integer i = this.getInteger(key, (Integer) null);
Integer i = this.getInteger(key, null);
if (i != null) {
return i;
} else {
@ -64,7 +64,7 @@ public interface Configuration {
}
default int getInt(String key, int defaultValue) {
Integer i = this.getInteger(key, (Integer) null);
Integer i = this.getInteger(key, null);
return i == null ? defaultValue : i;
}

View File

@ -171,7 +171,7 @@ public class Environment extends LifecycleAdapter implements ApplicationExt {
* All configurations will be converged into a data bus - URL, and then drive the subsequent process.
* <p>
* At present, there are many configuration sources, including AbstractConfig (API, XML, annotation), - D, config center, etc.
* This methood helps us t filter out the most priority values from various configuration sources.
* This method helps us t filter out the most priority values from various configuration sources.
*
* @param config
* @param prefix

View File

@ -126,9 +126,6 @@ public class ModuleEnvironment extends Environment implements ModuleExt {
public void destroy() throws IllegalStateException {
super.destroy();
this.orderedPropertiesConfiguration = null;
this.globalConfiguration = null;
this.dynamicGlobalConfiguration = null;
this.dynamicConfiguration = null;
}
@Override
@ -224,8 +221,5 @@ public class ModuleEnvironment extends Environment implements ModuleExt {
public void refreshClassLoaders() {
orderedPropertiesConfiguration.refresh();
applicationDelegate.refreshClassLoaders();
this.globalConfiguration = null;
this.globalConfigurationMaps = null;
this.dynamicGlobalConfiguration = null;
}
}

View File

@ -26,7 +26,7 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
public class OrderedPropertiesConfiguration implements Configuration{
public class OrderedPropertiesConfiguration implements Configuration {
private Properties properties;
private ModuleModel moduleModel;

View File

@ -20,10 +20,7 @@ package org.apache.dubbo.common.config;
import java.util.Map;
/**
* FIXME: is this really necessary? PropertiesConfiguration should have already covered this:
*
* @See ConfigUtils#getProperty(String)
* @see PropertiesConfiguration
* Configuration from system properties
*/
public class SystemConfiguration implements Configuration {

View File

@ -17,6 +17,7 @@
package org.apache.dubbo.common.lang;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.resource.Disposable;
import org.apache.dubbo.rpc.model.ApplicationModel;
import java.util.Collection;
@ -31,7 +32,7 @@ import static org.apache.dubbo.common.function.ThrowableAction.execute;
*
* @since 2.7.5
*/
public class ShutdownHookCallbacks {
public class ShutdownHookCallbacks implements Disposable {
private final List<ShutdownHookCallback> callbacks = new LinkedList<>();
@ -56,7 +57,7 @@ public class ShutdownHookCallbacks {
}
}
public void clear() {
public void destroy() {
synchronized (this) {
callbacks.clear();
}

View File

@ -37,7 +37,7 @@ public class GlobalResourceInitializer<T> extends CallableSafeInitializer<T> {
super(initializer);
}
public GlobalResourceInitializer(Callable initializer, Consumer<T> disposeAction) {
public GlobalResourceInitializer(Callable<T> initializer, Consumer<T> disposeAction) {
super(initializer);
this.disposeAction = disposeAction;
}
@ -59,7 +59,4 @@ public class GlobalResourceInitializer<T> extends CallableSafeInitializer<T> {
return value;
}
public interface DestroyHandler<T> {
void dispose(GlobalResourceInitializer<T> initializer);
}
}

View File

@ -27,7 +27,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Global resources repository between all framework models.
* Global resource repository between all framework models.
* It will be destroyed only after all framework model is destroyed.
*/
public class GlobalResourcesRepository {
@ -59,16 +59,22 @@ public class GlobalResourcesRepository {
* @param disposable
*/
public static void registerGlobalDisposable(Disposable disposable) {
synchronized (GlobalResourcesRepository.class) {
if (!globalReusedDisposables.contains(disposable)) {
globalReusedDisposables.add(disposable);
if (!globalReusedDisposables.contains(disposable)) {
synchronized (GlobalResourcesRepository.class) {
if (!globalReusedDisposables.contains(disposable)) {
globalReusedDisposables.add(disposable);
}
}
}
}
public void removeGlobalDisposable(Disposable disposable) {
synchronized (GlobalResourcesRepository.class) {
this.globalReusedDisposables.remove(disposable);
if (globalReusedDisposables.contains(disposable)) {
synchronized (GlobalResourcesRepository.class) {
if (globalReusedDisposables.contains(disposable)) {
this.globalReusedDisposables.remove(disposable);
}
}
}
}
@ -125,14 +131,24 @@ public class GlobalResourcesRepository {
* Register a one-off disposable, the disposable is removed automatically on first shutdown.
* @param disposable
*/
public synchronized void registerDisposable(Disposable disposable) {
public void registerDisposable(Disposable disposable) {
if (!oneoffDisposables.contains(disposable)) {
oneoffDisposables.add(disposable);
synchronized (this) {
if (!oneoffDisposables.contains(disposable)) {
oneoffDisposables.add(disposable);
}
}
}
}
public synchronized void removeDisposable(Disposable disposable) {
this.oneoffDisposables.remove(disposable);
public void removeDisposable(Disposable disposable) {
if (oneoffDisposables.contains(disposable)) {
synchronized (this) {
if (oneoffDisposables.contains(disposable)) {
oneoffDisposables.remove(disposable);
}
}
}
}

View File

@ -174,7 +174,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
protected String ondisconnect;
/**
* The metrics configuration
* The metadata report configuration
*/
protected MetadataReportConfig metadataReportConfig;
@ -224,11 +224,6 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
@Override
protected void postProcessAfterScopeModelChanged(ScopeModel oldScopeModel, ScopeModel newScopeModel) {
super.postProcessAfterScopeModelChanged(oldScopeModel, newScopeModel);
// remove this config from old ConfigManager
// if (oldScopeModel != null && oldScopeModel instanceof ModuleModel) {
// ((ModuleModel)oldScopeModel).getConfigManager().removeConfig(this);
// }
// change referenced config's scope model
ApplicationModel applicationModel = ScopeModelUtil.getApplicationModel(scopeModel);
if (this.configCenter != null && this.configCenter.getScopeModel() != applicationModel) {
@ -289,7 +284,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
}
/**
* To obtain the method list in the port, use reflection when in native mode and javaassist otherwise.
* To obtain the method list in the port, use reflection when in native mode and javassist otherwise.
* @param interfaceClass
* @return
*/
@ -457,7 +452,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
}
try {
//Check if the localClass a constructor with parameter who's type is interfaceClass
//Check if the localClass a constructor with parameter whose type is interfaceClass
ReflectUtils.findConstructor(localClass, interfaceClass);
} catch (NoSuchMethodException e) {
throw new IllegalStateException("No such constructor \"public " + localClass.getSimpleName() +
@ -597,7 +592,6 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
}
public void setProxy(String proxy) {
this.proxy = proxy;
}

View File

@ -235,21 +235,6 @@ public class ProtocolConfig extends AbstractConfig {
}
}
// @Override
// public List<String> getPrefixes() {
// List<String> prefixes = new ArrayList<>();
// if (StringUtils.hasText(this.getId())) {
// // dubbo.protocols.{protocol-id}
// prefixes.add(CommonConstants.DUBBO + "." + getPluralTagName(this.getClass()) + "." + this.getId());
// } else if (StringUtils.hasText(this.getName()) && !StringUtils.isEquals(this.getId(), this.getName())) {
// // dubbo.protocols.{protocol-name}
// prefixes.add(CommonConstants.DUBBO + "." + getPluralTagName(this.getClass()) + "." + this.getName());
// }
// // dubbo.protocol
// prefixes.add(getTypePrefix());
// return prefixes;
// }
@Parameter(excluded = true)
public String getName() {
return name;

View File

@ -172,7 +172,7 @@ public abstract class ReferenceConfigBase<T> extends AbstractReferenceConfig {
Class<?> actualInterface = interfaceClass;
if (interfaceClass == GenericService.class) {
try {
if(getInterfaceClassLoader() != null) {
if (getInterfaceClassLoader() != null) {
actualInterface = Class.forName(interfaceName, false, getInterfaceClassLoader());
} else {
actualInterface = Class.forName(interfaceName);
@ -198,7 +198,7 @@ public abstract class ReferenceConfigBase<T> extends AbstractReferenceConfig {
if (StringUtils.isBlank(generic) && getConsumer() != null) {
generic = getConsumer().getGeneric();
}
if(getInterfaceClassLoader() != null) {
if (getInterfaceClassLoader() != null) {
interfaceClass = determineInterfaceClass(generic, interfaceName, getInterfaceClassLoader());
} else {
interfaceClass = determineInterfaceClass(generic, interfaceName);
@ -290,7 +290,7 @@ public abstract class ReferenceConfigBase<T> extends AbstractReferenceConfig {
}
if (resolveFile != null && resolveFile.length() > 0) {
Properties properties = new RegexProperties();
try (FileInputStream fis = new FileInputStream(new File(resolveFile))) {
try (FileInputStream fis = new FileInputStream(resolveFile)) {
properties.load(fis);
} catch (IOException e) {
throw new IllegalStateException("Failed to load " + resolveFile + ", cause: " + e.getMessage(), e);
@ -299,7 +299,7 @@ public abstract class ReferenceConfigBase<T> extends AbstractReferenceConfig {
resolve = properties.getProperty(interfaceName);
}
}
if (resolve != null && resolve.length() > 0) {
if (StringUtils.isNotEmpty(resolve)) {
url = resolve;
if (logger.isWarnEnabled()) {
if (resolveFile != null) {

View File

@ -107,18 +107,6 @@ public abstract class ServiceConfigBase<T> extends AbstractServiceConfig {
setMethods(MethodConfig.constructMethodConfig(service.methods()));
}
@Deprecated
private static List<ProtocolConfig> convertProviderToProtocol(List<ProviderConfig> providers) {
if (CollectionUtils.isEmpty(providers)) {
return null;
}
List<ProtocolConfig> protocols = new ArrayList<ProtocolConfig>(providers.size());
for (ProviderConfig provider : providers) {
protocols.add(convertProviderToProtocol(provider));
}
return protocols;
}
@Override
protected void postProcessAfterScopeModelChanged(ScopeModel oldScopeModel, ScopeModel newScopeModel) {
super.postProcessAfterScopeModelChanged(oldScopeModel, newScopeModel);
@ -127,50 +115,6 @@ public abstract class ServiceConfigBase<T> extends AbstractServiceConfig {
}
}
@Deprecated
private static List<ProviderConfig> convertProtocolToProvider(List<ProtocolConfig> protocols) {
if (CollectionUtils.isEmpty(protocols)) {
return null;
}
List<ProviderConfig> providers = new ArrayList<ProviderConfig>(protocols.size());
for (ProtocolConfig provider : protocols) {
providers.add(convertProtocolToProvider(provider));
}
return providers;
}
@Deprecated
private static ProtocolConfig convertProviderToProtocol(ProviderConfig provider) {
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName(provider.getProtocol().getName());
protocol.setServer(provider.getServer());
protocol.setClient(provider.getClient());
protocol.setCodec(provider.getCodec());
protocol.setHost(provider.getHost());
protocol.setPort(provider.getPort());
protocol.setPath(provider.getPath());
protocol.setPayload(provider.getPayload());
protocol.setThreads(provider.getThreads());
protocol.setParameters(provider.getParameters());
return protocol;
}
@Deprecated
private static ProviderConfig convertProtocolToProvider(ProtocolConfig protocol) {
ProviderConfig provider = new ProviderConfig();
provider.setProtocol(protocol);
provider.setServer(protocol.getServer());
provider.setClient(protocol.getClient());
provider.setCodec(protocol.getCodec());
provider.setHost(protocol.getHost());
provider.setPort(protocol.getPort());
provider.setPath(protocol.getPath());
provider.setPayload(protocol.getPayload());
provider.setThreads(protocol.getThreads());
provider.setParameters(protocol.getParameters());
return provider;
}
public boolean shouldExport() {
Boolean export = getExport();
// default value is true
@ -399,36 +343,10 @@ public abstract class ServiceConfigBase<T> extends AbstractServiceConfig {
}
}
// @Override
// public void setMock(String mock) {
// throw new IllegalArgumentException("mock doesn't support on provider side");
// }
//
// @Override
// public void setMock(Object mock) {
// throw new IllegalArgumentException("mock doesn't support on provider side");
// }
public ServiceMetadata getServiceMetadata() {
return serviceMetadata;
}
// /**
// * @deprecated Replace to getProtocols()
// */
// @Deprecated
// public List<ProviderConfig> getProviders() {
// return convertProtocolToProvider(protocols);
// }
//
// /**
// * @deprecated Replace to setProtocols()
// */
// @Deprecated
// public void setProviders(List<ProviderConfig> providers) {
// this.protocols = convertProviderToProtocol(providers);
// }
@Override
@Parameter(excluded = true, attribute = false)
public List<String> getPrefixes() {

View File

@ -38,7 +38,7 @@ public class ProviderModel extends ServiceModel {
/**
* The url of the reference service
*/
private List<URL> serviceUrls = new ArrayList<URL>();
private List<URL> serviceUrls = new ArrayList<>();
public ProviderModel(String serviceKey,
Object serviceInstance,

View File

@ -76,9 +76,6 @@ public class ReflectionServiceDescriptor implements ServiceDescriptor {
methods.forEach((methodName, methodList) -> {
Map<String, MethodDescriptor> descMap = descToMethods.computeIfAbsent(methodName, k -> new HashMap<>());
methodList.forEach(methodModel -> descMap.put(methodModel.getParamDesc(), methodModel));
// Map<Class<?>[], MethodModel> typesMap = typeToMethods.computeIfAbsent(methodName, k -> new HashMap<>());
// methodList.forEach(methodModel -> typesMap.put(methodModel.getParameterClasses(), methodModel));
});
}

View File

@ -22,7 +22,7 @@ import java.util.List;
import java.util.Set;
/**
* ServiceModel and ServiceMetadata are to some extend duplicated with each other. We should merge them in the future.
* ServiceModel and ServiceMetadata are to some extent duplicated with each other. We should merge them in the future.
*/
public interface ServiceDescriptor {

View File

@ -23,12 +23,11 @@ import org.apache.dubbo.config.ServiceConfigBase;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Callable;
public class ServiceModel {
private String serviceKey;
private Object proxyObject;
private Callable<Void> destroyCaller;
private Runnable destroyRunner;
private ClassLoader classLoader;
private final ClassLoader interfaceClassLoader;
@ -165,12 +164,12 @@ public class ServiceModel {
return moduleModel;
}
public Callable<Void> getDestroyCaller() {
return destroyCaller;
public Runnable getDestroyRunner() {
return destroyRunner;
}
public void setDestroyCaller(Callable<Void> destroyCaller) {
this.destroyCaller = destroyCaller;
public void setDestroyRunner(Runnable destroyRunner) {
this.destroyRunner = destroyRunner;
}
public ClassLoader getInterfaceClassLoader() {
@ -186,11 +185,11 @@ public class ServiceModel {
return false;
}
ServiceModel that = (ServiceModel) o;
return Objects.equals(serviceKey, that.serviceKey) && Objects.equals(proxyObject, that.proxyObject) && Objects.equals(destroyCaller, that.destroyCaller) && Objects.equals(classLoader, that.classLoader) && Objects.equals(interfaceClassLoader, that.interfaceClassLoader) && Objects.equals(moduleModel, that.moduleModel) && Objects.equals(serviceModel, that.serviceModel) && Objects.equals(serviceMetadata, that.serviceMetadata);
return Objects.equals(serviceKey, that.serviceKey) && Objects.equals(proxyObject, that.proxyObject) && Objects.equals(destroyRunner, that.destroyRunner) && Objects.equals(classLoader, that.classLoader) && Objects.equals(interfaceClassLoader, that.interfaceClassLoader) && Objects.equals(moduleModel, that.moduleModel) && Objects.equals(serviceModel, that.serviceModel) && Objects.equals(serviceMetadata, that.serviceMetadata);
}
@Override
public int hashCode() {
return Objects.hash(serviceKey, proxyObject, destroyCaller, classLoader, interfaceClassLoader, moduleModel, serviceModel, serviceMetadata);
return Objects.hash(serviceKey, proxyObject, destroyRunner, classLoader, interfaceClassLoader, moduleModel, serviceModel, serviceMetadata);
}
}

View File

@ -16,9 +16,12 @@
*/
package org.apache.dubbo.common.bytecode;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
interface Builder<T> {
@ -27,18 +30,127 @@ interface Builder<T> {
void setName(Bean bean, T name);
}
class BaseClass {
public BaseClass() {
}
public BaseClass(StringBuilder sb) {
sb.append("constructor comes from BaseClass");
}
public String baseClassMethod() {
return "method comes from BaseClass";
}
}
interface BaseInterface {
}
public class ClassGeneratorTest {
@Test
public void test() throws Exception {
ClassGenerator cg = ClassGenerator.newInstance();
// add className, interface, superClass
String className = BaseClass.class.getPackage().getName() + ".TestClass";
cg.setClassName(className);
cg.addInterface(BaseInterface.class);
cg.setSuperClass(BaseClass.class);
// add constructor
cg.addDefaultConstructor();
cg.addConstructor(Modifier.PUBLIC, new Class[]{String.class, int.class}, new Class[]{Throwable.class, RuntimeException.class}, "this.strAttr = arg0;this.intAttr = arg1;");
cg.addConstructor(BaseClass.class.getConstructor(StringBuilder.class));
// add field
cg.addField("staticAttr", Modifier.PUBLIC | Modifier.STATIC | Modifier.VOLATILE, String.class, "\"defaultVal\"");
cg.addField("strAttr", Modifier.PROTECTED | Modifier.VOLATILE, String.class);
cg.addField("intAttr", Modifier.PRIVATE | Modifier.VOLATILE, int.class);
// add method
cg.addMethod("setStrAttr", Modifier.PUBLIC, void.class, new Class[]{String.class, int.class}, new Class[]{Throwable.class, RuntimeException.class}, "this.strAttr = arg0;");
cg.addMethod("setIntAttr", Modifier.PUBLIC, void.class, new Class[]{String.class, int.class}, new Class[]{Throwable.class, RuntimeException.class}, "this.intAttr = arg1;");
cg.addMethod("getStrAttr", Modifier.PUBLIC, String.class, new Class[]{}, new Class[]{Throwable.class, RuntimeException.class}, "return this.strAttr;");
cg.addMethod("getIntAttr", Modifier.PUBLIC, int.class, new Class[]{}, new Class[]{Throwable.class, RuntimeException.class}, "return this.intAttr;");
cg.addMethod(BaseClass.class.getMethod("baseClassMethod"));
// cg.toClass
Class<?> clz = cg.toClass(Bean.class);
// after cg.toClass, the TestClass.class generated by javassist is like the following file content
getClass().getResource("/org/apache/dubbo/common/bytecode/TestClass");
// verify class, superClass, interfaces
Assertions.assertTrue(ClassGenerator.isDynamicClass(clz));
Assertions.assertEquals(clz.getName(), className);
Assertions.assertEquals(clz.getSuperclass(), BaseClass.class);
Assertions.assertArrayEquals(clz.getInterfaces(), new Class[]{ClassGenerator.DC.class, BaseInterface.class});
// get constructors
Constructor<?>[] constructors = clz.getConstructors();
Assertions.assertEquals(constructors.length, 3);
Constructor<?> constructor0 = clz.getConstructor();
Constructor<?> constructor1 = clz.getConstructor(new Class[]{String.class, int.class});
Constructor<?> constructor2 = clz.getConstructor(new Class[]{StringBuilder.class});
Assertions.assertEquals(constructor1.getModifiers(), Modifier.PUBLIC);
Assertions.assertArrayEquals(constructor1.getExceptionTypes(), new Class[]{Throwable.class, RuntimeException.class});
// get fields
Field staticAttrField = clz.getDeclaredField("staticAttr");
Field strAttrField = clz.getDeclaredField("strAttr");
Field intAttrField = clz.getDeclaredField("intAttr");
Assertions.assertNotNull(staticAttrField);
Assertions.assertNotNull(strAttrField);
Assertions.assertNotNull(intAttrField);
Assertions.assertEquals(staticAttrField.get(null), "defaultVal");
// get methods
Method setStrAttrMethod = clz.getMethod("setStrAttr", new Class[]{String.class, int.class});
Method setIntAttrMethod = clz.getMethod("setIntAttr", new Class[]{String.class, int.class});
Method getStrAttrMethod = clz.getMethod("getStrAttr");
Method getIntAttrMethod = clz.getMethod("getIntAttr");
Method baseClassMethod = clz.getMethod("baseClassMethod");
Assertions.assertNotNull(setStrAttrMethod);
Assertions.assertNotNull(setIntAttrMethod);
Assertions.assertNotNull(getStrAttrMethod);
Assertions.assertNotNull(getIntAttrMethod);
Assertions.assertNotNull(baseClassMethod);
// verify constructor0
Object objByConstructor0 = constructor0.newInstance();
Assertions.assertEquals(getStrAttrMethod.invoke(objByConstructor0), null);
Assertions.assertEquals(getIntAttrMethod.invoke(objByConstructor0), 0);
// verify constructor1
Object objByConstructor1 = constructor1.newInstance("v1", 1);
Assertions.assertEquals(getStrAttrMethod.invoke(objByConstructor1), "v1");
Assertions.assertEquals(getIntAttrMethod.invoke(objByConstructor1), 1);
// verify getter setter method
setStrAttrMethod.invoke(objByConstructor0, "v2", 2);
setIntAttrMethod.invoke(objByConstructor0, "v3", 3);
Assertions.assertEquals(getStrAttrMethod.invoke(objByConstructor0), "v2");
Assertions.assertEquals(getIntAttrMethod.invoke(objByConstructor0), 3);
// verify constructor and method witch comes from baseClass
StringBuilder sb = new StringBuilder();
Object objByConstructor2 = constructor2.newInstance(sb);
Assertions.assertEquals(sb.toString(),"constructor comes from BaseClass");
Object res = baseClassMethod.invoke(objByConstructor2);
Assertions.assertEquals(res,"method comes from BaseClass");
cg.release();
}
@SuppressWarnings("unchecked")
@Test
public void testMain() throws Exception {
Bean b = new Bean();
Field fname = null, fs[] = Bean.class.getDeclaredFields();
for (Field f : fs) {
f.setAccessible(true);
if (f.getName().equals("name"))
fname = f;
}
Field fname = Bean.class.getDeclaredField("name");
fname.setAccessible(true);
ClassGenerator cg = ClassGenerator.newInstance();
cg.setClassName(Bean.class.getName() + "$Builder");
@ -63,12 +175,8 @@ public class ClassGeneratorTest {
@Test
public void testMain0() throws Exception {
Bean b = new Bean();
Field fname = null, fs[] = Bean.class.getDeclaredFields();
for (Field f : fs) {
f.setAccessible(true);
if (f.getName().equals("name"))
fname = f;
}
Field fname = Bean.class.getDeclaredField("name");
fname.setAccessible(true);
ClassGenerator cg = ClassGenerator.newInstance();
cg.setClassName(Bean.class.getName() + "$Builder2");

View File

@ -42,6 +42,12 @@ public class WrapperTest {
assertEquals(w.getPropertyValue(obj, "name"), "changed");
w.invokeMethod(obj, "hello", new Class<?>[]{String.class}, new Object[]{"qianlei"});
w.setPropertyValues(obj, new String[]{"name", "float"}, new Object[]{"mrh", 1.0f});
Object[] propertyValues = w.getPropertyValues(obj, new String[]{"name", "float"});
Assertions.assertEquals(propertyValues.length, 2);
Assertions.assertEquals(propertyValues[0], "mrh");
Assertions.assertEquals(propertyValues[1], 1.0f);
}
// bug: DUBBO-132
@ -78,8 +84,10 @@ public class WrapperTest {
public void testWrapperObject() throws Exception {
Wrapper w = Wrapper.getWrapper(Object.class);
Assertions.assertEquals(4, w.getMethodNames().length);
Assertions.assertEquals(4, w.getDeclaredMethodNames().length);
Assertions.assertEquals(0, w.getPropertyNames().length);
Assertions.assertNull(w.getPropertyType(null));
Assertions.assertFalse(w.hasProperty(null));
}
@Test
@ -98,14 +106,23 @@ public class WrapperTest {
});
}
@Test
public void testWrapPrimitive() throws Exception {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
Wrapper.getWrapper(Byte.TYPE);
});
}
@Test
public void testInvokeWrapperObject() throws Exception {
Wrapper w = Wrapper.getWrapper(Object.class);
Object instance = new Object();
Assertions.assertEquals(instance.getClass(), (Class<?>) w.invokeMethod(instance, "getClass", null, null));
Assertions.assertEquals(instance.getClass(), w.invokeMethod(instance, "getClass", null, null));
Assertions.assertEquals(instance.hashCode(), (int) w.invokeMethod(instance, "hashCode", null, null));
Assertions.assertEquals(instance.toString(), (String) w.invokeMethod(instance, "toString", null, null));
Assertions.assertTrue((boolean)w.invokeMethod(instance, "equals", null, new Object[] {instance}));
Assertions.assertEquals(instance.toString(), w.invokeMethod(instance, "toString", null, null));
Assertions.assertTrue((boolean) w.invokeMethod(instance, "equals", new Class[]{instance.getClass()}, new Object[]{instance}));
Assertions.assertThrows(IllegalArgumentException.class,
() -> w.invokeMethod(instance, "equals", new Class[]{instance.getClass()}, new Object[]{instance, instance}));
}
@Test
@ -151,6 +168,23 @@ public class WrapperTest {
assertArrayEquals(new String[]{"hello", "world"}, ClassUtils.getMethodNames(Son.class));
}
@Test
public void testWrapImplClass(){
Wrapper w = Wrapper.getWrapper(Impl0.class);
String[] propertyNames = w.getPropertyNames();
Assertions.assertArrayEquals(propertyNames, new String[]{"a", "b", "c"});
// fields that do not contain the static|final|transient modifier
Assertions.assertFalse(w.hasProperty("f"));
Assertions.assertFalse(w.hasProperty("l"));
Assertions.assertFalse(w.hasProperty("ch"));
// only has public methods, do not contain the private or comes from object methods
Assertions.assertTrue(w.hasMethod("publicMethod"));
Assertions.assertFalse(w.hasMethod("privateMethod"));
Assertions.assertFalse(w.hasMethod("hashcode"));
}
public interface I0 {
String getName();
}
@ -191,6 +225,17 @@ public class WrapperTest {
public static class Impl0 {
public float a, b, c;
public transient boolean f;
public static long l = 1;
public final char ch = 'c';
private void privateMethod() {
}
public void publicMethod() {
}
}
public static class Impl1 implements I1 {

View File

@ -53,7 +53,7 @@ public class ShutdownHookCallbacksTest {
@AfterEach
public void destroy() {
callbacks.clear();
callbacks.destroy();
assertTrue(callbacks.getCallbacks().isEmpty());
}
}

View File

@ -0,0 +1,59 @@
/*
* 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.dubbo.common.bytecode;
import org.apache.dubbo.common.bytecode.ClassGenerator.DC;
public class TestClass extends BaseClass implements DC, BaseInterface {
public static volatile String staticAttr = "defaultVal";
protected volatile String strAttr;
private volatile int intAttr;
public void setStrAttr(String var1, int var2) throws Throwable, RuntimeException {
this.strAttr = var1;
}
public void setIntAttr(String var1, int var2) throws Throwable, RuntimeException {
this.intAttr = var2;
}
public String getStrAttr() throws Throwable, RuntimeException {
return this.strAttr;
}
public int getIntAttr() throws Throwable, RuntimeException {
return this.intAttr;
}
public String baseClassMethod() {
return "method comes from BaseClass";
}
public TestClass() {
}
public TestClass(String var1, int var2) throws Throwable, RuntimeException {
this.strAttr = var1;
this.intAttr = var2;
}
public TestClass(StringBuilder sb) {
sb.append("constructor comes from BaseClass");
}
}

View File

@ -26,7 +26,7 @@ import org.apache.dubbo.rpc.model.ApplicationModel;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* The shutdown hook thread to do the clean up stuff.
* The shutdown hook thread to do the cleanup stuff.
* This is a singleton in order to ensure there is only one shutdown hook registered.
* Because {@link ApplicationShutdownHooks} use {@link java.util.IdentityHashMap}
* to store the shutdown hooks.
@ -58,14 +58,14 @@ public class DubboShutdownHook extends Thread {
Assert.notNull(this.applicationModel, "ApplicationModel is null");
ignoreListenShutdownHook = Boolean.parseBoolean(ConfigurationUtils.getProperty(applicationModel, CommonConstants.IGNORE_LISTEN_SHUTDOWN_HOOK));
if (ignoreListenShutdownHook) {
logger.info("dubbo.shutdownHook.listenIgnore configured, will ignore add shutdown hook to jvm.");
logger.info(CommonConstants.IGNORE_LISTEN_SHUTDOWN_HOOK + " configured, will ignore add shutdown hook to jvm.");
}
}
@Override
public void run() {
if (destroyed.compareAndSet(false, true) && !ignoreListenShutdownHook) {
if (!ignoreListenShutdownHook && destroyed.compareAndSet(false, true)) {
if (logger.isInfoEnabled()) {
logger.info("Run shutdown hook now.");
}
@ -82,7 +82,7 @@ public class DubboShutdownHook extends Thread {
* Register the ShutdownHook
*/
public void register() {
if (registered.compareAndSet(false, true) && !ignoreListenShutdownHook) {
if (!ignoreListenShutdownHook && registered.compareAndSet(false, true)) {
try {
Runtime.getRuntime().addShutdownHook(this);
} catch (IllegalStateException e) {
@ -97,7 +97,7 @@ public class DubboShutdownHook extends Thread {
* Unregister the ShutdownHook
*/
public void unregister() {
if (registered.compareAndSet(true, false) && !ignoreListenShutdownHook) {
if (!ignoreListenShutdownHook && registered.compareAndSet(true, false)) {
if (this.isAlive()) {
// DubboShutdownHook thread is running
return;

View File

@ -61,7 +61,6 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY;
@ -269,7 +268,7 @@ public class ReferenceConfig<T> extends ReferenceConfigBase<T> {
serviceMetadata.setServiceType(getServiceInterfaceClass());
// TODO, uncomment this line once service key is unified
serviceMetadata.setServiceKey(URL.buildKey(interfaceName, group, version));
serviceMetadata.generateServiceKey();
Map<String, String> referenceParameters = appendConfig();
// init service-application mapping
@ -298,7 +297,7 @@ public class ReferenceConfig<T> extends ReferenceConfigBase<T> {
serviceMetadata.setTarget(ref);
serviceMetadata.addAttribute(PROXY_CLASS_REF, ref);
consumerModel.setDestroyCaller(getDestroyRunner());
consumerModel.setDestroyRunner(getDestroyRunner());
consumerModel.setProxyObject(ref);
consumerModel.initMethodModels();
@ -735,7 +734,6 @@ public class ReferenceConfig<T> extends ReferenceConfigBase<T> {
* call, which is the default behavior
*/
protected boolean shouldJvmRefer(Map<String, String> map) {
URL tmpUrl = new ServiceConfigURL("temp", "localhost", 0, map);
boolean isJvmRefer;
if (isInjvm() == null) {
// if an url is specified, don't do local reference
@ -743,6 +741,7 @@ public class ReferenceConfig<T> extends ReferenceConfigBase<T> {
isJvmRefer = false;
} else {
// by default, reference local service if there is
URL tmpUrl = new ServiceConfigURL("temp", "localhost", 0, map);
isJvmRefer = InjvmProtocol.getInjvmProtocol(getScopeModel()).isInjvmRefer(tmpUrl);
}
} else {
@ -767,10 +766,7 @@ public class ReferenceConfig<T> extends ReferenceConfigBase<T> {
return invoker;
}
public Callable<Void> getDestroyRunner() {
return () -> {
this.destroy();
return null;
};
public Runnable getDestroyRunner() {
return this::destroy;
}
}

View File

@ -56,7 +56,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@ -374,7 +373,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
} else {
serviceDescriptor = repository.registerService(getInterfaceClass());
}
providerModel = new ProviderModel(getUniqueServiceName(),
providerModel = new ProviderModel(serviceMetadata.getServiceKey(),
ref,
serviceDescriptor,
getScopeModel(),
@ -383,7 +382,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
// Compatible with dependencies on ServiceModel#getServiceConfig(), and will be removed in a future version
providerModel.setConfig(this);
providerModel.setDestroyCaller(getDestroyRunner());
providerModel.setDestroyRunner(getDestroyRunner());
repository.registerProvider(providerModel);
List<URL> registryURLs = ConfigValidationUtils.loadRegistries(this, true);
@ -407,7 +406,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
Map<String, String> map = buildAttributes(protocolConfig);
// remove null key and null value
map.keySet().removeIf(key -> key == null || map.get(key) == null);
map.keySet().removeIf(key -> StringUtils.isEmpty(key) || StringUtils.isEmpty(map.get(key)));
// init serviceMetadata attachments
serviceMetadata.getAttachments().putAll(map);
@ -442,7 +441,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
map.put(METHODS_KEY, ANY_VALUE);
} else {
String revision = Version.getVersion(interfaceClass, version);
if (revision != null && revision.length() > 0) {
if (StringUtils.isNotEmpty(revision)) {
map.put(REVISION_KEY, revision);
}
@ -711,7 +710,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
boolean anyhost = false;
String hostToBind = getValueFromConfig(protocolConfig, DUBBO_IP_TO_BIND);
if (hostToBind != null && hostToBind.length() > 0 && isInvalidLocalHost(hostToBind)) {
if (StringUtils.isNotEmpty(hostToBind) && isInvalidLocalHost(hostToBind)) {
throw new IllegalArgumentException("Specified invalid bind ip from property:" + DUBBO_IP_TO_BIND + ", value:" + hostToBind);
}
@ -724,7 +723,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
if (isInvalidLocalHost(hostToBind)) {
anyhost = true;
if (logger.isDebugEnabled()) {
logger.info("No valid ip found from environment, try to get local host.");
logger.debug("No valid ip found from environment, try to get local host.");
}
hostToBind = getLocalHost();
}
@ -732,7 +731,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
map.put(BIND_IP_KEY, hostToBind);
// registry ip is not used for bind ip by default
// bind ip is not used for registry ip by default
String hostToRegistry = getValueFromConfig(protocolConfig, DUBBO_IP_TO_REGISTRY);
if (StringUtils.isNotEmpty(hostToRegistry) && isInvalidLocalHost(hostToRegistry)) {
throw new IllegalArgumentException("Specified invalid registry ip from property:" + DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry);
@ -788,7 +787,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
// save bind port, used as url's key later
map.put(BIND_PORT_KEY, String.valueOf(portToBind));
// registry port, not used as bind port by default
// bind port is not used as registry port by default
String portToRegistryStr = getValueFromConfig(protocolConfig, DUBBO_PORT_TO_REGISTRY);
Integer portToRegistry = parsePort(portToRegistryStr);
if (portToRegistry == null) {
@ -836,10 +835,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
}
}
public Callable<Void> getDestroyRunner() {
return () -> {
this.unexport();
return null;
};
public Runnable getDestroyRunner() {
return this::unexport;
}
}

View File

@ -125,7 +125,14 @@ public class DefaultModuleDeployer extends AbstractDeployer<ModuleModel> impleme
}
@Override
public synchronized Future start() throws IllegalStateException {
public Future start() throws IllegalStateException {
// initializemaybe deadlock applicationDeployer lock & moduleDeployer lock
applicationDeployer.initialize();
return startSync();
}
private synchronized Future startSync() throws IllegalStateException {
if (isStopping() || isStopped() || isFailed()) {
throw new IllegalStateException(getIdentifier() + " is stopping or stopped, can not start again");
}
@ -137,8 +144,7 @@ public class DefaultModuleDeployer extends AbstractDeployer<ModuleModel> impleme
onModuleStarting();
// initialize
applicationDeployer.initialize();
initialize();
// export services
@ -213,8 +219,8 @@ public class DefaultModuleDeployer extends AbstractDeployer<ModuleModel> impleme
for (ConsumerModel consumerModel : consumerModels) {
try {
if (consumerModel.getDestroyCaller() != null) {
consumerModel.getDestroyCaller().call();
if (consumerModel.getDestroyRunner() != null) {
consumerModel.getDestroyRunner().run();
}
} catch (Throwable t) {
logger.error("5-13", "there are problems with the custom implementation.", "", "Unable to destroy model: consumerModel.", t);
@ -224,8 +230,8 @@ public class DefaultModuleDeployer extends AbstractDeployer<ModuleModel> impleme
List<ProviderModel> exportedServices = serviceRepository.getExportedServices();
for (ProviderModel providerModel : exportedServices) {
try {
if (providerModel.getDestroyCaller() != null) {
providerModel.getDestroyCaller().call();
if (providerModel.getDestroyRunner() != null) {
providerModel.getDestroyRunner().run();
}
} catch (Throwable t) {
logger.error("5-13", "there are problems with the custom implementation.", "", "Unable to destroy model: providerModel.", t);

View File

@ -291,22 +291,6 @@ public class ServiceConfigTest {
});
}
// @Test
// public void testMock() throws Exception {
// Assertions.assertThrows(IllegalArgumentException.class, () -> {
// ServiceConfig service = new ServiceConfig();
// service.setMock("true");
// });
// }
//
// @Test
// public void testMock2() throws Exception {
// Assertions.assertThrows(IllegalArgumentException.class, () -> {
// ServiceConfig service = new ServiceConfig();
// service.setMock(true);
// });
// }
@Test
public void testApplicationInUrl() {
service.export();

View File

@ -83,23 +83,23 @@ public class ReferenceCacheTest {
assertEquals(value, cache.get("group1/org.apache.dubbo.config.utils.service.FooService:1.0.0", FooService.class));
}
// @Test
// public void testGetCacheDiffName() throws Exception {
// ReferenceCache cache = ReferenceCache.getCache();
// MockReferenceConfig config = buildMockReferenceConfig("org.apache.dubbo.config.utils.service.FooService", "group1", "1.0.0");
// assertEquals(0L, config.getCounter());
// cache.get(config);
// assertTrue(config.isGetMethodRun());
// assertEquals(1L, config.getCounter());
//
// cache = ReferenceCache.getCache("foo");
// config = buildMockReferenceConfig("org.apache.dubbo.config.utils.service.FooService", "group1", "1.0.0");
// assertEquals(1L, config.getCounter());
// cache.get(config);
// // still init for the same ReferenceConfig if the cache is different
// assertTrue(config.isGetMethodRun());
// assertEquals(2L, config.getCounter());
// }
@Test
public void testGetCacheDiffName() throws Exception {
SimpleReferenceCache cache = SimpleReferenceCache.getCache();
MockReferenceConfig config = buildMockReferenceConfig("org.apache.dubbo.config.utils.service.FooService", "group1", "1.0.0");
assertEquals(0L, config.getCounter());
cache.get(config);
assertTrue(config.isGetMethodRun());
assertEquals(1L, config.getCounter());
cache = SimpleReferenceCache.getCache("foo");
config = buildMockReferenceConfig("org.apache.dubbo.config.utils.service.FooService", "group1", "1.0.0");
assertEquals(1L, config.getCounter());
cache.get(config);
// still init for the same ReferenceConfig if the cache is different
assertTrue(config.isGetMethodRun());
assertEquals(2L, config.getCounter());
}
@Test
public void testDestroy() throws Exception {

View File

@ -29,7 +29,7 @@ import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.model.ApplicationModel;
@Activate(group = CommonConstants.PROVIDER, order = -10000)
@Activate(group = CommonConstants.PROVIDER, value = Constants.SERVICE_AUTH, order = -10000)
public class ProviderAuthFilter implements Filter {
private ApplicationModel applicationModel;

View File

@ -64,7 +64,7 @@ public abstract class AbstractProxyTest {
public void testGetInvoker() throws Exception {
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
DemoService origin = new org.apache.dubbo.rpc.support.DemoServiceImpl();
DemoService origin = new DemoServiceImpl();
Invoker<DemoService> invoker = factory.getInvoker(new DemoServiceImpl(), DemoService.class, url);