-
Notifications
You must be signed in to change notification settings - Fork 26.4k
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
enhance unit test #2920
enhance unit test #2920
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ | |
import org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance; | ||
import org.apache.dubbo.rpc.cluster.router.script.ScriptRouter; | ||
import org.apache.dubbo.rpc.cluster.router.script.ScriptRouterFactory; | ||
|
||
import org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
@@ -1014,6 +1014,37 @@ public void test_Notified_acceptProtocol2() { | |
List<Invoker<DemoService>> invokers = registryDirectory.list(invocation); | ||
Assert.assertEquals(2, invokers.size()); | ||
} | ||
|
||
@Test | ||
public void test_Notified_withGroupFilter() { | ||
URL directoryUrl = noMeaningUrl.addParameterAndEncoded(Constants.REFER_KEY, "interface" + service + "&group=group1,group2"); | ||
RegistryDirectory directory = this.getRegistryDirectory(directoryUrl); | ||
URL provider1 = URL.valueOf("dubbo://10.134.108.1:20880?methods=getXXX&group=group1&mock=false"); | ||
URL provider2 = URL.valueOf("dubbo://10.134.108.1:20880?methods=getXXX&group=group2&mock=false"); | ||
|
||
List<URL> providers = new ArrayList<>(); | ||
providers.add(provider1); | ||
providers.add(provider2); | ||
directory.notify(providers); | ||
|
||
invocation = new RpcInvocation(); | ||
invocation.setMethodName("getXXX"); | ||
lixiaojiee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
List<Invoker<DemoService>> invokers = directory.list(invocation); | ||
|
||
Assert.assertEquals(2, invokers.size()); | ||
Assert.assertTrue(invokers.get(0) instanceof MockClusterInvoker); | ||
Assert.assertTrue(invokers.get(1) instanceof MockClusterInvoker); | ||
|
||
directoryUrl = noMeaningUrl.addParameterAndEncoded(Constants.REFER_KEY, "interface" + service + "&group=group1"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. group1 can be also defined a variable so that it can be reuse here, so in future even we change value of it, it would be a single place change only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I appreciate your spirit of code refinement, we should code with specification,and I also found that some unit tests were not written in strict accordance with the code specification,I wonder if we have any hard and fast rules for coding unit tests @carryxyh There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lixiaojiee Would you please bring your question to the dev mailing list, we can discuss it there. For now, it looks good to me. I will merge it. |
||
directory = this.getRegistryDirectory(directoryUrl); | ||
directory.notify(providers); | ||
|
||
invokers = directory.list(invocation); | ||
|
||
Assert.assertEquals(2, invokers.size()); | ||
Assert.assertFalse(invokers.get(0) instanceof MockClusterInvoker); | ||
Assert.assertFalse(invokers.get(1) instanceof MockClusterInvoker); | ||
} | ||
|
||
enum Param { | ||
MORGAN, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you feel it below mention way could be a better approach
URL provider1=URL.valueOf("dubbo://10.134.108.1:20880")
.addParameter("methods", "getXXX")
.addParameter("group", "group1")
.addParameter("mock","false");
This might give better readability and might prevent accidental mistake of placing url escape character.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your approach is clear, but I think the simpler the code, the better.