Skip to content

Commit

Permalink
Improve UT grammar and remove unnecessary braces. (#2930)
Browse files Browse the repository at this point in the history
* Improve UT grammer, fix compiler warnings.

* Remove unnecessary braces.
  • Loading branch information
ralf0131 authored and beiwei30 committed Dec 10, 2018
1 parent 833ba03 commit bb3216d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,18 @@ protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation,

boolean sticky = invokers.get(0).getUrl()
.getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY);
{
//ignore overloaded method
if (stickyInvoker != null && !invokers.contains(stickyInvoker)) {
stickyInvoker = null;
}
//ignore concurrency problem
if (sticky && stickyInvoker != null && (selected == null || !selected.contains(stickyInvoker))) {
if (availablecheck && stickyInvoker.isAvailable()) {
return stickyInvoker;
}

//ignore overloaded method
if (stickyInvoker != null && !invokers.contains(stickyInvoker)) {
stickyInvoker = null;
}
//ignore concurrency problem
if (sticky && stickyInvoker != null && (selected == null || !selected.contains(stickyInvoker))) {
if (availablecheck && stickyInvoker.isAvailable()) {
return stickyInvoker;
}
}

Invoker<T> invoker = doSelect(loadbalance, invocation, invokers, selected);

if (sticky) {
Expand Down Expand Up @@ -210,19 +210,18 @@ private Invoker<T> reselect(LoadBalance loadbalance, Invocation invocation,
}

// Just pick an available invoker using loadbalance policy
{
if (selected != null) {
for (Invoker<T> invoker : selected) {
if ((invoker.isAvailable()) // available first
&& !reselectInvokers.contains(invoker)) {
reselectInvokers.add(invoker);
}
if (selected != null) {
for (Invoker<T> invoker : selected) {
if ((invoker.isAvailable()) // available first
&& !reselectInvokers.contains(invoker)) {
reselectInvokers.add(invoker);
}
}
if (!reselectInvokers.isEmpty()) {
return loadbalance.select(reselectInvokers, getUrl(), invocation);
}
}
if (!reselectInvokers.isEmpty()) {
return loadbalance.select(reselectInvokers, getUrl(), invocation);
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public void testStaticDirectory() {
invokers.add(invoker2);
invokers.add(invoker3);
List<Invoker<String>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
StaticDirectory staticDirectory = new StaticDirectory(filteredInvokers);
Boolean isAvailable = staticDirectory.isAvailable();
StaticDirectory<String> staticDirectory = new StaticDirectory<>(filteredInvokers);
boolean isAvailable = staticDirectory.isAvailable();
Assert.assertTrue(!isAvailable);
List<Invoker> newInvokers = staticDirectory.list(new MockDirInvocation());
List<Invoker<String>> newInvokers = staticDirectory.list(new MockDirInvocation());
Assert.assertTrue(newInvokers.size() > 0);
staticDirectory.destroy();
Assert.assertTrue(newInvokers.size() == 0);
Assert.assertEquals(0, newInvokers.size());
}
}

0 comments on commit bb3216d

Please sign in to comment.