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

enhance unit test #2920

Merged
merged 1 commit into from
Dec 8, 2018
Merged
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 @@ -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;
Expand Down Expand Up @@ -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");
Copy link
Contributor

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.

Copy link
Contributor Author

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.

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");
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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,
Expand Down