Skip to content

Commit

Permalink
[type:fix] Make the default value of ShenyuDubboService annotation eq…
Browse files Browse the repository at this point in the history
…ual to that of DubboService annotation
  • Loading branch information
eye-gu committed Nov 27, 2024
1 parent 3c36999 commit d65eb66
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -170,7 +167,7 @@
* @return the int
*/
@AliasFor(annotation = DubboService.class)
int executes() default 0;
int executes() default -1;

/**
* Alias for {@link DubboService#register()} .
Expand All @@ -186,7 +183,7 @@
* @return the int
*/
@AliasFor(annotation = DubboService.class)
int weight() default 0;
int weight() default -1;

/**
* Alias for {@link DubboService#document()} .
Expand All @@ -202,7 +199,7 @@
* @return the int
*/
@AliasFor(annotation = DubboService.class)
int delay() default 0;
int delay() default -1;

/**
* Alias for {@link DubboService#local()} .
Expand Down Expand Up @@ -242,15 +239,15 @@
* @return the int
*/
@AliasFor(annotation = DubboService.class)
int connections() default 0;
int connections() default -1;

/**
* Alias for {@link DubboService#callbacks()} .
*
* @return the int
*/
@AliasFor(annotation = DubboService.class)
int callbacks() default DEFAULT_CALLBACK_INSTANCES;
int callbacks() default -1;

/**
* Alias for {@link DubboService#onconnect()} .
Expand Down Expand Up @@ -290,15 +287,15 @@
* @return the int
*/
@AliasFor(annotation = DubboService.class)
int retries() default DEFAULT_RETRIES;
int retries() default -1;

/**
* Alias for {@link DubboService#loadbalance()} .
*
* @return the string
*/
@AliasFor(annotation = DubboService.class)
String loadbalance() default LoadbalanceRules.RANDOM;
String loadbalance() default LoadbalanceRules.EMPTY;

/**
* Alias for {@link DubboService#async()} .
Expand All @@ -314,7 +311,7 @@
* @return the int
*/
@AliasFor(annotation = DubboService.class)
int actives() default 0;
int actives() default -1;

/**
* Alias for {@link DubboService#sent()} .
Expand Down Expand Up @@ -346,7 +343,7 @@
* @return the int
*/
@AliasFor(annotation = DubboService.class)
int timeout() default 0;
int timeout() default -1;

/**
* Alias for {@link DubboService#cache()} .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -170,7 +166,7 @@
* @return the int
*/
@AliasFor(annotation = Service.class)
int executes() default 0;
int executes() default -1;

/**
* Alias for {@link Service#register()} .
Expand All @@ -186,7 +182,7 @@
* @return the int
*/
@AliasFor(annotation = Service.class)
int weight() default 0;
int weight() default -1;

/**
* Alias for {@link Service#document()} .
Expand All @@ -202,7 +198,7 @@
* @return the int
*/
@AliasFor(annotation = Service.class)
int delay() default 0;
int delay() default -1;

/**
* Alias for {@link Service#local()} .
Expand Down Expand Up @@ -242,15 +238,15 @@
* @return the int
*/
@AliasFor(annotation = Service.class)
int connections() default 0;
int connections() default -1;

/**
* Alias for {@link Service#callbacks()} .
*
* @return the int
*/
@AliasFor(annotation = Service.class)
int callbacks() default DEFAULT_CALLBACK_INSTANCES;
int callbacks() default -1;

/**
* Alias for {@link Service#onconnect()} .
Expand Down Expand Up @@ -290,15 +286,15 @@
* @return the int
*/
@AliasFor(annotation = Service.class)
int retries() default DEFAULT_RETRIES;
int retries() default -1;

/**
* Alias for {@link Service#loadbalance()} .
*
* @return the string
*/
@AliasFor(annotation = Service.class)
String loadbalance() default LoadbalanceRules.RANDOM;
String loadbalance() default "";

/**
* Alias for {@link Service#async()} .
Expand All @@ -314,7 +310,7 @@
* @return the int
*/
@AliasFor(annotation = Service.class)
int actives() default 0;
int actives() default -1;

/**
* Alias for {@link Service#sent()} .
Expand Down Expand Up @@ -346,7 +342,7 @@
* @return the int
*/
@AliasFor(annotation = Service.class)
int timeout() default 0;
int timeout() default -1;

/**
* Alias for {@link Service#cache()} .
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

}
}

0 comments on commit d65eb66

Please sign in to comment.