Skip to content
Permalink
Browse files
[3.0]fix #9863, @method annotation parma isReturn invalid (#9865)
  • Loading branch information
wangchengming666 committed May 7, 2022
1 parent bce439e commit a2f165052661bbdcf7c97b04e7be7cf7ee1ccffd
Showing 3 changed files with 46 additions and 38 deletions.
@@ -177,7 +177,7 @@ public MethodConfig(Method method) {
}

if (method.arguments() != null && method.arguments().length != 0) {
List<ArgumentConfig> argumentConfigs = new ArrayList<ArgumentConfig>(method.arguments().length);
List<ArgumentConfig> argumentConfigs = new ArrayList<>(method.arguments().length);
this.setArguments(argumentConfigs);
for (int i = 0; i < method.arguments().length; i++) {
ArgumentConfig argumentConfig = new ArgumentConfig(method.arguments()[i]);
@@ -57,8 +57,13 @@ public class ReferenceCreator {
static final String[] IGNORE_FIELD_NAMES = of("application", "module", "consumer", "monitor", "registry", "interfaceClass");

private static final String ONRETURN = "onreturn";

private static final String ONTHROW = "onthrow";

private static final String ONINVOKE = "oninvoke";

private static final String ISRETURN = "isReturn";

private static final String METHOD = "Method";

protected final Log logger = LogFactory.getLog(getClass());
@@ -78,7 +83,7 @@ private ReferenceCreator(Map<String, Object> attributes, ApplicationContext appl
this.attributes = attributes;
this.applicationContext = applicationContext;
this.classLoader = applicationContext.getClassLoader() != null ?
applicationContext.getClassLoader() : Thread.currentThread().getContextClassLoader();
applicationContext.getClassLoader() : Thread.currentThread().getContextClassLoader();
moduleModel = DubboBeanUtils.getModuleModel(applicationContext);
Assert.notNull(moduleModel, "ModuleModel not found in Spring ApplicationContext");
}
@@ -145,7 +150,7 @@ private void configureConsumerConfig(ReferenceConfig<?> referenceBean) {
} else if (consumer instanceof ConsumerConfig) {
consumerConfig = (ConsumerConfig) consumer;
} else {
throw new IllegalArgumentException("Unexpected 'consumer' attribute value: "+consumer);
throw new IllegalArgumentException("Unexpected 'consumer' attribute value: " + consumer);
}
referenceBean.setConsumer(consumerConfig);
}
@@ -226,7 +231,7 @@ private MethodConfig createMethodConfig(Map<String, Object> methodAttributes, De
String beanName = strValue.substring(0, index);
String methodName = strValue.substring(index + 1);
methodAttributes.put(callbackName, applicationContext.getBean(beanName));
methodAttributes.put(callbackName+METHOD, methodName);
methodAttributes.put(callbackName + METHOD, methodName);
} else {
methodAttributes.put(callbackName, applicationContext.getBean(strValue));
}
@@ -235,6 +240,7 @@ private MethodConfig createMethodConfig(Map<String, Object> methodAttributes, De

MethodConfig methodConfig = new MethodConfig();
DataBinder mcDataBinder = new DataBinder(methodConfig);
methodConfig.setReturn((Boolean) methodAttributes.get(ISRETURN));
mcDataBinder.setConversionService(conversionService);
AnnotationPropertyValuesAdapter propertyValues = new AnnotationPropertyValuesAdapter(methodAttributes, applicationContext.getEnvironment());
mcDataBinder.bind(propertyValues);
@@ -77,35 +77,36 @@ public class ReferenceCreatorTest {
private static final String REGISTRY_CONFIG_ID = "myregistry";

@DubboReference(
//interfaceClass = HelloService.class,
version = "1.0.0", group = "TEST_GROUP", url = "dubbo://localhost:12345",
client = "client", generic = false, injvm = false,
check = false, init = false, lazy = true,
stubevent = true, reconnect = "reconnect", sticky = true,
proxy = "javassist", stub = "org.apache.dubbo.config.spring.api.HelloService", cluster = "failover",
connections = 3, callbacks = 1, onconnect = "onconnect", ondisconnect = "ondisconnect",
owner = "owner", layer = "layer", retries = 1,
loadbalance = "random", async = true, actives = 3,
sent = true, mock = "mock", validation = "validation",
timeout = 3, cache = "cache", filter = {"echo", "generic", "accesslog"},
listener = {"deprecated"}, parameters = {"n1=v1 ", "n2 = v2 ", " n3 = v3 "},
application = "application",
module = MODULE_CONFIG_ID, consumer = CONSUMER_CONFIG_ID, monitor = MONITOR_CONFIG_ID, registry = {REGISTRY_CONFIG_ID},
// @since 2.7.3
id = "reference",
// @since 2.7.8
services = {"service1", "service2", "service3", "service2", "service1"},
providedBy = {"service1", "service2", "service3"},
methods = @Method(name = "sayHello",
loadbalance = "loadbalance",
oninvoke = "notifyService.onInvoke",
onreturn = "notifyService.onReturn",
onthrow = "notifyService.onThrow",
timeout = 1000,
retries = 2,
parameters = {"a", "1", "b", "2"},
arguments = @Argument(index = 0, callback = true)
)
//interfaceClass = HelloService.class,
version = "1.0.0", group = "TEST_GROUP", url = "dubbo://localhost:12345",
client = "client", generic = false, injvm = false,
check = false, init = false, lazy = true,
stubevent = true, reconnect = "reconnect", sticky = true,
proxy = "javassist", stub = "org.apache.dubbo.config.spring.api.HelloService", cluster = "failover",
connections = 3, callbacks = 1, onconnect = "onconnect", ondisconnect = "ondisconnect",
owner = "owner", layer = "layer", retries = 1,
loadbalance = "random", async = true, actives = 3,
sent = true, mock = "mock", validation = "validation",
timeout = 3, cache = "cache", filter = {"echo", "generic", "accesslog"},
listener = {"deprecated"}, parameters = {"n1=v1 ", "n2 = v2 ", " n3 = v3 "},
application = "application",
module = MODULE_CONFIG_ID, consumer = CONSUMER_CONFIG_ID, monitor = MONITOR_CONFIG_ID, registry = {REGISTRY_CONFIG_ID},
// @since 2.7.3
id = "reference",
// @since 2.7.8
services = {"service1", "service2", "service3", "service2", "service1"},
providedBy = {"service1", "service2", "service3"},
methods = @Method(name = "sayHello",
isReturn = false,
loadbalance = "loadbalance",
oninvoke = "notifyService.onInvoke",
onreturn = "notifyService.onReturn",
onthrow = "notifyService.onThrow",
timeout = 1000,
retries = 2,
parameters = {"a", "1", "b", "2"},
arguments = @Argument(index = 0, callback = true)
)
)
private HelloService helloService;

@@ -128,8 +129,8 @@ public void testBuild() throws Exception {
// filter default value
AnnotationAttributes attributes = AnnotationUtils.getAnnotationAttributes(reference, true);
ReferenceConfig referenceBean = ReferenceCreator.create(attributes, context)
.defaultInterfaceClass(helloServiceField.getType())
.build();
.defaultInterfaceClass(helloServiceField.getType())
.build();
Assertions.assertEquals(HelloService.class, referenceBean.getInterfaceClass());
Assertions.assertEquals("org.apache.dubbo.config.spring.api.HelloService", referenceBean.getInterface());
Assertions.assertEquals("1.0.0", referenceBean.getVersion());
@@ -182,6 +183,7 @@ public void testBuild() throws Exception {
Assertions.assertEquals(1, methods.size());
MethodConfig methodConfig = methods.get(0);
Assertions.assertEquals("sayHello", methodConfig.getName());
Assertions.assertEquals(false, methodConfig.isReturn());
Assertions.assertEquals(1000, methodConfig.getTimeout());
Assertions.assertEquals(2, methodConfig.getRetries());
Assertions.assertEquals("loadbalance", methodConfig.getLoadbalance());
@@ -205,7 +207,7 @@ public void testBuild() throws Exception {
Assertions.assertEquals(true, argumentConfig.isCallback());

// Asserts Null fields
Assertions.assertThrows(IllegalStateException.class, () -> referenceBean.getApplication());
Assertions.assertThrows(IllegalStateException.class, referenceBean::getApplication);
Assertions.assertNotNull(referenceBean.getModule());
Assertions.assertNotNull(referenceBean.getConsumer());
Assertions.assertNotNull(referenceBean.getMonitor());
@@ -231,12 +233,12 @@ public ConsumerConfig consumerConfig() {
}

@Bean(MONITOR_CONFIG_ID)
public MonitorConfig monitorConfig(){
public MonitorConfig monitorConfig() {
return new MonitorConfig();
}

@Bean(MODULE_CONFIG_ID)
public ModuleConfig moduleConfig(){
public ModuleConfig moduleConfig() {
return new ModuleConfig();
}

0 comments on commit a2f1650

Please sign in to comment.