test_class.declarator: invokers = new ArrayList<Invoker<IHelloService>>()
test_class.original_string: List<Invoker<IHelloService>> invokers = new ArrayList<Invoker<IHelloService>>();
test_class.type: List<Invoker<IHelloService>>
test_class.var_name: invokers
test_class.file: dubbo-cluster/src/test/java/com/alibaba/dubbo/rpc/cluster/support/wrapper/MockClusterInvokerTest.java
test_class.identifier: MockClusterInvokerTest
test_case.body: @Test
      public void testMockInvokerInvoke_failmock() {
          URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName())
                  .addParameter(Constants.MOCK_KEY, "fail:return null")
                  .addParameter("invoke_return_error", "true");
          Invoker<IHelloService> cluster = getClusterInvoker(url);
          URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName()
                  + "?getSomething.mock=return aa").addParameters(url.getParameters());
  
          Protocol protocol = new MockProtocol();
          Invoker<IHelloService> mInvoker1 = protocol.refer(IHelloService.class, mockUrl);
          invokers.add(mInvoker1);
  
          //Configured with mock
          RpcInvocation invocation = new RpcInvocation();
          invocation.setMethodName("getSomething");
          Result ret = cluster.invoke(invocation);
          Assert.assertEquals("aa", ret.getValue());
  
          // If no mock was configured, return null directly
          invocation = new RpcInvocation();
          invocation.setMethodName("getSomething2");
          ret = cluster.invoke(invocation);
          Assert.assertEquals(null, ret.getValue());
  
          // If no mock was configured, return null directly
          invocation = new RpcInvocation();
          invocation.setMethodName("sayHello");
          ret = cluster.invoke(invocation);
          Assert.assertEquals(null, ret.getValue());
      }
test_case.class_method_signature: MockClusterInvokerTest.testMockInvokerInvoke_failmock()
test_case.full_signature: @Test public void testMockInvokerInvoke_failmock()
test_case.identifier: testMockInvokerInvoke_failmock
test_case.invocations: addParameter addParameter valueOf getName getClusterInvoker addParameters valueOf getName getParameters refer add setMethodName invoke assertEquals getValue setMethodName invoke assertEquals getValue setMethodName invoke assertEquals getValue
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testMockInvokerInvoke_failmock()
focal_class.declarator: logger = LoggerFactory.getLogger(MockClusterInvoker.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = LoggerFactory.getLogger(MockClusterInvoker.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: directory
focal_class.modifier: private final
focal_class.original_string: private final Directory<T> directory;
focal_class.type: Directory<T>
focal_class.var_name: directory
focal_class.declarator: invoker
focal_class.modifier: private final
focal_class.original_string: private final Invoker<T> invoker;
focal_class.type: Invoker<T>
focal_class.var_name: invoker
focal_class.file: dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java
focal_class.identifier: MockClusterInvoker
focal_class.interfaces: implements Invoker<T>
focal_class.class_method_signature: MockClusterInvoker.MockClusterInvoker(Directory<T> directory, Invoker<T> invoker)
focal_class.full_signature: public  MockClusterInvoker(Directory<T> directory, Invoker<T> invoker)
focal_class.identifier: MockClusterInvoker
focal_class.modifiers: public
focal_class.parameters: (Directory<T> directory, Invoker<T> invoker)
focal_class.signature:  MockClusterInvoker(Directory<T> directory, Invoker<T> invoker)
focal_class.class_method_signature: MockClusterInvoker.getUrl()
focal_class.full_signature: @Override public URL getUrl()
focal_class.identifier: getUrl
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: URL
focal_class.signature: URL getUrl()
focal_class.class_method_signature: MockClusterInvoker.isAvailable()
focal_class.full_signature: @Override public boolean isAvailable()
focal_class.identifier: isAvailable
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean isAvailable()
focal_class.class_method_signature: MockClusterInvoker.destroy()
focal_class.full_signature: @Override public void destroy()
focal_class.identifier: destroy
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void destroy()
focal_class.class_method_signature: MockClusterInvoker.getInterface()
focal_class.full_signature: @Override public Class<T> getInterface()
focal_class.identifier: getInterface
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: Class<T>
focal_class.signature: Class<T> getInterface()
focal_class.class_method_signature: MockClusterInvoker.invoke(Invocation invocation)
focal_class.full_signature: @Override public Result invoke(Invocation invocation)
focal_class.identifier: invoke
focal_class.modifiers: @Override public
focal_class.parameters: (Invocation invocation)
focal_class.return: Result
focal_class.signature: Result invoke(Invocation invocation)
focal_class.class_method_signature: MockClusterInvoker.doMockInvoke(Invocation invocation, RpcException e)
focal_class.full_signature: @SuppressWarnings({"unchecked", "rawtypes"}) private Result doMockInvoke(Invocation invocation, RpcException e)
focal_class.identifier: doMockInvoke
focal_class.modifiers: @SuppressWarnings({"unchecked", "rawtypes"}) private
focal_class.parameters: (Invocation invocation, RpcException e)
focal_class.return: Result
focal_class.signature: Result doMockInvoke(Invocation invocation, RpcException e)
focal_class.class_method_signature: MockClusterInvoker.getMockExceptionMessage(Throwable t, Throwable mt)
focal_class.full_signature: private String getMockExceptionMessage(Throwable t, Throwable mt)
focal_class.identifier: getMockExceptionMessage
focal_class.modifiers: private
focal_class.parameters: (Throwable t, Throwable mt)
focal_class.return: String
focal_class.signature: String getMockExceptionMessage(Throwable t, Throwable mt)
focal_class.class_method_signature: MockClusterInvoker.selectMockInvoker(Invocation invocation)
focal_class.full_signature: private List<Invoker<T>> selectMockInvoker(Invocation invocation)
focal_class.identifier: selectMockInvoker
focal_class.modifiers: private
focal_class.parameters: (Invocation invocation)
focal_class.return: List<Invoker<T>>
focal_class.signature: List<Invoker<T>> selectMockInvoker(Invocation invocation)
focal_class.class_method_signature: MockClusterInvoker.toString()
focal_class.full_signature: @Override public String toString()
focal_class.identifier: toString
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String toString()
focal_method.body: @Override
      public Result invoke(Invocation invocation) throws RpcException {
          Result result = null;
  
          String value = directory.getUrl().getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim();
          if (value.length() == 0 || value.equalsIgnoreCase("false")) {
              //no mock
              result = this.invoker.invoke(invocation);
          } else if (value.startsWith("force")) {
              if (logger.isWarnEnabled()) {
                  logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl());
              }
              //force:direct mock
              // 屏蔽：系统准备大型促销活动时，有目的的直接屏蔽某些不影响主业务逻辑的接口  ===> mock=force:return null
              result = doMockInvoke(invocation, null);
          } else {
              //fail-mock
              try {
                  result = this.invoker.invoke(invocation);
              } catch (RpcException e) {
                  // 容错：当系统出现非业务异常(如：高并发导致超时、网络异常等)  ===> mock=fail:return null
                  if (e.isBiz()) {
                      throw e;
                  } else {
                      if (logger.isWarnEnabled()) {
                          logger.warn("fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e);
                      }
                      result = doMockInvoke(invocation, e);
                  }
              }
          }
          return result;
      }
focal_method.class_method_signature: MockClusterInvoker.invoke(Invocation invocation)
focal_method.full_signature: @Override public Result invoke(Invocation invocation)
focal_method.identifier: invoke
focal_method.invocations: trim getMethodParameter getUrl getMethodName toString length equalsIgnoreCase invoke startsWith isWarnEnabled info getMethodName getUrl doMockInvoke invoke isBiz isWarnEnabled warn getMethodName getUrl doMockInvoke
focal_method.modifiers: @Override public
focal_method.parameters: (Invocation invocation)
focal_method.return: Result
focal_method.signature: Result invoke(Invocation invocation)