Skip to content

Commit

Permalink
Fix test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjboy committed Apr 11, 2018
1 parent c9242bb commit ffe0cc9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ before_install:
&& /bin/bash zookeeper-3.4.11/bin/zkServer.sh start

install:
- mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -U -e
- mvn clean install -DskipTests=true -B -U -e
- sh ./tools/check_format.sh

script:
- sh ./tools/check_format.sh
- mvn test -Plocal
- mvn clean package -Plocal -Dmaven.javadoc.skip=true

after_success:
- bash <(curl -s https://codecov.io/bash)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.alipay.sofa.rpc.config.RegistryConfig;
import com.alipay.sofa.rpc.config.ServerConfig;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
Expand All @@ -39,4 +40,12 @@ public class DubboSingleton {
*/
final static ConcurrentHashMap<RegistryConfig, com.alibaba.dubbo.config.RegistryConfig> REGISTRY_MAP = new ConcurrentHashMap<RegistryConfig, com.alibaba.dubbo.config.RegistryConfig>();

/**
* Destroy all dubbo resources
*/
public static void destroyAll() {
for (Map.Entry<ServerConfig, ProtocolConfig> entry : SERVER_MAP.entrySet()) {
entry.getValue().destory();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
import com.alipay.sofa.rpc.config.ServerConfig;
import com.alipay.sofa.rpc.context.RpcInternalContext;
import com.alipay.sofa.rpc.context.RpcInvokeContext;
import com.alipay.sofa.rpc.context.RpcRunningState;
import com.alipay.sofa.rpc.context.RpcRuntimeContext;
import org.junit.After;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.ArrayList;
Expand All @@ -68,7 +70,7 @@ public void testSync() {
// 只有1个线程 执行
ServerConfig serverConfig = new ServerConfig()
.setStopTimeout(60000)
.setPort(22222)
.setPort(20880)
.setProtocol("dubbo")
.setQueues(100).setCoreThreads(1).setMaxThreads(2);

Expand All @@ -88,7 +90,7 @@ public void testSync() {
clientApplication.setAppName("client");
consumerConfig = new ConsumerConfig<DemoService>()
.setInterfaceId(DemoService.class.getName())
.setDirectUrl("dubbo://127.0.0.1:22222")
.setDirectUrl("dubbo://127.0.0.1:20880")
.setBootstrap("dubbo")
.setTimeout(30000)
.setRegister(false).setProtocol("dubbo").setApplication(clientApplication);
Expand All @@ -105,7 +107,7 @@ public void testOneWay() {
// 只有1个线程 执行
ServerConfig serverConfig = new ServerConfig()
.setStopTimeout(60000)
.setPort(22222)
.setPort(20880)
.setProtocol("dubbo")
.setQueues(100).setCoreThreads(1).setMaxThreads(2);

Expand Down Expand Up @@ -133,7 +135,7 @@ public void testOneWay() {
methodConfigs.add(methodConfig);
consumerConfig = new ConsumerConfig<DemoService>()
.setInterfaceId(DemoService.class.getName())
.setDirectUrl("dubbo://127.0.0.1:22222")
.setDirectUrl("dubbo://127.0.0.1:20880")
.setTimeout(30000)
.setRegister(false)
.setProtocol("dubbo")
Expand All @@ -153,7 +155,7 @@ public void testFuture() {
// 只有1个线程 执行
ServerConfig serverConfig = new ServerConfig()
.setStopTimeout(60000)
.setPort(22222)
.setPort(20880)
.setProtocol("dubbo")
.setQueues(100).setCoreThreads(1).setMaxThreads(2);

Expand All @@ -178,7 +180,7 @@ public void testFuture() {
methodConfig.setName("sayHello");
consumerConfig = new ConsumerConfig<DemoService>()
.setInterfaceId(DemoService.class.getName())
.setDirectUrl("dubbo://127.0.0.1:22222")
.setDirectUrl("dubbo://127.0.0.1:20880")
.setTimeout(30000)
.setRegister(false).setProtocol("dubbo")
.setBootstrap("dubbo")
Expand Down Expand Up @@ -206,8 +208,14 @@ public void testFuture() {

}

@BeforeClass
public static void adBeforeClass() {
RpcRunningState.setUnitTestMode(true);
}

@After
public void aferMethod() {
public void afterMethod() {
DubboSingleton.destroyAll();
RpcRuntimeContext.destroy();
RpcInternalContext.removeAllContext();
RpcInvokeContext.removeContext();
Expand Down
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<detectOfflineLinks>true</detectOfflineLinks>
<additionalparam>-Xdoclint:none</additionalparam>
<breakiterator>true</breakiterator>
<author>false</author>
<keywords>true</keywords>
Expand Down Expand Up @@ -216,4 +215,16 @@
</plugins>
</build>

<profiles>
<profile>
<id>jdk8</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<properties>
<maven.javadoc.failOnError>false</maven.javadoc.failOnError>
<maven.javadoc.quiet>true</maven.javadoc.quiet>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@
import com.alipay.sofa.rpc.config.ServerConfig;
import com.alipay.sofa.rpc.context.RpcInternalContext;
import com.alipay.sofa.rpc.context.RpcInvokeContext;
import com.alipay.sofa.rpc.context.RpcRunningState;
import com.alipay.sofa.rpc.context.RpcRuntimeContext;
import com.alipay.sofa.rpc.test.HelloService;
import com.alipay.sofa.rpc.test.HelloServiceImpl;
import org.junit.After;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.ArrayList;
Expand All @@ -61,7 +63,7 @@ public void testRegistrySync() {
// 只有1个线程 执行
ServerConfig serverConfig = new ServerConfig()
.setStopTimeout(60000)
.setPort(22222)
.setPort(20880)
.setProtocol("dubbo")
.setQueues(100).setCoreThreads(1).setMaxThreads(2).setHost(SystemInfo.getLocalHost());

Expand Down Expand Up @@ -106,8 +108,14 @@ public void testRegistrySync() {
Assert.assertNotNull(result);
}

@BeforeClass
public static void adBeforeClass() {
RpcRunningState.setUnitTestMode(true);
}

@After
public void aferMethod() {
DubboSingleton.destroyAll();
RpcRuntimeContext.destroy();
RpcInternalContext.removeAllContext();
RpcInvokeContext.removeContext();
Expand Down

0 comments on commit ffe0cc9

Please sign in to comment.