-
Notifications
You must be signed in to change notification settings - Fork 5
/
DubboServiceTestRunner.java
82 lines (69 loc) · 2.41 KB
/
DubboServiceTestRunner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.alibaba.dubbo.test;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.rpc.service.GenericService;
import com.alibaba.dubbo.test.service.AnnotateService;
import com.alibaba.dubbo.test.service.AsyncService;
import com.alibaba.dubbo.test.service.DemoService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* 自动执行一遍所有服务调用
*
* @author ken.lj
* @date 2017/11/3
*/
@Service
public class DubboServiceTestRunner implements ApplicationContextAware {
Logger logger = LoggerFactory.getLogger(DubboServiceTestRunner.class);
private ApplicationContext context;
@Autowired
private DemoService demoService;
@Autowired
private AsyncService asyncService;
@Reference
private AnnotateService annotateService;
@PostConstruct
public void start() {
logger.info("****** start testcase! ******");
try {
runSimple();
runAync();
runAnnotate();
runGeneric();
} catch (Throwable t) {
logger.error("有测试用例报错,请检查!", t);
}
}
public void runSimple() {
demoService.testString("string param");
}
public void runAync() {
asyncService.asyncMethod();
}
public void runAnnotate() {
annotateService.sayHello();
}
public void runGeneric() {
GenericService genericService = (GenericService) context.getBean("genericTestService");
Map<String, Set<String>> map = new HashMap<String, Set<String>>();
Set<String> set = new HashSet<String>();
set.add("v1");
set.add("v2");
map.put("key", set);
Object result = genericService.$invoke("testGenericWithJsonSerialization", new String[]{"java.util.Map"}, new Object[]{map});
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.context = applicationContext;
}
}