Skip to content
17 changes: 12 additions & 5 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ comment:

coverage: # https://docs.codecov.com/docs/codecovyml-reference#coverage
precision: 5
range:
- 70.0
- 75.0
range: "80...100"
status:
project:
default:
branches:
- ^master$
target: 70.0 # the minimum coverage ratio that the commit must meet to be considered a success.
threshold: 1% # allow the coverage to drop by X%, and posting a success status.
target: 80.0
threshold: 1%
ignore:
- "**/test/**"
- "**/*Test.java"
- "**/*AuthCenter.java"
- "**/*QappPackage.java"
- "**/*TRPCProtocol.java"
parsers:
jacoco:
partials_as_hits: true
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public Map<String, Object> parseMap(String configPath) {
this.localConfigMap = this.applicationConfigParser.parseMap(configPath);
this.overrideConfig();
if (override) {
logger.debug("use part of system config instead of local yaml config.");
return this.propertySourceParser.parseFlattableMap(this.localFlattableConfigMap);
}
return this.localConfigMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public static void shutdownBackendConfig(BackendConfig backendConfig) {
.ifPresent(proxyMap -> proxyMap.forEach((k, v) -> {
try {
v.close();
logger.debug("Shutdown client:{} backendConfig:{} success", k, backendConfig.toSimpleString());
if (logger.isDebugEnabled()) {
logger.debug("Shutdown client:{} backendConfig:{} success", k,
backendConfig.toSimpleString());
}
} catch (Exception ex) {
logger.error("Shutdown client:{} backendConfig:{},exception", k, backendConfig.toSimpleString(),
ex);
Expand Down Expand Up @@ -107,8 +110,10 @@ private static ScheduledFuture<?> startRpcClientCleaner() {
public static void scanUnusedClient() {
Map<BackendConfig, List<RpcClient>> unusedClientMap = Maps.newHashMap();
CLUSTER_MAP.forEach((bConfig, clusterMap) -> {
logger.debug("RpcClusterClient scheduler report clusterName={}, naming={}, num of client is {}",
bConfig.getName(), bConfig.getNamingOptions().getServiceNaming(), clusterMap.keySet().size());
if (logger.isDebugEnabled()) {
logger.debug("RpcClusterClient scheduler report clusterName={}, naming={}, num of client is {}",
bConfig.getName(), bConfig.getNamingOptions().getServiceNaming(), clusterMap.keySet().size());
}
clusterMap.forEach((clientKey, clientValue) -> {
try {
if (isIdleTimeout(bConfig, clientValue)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ private void fillCallInfo(Request request, ServiceInstance serviceInstance) {
Constants.CONTAINER_NAME));
request.getMeta().getCallInfo().setCalleeSetName(serviceInstance.getParameter(
Constants.SET_DIVISION));
logger.debug("[invoke] container:{},set:{}", serviceInstance.getParameter(
Constants.CONTAINER_NAME), serviceInstance.getParameter(Constants.SET_DIVISION));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ private synchronized void setStateInternal(LifecycleState state) {
}

private synchronized void setStateInternal(LifecycleState state, Throwable ex) {
logger.debug(">>>Lifecycle state transfer,{obj={}, state({} -> {})}", this, getState(), state);
if (logger.isDebugEnabled()) {
logger.debug(">>>Lifecycle state transfer,{obj={}, state({} -> {})}", this, getState(), state);
}
this.state = state;
fireLifecycleEvent(state, ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ public synchronized void init() {
validateInterceptor();
namingServiceId = toNamingServiceId();
simpleString = "BackendConfig[name=" + name + ", naming=" + namingOptions.getServiceNaming() + "]";
logger.debug("ConsumerConfig initialized:{}", toString());
if (logger.isDebugEnabled()) {
logger.debug("ConsumerConfig initialized:{}", toString());
}
SelectorManager.getManager().validate(namingOptions.getSelectorId());
initRpcClusterClient();
inited = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ private T createInstance() {
T t = clazz.newInstance();
injectExtension(t, pluginConfig);
initExtension(t);
logger.debug("Create plugin instance (name={}, type={}), config={}) success", name,
extensionType, ExtensionLoader.getPluginConfigMap(extensionType));
if (logger.isDebugEnabled()) {
logger.debug("Create plugin instance (name={}, type={}), config={}) success", name,
extensionType, ExtensionLoader.getPluginConfigMap(extensionType));
}
return t;
} catch (Exception e) {
throw new TRpcExtensionException(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Tencent is pleased to support the open source community by making tRPC available.
*
* Copyright (C) 2023 Tencent.
* Copyright (C) 2023 Tencent.
* All rights reserved.
*
* If you have downloaded a copy of the tRPC source code from Tencent,
Expand Down Expand Up @@ -49,7 +49,6 @@ private static <T> ProviderInvoker<T> buildProviderChain(boolean disableDefaultF
: Stream.of(new ProviderInvokerHeadFilter(), new ProviderInvokerTailFilter());
List<Filter> filters = Stream.concat(filterNames.stream().map(FilterManager::get), defaultFilters)
.sorted(Comparator.comparing(Filter::getOrder)).collect(Collectors.toList());
logger.debug("===Build invoke provider filter size: {}", filters.size());

for (int i = filters.size() - 1; i >= 0; i--) {
final Filter filter = filters.get(i);
Expand All @@ -68,12 +67,17 @@ public Class<T> getInterface() {
@Override
public CompletionStage<Response> invoke(Request request) {
RpcInvocation inv = request.getInvocation();
logger.debug(">>>Before Invoke provider filter(service={}, rpcServiceName={}, rpcMehthodName={})",
filter.getClass(), inv.getRpcServiceName(), inv.getRpcMethodName());
if (logger.isDebugEnabled()) {
logger.debug(">>>Before Invoke provider filter(service={}, rpcServiceName={}, "
+ "rpcMehthodName={})",
filter.getClass(), inv.getRpcServiceName(), inv.getRpcMethodName());
}

CompletionStage<Response> f = filter.filter(before, request);
logger.debug("<<<After Invoke provider filter(service={}, rpcServiceName={},rpcMehthodName={})",
filter.getClass(), inv.getRpcServiceName(), inv.getRpcMethodName());
if (logger.isDebugEnabled()) {
logger.debug("<<<After Invoke provider filter(service={}, rpcServiceName={},rpcMehthodName={})",
filter.getClass(), inv.getRpcServiceName(), inv.getRpcMethodName());
}

PreconditionUtils.checkArgument(f != null,
"Invoke provider filter(service=%s, rpcServiceName=%s,rpcMehthodName=%s) return Null",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public CompletionStage<Response> filter(Invoker<?> invoker, Request request)
Span span = null;
try {
span = buildSpan(invoker, request, context, meta, tracer, parentSpan);
logger.debug("before tjg TraceClientFilter reporting, span: {}", span);
if (logger.isDebugEnabled()) {
logger.debug("before tjg TraceClientFilter reporting, span: {}", span);
}
} catch (Exception e) {
logger.error("create trace client span error: ", e);
}
Expand All @@ -59,7 +61,9 @@ public CompletionStage<Response> filter(Invoker<?> invoker, Request request)
updateUpstreamSpanFlag(parentSpan, tempSpan);
finish(tempSpan, request, r, t);
}
logger.debug("after tjg TraceClientFilter reporting, span: {}", tempSpan);
if (logger.isDebugEnabled()) {
logger.debug("after tjg TraceClientFilter reporting, span: {}", tempSpan);
}
} catch (Exception e) {
logger.error("finish span error: ", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public abstract Span start(SpanBuilder spanBuilder, RpcContext context, Invoker<
*/
public Tracer getTracer(RpcContext context, RequestMeta meta) throws TRpcException {
try {
logger.debug("c context:{},meta:{}", context, meta);
if (logger.isDebugEnabled()) {
logger.debug("c context:{},meta:{}", context, meta);
}
Tracer tracer = RpcContextUtils.getTracer(context);
if (tracer != null) {
return tracer;
Expand All @@ -114,7 +116,9 @@ public Tracer getTracer(RpcContext context, RequestMeta meta) throws TRpcExcepti
logger.error("tracer is null,this self server name is null");
}
}
logger.debug("getTracer tracer:{}}", tracer);
if (logger.isDebugEnabled()) {
logger.debug("getTracer tracer:{}}", tracer);
}
return tracer;
} catch (Exception e) {
logger.error("getTracer error", e);
Expand All @@ -133,8 +137,10 @@ public Tracer getTracer(RpcContext context, RequestMeta meta) throws TRpcExcepti
public SpanBuilder createSpanBuilder(Tracer tracer, SpanContext parentSpanContext,
RequestMeta meta) {
try {
logger.debug("createSpanBuilder tracer:{},parentSpanContext:{},meta:{}", tracer,
parentSpanContext, meta);
if (logger.isDebugEnabled()) {
logger.debug("createSpanBuilder tracer:{},parentSpanContext:{},meta:{}", tracer,
parentSpanContext, meta);
}
if (tracer == null) {
return null;
}
Expand Down Expand Up @@ -164,7 +170,9 @@ public SpanBuilder createSpanBuilder(Tracer tracer, SpanContext parentSpanContex
*/
public void updateSpanErrorFlag(Response response, Throwable throwable, Span span) {
try {
logger.debug("updateSpanErrorFlag response:{},throwable:{},span:{}", response, throwable, span);
if (logger.isDebugEnabled()) {
logger.debug("updateSpanErrorFlag response:{},throwable:{},span:{}", response, throwable, span);
}
if (span == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public CompletionStage<Response> filter(Invoker<?> invoker, Request request)
RpcContextUtils.putValueMapValue(context, RpcContextValueKeys.CTX_TRACE_SPAN, span);
}
}
logger.debug("before tjg TraceServerFilter reporting,span: {}", span);
if (logger.isDebugEnabled()) {
logger.debug("before tjg TraceServerFilter reporting,span: {}", span);
}
} catch (Exception e) {
logger.error("create trace server span error", e);
}
Expand All @@ -74,7 +76,9 @@ public CompletionStage<Response> filter(Invoker<?> invoker, Request request)
}
finish(tempSpan, request, r, t);
}
logger.debug("after tjg TraceClientFilter reporting,span:{}", tempSpan);
if (logger.isDebugEnabled()) {
logger.debug("after tjg TraceClientFilter reporting,span:{}", tempSpan);
}
} catch (Exception e) {
logger.error("finish span error", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ protected CompletionStage<Channel> createChannel() throws TransportException {
} else {
logger.debug("Client transport(remote addr={}, network={}) create connection success",
rAddr, config.getNetwork());

}
// to prevent connection leakage, do one more check: when the connection is successfully established, if
// it is found to be closed, close the established connection directly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public void connected(com.tencent.trpc.core.transport.Channel channel) {

@Override
public void disconnected(com.tencent.trpc.core.transport.Channel channel) {
logger.debug("disconnected channel|{}", channel);
if (logger.isDebugEnabled()) {
logger.debug("disconnected channel|{}", channel);
}
disconnectedCnt.incrementAndGet();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,59 @@ public void test() throws IllegalArgumentException, IllegalAccessException, NoSu
Thread.sleep(10);
RpcClusterClientManager.scanUnusedClient();
assertEquals(0, clusterMap.get(backendConfig).size());
BackendConfig backend = new BackendConfig();
backend.setNamingUrl("ip://127.0.0.1:8081");
RpcClusterClientManager.getOrCreateClient(backend, config);
RpcClusterClientManager.shutdownBackendConfig(backend);
}

@Test
public void testDebugLog() throws Exception {
BackendConfig backendConfig = new BackendConfig();
backendConfig.setIdleTimeout(100000);
backendConfig.setNamingUrl("ip://127.0.0.1:8082");
ProtocolConfigTest config = new ProtocolConfigTest();
RpcClient rpcClient = RpcClusterClientManager.getOrCreateClient(backendConfig, config);
Assert.assertNotNull(rpcClient);
RpcClusterClientManager.scanUnusedClient();
RpcClusterClientManager.shutdownBackendConfig(backendConfig);
}

@Test
public void testGetOrCreateClientTwice() throws Exception {
BackendConfig backendConfig = new BackendConfig();
backendConfig.setIdleTimeout(100000);
backendConfig.setNamingUrl("ip://127.0.0.1:8083");
ProtocolConfigTest config = new ProtocolConfigTest();
RpcClient rpcClient1 = RpcClusterClientManager.getOrCreateClient(backendConfig, config);
RpcClient rpcClient2 = RpcClusterClientManager.getOrCreateClient(backendConfig, config);
Assert.assertNotNull(rpcClient1);
Assert.assertNotNull(rpcClient2);
RpcClusterClientManager.shutdownBackendConfig(backendConfig);
}

@Test
public void testClose() throws Exception {
BackendConfig backendConfig = new BackendConfig();
backendConfig.setIdleTimeout(100000);
backendConfig.setNamingUrl("ip://127.0.0.1:8084");
ProtocolConfigTest config = new ProtocolConfigTest();
RpcClient rpcClient = RpcClusterClientManager.getOrCreateClient(backendConfig, config);
Assert.assertNotNull(rpcClient);
RpcClusterClientManager.close();
RpcClusterClientManager.reset();
}

@Test
public void testShutdownNonExistBackend() {
BackendConfig backendConfig = new BackendConfig();
backendConfig.setNamingUrl("ip://127.0.0.1:9999");
RpcClusterClientManager.shutdownBackendConfig(backendConfig);
}

@Test
public void testScanWithEmptyCluster() {
RpcClusterClientManager.scanUnusedClient();
}

private static class ProtocolConfigTest extends ProtocolConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import com.tencent.trpc.core.worker.handler.TrpcThreadExceptionHandler;
import com.tencent.trpc.core.worker.spi.WorkerPool;
import com.tencent.trpc.core.worker.support.thread.ThreadWorkerPool;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
Expand Down Expand Up @@ -205,4 +207,45 @@ public void testDoInvoke() {
}
}

@Test
public void testDebugLog() {
DefRequest defRequest = new DefRequest();
RpcInvocation invocation = new RpcInvocation();
invocation.setFunc("a");
defRequest.setInvocation(invocation);
consumerInvokerProxy.invoke(defRequest, new ServiceInstance());
invocation.setFunc("n");
consumerInvokerProxy.invoke(defRequest, new ServiceInstance());
}

@Test
public void testProxyIsAvailable() {
Assert.assertFalse(consumerInvokerProxy.isAvailable());
}

@Test
public void testProxyInvokeWithServiceInstance() {
DefRequest defRequest = new DefRequest();
RpcInvocation invocation = new RpcInvocation();
invocation.setFunc("a");
defRequest.setInvocation(invocation);
Map<String, Object> params = new HashMap<>();
params.put("container_name", "test-container");
params.put("set_division", "test-set");
ServiceInstance instance = new ServiceInstance("127.0.0.1", 12345, params);
consumerInvokerProxy.invoke(defRequest, instance);
}

@Test
public void testDoInvokeWithCompletedFuture() {
DefRequest defRequest = new DefRequest();
ServiceInstance instance = new ServiceInstance("127.0.0.1", 12345);
CompletionStage<ServiceInstance> completedInstance = CompletableFuture.completedFuture(instance);
try {
defClusterInvoker.doInvoke(defRequest, completedInstance).toCompletableFuture().join();
} catch (Exception e) {
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.tencent.trpc.core.common;

import org.junit.Test;

public class LifecycleBaseTest {

@Test
public void testDebug() {
TestLifecycle testLifecycle = new TestLifecycle();
testLifecycle.init();
}

public class TestLifecycle extends LifecycleBase {

}
}
Loading