Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
2 tasks done
zonghaishang opened this issue Sep 11, 2018 · 2 comments · Fixed by #2742
Closed
2 tasks done
Assignees
Labels
type/bug Bugs to being fixed

Comments

@zonghaishang
Copy link
Member

  • 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);
    } 
       // ….
}
@zonghaishang zonghaishang added type/bug Bugs to being fixed priority/normal labels Sep 13, 2018
@zonghaishang zonghaishang self-assigned this Sep 13, 2018
@chickenlj
Copy link
Contributor

chickenlj commented Sep 19, 2018

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

jsen-joker pushed a commit to jsen-joker/incubator-dubbo that referenced this issue Sep 19, 2018
@jsen-joker
Copy link

<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>

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type/bug Bugs to being fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants