Skip to content

Commit

Permalink
add codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
rayzhang0603 committed Feb 18, 2025
1 parent a9f706b commit 3f64beb
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 102 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Workflow for Codecov
on: [ push, pull_request ]
jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8
- name: Install dependencies
run: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
- name: Run tests and collect coverage
run: mvn -B test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
1 change: 0 additions & 1 deletion .travis.yml

This file was deleted.

4 changes: 3 additions & 1 deletion motan-benchmark/motan-benchmark-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>src/main/assembly/assembly.xml</descriptor>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
Expand Down
4 changes: 3 additions & 1 deletion motan-benchmark/motan-benchmark-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>src/main/assembly/assembly.xml</descriptor>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,105 +15,103 @@
*/
package com.weibo.api.motan.serialize.protobuf;

import com.weibo.api.motan.exception.MotanBizException;
import com.weibo.api.motan.exception.MotanServiceException;
import com.weibo.api.motan.serialize.ProtobufSerialization;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.weibo.api.motan.config.ProtocolConfig;
import com.weibo.api.motan.config.RefererConfig;
import com.weibo.api.motan.config.RegistryConfig;
import com.weibo.api.motan.config.ServiceConfig;
import com.weibo.api.motan.exception.MotanBizException;
import com.weibo.api.motan.exception.MotanServiceException;
import com.weibo.api.motan.serialize.protobuf.gen.UserProto.Address;
import com.weibo.api.motan.serialize.protobuf.gen.UserProto.User;

import java.io.IOException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class TestProtoBuf {
private ServiceConfig<HelloService> serviceConfig;
private RefererConfig<HelloService> refererConfig;
private HelloService service;

@Before
public void setUp() throws InterruptedException {
ProtocolConfig protocolConfig = new ProtocolConfig();
protocolConfig.setId("testMotan");
protocolConfig.setName("motan");
protocolConfig.setSerialization("protobuf");
protocolConfig.setCodec("motan");

RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("127.0.0.1");
registryConfig.setPort(8002);

serviceConfig = new ServiceConfig<>();
serviceConfig.setRef(new HelloServiceImpl());
serviceConfig.setInterface(HelloService.class);
serviceConfig.setProtocol(protocolConfig);
serviceConfig.setExport("testMotan:18002");
serviceConfig.setRegistry(registryConfig);
serviceConfig.setShareChannel(true);
serviceConfig.export();

refererConfig = new RefererConfig<>();
refererConfig.setDirectUrl("127.0.0.1:18002");
refererConfig.setProtocol(protocolConfig);
refererConfig.setInterface(HelloService.class);

service = refererConfig.getRef();
Thread.sleep(20L);
}

@Test
public void testPrimitiveType() {
Assert.assertEquals("-1", service.sumAsString(Integer.MAX_VALUE, Integer.MIN_VALUE));
Assert.assertEquals("-1", service.sumAsString(-2, 1));
Assert.assertEquals((Long) 100L, service.boxIfNotZero(100));
Assert.assertNull(service.boxIfNotZero(0));
}

@Test
public void testException() {
try {
service.testException();
Assert.fail("should throw MotanServiceException");
} catch (MotanServiceException mse){
Assert.assertTrue(mse.getMessage().contains(MotanBizException.class.getName()));
Assert.assertTrue(mse.getMessage().contains("provider call process error"));
}
}

@Test
public void testNull() {
Assert.assertTrue(service.isNull(null));

User user = User.newBuilder().setId(120).setName("zhou").build();

Assert.assertFalse(service.isNull(user));
}

@Test
public void testProtobuf() {
Address address = service.queryByUid(1);
Assert.assertEquals(1, address.getId());

User user = User.newBuilder().setId(120).setName("zhou").setGender(false).addAddress(address).build();

Assert.assertTrue(service.isUserAddress(user, address));

User newOne = service.copy(user);
Assert.assertEquals(user.getId(), newOne.getId());
Assert.assertEquals(user.getName(), newOne.getName());
Assert.assertEquals(user.getGender(), newOne.getGender());
Assert.assertEquals(user.getAddress(0).getId(), newOne.getAddress(0).getId());
}

@After
public void tearDown() {
refererConfig.destroy();
serviceConfig.unexport();
}
private ServiceConfig<HelloService> serviceConfig;
private RefererConfig<HelloService> refererConfig;
private HelloService service;

@Before
public void setUp() throws InterruptedException {
ProtocolConfig protocolConfig = new ProtocolConfig();
protocolConfig.setId("testMotan");
protocolConfig.setName("motan");
protocolConfig.setSerialization("protobuf");
protocolConfig.setCodec("motan");

RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("127.0.0.1");
registryConfig.setPort(8002);

serviceConfig = new ServiceConfig<>();
serviceConfig.setRef(new HelloServiceImpl());
serviceConfig.setInterface(HelloService.class);
serviceConfig.setProtocol(protocolConfig);
serviceConfig.setExport("testMotan:18002");
serviceConfig.setRegistry(registryConfig);
serviceConfig.setShareChannel(true);
serviceConfig.export();

refererConfig = new RefererConfig<>();
refererConfig.setDirectUrl("127.0.0.1:18002");
refererConfig.setProtocol(protocolConfig);
refererConfig.setInterface(HelloService.class);
// 设置超时时间为1秒
refererConfig.setRequestTimeout(1000);

service = refererConfig.getRef();
Thread.sleep(20L);
}

@Test
public void testPrimitiveType() {
Assert.assertEquals("-1", service.sumAsString(Integer.MAX_VALUE, Integer.MIN_VALUE));
Assert.assertEquals("-1", service.sumAsString(-2, 1));
Assert.assertEquals((Long) 100L, service.boxIfNotZero(100));
Assert.assertNull(service.boxIfNotZero(0));
}

@Test
public void testException() {
try {
service.testException();
Assert.fail("should throw MotanServiceException");
} catch (MotanServiceException mse) {
Assert.assertTrue(mse.getMessage().contains(MotanBizException.class.getName()));
Assert.assertTrue(mse.getMessage().contains("provider call process error"));
}
}

@Test
public void testNull() {
Assert.assertTrue(service.isNull(null));

User user = User.newBuilder().setId(120).setName("zhou").build();

Assert.assertFalse(service.isNull(user));
}

@Test
public void testProtobuf() {
Address address = service.queryByUid(1);
Assert.assertEquals(1, address.getId());

User user = User.newBuilder().setId(120).setName("zhou").setGender(false).addAddress(address).build();

Assert.assertTrue(service.isUserAddress(user, address));

User newOne = service.copy(user);
Assert.assertEquals(user.getId(), newOne.getId());
Assert.assertEquals(user.getName(), newOne.getName());
Assert.assertEquals(user.getGender(), newOne.getGender());
Assert.assertEquals(user.getAddress(0).getId(), newOne.getAddress(0).getId());
}

@After
public void tearDown() {
refererConfig.destroy();
serviceConfig.unexport();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public class MeshRegistryTest {

@Before
public void setUp() throws Exception {
//开关默认值
MotanSwitcherUtil.setSwitcherValue(MeshRegistry.MESH_REGISTRY_SWITCHER_NAME, true);
MotanSwitcherUtil.setSwitcherValue(MeshRegistry.MESH_REGISTRY_HEALTH_CHECK_SWITCHER_NAME, true);

copy = 3; //默认副本数
requestTimeout = 100;
URL agentMockUrl = new URL("motan2", "localhost", 0, "testpath", new HashMap<>());
Expand All @@ -83,9 +87,7 @@ public void setUp() throws Exception {
//因为测试流程原因,单测时需要手动触发健康检测
registry.initHealthCheck();

//开关默认值
MotanSwitcherUtil.setSwitcherValue(MeshRegistry.MESH_REGISTRY_SWITCHER_NAME, true);
MotanSwitcherUtil.setSwitcherValue(MeshRegistry.MESH_REGISTRY_HEALTH_CHECK_SWITCHER_NAME, true);

}

@Test
Expand Down Expand Up @@ -120,12 +122,13 @@ public void testDoSubscribe() throws Exception {
assertEquals(notifyListener.urls.get(0).getGroup(), subUrl.getGroup());

// 验证降级开关
Thread.sleep(50l); // 等待proxyRegistry的notify
MotanSwitcherUtil.setSwitcherValue(MeshRegistry.MESH_REGISTRY_SWITCHER_NAME, false);
Thread.sleep(100l);
Thread.sleep(50l);
assertEquals(notifyListener.urls, mockProxyRegistry.discover(subUrl));

MotanSwitcherUtil.setSwitcherValue(MeshRegistry.MESH_REGISTRY_SWITCHER_NAME, true);
Thread.sleep(100l);
Thread.sleep(50l);
assertEquals(notifyListener.urls.size(), copy);

// health check
Expand Down Expand Up @@ -177,9 +180,12 @@ public void testDoDiscover() throws Exception {
result = registry.doDiscover(subUrl);
assertEquals(copy, result.size());

registry.setUseMesh(true); // 确保订阅节点(有backup节点)
TestNotifyListener notifyListener = new TestNotifyListener();
registry.doSubscribe(subUrl, notifyListener);
Thread.sleep(50l);
Thread.sleep(100L);

registry.setUseMesh(false);
result = registry.doDiscover(subUrl);
assertEquals(mockProxyRegistry.discover(subUrl), result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,17 @@ public void testAbNormal() throws TransportException {
@SuppressWarnings("all")
public void testForceClose() throws Exception {
nettyServer.close();
Thread.sleep(1000l);
URL providerUrl = new URL("motan", "localhost", 0, Codec.class.getName()); // any interface just for test provider runtime info
nettyServer = new NettyServer(url, new ProviderMessageRouter(new DefaultProvider(new DefaultRpcCodec(), providerUrl, Codec.class)));
nettyServer.open();
Thread.sleep(1000l);
NettyTestClient nettyClient = new NettyTestClient(url);
this.nettyClient = nettyClient;
nettyClient.open();
assertTrue(nettyClient.isAvailable());
assertFalse(nettyClient.forceClosed);
Thread.sleep(100l);

// provider not exist
request.setInterfaceName("unknownService");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ public void testAbNormal2() throws Exception {
@Test
public void testForceClose() throws Exception {
nettyServer.close();
Thread.sleep(100l);
URL providerUrl = new URL("motan", "localhost", 0, Codec.class.getName()); // any interface just for test provider runtime info
nettyServer = new NettyServer(url, new ProviderMessageRouter(new DefaultProvider(new DefaultRpcCodec(), providerUrl, Codec.class)));
nettyServer.open();
Thread.sleep(100l);
NettyTestClient nettyClient = new NettyTestClient(url);
this.nettyClient = nettyClient;
nettyClient.open();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class AdminRpcServerTest extends TestCase {
public void testAdminRpcServer() throws Exception {
final Request[] requests = new Request[1];
URL url = new URL("motan2", "127.0.0.1", 0, "tempPath");
// 设置超时时间为1s
url.addParameter(URLParamType.requestTimeout.getName(), "1000");
AdminRpcServer server = new AdminRpcServer(url, new DefaultAdminHandler() {
@Override
public Response handle(Request request) {
Expand Down
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.12</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<licenses>
Expand Down

0 comments on commit 3f64beb

Please sign in to comment.