Skip to content

Commit

Permalink
support 'merge' attribute in @reference annotation and @method @annot…
Browse files Browse the repository at this point in the history
  • Loading branch information
shalk committed Jul 21, 2019
1 parent 9960d23 commit 306954a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

/**
* @since 2.6.5
* *
* * 2018/9/29
* *
* * 2018/9/29
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
Expand Down Expand Up @@ -66,4 +66,6 @@
String validation() default "";

Argument[] arguments() default {};

String merger() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,10 @@
* @since 2.7.3
*/
String id() default "";

/**
* Group merger
* @return
*/
String merger() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ public class MethodConfigTest {
private static final int ARGUMENTS_INDEX = 24;
private static final boolean ARGUMENTS_CALLBACK = true;
private static final String ARGUMENTS_TYPE = "sss";
private static final String MERGER = "false";

@Reference(methods = {@Method(name = METHOD_NAME, timeout = TIMEOUT, retries = RETRIES, loadbalance = LOADBALANCE, async = ASYNC,
actives = ACTIVES, executes = EXECUTES, deprecated = DEPERECATED, sticky = STICKY, oninvoke = ONINVOKE, onthrow = ONTHROW, onreturn = ONRETURN, cache = CACHE, validation = VALIDATION,
arguments = {@Argument(index = ARGUMENTS_INDEX, callback = ARGUMENTS_CALLBACK, type = ARGUMENTS_TYPE)})})
arguments = {@Argument(index = ARGUMENTS_INDEX, callback = ARGUMENTS_CALLBACK, type = ARGUMENTS_TYPE)}, merger = MERGER)})
private String testField;

@Test
Expand All @@ -90,10 +91,11 @@ public void testStaticConstructor() throws NoSuchFieldException {
assertThat(ARGUMENTS_INDEX, equalTo(methodConfig.getArguments().get(0).getIndex().intValue()));
assertThat(ARGUMENTS_CALLBACK, equalTo(methodConfig.getArguments().get(0).isCallback()));
assertThat(ARGUMENTS_TYPE, equalTo(methodConfig.getArguments().get(0).getType()));
assertThat(MERGER,equalTo(methodConfig.getMerger()));
}

@Test
public void testName() throws Exception {
public void testName() throws Exception {
MethodConfig method = new MethodConfig();
method.setName("hello");
assertThat(method.getName(), equalTo("hello"));
Expand Down Expand Up @@ -237,4 +239,11 @@ public void testReturn() throws Exception {
method.setReturn(true);
assertThat(method.isReturn(), is(true));
}

@Test
public void testSetMerger() throws Exception {
MethodConfig method = new MethodConfig();
method.setMerger("default");
assertThat(method.getMerger(),equalTo("default"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,14 @@ public void testConstructWithReferenceAnnotation() throws NoSuchFieldException {
Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOnreturn(), "r");
Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOnthrow(), "t");
Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getCache(), "c");
Assertions.assertEquals("true", referenceConfig.getMerger());
Assertions.assertEquals("false", ((MethodConfig) referenceConfig.getMethods().get(0)).getMerger());
}


@Reference(methods = {@Method(name = "sayHello", timeout = 1300, retries = 4, loadbalance = "random", async = true,
@Reference(merger="true", methods = {@Method(name = "sayHello", timeout = 1300, retries = 4, loadbalance = "random", async = true,
actives = 3, executes = 5, deprecated = true, sticky = true, oninvoke = "i", onthrow = "t", onreturn = "r", cache = "c", validation = "v",
arguments = {@Argument(index = 24, callback = true, type = "sss")})})
arguments = {@Argument(index = 24, callback = true, type = "sss")}, merger = "false")})
private InnerTest innerTest;

private class InnerTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,6 @@ public static Map<String, Object> getAttributes(Annotation annotation, PropertyR
continue;
}

/**
* @since 2.7.1
* ignore annotation member
*/
if (attributeValue.getClass().isAnnotation()) {
continue;
}
if (attributeValue.getClass().isArray() && attributeValue.getClass().getComponentType().isAnnotation()) {
continue;
}
actualAttributes.put(attributeName, attributeValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public Map<String, String> convert(String[] source) {
Assert.assertEquals("cache", referenceBean.getCache());
Assert.assertEquals("default,default", referenceBean.getFilter());
Assert.assertEquals("default,default", referenceBean.getListener());
Assert.assertEquals("true",referenceBean.getMerger());

Map<String, String> data = new LinkedHashMap<String, String>();
data.put("key1", "value1");
Expand All @@ -151,7 +152,7 @@ private static class TestBean {
loadbalance = "random", async = true, actives = 1, sent = true,
mock = "mock", validation = "validation", timeout = 2, cache = "cache",
filter = {"default", "default"}, listener = {"default", "default"}, parameters = {"key1", "value1"}, application = "application",
module = "module", consumer = "consumer", monitor = "monitor", registry = {"registry1", "registry2"}
module = "module", consumer = "consumer", monitor = "monitor", registry = {"registry1", "registry2"}, merger = "true"
)
private DemoService demoService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.apache.dubbo.config.spring.beans.factory.annotation;


import org.apache.dubbo.config.MethodConfig;
import org.apache.dubbo.config.annotation.Method;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.spring.ReferenceBean;

Expand All @@ -30,6 +32,7 @@

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

import static org.springframework.core.annotation.AnnotationUtils.findAnnotation;
Expand Down Expand Up @@ -61,7 +64,8 @@ public class ReferenceBeanBuilderTest {
timeout = 3, cache = "cache", filter = {"echo", "generic", "accesslog"},
listener = {"deprecated"}, parameters = {"n1=v1 ", "n2 = v2 ", " n3 = v3 "},
application = "application",
module = "module", consumer = "consumer", monitor = "monitor", registry = {"registry"}
module = "module", consumer = "consumer", monitor = "monitor", registry = {"registry"},
merger = "true", methods = {@Method(name = "method1", timeout = 1000, merger = "false")}
)
private static final Object TEST_FIELD = new Object();

Expand Down Expand Up @@ -121,5 +125,17 @@ public void testBuild() throws Exception {
Assert.assertNull(referenceBean.getConsumer());
Assert.assertNull(referenceBean.getMonitor());
Assert.assertEquals(Collections.emptyList(), referenceBean.getRegistries());

// merge
Assert.assertEquals("true", referenceBean.getMerger());

// method
List<MethodConfig> methods = referenceBean.getMethods();
Assert.assertNotNull(methods);
Assert.assertEquals(1, methods.size());
MethodConfig methodConfig = methods.get(0);
Assert.assertEquals("false", methodConfig.getMerger());
Assert.assertEquals(1000, methodConfig.getTimeout().intValue());

}
}

0 comments on commit 306954a

Please sign in to comment.