Skip to content

MockClusterInvoker provides local forced mock,I tested it locally, but it doesn't work. #2489

Closed

Description

@zonghaishang
  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 2.7.0
  • Operating System version: 2.7.0
  • Java version: 1.8

Steps to reproduce this issue

  1. Here is demo: Here is demo: https://github.com/dubbo/dubbo-samples/tree/master/dubbo-samples-mock
  2. change consumer configuraton: <dubbo:reference id="demoService" check="false" interface="com.alibaba.dubbo.samples.mock.api.DemoService" mock="force”/>

Pls. provide [GitHub address] to reproduce this issue.

Expected Result

force mock should be trigged.

Actual Result

start failed.

I have checked code(MockClusterInvoker) :

@Override
public Result invoke(Invocation invocation) throws RpcException {
    // ….
    else if (value.startsWith("force")) {
        if (logger.isWarnEnabled()) {
            logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl());
        }
        //force:direct mock
        result = doMockInvoke(invocation, null);
    } 
       // ….
}

Activity

  1. self-assigned this
    on Sep 13, 2018
  2. chickenlj commented on Sep 19, 2018

    @chickenlj
    Contributor

    When I add this configuration:

    <dubbo:reference mock="force:org.apache.dubbo.demo.consumer.DemoServiceMock" id="demoService" check="false" interface="org.apache.dubbo.demo.DemoService"/>

    the following exception occurs:

    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoService': Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
    PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'mock' threw exception; nested exception is java.lang.IllegalStateException: Invalid mock="force\:org.apache.dubbo.demo.consumer.DemoServiceMock" contains illegal character, only digit, letter, '-', '_' or '.' is legal.
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1570)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1280)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
    	at org.apache.dubbo.demo.consumer.Consumer.main(Consumer.java:31)
    Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
    PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'mock' threw exception; nested exception is java.lang.IllegalStateException: Invalid mock="force\:org.apache.dubbo.demo.consumer.DemoServiceMock" contains illegal character, only digit, letter, '-', '_' or '.' is legal.
    	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:121)
    	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1566)
    	... 13 more
  3. added a commit that references this issue on Sep 19, 2018
  4. jsen-joker commented on Sep 19, 2018

    @jsen-joker

    <dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.demo.DemoService" mock="true">
    <dubbo:method name="sayHello" />
    </dubbo:reference>

    or

    <dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.demo.DemoService" mock="org.apache.dubbo.demo.DemoServiceMock">
    <dubbo:method name="sayHello" />
    </dubbo:reference>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions