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 9716713
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 111 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_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 @@ -234,7 +234,7 @@ public Class<IHello> getInterface() {
@Override
public Response call(Request request) {
AtomicLong time = (AtomicLong) request.getArguments()[0];
final ResponseFuture response = new DefaultResponseFuture(request, 100, new URL(MotanConstants.PROTOCOL_MOTAN2, "localhost", 0, "tempService"));
final ResponseFuture response = new DefaultResponseFuture(request, 200, new URL(MotanConstants.PROTOCOL_MOTAN2, "localhost", 0, "tempService"));
new Thread(() -> {
try {
Thread.sleep(time.get());
Expand Down
3 changes: 2 additions & 1 deletion motan-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

<properties>
<spring-boot.version>2.3.1.RELEASE</spring-boot.version>
<skip.jacoco>true</skip.jacoco>
</properties>

<dependencies>
Expand Down Expand Up @@ -114,7 +115,7 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<!-- <version>4.1.3.Final</version> &lt;!&ndash; to be compatible with motan-protocol-grpc modules &ndash;&gt;-->
<!-- <version>4.1.3.Final</version> &lt;!&ndash; to be compatible with motan-protocol-grpc modules &ndash;&gt;-->
<version>4.1.44.Final</version>
</dependency>

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(50l);
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(50l);
NettyTestClient nettyClient = new NettyTestClient(url);
this.nettyClient = nettyClient;
nettyClient.open();
assertTrue(nettyClient.isAvailable());
assertFalse(nettyClient.forceClosed);
Thread.sleep(50l);

// provider not exist
request.setInterfaceName("unknownService");
Expand All @@ -150,12 +153,13 @@ public void testForceClose() throws Exception {
nettyClient.request(request);
fail();
} catch (MotanServiceException e) {
if (i < forceCloseTimes) {
if (i < forceCloseTimes - 1) {
// check provide not exist exception
assertTrue(nettyClient.isAvailable());
assertEquals(e.getErrorCode(), MotanErrorMsgConstant.PROVIDER_NOT_EXIST.getErrorCode());
assertTrue(e.getOriginMessage().contains(MotanErrorMsgConstant.PROVIDER_NOT_EXIST_EXCEPTION_PREFIX));
} else {
}
if (i == forceCloseTimes) {
assertTrue(e.getErrorCode() != MotanErrorMsgConstant.PROVIDER_NOT_EXIST.getErrorCode());
}
}
Expand All @@ -170,7 +174,7 @@ public void testForceClose() throws Exception {
assertFalse(((Map<String, Object>) serverInfos.get(RuntimeInfoKeys.PROTECT_STRATEGY_KEY)).isEmpty());
// check client force closed info
assertTrue((Boolean) clientInfos.get(RuntimeInfoKeys.FORCE_CLOSED_KEY));
assertTrue((Long) clientInfos.get(RuntimeInfoKeys.ERROR_COUNT_KEY) > (Integer) clientInfos.get(RuntimeInfoKeys.FUSING_THRESHOLD_KEY));
assertTrue((Long) clientInfos.get(RuntimeInfoKeys.ERROR_COUNT_KEY) >= (Integer) clientInfos.get(RuntimeInfoKeys.FUSING_THRESHOLD_KEY));

// check force close
assertFalse(nettyClient.isAvailable());
Expand Down
Loading

0 comments on commit 9716713

Please sign in to comment.