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 Sep 18, 2019
1 parent 3844ac7 commit 5d0e103
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
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,6 +91,7 @@ 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
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 @@ -115,6 +115,7 @@ public void test() {
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 @@ -141,7 +142,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 5d0e103

Please sign in to comment.