Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[type:fix] Make the default value of ShenyuDubboService annotation equal to that of DubboService annotation #5816

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between -1 and 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@eye-gu eye-gu Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the default values consistent can make the behavior of two annotations consistent. Even if there is currently no difference between the two, they are still compatible with Dubbo's future modifications

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good job.


/**
* 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why empty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default value for DubboService annotation. Empty and random are different. If the configuration file specifies load balancing is RoundRobin, then the final result for Empty is RoundRobin.


/**
* 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 {

}
}
Loading