Skip to content

Commit

Permalink
fix UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenlj committed Nov 21, 2019
1 parent 028d5f0 commit b576bb7
Show file tree
Hide file tree
Showing 44 changed files with 387 additions and 329 deletions.
Binary file modified compiler/.gradle/4.9/fileContent/fileContent.lock
Binary file not shown.
Binary file modified compiler/.gradle/4.9/fileContent/parsedCSource.bin
Binary file not shown.
Binary file modified compiler/.gradle/4.9/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified compiler/.gradle/4.9/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified compiler/.gradle/4.9/nativeCompile/nativeCompile.bin
Binary file not shown.
Binary file modified compiler/.gradle/4.9/nativeCompile/nativeCompile.lock
Binary file not shown.
Binary file modified compiler/.gradle/4.9/taskHistory/taskHistory.bin
Binary file not shown.
Binary file modified compiler/.gradle/4.9/taskHistory/taskHistory.lock
Binary file not shown.
Binary file modified compiler/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
21 changes: 9 additions & 12 deletions dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ class URL implements Serializable {

private volatile transient String string;

private final transient String serviceKey;

private final transient String serviceInterface;
private transient String serviceKey;

protected URL() {
this.protocol = null;
Expand All @@ -141,8 +139,6 @@ protected URL() {
this.path = null;
this.parameters = null;
this.methodParameters = null;
this.serviceKey = null;
this.serviceInterface = null;
}

public URL(String protocol, String host, int port) {
Expand Down Expand Up @@ -216,13 +212,6 @@ public URL(String protocol,
}
this.parameters = Collections.unmodifiableMap(parameters);
this.methodParameters = Collections.unmodifiableMap(methodParameters);

this.serviceInterface = getParameter(INTERFACE_KEY, path);
if (this.serviceInterface == null) {
this.serviceKey = null;
} else {
this.serviceKey = buildKey(serviceInterface, getParameter(GROUP_KEY), getParameter(VERSION_KEY));
}
}

/**
Expand Down Expand Up @@ -1410,6 +1399,14 @@ private void append(StringBuilder target, String parameterName, boolean first) {
* @return
*/
public String getServiceKey() {
if (serviceKey != null) {
return serviceKey;
}
String inf = getServiceInterface();
if (inf == null) {
return null;
}
serviceKey = buildKey(inf, getParameter(GROUP_KEY), getParameter(VERSION_KEY));
return serviceKey;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ public URL build() {
path = path.substring(firstNonSlash);
}
}
return new URL(protocol, username, password, host, port, path, parameters, methodParameters);
if (CollectionUtils.isEmptyMap(methodParameters)) {
return new URL(protocol, username, password, host, port, path, parameters);
} else {
return new URL(protocol, username, password, host, port, path, parameters, methodParameters);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.context.FrameworkExt;
import org.apache.dubbo.common.context.LifecycleAdapter;
import org.apache.dubbo.common.extension.DisableInject;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.ConfigCenterConfig;
import org.apache.dubbo.config.context.ConfigManager;
Expand Down Expand Up @@ -87,12 +88,14 @@ public EnvironmentConfiguration getEnvironmentConfig(String prefix, String id) {
return environmentConfigs.computeIfAbsent(toKey(prefix, id), k -> new EnvironmentConfiguration(prefix, id));
}

@DisableInject
public void setExternalConfigMap(Map<String, String> externalConfiguration) {
if (externalConfiguration != null) {
this.externalConfigurationMap = externalConfiguration;
}
}

@DisableInject
public void setAppExternalConfigMap(Map<String, String> appExternalConfiguration) {
if (appExternalConfiguration != null) {
this.appExternalConfigurationMap = appExternalConfiguration;
Expand Down Expand Up @@ -162,6 +165,7 @@ public boolean isConfigCenterFirst() {
return configCenterFirst;
}

@DisableInject
public void setConfigCenterFirst(boolean configCenterFirst) {
this.configCenterFirst = configCenterFirst;
}
Expand All @@ -170,6 +174,7 @@ public Optional<DynamicConfiguration> getDynamicConfiguration() {
return Optional.ofNullable(dynamicConfiguration);
}

@DisableInject
public void setDynamicConfiguration(DynamicConfiguration dynamicConfiguration) {
this.dynamicConfiguration = dynamicConfiguration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.D_REGISTRY_SPLIT_PATTERN;
import static org.apache.dubbo.common.constants.CommonConstants.INVOKER_LISTENER_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PID_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.REFERENCE_FILTER_KEY;
Expand Down Expand Up @@ -171,8 +170,6 @@ public List<URL> toUrls() {
* Check whether the registry config is exists, and then conversion it to {@link RegistryConfig}
*/
public void checkRegistry() {
loadRegistriesFromBackwardConfig();

convertRegistryIdsToRegistries();

for (RegistryConfig registryConfig : registries) {
Expand Down Expand Up @@ -313,25 +310,6 @@ protected void computeValidRegistryIds() {
}
}

private void loadRegistriesFromBackwardConfig() {
// for backward compatibility
// -Ddubbo.registry.address is now deprecated.
if (registries == null || registries.isEmpty()) {
String address = ConfigUtils.getProperty("dubbo.registry.address");
if (address != null && address.length() > 0) {
List<RegistryConfig> tmpRegistries = new ArrayList<RegistryConfig>();
String[] as = D_REGISTRY_SPLIT_PATTERN.split(address);
for (String a : as) {
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress(a);
registryConfig.refresh();
tmpRegistries.add(registryConfig);
}
setRegistries(tmpRegistries);
}
}
}

/**
* @return local
* @deprecated Replace to <code>getStub()</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,5 @@ public static void reset() {
getConfigManager().destroy();
getEnvironment().destroy();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.util.Set;

/**
* This model is bind to your reference's configuration, for example, group, version or method level configuration.
* This model is bound to your reference's configuration, for example, group, version or method level configuration.
*/
public class ConsumerModel {
private final String serviceKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,21 @@

import com.alibaba.dubbo.config.ModuleConfig;
import com.alibaba.dubbo.config.RegistryConfig;

import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;

public class ModuleConfigTest {
@Test
public void testName1() throws Exception {
Assertions.assertThrows(IllegalStateException.class, () -> {
ModuleConfig module = new ModuleConfig();
Map<String, String> parameters = new HashMap<String, String>();
ModuleConfig.appendParameters(parameters, module);
});
}

@Test
public void testName2() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ public void tearMethodAfterEachUT() {

@Test
public void testCheckRegistry1() {
System.setProperty("dubbo.registry.address", "addr1|addr2");
System.setProperty("dubbo.registry.address", "addr1");
try {
InterfaceConfig interfaceConfig = new InterfaceConfig();
interfaceConfig.setApplication(new ApplicationConfig("testCheckRegistry1"));
interfaceConfig.checkRegistry();
Assertions.assertEquals(2, interfaceConfig.getRegistries().size());
Assertions.assertEquals(1, interfaceConfig.getRegistries().size());
Assertions.assertEquals("addr1", interfaceConfig.getRegistries().get(0).getAddress());
} finally {
System.clearProperty("dubbo.registry.address");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import java.util.Objects;

/**
* ServiceFactoryBean
*
* @export
*/
public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean, DisposableBean,
ApplicationContextAware, BeanNameAware, ApplicationListener<ContextRefreshedEvent>,
ApplicationContextAware, BeanNameAware,
ApplicationEventPublisherAware {


Expand Down Expand Up @@ -147,23 +143,4 @@ protected Class getServiceClass(T ref) {
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.applicationEventPublisher = applicationEventPublisher;
}

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {

if (!isOriginEventSource(event)) {
return;
}

if (!isExported() && !isUnexported()) {
if (logger.isInfoEnabled()) {
logger.info("The service ready on spring started. service: " + getInterface());
}
export();
}
}

private boolean isOriginEventSource(ContextRefreshedEvent event) {
return Objects.equals(applicationContext, event.getApplicationContext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ public <T> T getExtension(Class<T> type, String name) {
}

for (ApplicationContext context : CONTEXTS) {
// if (context.containsBean(name)) {
// Object bean = context.getBean(name);
// if (type.isInstance(bean)) {
// return (T) bean;
// }
// }
T bean = BeanFactoryUtils.getOptionalBean(context, name, type);
if (bean != null) {
return bean;
Expand All @@ -88,24 +82,6 @@ public <T> T getExtension(Class<T> type, String name) {

logger.warn("No spring extension (bean) named:" + name + ", try to find an extension (bean) of type " + type.getName());

if (Object.class == type) {
return null;
}

// for (ApplicationContext context : CONTEXTS) {
// try {
// return context.getBean(type);
// } catch (NoUniqueBeanDefinitionException multiBeanExe) {
// logger.warn("Find more than 1 spring extensions (beans) of type " + type.getName() + ", will stop auto injection. Please make sure you have specified the concrete parameter type and there's only one extension of that type.");
// } catch (NoSuchBeanDefinitionException noBeanExe) {
// if (logger.isDebugEnabled()) {
// logger.debug("Error when get spring extension(bean) for type:" + type.getName(), noBeanExe);
// }
// }
// }
//
// logger.warn("No spring extension (bean) named:" + name + ", type:" + type.getName() + " found, stop get bean.");

return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.config.spring.beans.factory;

import org.apache.dubbo.config.spring.ServiceBean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class ServiceBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof ServiceBean) {
((ServiceBean) bean).export();
}
return bean;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ public Map<String, String> convert(String[] source) {

Assert.assertEquals(data, referenceBean.getParameters());
// Bean compare
Assert.assertNull(referenceBean.getApplication());
Assert.assertNull(referenceBean.getModule());
Assert.assertNull(referenceBean.getConsumer());
Assert.assertNull(referenceBean.getMonitor());
Assert.assertNull(referenceBean.getRegistry());

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public ReferenceAnnotationBeanPostProcessor referenceAnnotationBeanPostProcessor
private HelloService helloServiceImpl;

// #4 ReferenceBean (Field Injection #2)
@Reference(id = "helloService", methods = @Method(name = "sayName", timeout = 100))
@Reference(id = "helloService", methods = @Method(name = "sayHello", timeout = 100))
private HelloService helloService;

// #5 ReferenceBean (Field Injection #3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.config.spring.beans.factory.ServiceBeanPostProcessor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -85,6 +86,11 @@ public ProtocolConfig protocolConfig() {
return protocolConfig;
}

@Bean
public ServiceBeanPostProcessor serviceBeanPostProcessor() {
return new ServiceBeanPostProcessor();
}

@Primary
@Bean
public PlatformTransactionManager platformTransactionManager() {
Expand Down
Loading

0 comments on commit b576bb7

Please sign in to comment.