Skip to content

Commit 45558b8

Browse files
committed
add codecov
1 parent a9f706b commit 45558b8

File tree

8 files changed

+151
-102
lines changed

8 files changed

+151
-102
lines changed

.github/workflows/ci.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Workflow for Codecov
2+
on: [ push, pull_request ]
3+
jobs:
4+
run:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout
8+
uses: actions/checkout@v4
9+
- name: Set up JDK 8
10+
uses: actions/setup-java@v1
11+
with:
12+
java-version: 8
13+
- name: Install dependencies
14+
run: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
15+
- name: Run tests and collect coverage
16+
run: mvn -B test
17+
- name: Upload coverage to Codecov
18+
uses: codecov/codecov-action@v5
19+
env:
20+
CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}

.travis.yml

-1
This file was deleted.

motan-benchmark/motan-benchmark-client/pom.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
<plugin>
4141
<artifactId>maven-assembly-plugin</artifactId>
4242
<configuration>
43-
<descriptor>src/main/assembly/assembly.xml</descriptor>
43+
<descriptors>
44+
<descriptor>src/main/assembly/assembly.xml</descriptor>
45+
</descriptors>
4446
</configuration>
4547
<executions>
4648
<execution>

motan-benchmark/motan-benchmark-server/pom.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
<plugin>
4141
<artifactId>maven-assembly-plugin</artifactId>
4242
<configuration>
43-
<descriptor>src/main/assembly/assembly.xml</descriptor>
43+
<descriptors>
44+
<descriptor>src/main/assembly/assembly.xml</descriptor>
45+
</descriptors>
4446
</configuration>
4547
<executions>
4648
<execution>

motan-extension/serialization-extension/src/test/java/com/weibo/api/motan/serialize/protobuf/TestProtoBuf.java

+91-93
Original file line numberDiff line numberDiff line change
@@ -15,105 +15,103 @@
1515
*/
1616
package com.weibo.api.motan.serialize.protobuf;
1717

18-
import com.weibo.api.motan.exception.MotanBizException;
19-
import com.weibo.api.motan.exception.MotanServiceException;
20-
import com.weibo.api.motan.serialize.ProtobufSerialization;
21-
import org.junit.After;
22-
import org.junit.Assert;
23-
import org.junit.Before;
24-
import org.junit.Test;
25-
2618
import com.weibo.api.motan.config.ProtocolConfig;
2719
import com.weibo.api.motan.config.RefererConfig;
2820
import com.weibo.api.motan.config.RegistryConfig;
2921
import com.weibo.api.motan.config.ServiceConfig;
22+
import com.weibo.api.motan.exception.MotanBizException;
23+
import com.weibo.api.motan.exception.MotanServiceException;
3024
import com.weibo.api.motan.serialize.protobuf.gen.UserProto.Address;
3125
import com.weibo.api.motan.serialize.protobuf.gen.UserProto.User;
32-
33-
import java.io.IOException;
26+
import org.junit.After;
27+
import org.junit.Assert;
28+
import org.junit.Before;
29+
import org.junit.Test;
3430

3531
public class TestProtoBuf {
36-
private ServiceConfig<HelloService> serviceConfig;
37-
private RefererConfig<HelloService> refererConfig;
38-
private HelloService service;
39-
40-
@Before
41-
public void setUp() throws InterruptedException {
42-
ProtocolConfig protocolConfig = new ProtocolConfig();
43-
protocolConfig.setId("testMotan");
44-
protocolConfig.setName("motan");
45-
protocolConfig.setSerialization("protobuf");
46-
protocolConfig.setCodec("motan");
47-
48-
RegistryConfig registryConfig = new RegistryConfig();
49-
registryConfig.setAddress("127.0.0.1");
50-
registryConfig.setPort(8002);
51-
52-
serviceConfig = new ServiceConfig<>();
53-
serviceConfig.setRef(new HelloServiceImpl());
54-
serviceConfig.setInterface(HelloService.class);
55-
serviceConfig.setProtocol(protocolConfig);
56-
serviceConfig.setExport("testMotan:18002");
57-
serviceConfig.setRegistry(registryConfig);
58-
serviceConfig.setShareChannel(true);
59-
serviceConfig.export();
60-
61-
refererConfig = new RefererConfig<>();
62-
refererConfig.setDirectUrl("127.0.0.1:18002");
63-
refererConfig.setProtocol(protocolConfig);
64-
refererConfig.setInterface(HelloService.class);
65-
66-
service = refererConfig.getRef();
67-
Thread.sleep(20L);
68-
}
69-
70-
@Test
71-
public void testPrimitiveType() {
72-
Assert.assertEquals("-1", service.sumAsString(Integer.MAX_VALUE, Integer.MIN_VALUE));
73-
Assert.assertEquals("-1", service.sumAsString(-2, 1));
74-
Assert.assertEquals((Long) 100L, service.boxIfNotZero(100));
75-
Assert.assertNull(service.boxIfNotZero(0));
76-
}
77-
78-
@Test
79-
public void testException() {
80-
try {
81-
service.testException();
82-
Assert.fail("should throw MotanServiceException");
83-
} catch (MotanServiceException mse){
84-
Assert.assertTrue(mse.getMessage().contains(MotanBizException.class.getName()));
85-
Assert.assertTrue(mse.getMessage().contains("provider call process error"));
86-
}
87-
}
88-
89-
@Test
90-
public void testNull() {
91-
Assert.assertTrue(service.isNull(null));
92-
93-
User user = User.newBuilder().setId(120).setName("zhou").build();
94-
95-
Assert.assertFalse(service.isNull(user));
96-
}
97-
98-
@Test
99-
public void testProtobuf() {
100-
Address address = service.queryByUid(1);
101-
Assert.assertEquals(1, address.getId());
102-
103-
User user = User.newBuilder().setId(120).setName("zhou").setGender(false).addAddress(address).build();
104-
105-
Assert.assertTrue(service.isUserAddress(user, address));
106-
107-
User newOne = service.copy(user);
108-
Assert.assertEquals(user.getId(), newOne.getId());
109-
Assert.assertEquals(user.getName(), newOne.getName());
110-
Assert.assertEquals(user.getGender(), newOne.getGender());
111-
Assert.assertEquals(user.getAddress(0).getId(), newOne.getAddress(0).getId());
112-
}
113-
114-
@After
115-
public void tearDown() {
116-
refererConfig.destroy();
117-
serviceConfig.unexport();
118-
}
32+
private ServiceConfig<HelloService> serviceConfig;
33+
private RefererConfig<HelloService> refererConfig;
34+
private HelloService service;
35+
36+
@Before
37+
public void setUp() throws InterruptedException {
38+
ProtocolConfig protocolConfig = new ProtocolConfig();
39+
protocolConfig.setId("testMotan");
40+
protocolConfig.setName("motan");
41+
protocolConfig.setSerialization("protobuf");
42+
protocolConfig.setCodec("motan");
43+
44+
RegistryConfig registryConfig = new RegistryConfig();
45+
registryConfig.setAddress("127.0.0.1");
46+
registryConfig.setPort(8002);
47+
48+
serviceConfig = new ServiceConfig<>();
49+
serviceConfig.setRef(new HelloServiceImpl());
50+
serviceConfig.setInterface(HelloService.class);
51+
serviceConfig.setProtocol(protocolConfig);
52+
serviceConfig.setExport("testMotan:18002");
53+
serviceConfig.setRegistry(registryConfig);
54+
serviceConfig.setShareChannel(true);
55+
serviceConfig.export();
56+
57+
refererConfig = new RefererConfig<>();
58+
refererConfig.setDirectUrl("127.0.0.1:18002");
59+
refererConfig.setProtocol(protocolConfig);
60+
refererConfig.setInterface(HelloService.class);
61+
// 设置超时时间为1秒
62+
refererConfig.setRequestTimeout(1000);
63+
64+
service = refererConfig.getRef();
65+
Thread.sleep(20L);
66+
}
67+
68+
@Test
69+
public void testPrimitiveType() {
70+
Assert.assertEquals("-1", service.sumAsString(Integer.MAX_VALUE, Integer.MIN_VALUE));
71+
Assert.assertEquals("-1", service.sumAsString(-2, 1));
72+
Assert.assertEquals((Long) 100L, service.boxIfNotZero(100));
73+
Assert.assertNull(service.boxIfNotZero(0));
74+
}
75+
76+
@Test
77+
public void testException() {
78+
try {
79+
service.testException();
80+
Assert.fail("should throw MotanServiceException");
81+
} catch (MotanServiceException mse) {
82+
Assert.assertTrue(mse.getMessage().contains(MotanBizException.class.getName()));
83+
Assert.assertTrue(mse.getMessage().contains("provider call process error"));
84+
}
85+
}
86+
87+
@Test
88+
public void testNull() {
89+
Assert.assertTrue(service.isNull(null));
90+
91+
User user = User.newBuilder().setId(120).setName("zhou").build();
92+
93+
Assert.assertFalse(service.isNull(user));
94+
}
95+
96+
@Test
97+
public void testProtobuf() {
98+
Address address = service.queryByUid(1);
99+
Assert.assertEquals(1, address.getId());
100+
101+
User user = User.newBuilder().setId(120).setName("zhou").setGender(false).addAddress(address).build();
102+
103+
Assert.assertTrue(service.isUserAddress(user, address));
104+
105+
User newOne = service.copy(user);
106+
Assert.assertEquals(user.getId(), newOne.getId());
107+
Assert.assertEquals(user.getName(), newOne.getName());
108+
Assert.assertEquals(user.getGender(), newOne.getGender());
109+
Assert.assertEquals(user.getAddress(0).getId(), newOne.getAddress(0).getId());
110+
}
111+
112+
@After
113+
public void tearDown() {
114+
refererConfig.destroy();
115+
serviceConfig.unexport();
116+
}
119117
}

motan-registry-weibomesh/src/test/java/com/weibo/api/motan/registry/weibomesh/MeshRegistryTest.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public class MeshRegistryTest {
5757

5858
@Before
5959
public void setUp() throws Exception {
60+
//开关默认值
61+
MotanSwitcherUtil.setSwitcherValue(MeshRegistry.MESH_REGISTRY_SWITCHER_NAME, true);
62+
MotanSwitcherUtil.setSwitcherValue(MeshRegistry.MESH_REGISTRY_HEALTH_CHECK_SWITCHER_NAME, true);
63+
6064
copy = 3; //默认副本数
6165
requestTimeout = 100;
6266
URL agentMockUrl = new URL("motan2", "localhost", 0, "testpath", new HashMap<>());
@@ -83,9 +87,7 @@ public void setUp() throws Exception {
8387
//因为测试流程原因,单测时需要手动触发健康检测
8488
registry.initHealthCheck();
8589

86-
//开关默认值
87-
MotanSwitcherUtil.setSwitcherValue(MeshRegistry.MESH_REGISTRY_SWITCHER_NAME, true);
88-
MotanSwitcherUtil.setSwitcherValue(MeshRegistry.MESH_REGISTRY_HEALTH_CHECK_SWITCHER_NAME, true);
90+
8991
}
9092

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

122124
// 验证降级开关
125+
Thread.sleep(50l); // 等待proxyRegistry的notify
123126
MotanSwitcherUtil.setSwitcherValue(MeshRegistry.MESH_REGISTRY_SWITCHER_NAME, false);
124-
Thread.sleep(100l);
127+
Thread.sleep(50l);
125128
assertEquals(notifyListener.urls, mockProxyRegistry.discover(subUrl));
126129

127130
MotanSwitcherUtil.setSwitcherValue(MeshRegistry.MESH_REGISTRY_SWITCHER_NAME, true);
128-
Thread.sleep(100l);
131+
Thread.sleep(50l);
129132
assertEquals(notifyListener.urls.size(), copy);
130133

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

183+
registry.setUseMesh(true); // 确保订阅节点(有backup节点)
180184
TestNotifyListener notifyListener = new TestNotifyListener();
181185
registry.doSubscribe(subUrl, notifyListener);
182-
Thread.sleep(50l);
186+
Thread.sleep(100L);
187+
188+
registry.setUseMesh(false);
183189
result = registry.doDiscover(subUrl);
184190
assertEquals(mockProxyRegistry.discover(subUrl), result);
185191
}

motan-transport-netty4/src/test/java/com/weibo/api/motan/transport/netty4/admin/AdminRpcServerTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class AdminRpcServerTest extends TestCase {
4343
public void testAdminRpcServer() throws Exception {
4444
final Request[] requests = new Request[1];
4545
URL url = new URL("motan2", "127.0.0.1", 0, "tempPath");
46+
// 设置超时时间为1s
47+
url.addParameter(URLParamType.requestTimeout.getName(), "1000");
4648
AdminRpcServer server = new AdminRpcServer(url, new DefaultAdminHandler() {
4749
@Override
4850
public Response handle(Request request) {

pom.xml

+20
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,26 @@
159159
<encoding>${project.build.sourceEncoding}</encoding>
160160
</configuration>
161161
</plugin>
162+
<plugin>
163+
<groupId>org.jacoco</groupId>
164+
<artifactId>jacoco-maven-plugin</artifactId>
165+
<version>0.8.12</version>
166+
<executions>
167+
<execution>
168+
<id>prepare-agent</id>
169+
<goals>
170+
<goal>prepare-agent</goal>
171+
</goals>
172+
</execution>
173+
<execution>
174+
<id>report</id>
175+
<phase>test</phase>
176+
<goals>
177+
<goal>report</goal>
178+
</goals>
179+
</execution>
180+
</executions>
181+
</plugin>
162182
</plugins>
163183
</build>
164184
<licenses>

0 commit comments

Comments
 (0)