diff --git a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/annotation/ShenyuDubboService.java b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/annotation/ShenyuDubboService.java index 6d2fc21656a0..76cb51889a37 100644 --- a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/annotation/ShenyuDubboService.java +++ b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/annotation/ShenyuDubboService.java @@ -30,9 +30,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CALLBACK_INSTANCES; -import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_RETRIES; - /** * The interface shenyu service. @@ -170,7 +167,7 @@ * @return the int */ @AliasFor(annotation = DubboService.class) - int executes() default 0; + int executes() default -1; /** * Alias for {@link DubboService#register()} . @@ -186,7 +183,7 @@ * @return the int */ @AliasFor(annotation = DubboService.class) - int weight() default 0; + int weight() default -1; /** * Alias for {@link DubboService#document()} . @@ -202,7 +199,7 @@ * @return the int */ @AliasFor(annotation = DubboService.class) - int delay() default 0; + int delay() default -1; /** * Alias for {@link DubboService#local()} . @@ -242,7 +239,7 @@ * @return the int */ @AliasFor(annotation = DubboService.class) - int connections() default 0; + int connections() default -1; /** * Alias for {@link DubboService#callbacks()} . @@ -250,7 +247,7 @@ * @return the int */ @AliasFor(annotation = DubboService.class) - int callbacks() default DEFAULT_CALLBACK_INSTANCES; + int callbacks() default -1; /** * Alias for {@link DubboService#onconnect()} . @@ -290,7 +287,7 @@ * @return the int */ @AliasFor(annotation = DubboService.class) - int retries() default DEFAULT_RETRIES; + int retries() default -1; /** * Alias for {@link DubboService#loadbalance()} . @@ -298,7 +295,7 @@ * @return the string */ @AliasFor(annotation = DubboService.class) - String loadbalance() default LoadbalanceRules.RANDOM; + String loadbalance() default LoadbalanceRules.EMPTY; /** * Alias for {@link DubboService#async()} . @@ -314,7 +311,7 @@ * @return the int */ @AliasFor(annotation = DubboService.class) - int actives() default 0; + int actives() default -1; /** * Alias for {@link DubboService#sent()} . @@ -346,7 +343,7 @@ * @return the int */ @AliasFor(annotation = DubboService.class) - int timeout() default 0; + int timeout() default -1; /** * Alias for {@link DubboService#cache()} . diff --git a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/annotation/ShenyuService.java b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/annotation/ShenyuService.java index 2bd537c55a55..92e9a932553a 100644 --- a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/annotation/ShenyuService.java +++ b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/annotation/ShenyuService.java @@ -18,7 +18,6 @@ package org.apache.shenyu.client.apache.dubbo.annotation; import org.apache.dubbo.common.constants.ClusterRules; -import org.apache.dubbo.common.constants.LoadbalanceRules; import org.apache.dubbo.config.annotation.Method; import org.apache.dubbo.config.annotation.Service; import org.apache.shenyu.client.dubbo.common.annotation.ShenyuDubboClient; @@ -30,9 +29,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CALLBACK_INSTANCES; -import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_RETRIES; - /** * The interface shenyu service. @@ -170,7 +166,7 @@ * @return the int */ @AliasFor(annotation = Service.class) - int executes() default 0; + int executes() default -1; /** * Alias for {@link Service#register()} . @@ -186,7 +182,7 @@ * @return the int */ @AliasFor(annotation = Service.class) - int weight() default 0; + int weight() default -1; /** * Alias for {@link Service#document()} . @@ -202,7 +198,7 @@ * @return the int */ @AliasFor(annotation = Service.class) - int delay() default 0; + int delay() default -1; /** * Alias for {@link Service#local()} . @@ -242,7 +238,7 @@ * @return the int */ @AliasFor(annotation = Service.class) - int connections() default 0; + int connections() default -1; /** * Alias for {@link Service#callbacks()} . @@ -250,7 +246,7 @@ * @return the int */ @AliasFor(annotation = Service.class) - int callbacks() default DEFAULT_CALLBACK_INSTANCES; + int callbacks() default -1; /** * Alias for {@link Service#onconnect()} . @@ -290,7 +286,7 @@ * @return the int */ @AliasFor(annotation = Service.class) - int retries() default DEFAULT_RETRIES; + int retries() default -1; /** * Alias for {@link Service#loadbalance()} . @@ -298,7 +294,7 @@ * @return the string */ @AliasFor(annotation = Service.class) - String loadbalance() default LoadbalanceRules.RANDOM; + String loadbalance() default ""; /** * Alias for {@link Service#async()} . @@ -314,7 +310,7 @@ * @return the int */ @AliasFor(annotation = Service.class) - int actives() default 0; + int actives() default -1; /** * Alias for {@link Service#sent()} . @@ -346,7 +342,7 @@ * @return the int */ @AliasFor(annotation = Service.class) - int timeout() default 0; + int timeout() default -1; /** * Alias for {@link Service#cache()} . diff --git a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/test/java/org/apache/shenyu/client/apache/dubbo/annotation/ShenyuDubboServiceDefaultValueTest.java b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/test/java/org/apache/shenyu/client/apache/dubbo/annotation/ShenyuDubboServiceDefaultValueTest.java new file mode 100644 index 000000000000..36247b9c0174 --- /dev/null +++ b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/test/java/org/apache/shenyu/client/apache/dubbo/annotation/ShenyuDubboServiceDefaultValueTest.java @@ -0,0 +1,150 @@ +/* + * 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.shenyu.client.apache.dubbo.annotation; + +import org.apache.dubbo.config.annotation.DubboService; +import org.apache.dubbo.config.annotation.Service; +import org.junit.Assert; +import org.junit.Test; + +public class ShenyuDubboServiceDefaultValueTest { + + @Test + public void dubboServiceDefaultValue() { + ShenyuDubboService shenyuDubboService = ShenyuDubboServiceTest.class.getAnnotation(ShenyuDubboService.class); + DubboService dubboService = DubboServiceTest.class.getAnnotation(DubboService.class); + + Assert.assertEquals(shenyuDubboService.interfaceClass(), dubboService.interfaceClass()); + Assert.assertEquals(shenyuDubboService.interfaceName(), dubboService.interfaceName()); + Assert.assertEquals(shenyuDubboService.version(), dubboService.version()); + Assert.assertEquals(shenyuDubboService.group(), dubboService.group()); + Assert.assertEquals(shenyuDubboService.dubboPath(), dubboService.path()); + Assert.assertEquals(shenyuDubboService.export(), dubboService.export()); + Assert.assertEquals(shenyuDubboService.token(), dubboService.token()); + Assert.assertEquals(shenyuDubboService.deprecated(), dubboService.deprecated()); + Assert.assertEquals(shenyuDubboService.dynamic(), dubboService.dynamic()); + Assert.assertEquals(shenyuDubboService.accesslog(), dubboService.accesslog()); + Assert.assertEquals(shenyuDubboService.executes(), dubboService.executes()); + Assert.assertEquals(shenyuDubboService.register(), dubboService.register()); + Assert.assertEquals(shenyuDubboService.weight(), dubboService.weight()); + Assert.assertEquals(shenyuDubboService.document(), dubboService.document()); + Assert.assertEquals(shenyuDubboService.delay(), dubboService.delay()); + Assert.assertEquals(shenyuDubboService.local(), dubboService.local()); + Assert.assertEquals(shenyuDubboService.stub(), dubboService.stub()); + Assert.assertEquals(shenyuDubboService.cluster(), dubboService.cluster()); + Assert.assertEquals(shenyuDubboService.proxy(), dubboService.proxy()); + Assert.assertEquals(shenyuDubboService.connections(), dubboService.connections()); + Assert.assertEquals(shenyuDubboService.callbacks(), dubboService.callbacks()); + Assert.assertEquals(shenyuDubboService.onconnect(), dubboService.onconnect()); + Assert.assertEquals(shenyuDubboService.ondisconnect(), dubboService.ondisconnect()); + Assert.assertEquals(shenyuDubboService.owner(), dubboService.owner()); + Assert.assertEquals(shenyuDubboService.layer(), dubboService.layer()); + Assert.assertEquals(shenyuDubboService.retries(), dubboService.retries()); + Assert.assertEquals(shenyuDubboService.loadbalance(), dubboService.loadbalance()); + Assert.assertEquals(shenyuDubboService.async(), dubboService.async()); + Assert.assertEquals(shenyuDubboService.actives(), dubboService.actives()); + Assert.assertEquals(shenyuDubboService.sent(), dubboService.sent()); + Assert.assertEquals(shenyuDubboService.mock(), dubboService.mock()); + Assert.assertEquals(shenyuDubboService.validation(), dubboService.validation()); + Assert.assertEquals(shenyuDubboService.timeout(), dubboService.timeout()); + Assert.assertEquals(shenyuDubboService.cache(), dubboService.cache()); + Assert.assertArrayEquals(shenyuDubboService.filter(), dubboService.filter()); + Assert.assertArrayEquals(shenyuDubboService.listener(), dubboService.listener()); + Assert.assertArrayEquals(shenyuDubboService.parameters(), dubboService.parameters()); + Assert.assertEquals(shenyuDubboService.application(), dubboService.application()); + Assert.assertEquals(shenyuDubboService.module(), dubboService.module()); + Assert.assertEquals(shenyuDubboService.provider(), dubboService.provider()); + Assert.assertArrayEquals(shenyuDubboService.protocol(), dubboService.protocol()); + Assert.assertEquals(shenyuDubboService.monitor(), dubboService.monitor()); + Assert.assertArrayEquals(shenyuDubboService.registry(), dubboService.registry()); + Assert.assertEquals(shenyuDubboService.tag(), dubboService.tag()); + Assert.assertArrayEquals(shenyuDubboService.methods(), dubboService.methods()); + } + + @Test + public void serviceDefaultValue() { + Service service = ServiceTest.class.getAnnotation(Service.class); + ShenyuService shenyuService = ShenyuServiceTest.class.getAnnotation(ShenyuService.class); + + Assert.assertEquals(shenyuService.interfaceClass(), service.interfaceClass()); + Assert.assertEquals(shenyuService.interfaceName(), service.interfaceName()); + Assert.assertEquals(shenyuService.version(), service.version()); + Assert.assertEquals(shenyuService.group(), service.group()); + Assert.assertEquals(shenyuService.dubboPath(), service.path()); + Assert.assertEquals(shenyuService.export(), service.export()); + Assert.assertEquals(shenyuService.token(), service.token()); + Assert.assertEquals(shenyuService.deprecated(), service.deprecated()); + Assert.assertEquals(shenyuService.dynamic(), service.dynamic()); + Assert.assertEquals(shenyuService.accesslog(), service.accesslog()); + Assert.assertEquals(shenyuService.executes(), service.executes()); + Assert.assertEquals(shenyuService.register(), service.register()); + Assert.assertEquals(shenyuService.weight(), service.weight()); + Assert.assertEquals(shenyuService.document(), service.document()); + Assert.assertEquals(shenyuService.delay(), service.delay()); + Assert.assertEquals(shenyuService.local(), service.local()); + Assert.assertEquals(shenyuService.stub(), service.stub()); + Assert.assertEquals(shenyuService.cluster(), service.cluster()); + Assert.assertEquals(shenyuService.proxy(), service.proxy()); + Assert.assertEquals(shenyuService.connections(), service.connections()); + Assert.assertEquals(shenyuService.callbacks(), service.callbacks()); + Assert.assertEquals(shenyuService.onconnect(), service.onconnect()); + Assert.assertEquals(shenyuService.ondisconnect(), service.ondisconnect()); + Assert.assertEquals(shenyuService.owner(), service.owner()); + Assert.assertEquals(shenyuService.layer(), service.layer()); + Assert.assertEquals(shenyuService.retries(), service.retries()); + Assert.assertEquals(shenyuService.loadbalance(), service.loadbalance()); + Assert.assertEquals(shenyuService.async(), service.async()); + Assert.assertEquals(shenyuService.actives(), service.actives()); + Assert.assertEquals(shenyuService.sent(), service.sent()); + Assert.assertEquals(shenyuService.mock(), service.mock()); + Assert.assertEquals(shenyuService.validation(), service.validation()); + Assert.assertEquals(shenyuService.timeout(), service.timeout()); + Assert.assertEquals(shenyuService.cache(), service.cache()); + Assert.assertArrayEquals(shenyuService.filter(), service.filter()); + Assert.assertArrayEquals(shenyuService.listener(), service.listener()); + Assert.assertArrayEquals(shenyuService.parameters(), service.parameters()); + Assert.assertEquals(shenyuService.application(), service.application()); + Assert.assertEquals(shenyuService.module(), service.module()); + Assert.assertEquals(shenyuService.provider(), service.provider()); + Assert.assertArrayEquals(shenyuService.protocol(), service.protocol()); + Assert.assertEquals(shenyuService.monitor(), service.monitor()); + Assert.assertArrayEquals(shenyuService.registry(), service.registry()); + Assert.assertEquals(shenyuService.tag(), service.tag()); + Assert.assertArrayEquals(shenyuService.methods(), service.methods()); + } + + @ShenyuDubboService + private static class ShenyuDubboServiceTest { + + } + + @DubboService + private static class DubboServiceTest { + + } + + @Service + private static class ServiceTest { + + } + + @ShenyuService + private static class ShenyuServiceTest { + + } +}