Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
46 changed files
with
373 additions
and
640 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -4,4 +4,6 @@ | ||
* Created by ken.lj on 2017/9/24. | ||
*/ | ||
public interface AsyncService { | ||
|
||
String asyncMethod(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,24 @@ | ||
package com.alibaba.dubbo.test.web; | ||
|
||
import com.alibaba.dubbo.config.annotation.Reference; | ||
import com.alibaba.dubbo.test.service.AnnotateService; | ||
|
||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* @author ken.lj | ||
* @date 2017/09/10 | ||
*/ | ||
@RestController("annotation") | ||
public class AnnotationParentReferenceController extends BaseController<AnnotateService> { | ||
|
||
@Reference | ||
public AnnotateService annotateServiceSub; | ||
|
||
@RequestMapping("/subclass") | ||
String subHello() { | ||
return annotateServiceSub.sayHello(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,31 @@ | ||
package com.alibaba.dubbo.test.web; | ||
|
||
import com.alibaba.dubbo.rpc.RpcContext; | ||
import com.alibaba.dubbo.test.service.AsyncService; | ||
|
||
import org.junit.Assert; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.concurrent.Future; | ||
|
||
/** | ||
* @author ken.lj | ||
* @date 2017/11/3 | ||
*/ | ||
@RestController | ||
@RequestMapping("/async") | ||
public class AsyncController { | ||
@Autowired(required = false) | ||
private AsyncService asyncService; | ||
|
||
@RequestMapping("/hello") | ||
public String testSimple() throws Exception { | ||
String result = asyncService.asyncMethod(); | ||
Assert.assertNull(result); | ||
Future<String> future = RpcContext.getContext().getFuture(); | ||
|
||
return future.get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,42 @@ | ||
package com.alibaba.dubbo.test.web; | ||
|
||
import com.alibaba.dubbo.rpc.service.GenericService; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author ken.lj | ||
* @date 2017/11/3 | ||
*/ | ||
@RestController | ||
@RequestMapping("/simple") | ||
public class GenericReferenceController implements ApplicationContextAware { | ||
|
||
private ApplicationContext context; | ||
|
||
@RequestMapping("/reference/generic") | ||
public String testReferenceGeneric() { | ||
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}); | ||
return "generic"; | ||
} | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
this.context = applicationContext; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.