fix: Adjusting cluster invoker checks (#12139)
* Adjustment check(#12138) * Unit test optimization * Code optimization
This commit is contained in:
parent
073a13dd9b
commit
1138b97492
|
|
@ -333,6 +333,8 @@ public abstract class AbstractClusterInvoker<T> implements ClusterInvoker<T> {
|
|||
List<Invoker<T>> invokers = list(invocation);
|
||||
InvocationProfilerUtils.releaseDetailProfiler(invocation);
|
||||
|
||||
checkInvokers(invokers, invocation);
|
||||
|
||||
LoadBalance loadbalance = initLoadBalance(invokers, invocation);
|
||||
RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ public class BroadcastClusterInvoker<T> extends AbstractClusterInvoker<T> {
|
|||
@Override
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public Result doInvoke(final Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
|
||||
checkInvokers(invokers, invocation);
|
||||
RpcContext.getServiceContext().setInvokers((List) invokers);
|
||||
RpcException exception = null;
|
||||
Result result = null;
|
||||
|
|
|
|||
|
|
@ -104,7 +104,6 @@ public class FailbackClusterInvoker<T> extends AbstractClusterInvoker<T> {
|
|||
Invoker<T> invoker = null;
|
||||
URL consumerUrl = RpcContext.getServiceContext().getConsumerUrl();
|
||||
try {
|
||||
checkInvokers(invokers, invocation);
|
||||
invoker = select(loadbalance, invocation, invokers, null);
|
||||
// Asynchronous call method must be used here, because failback will retry in the background.
|
||||
// Then the serviceContext will be cleared after the call is completed.
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ public class FailfastClusterInvoker<T> extends AbstractClusterInvoker<T> {
|
|||
|
||||
@Override
|
||||
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
|
||||
checkInvokers(invokers, invocation);
|
||||
Invoker<T> invoker = select(loadbalance, invocation, invokers, null);
|
||||
try {
|
||||
return invokeWithContext(invoker, invocation);
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ public class FailoverClusterInvoker<T> extends AbstractClusterInvoker<T> {
|
|||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public Result doInvoke(Invocation invocation, final List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
|
||||
List<Invoker<T>> copyInvokers = invokers;
|
||||
checkInvokers(copyInvokers, invocation);
|
||||
String methodName = RpcUtils.getMethodName(invocation);
|
||||
int len = calculateInvokeTimes(methodName);
|
||||
// retry loop.
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ public class FailsafeClusterInvoker<T> extends AbstractClusterInvoker<T> {
|
|||
@Override
|
||||
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
|
||||
try {
|
||||
checkInvokers(invokers, invocation);
|
||||
Invoker<T> invoker = select(loadbalance, invocation, invokers, null);
|
||||
return invokeWithContext(invoker, invocation);
|
||||
} catch (Throwable e) {
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ public class ForkingClusterInvoker<T> extends AbstractClusterInvoker<T> {
|
|||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public Result doInvoke(final Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
|
||||
try {
|
||||
checkInvokers(invokers, invocation);
|
||||
final List<Invoker<T>> selected;
|
||||
final int forks = getUrl().getParameter(FORKS_KEY, DEFAULT_FORKS);
|
||||
final int timeout = getUrl().getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ public class MergeableClusterInvoker<T> extends AbstractClusterInvoker<T> {
|
|||
|
||||
@Override
|
||||
protected Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
|
||||
checkInvokers(invokers, invocation);
|
||||
String merger = getUrl().getMethodParameter(invocation.getMethodName(), MERGER_KEY);
|
||||
if (ConfigUtils.isEmpty(merger)) { // If a method doesn't have a merger, only invoke one Group
|
||||
for (final Invoker<T> invoker : invokers) {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class AvailableClusterInvokerTest {
|
|||
invoker.invoke(invocation);
|
||||
fail();
|
||||
} catch (RpcException e) {
|
||||
Assertions.assertTrue(e.getMessage().contains("No provider available in"));
|
||||
Assertions.assertTrue(e.getMessage().contains("No provider available"));
|
||||
assertFalse(e.getCause() instanceof RpcException);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package org.apache.dubbo.rpc.cluster.support;
|
||||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.utils.LogUtil;
|
||||
import org.apache.dubbo.rpc.AppResponse;
|
||||
import org.apache.dubbo.rpc.Invoker;
|
||||
import org.apache.dubbo.rpc.Result;
|
||||
|
|
@ -25,6 +24,7 @@ import org.apache.dubbo.rpc.RpcContext;
|
|||
import org.apache.dubbo.rpc.RpcInvocation;
|
||||
import org.apache.dubbo.rpc.cluster.Directory;
|
||||
import org.apache.dubbo.rpc.cluster.filter.DemoService;
|
||||
import org.apache.dubbo.rpc.RpcException;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
|
@ -33,7 +33,7 @@ import org.junit.jupiter.api.Test;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
|
@ -113,10 +113,13 @@ class FailSafeClusterInvokerTest {
|
|||
resetInvokerToNoException();
|
||||
|
||||
FailsafeClusterInvoker<DemoService> invoker = new FailsafeClusterInvoker<DemoService>(dic);
|
||||
LogUtil.start();
|
||||
invoker.invoke(invocation);
|
||||
assertTrue(LogUtil.findMessage("No provider") > 0);
|
||||
LogUtil.stop();
|
||||
|
||||
try{
|
||||
invoker.invoke(invocation);
|
||||
} catch (RpcException e){
|
||||
Assertions.assertTrue(e.getMessage().contains("No provider available"));
|
||||
assertFalse(e.getCause() instanceof RpcException);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,10 @@ import org.apache.dubbo.common.utils.LogUtil;
|
|||
import org.apache.dubbo.rpc.AppResponse;
|
||||
import org.apache.dubbo.rpc.Invoker;
|
||||
import org.apache.dubbo.rpc.Result;
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
import org.apache.dubbo.rpc.RpcInvocation;
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
import org.apache.dubbo.rpc.cluster.Directory;
|
||||
import org.apache.dubbo.rpc.RpcException;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
|
@ -37,6 +38,7 @@ import org.junit.jupiter.api.MethodOrderer;
|
|||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -45,7 +47,7 @@ import java.util.concurrent.CountDownLatch;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.RETRIES_KEY;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
|
@ -110,6 +112,9 @@ class FailbackClusterInvokerTest {
|
|||
given(dic.getUrl()).willReturn(url);
|
||||
given(dic.getConsumerUrl()).willReturn(url);
|
||||
given(dic.getInterface()).willReturn(FailbackClusterInvokerTest.class);
|
||||
given(dic.list(invocation)).willReturn(invokers);
|
||||
given(invoker.getUrl()).willReturn(url);
|
||||
|
||||
FailbackClusterInvoker<FailbackClusterInvokerTest> invoker = new FailbackClusterInvoker<>(dic);
|
||||
invoker.invoke(invocation);
|
||||
Assertions.assertNull(RpcContext.getServiceContext().getInvoker());
|
||||
|
|
@ -123,6 +128,9 @@ class FailbackClusterInvokerTest {
|
|||
given(dic.getUrl()).willReturn(url);
|
||||
given(dic.getConsumerUrl()).willReturn(url);
|
||||
given(dic.getInterface()).willReturn(FailbackClusterInvokerTest.class);
|
||||
given(dic.list(invocation)).willReturn(invokers);
|
||||
given(invoker.getUrl()).willReturn(url);
|
||||
|
||||
FailbackClusterInvoker<FailbackClusterInvokerTest> invoker = new FailbackClusterInvoker<>(dic);
|
||||
invoker.invoke(invocation);
|
||||
Assertions.assertNull(RpcContext.getServiceContext().getInvoker());
|
||||
|
|
@ -161,17 +169,15 @@ class FailbackClusterInvokerTest {
|
|||
given(dic.getInterface()).willReturn(FailbackClusterInvokerTest.class);
|
||||
|
||||
invocation.setMethodName("method1");
|
||||
|
||||
invokers.add(invoker);
|
||||
|
||||
resetInvokerToNoException();
|
||||
|
||||
FailbackClusterInvoker<FailbackClusterInvokerTest> invoker = new FailbackClusterInvoker<>(dic);
|
||||
LogUtil.start();
|
||||
DubboAppender.clear();
|
||||
invoker.invoke(invocation);
|
||||
assertEquals(1, LogUtil.findMessage("Failback to invoke"));
|
||||
LogUtil.stop();
|
||||
try{
|
||||
invoker.invoke(invocation);
|
||||
} catch (RpcException e){
|
||||
Assertions.assertTrue(e.getMessage().contains("No provider available"));
|
||||
assertFalse(e.getCause() instanceof RpcException);
|
||||
}
|
||||
}
|
||||
|
||||
@Disabled
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.apache.dubbo.rpc.RpcException;
|
|||
import org.apache.dubbo.rpc.cluster.ClusterInvoker;
|
||||
import org.apache.dubbo.rpc.cluster.Directory;
|
||||
|
||||
import org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
@ -174,6 +175,7 @@ class ZoneAwareClusterInvokerTest {
|
|||
given(directory.getUrl()).willReturn(url);
|
||||
given(directory.getConsumerUrl()).willReturn(url);
|
||||
given(directory.list(invocation)).willReturn(new ArrayList<>(0));
|
||||
given(directory.getInterface()).willReturn(ZoneAwareClusterInvokerTest.class);
|
||||
|
||||
zoneAwareClusterInvoker = new ZoneAwareClusterInvoker<>(directory);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue