Skip to content
Permalink
Browse files
增加Generic泛化调用测试场景
  • Loading branch information
chickenlj committed Oct 22, 2017
1 parent 06af87f commit 3d5f0af28898217bcb4bd6fbf7bc022eea8dc19d
Showing 16 changed files with 121 additions and 14 deletions.
@@ -0,0 +1,10 @@
package com.alibaba.dubbo.test.dto;

import java.util.HashMap;

/**
* @author ken.lj
* @date 2017/10/20
*/
public class SubMap extends HashMap<String, Object> {
}
@@ -1,9 +1,11 @@
package com.alibaba.dubbo.test.service;

import com.alibaba.dubbo.test.dto.Bean;
import com.alibaba.dubbo.test.dto.SubMap;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Created by ken.lj on 2017/9/24.
@@ -17,6 +19,8 @@ public interface DemoService {

Map<String, Object> testMap(Map<String, Object> map);

Map<String, Object> testTelnetSubMap(SubMap subMap);

/*LocalDateTime testJava8Time(LocalDateTime instant);
ZonedDateTime testJava8Time(ZonedDateTime zonedDateTime);*/
@@ -42,6 +42,11 @@
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>

<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
@@ -1,5 +1,6 @@
package com.alibaba.dubbo.test.web;

import com.alibaba.dubbo.rpc.service.GenericService;
import com.alibaba.dubbo.test.dto.Bean;
import com.alibaba.dubbo.test.service.AnnotateService;
import com.alibaba.dubbo.test.service.AsyncService;
@@ -8,21 +9,27 @@
import com.alibaba.dubbo.test.service.WSService;

import org.junit.Assert;
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.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Created by ken.lj on 2017/9/25.
*/
@RestController
@RequestMapping("/testcase")
public class TestcaseController {
public class TestcaseController implements ApplicationContextAware{
private ApplicationContext context;

@Autowired
private DemoService demoService;
@@ -87,6 +94,23 @@ public String testAnnotate() {
return "annotate";
}

@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;
}

/* @RequestMapping("/java8time")
public String testJava8Time() {
LocalDateTime localDateTime = LocalDateTime.now();
@@ -24,9 +24,9 @@
<dubbo:application name="dubbo-feature-test" />

<!-- 使用multicast广播注册中心暴露服务地址 -->
<dubbo:registry client="curator" address="zookeeper://11.160.112.23:2181?backup=11.239.190.141:2181,11.239.172.213:2181"/>
<dubbo:registry client="curator" address="zookeeper://127.0.0.1:2181"/>

<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="-1"/>
<dubbo:protocol name="dubbo" port="-1" transporter="mina"/>

</beans>
@@ -32,4 +32,6 @@

<dubbo:reference id="annotateService" interface="com.alibaba.dubbo.test.service.AnnotateService" />

<dubbo:reference id="genericTestService" generic="true" interface="com.alibaba.dubbo.test.service.GenericTestService" />

</beans>
@@ -50,7 +50,7 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.6-SNAPSHOT</version>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
@@ -67,6 +67,11 @@
<artifactId>curator-framework</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.31</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
@@ -23,8 +23,13 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
@@ -42,10 +47,20 @@
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
@@ -0,0 +1,13 @@
package com.alibaba.dubbo.test.service;

import java.util.Map;
import java.util.Set;

/**
* @author ken.lj
* @date 2017/10/22
*/
public interface GenericTestService {

public void testGenericWithJsonSerialization(Map<String, Set<String>> params);
}
@@ -3,14 +3,16 @@
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.test.service.AnnotateService;

import org.springframework.transaction.annotation.Transactional;


/**
* Created by ken.lj on 2017/9/19.
*/
@org.springframework.stereotype.Service
@Service
public class AnnotateServiceImpl implements AnnotateService {
@Override
@Transactional
public String sayHello() {
return "Hello";
}
@@ -1,10 +1,12 @@
package com.alibaba.dubbo.test.service.impl;

import com.alibaba.dubbo.test.dto.Bean;
import com.alibaba.dubbo.test.dto.SubMap;
import com.alibaba.dubbo.test.service.DemoService;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Created by ken.lj on 2017/9/24.
@@ -30,6 +32,11 @@ public Map<String, Object> testMap(Map<String, Object> map) {
return map;
}

@Override
public Map<String, Object> testTelnetSubMap(SubMap subMap) {
return subMap;
}

/*@Override
public LocalDateTime testJava8Time(LocalDateTime instant) {
return instant;
@@ -0,0 +1,18 @@
package com.alibaba.dubbo.test.service.impl;

import com.alibaba.dubbo.test.service.GenericTestService;

import java.util.Map;
import java.util.Set;

/**
* @author ken.lj
* @date 2017/10/22
*/
public class GenericTestServiceImpl implements GenericTestService {
@Override
public void testGenericWithJsonSerialization(Map<String, Set<String>> params) {
Set<String> set = params.get("key");
System.out.print(set);
}
}
@@ -22,11 +22,10 @@
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<dubbo:annotation package="com.alibaba.dubbo.test.service"/>

<bean id="mouseService" class="com.alibaba.dubbo.MouseServiceImpl" />
<context:component-scan base-package="com.alibaba.dubbo.test.service"> </context:component-scan>

<dubbo:annotation />

<context:component-scan base-package="com.alibaba.dubbo.test.service"> </context:component-scan>

</beans>
@@ -21,12 +21,11 @@
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="dubbo-feature-test" />

<!-- 使用multicast广播注册中心暴露服务地址 -->
<dubbo:registry client="curator" address="zookeeper://11.160.112.23:2181?backup=11.239.190.141:2181,11.239.172.213:2181"/>
<dubbo:registry client="curator" address="zookeeper://127.0.0.1:2181"/>

<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="-1" transporter="netty"/>
<dubbo:protocol name="dubbo" port="-1" transporter="netty4" />

</beans>
@@ -20,7 +20,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

<dubbo:provider delay="-1"/>
<dubbo:provider delay="-1" protocol="" serialization="fastjson"/>

<dubbo:service interface="com.alibaba.dubbo.test.service.DemoService" ref="demoService"/>

@@ -31,11 +31,13 @@
<dubbo:service interface="com.alibaba.dubbo.test.service.WSService" ref="wsService"/>

<dubbo:service interface="com.alibaba.dubbo.test.service.AnnotateService" ref="annotateService"/>
<dubbo:service interface="com.alibaba.dubbo.test.service.GenericTestService" ref="genericTestService"/>

<bean id="demoService" class="com.alibaba.dubbo.test.service.impl.DemoServiceImpl" />
<bean id="asyncService" class="com.alibaba.dubbo.test.service.impl.AsycServiceImpl" />
<bean id="cacheService" class="com.alibaba.dubbo.test.service.impl.CacheServiceImpl" />
<bean id="wsService" class="com.alibaba.dubbo.test.service.impl.WSServiceImpl" />
<bean id="annotateService" class="com.alibaba.dubbo.test.service.impl.AnnotateServiceImpl" />
<bean id="genericTestService" class="com.alibaba.dubbo.test.service.impl.GenericTestServiceImpl" />

</beans>
@@ -0,0 +1,2 @@
dubbo.application.dump.directory=/home/ken.lj
dubbo.application.name=xxx

0 comments on commit 3d5f0af

Please sign in to comment.