dubbo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] apel-apel commented on issue #1498: 服务端崩溃,报RpcException(Forbid consumer)时,mock无效
Date Thu, 22 Mar 2018 04:03:09 GMT
apel-apel commented on issue #1498: 服务端崩溃,报RpcException(Forbid consumer)时,mock无效
URL: https://github.com/apache/incubator-dubbo/issues/1498#issuecomment-375172819
 
 
   ### similar question
   I feel that the mock is not work,this is my spring xml config about dubbo below:
   
   provider.xml
   ```xml 
   <!-- provider's application name, used for tracing dependency relationship -->
       <dubbo:application name="demo-provider"/>
   
       <!-- use multicast registry center to export service -->
       <dubbo:registry address="multicast://224.5.6.7:1234"/>
   
       <!-- use dubbo protocol to export service on port 20880 -->
       <dubbo:protocol name="dubbo" port="20880"/>
   
       <!-- service implementation, as same as regular local bean -->
       <bean id="demoService" class="com.alibaba.dubbo.demo.provider.DemoServiceImpl"/>
   
       <!-- declare the service interface to be exported -->
       <!--<dubbo:service interface="com.alibaba.dubbo.demo.DemoService" mock="com.alibaba.dubbo.demo.DemoServiceMock"/>-->
       <dubbo:service interface="com.alibaba.dubbo.demo.DemoService" ref="demoService"
mock="com.alibaba.dubbo.demo.DemoServiceMock" />
   ```
   consumer.xml
   ```xml
   <!-- consumer's application name, used for tracing dependency relationship (not a matching
criterion),
       don't set it same as provider -->
       <dubbo:application name="demo-consumer"/>
   
       <!-- use multicast registry center to discover service -->
       <dubbo:registry address="multicast://224.5.6.7:1234"/>
   
       <!-- generate proxy for the remote service, then demoService can be used in the
same way as the
       local regular interface -->
       <dubbo:reference id="demoService" check="false" interface="com.alibaba.dubbo.demo.DemoService"
/>
   ```
   my provider obviously throw a RpcExcepton, and I expect the mock result return, but consumer
still throws the exception;
   
   my provider class:
   ```java
   public class DemoServiceImpl implements DemoService {
   
       public String sayHello(String name) {
           System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) +
"] Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
           if (true) {
               throw new RpcException("system error");
           }
           return "Hello " + name + ", response form provider: " + RpcContext.getContext().getLocalAddress();
       }
   
   }
   ```
   
   my mock class:
   ```java
   public class DemoServiceMock implements DemoService {
   
       public DemoServiceMock() {
       }
   
       @Override
       public String sayHello(String name) {
           return "I am mock";
       }
   }
   ```
   
   is there something wrong?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message