diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 6e649991e..000000000 --- a/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -service_name: travis-ci \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e7fa2598a..23bda6fcd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,9 +22,9 @@ name: build on: push: - branches: [ 3.x ] + branches: [ master ] pull_request: - branches: [ 3.x ] + branches: [ master ] jobs: build: @@ -32,14 +32,16 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Build with Maven - run: mvn clean install -DskipTests -B -V - && sh ./check_format.sh - && mvn clean test - - name: Codecov - uses: codecov/codecov-action@v1 + - uses: actions/checkout@v2 + with: + fetch-depth: 2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Build with Maven + run: mvn clean install -DskipTests -B -V + && sh ./check_format.sh + && mvn clean test + - name: Codecov + uses: codecov/codecov-action@v1 diff --git a/.gitignore b/.gitignore index b687a484e..6574c1ad3 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,4 @@ nb-configuration.xml coverage-report logs *.log -pom.xml.versionsBackup - +pom.xml.versionsBackup \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d3f1f3a44..000000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: java -sudo: false - -jdk: -- openjdk8 - -install: - -- mvn clean install -B -V - -script: -- sh ./check_format.sh - -after_success: -- mvn clean test cobertura:cobertura org.eluder.coveralls:coveralls-maven-plugin:report \ No newline at end of file diff --git a/README.md b/README.md index a4f7cbcc5..bd12a3052 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## SOFATracer -[![Build Status](https://github.com/sofastack/sofa-tracer/workflows/build/badge.svg?branch=3.x)](https://github.com/sofastack/sofa-tracer/workflows/build/badge.svg?branch=3.x) -[![Coverage Status](https://coveralls.io/repos/github/alipay/sofa-tracer/badge.svg?branch=master)](https://coveralls.io/github/alipay/sofa-tracer?branch=master) +[![Build Status](https://github.com/sofastack/sofa-tracer/workflows/build/badge.svg?branch=master)](https://github.com/sofastack/sofa-tracer/workflows/build/badge.svg?branch=master) +[![Coverage Status](https://codecov.io/gh/sofastack/sofa-tracer/branch/master/graph/badge.svg)](https://codecov.io/gh/sofastack/sofa-tracer/branch/master) ![license](https://img.shields.io/badge/license-Apache--2.0-green.svg) [![Maven](https://img.shields.io/github/release/alipay/sofa-tracer.svg)](https://github.com/alipay/sofa-tracer/releases) @@ -43,7 +43,7 @@ SOFATracer 可以将链路跟踪数据远程上报到开源产品 [Zipkin](https ## 三、快速开始 -请查看文档中的[快速开始](http://www.sofastack.tech/sofa-tracer/docs/QuickStart)来了解如何快速上手使用 SOFATracer。 +请查看文档中的[快速开始](https://www.sofastack.tech/projects/sofa-tracer/component-access/)来了解如何快速上手使用 SOFATracer。 ## 四、如何贡献 diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index bb6efec5f..000000000 --- a/appveyor.yml +++ /dev/null @@ -1,31 +0,0 @@ -# build version -version: '{build}' - -# environment settings -environment: - matrix: - - JAVA_HOME: C:\Program Files\Java\jdk1.7.0 - - JAVA_HOME: C:\Program Files\Java\jdk1.8.0 - -platform: x64 - -# install required tools (java, maven) -install: - - cmd: echo %JAVA_HOME% - - cmd: echo %M2_HOME% - -# Do not build on tags -skip_tags: true - -# build and install artifacts -build_script: - - mvn clean install -DskipTests - -# verify artifacts -test_script: - - mvn test - -# preserve dependencies between builds -cache: - - C:\maven\ - - C:\Users\appveyor\.m \ No newline at end of file diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..f3dd810a8 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,2 @@ +ignore: + - "pom.xml" \ No newline at end of file diff --git a/pom.xml b/pom.xml index f6352fa6f..9764545bf 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ tracer-all-parent - 3.1.0 + 3.1.1 pom tracer-all-parent Alipay SOFATracer Log Implemented by OpenTracing @@ -51,8 +51,6 @@ ${user.dir} 1.6.7 1.5 - 3.1.0 - 2.6 @@ -275,7 +273,7 @@ junit junit - 4.12 + 4.13.1 test @@ -404,26 +402,29 @@ + - org.eluder.coveralls - coveralls-maven-plugin - ${coveralls.maven.plugin} - - ${project.encoding} - - - - org.codehaus.mojo - cobertura-maven-plugin - ${cobertura.maven.plugin} + org.jacoco + jacoco-maven-plugin + 0.7.9 - ${project.encoding} - true - - xml - html - + false + + + default-prepare-agent + + prepare-agent + + + + default-report + test + + report-aggregate + + + org.apache.maven.plugins diff --git a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/pom.xml index 38a4c21cf..a9759ecba 100644 --- a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/MethodRegistry.java b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/MethodRegistry.java index 339d1b986..4c3db96f8 100644 --- a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/MethodRegistry.java +++ b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/MethodRegistry.java @@ -24,7 +24,18 @@ import java.lang.reflect.Method; import java.math.BigDecimal; import java.net.URL; -import java.sql.*; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.PreparedStatement; +import java.sql.Ref; +import java.sql.RowId; +import java.sql.SQLXML; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; import java.util.Calendar; import java.util.HashMap; import java.util.Map; diff --git a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/SmartDataSource.java b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/SmartDataSource.java index be44cc3d6..96910fc8b 100644 --- a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/SmartDataSource.java +++ b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/SmartDataSource.java @@ -17,7 +17,12 @@ package com.alipay.sofa.tracer.plugins.datasource; import com.alipay.common.tracer.core.utils.StringUtils; -import com.alipay.sofa.tracer.plugins.datasource.tracer.*; +import com.alipay.sofa.tracer.plugins.datasource.tracer.ConnectionTraceInterceptor; +import com.alipay.sofa.tracer.plugins.datasource.tracer.DataSourceClientTracer; +import com.alipay.sofa.tracer.plugins.datasource.tracer.DataSourceTracerKeys; +import com.alipay.sofa.tracer.plugins.datasource.tracer.Endpoint; +import com.alipay.sofa.tracer.plugins.datasource.tracer.KeyValueAnnotation; +import com.alipay.sofa.tracer.plugins.datasource.tracer.StatementTracerInterceptor; import com.alipay.sofa.tracer.plugins.datasource.utils.DataSourceUtils; import javax.sql.DataSource; diff --git a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/ConnectionTraceInterceptor.java b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/ConnectionTraceInterceptor.java index cbdd68b34..b81c2a75b 100644 --- a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/ConnectionTraceInterceptor.java +++ b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/ConnectionTraceInterceptor.java @@ -17,6 +17,7 @@ package com.alipay.sofa.tracer.plugins.datasource.tracer; import com.alipay.sofa.tracer.plugins.datasource.Interceptor; + import java.util.List; /** diff --git a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/DataSourceClientStatJsonReporter.java b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/DataSourceClientStatJsonReporter.java index f5bbdbea0..b4a802903 100644 --- a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/DataSourceClientStatJsonReporter.java +++ b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/DataSourceClientStatJsonReporter.java @@ -22,6 +22,7 @@ import com.alipay.common.tracer.core.span.CommonSpanTags; import com.alipay.common.tracer.core.span.SofaTracerSpan; import com.alipay.common.tracer.core.utils.TracerUtils; + import java.util.Map; /** @@ -45,7 +46,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) { tagsWithStr.get(DataSourceTracerKeys.DATABASE_NAME)); statKey.addKey(DataSourceTracerKeys.SQL, tagsWithStr.get(DataSourceTracerKeys.SQL)); //result - String result = SofaTracerConstant.RESULT_CODE_SUCCESS.equals(tagsWithStr + String result = SofaTracerConstant.RESULT_SUCCESS.equals(tagsWithStr .get(CommonSpanTags.RESULT_CODE)) ? SofaTracerConstant.STAT_FLAG_SUCCESS : SofaTracerConstant.STAT_FLAG_FAILS; statKey.setResult(result); diff --git a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/DataSourceClientStatReporter.java b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/DataSourceClientStatReporter.java index 9e052ae4a..6eb597f7f 100644 --- a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/DataSourceClientStatReporter.java +++ b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/DataSourceClientStatReporter.java @@ -44,7 +44,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) { tagsWithStr.get(DataSourceTracerKeys.DATABASE_NAME), tagsWithStr.get(DataSourceTracerKeys.SQL) })); //result - String resultCode = SofaTracerConstant.RESULT_CODE_SUCCESS.equals(tagsWithStr + String resultCode = SofaTracerConstant.RESULT_SUCCESS.equals(tagsWithStr .get(CommonSpanTags.RESULT_CODE)) ? SofaTracerConstant.STAT_FLAG_SUCCESS : SofaTracerConstant.STAT_FLAG_FAILS; statKey.setResult(resultCode); diff --git a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/utils/DataSourceUtils.java b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/utils/DataSourceUtils.java index 489b4cfa2..5dbdfcfee 100644 --- a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/utils/DataSourceUtils.java +++ b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/utils/DataSourceUtils.java @@ -16,8 +16,10 @@ */ package com.alipay.sofa.tracer.plugins.datasource.utils; +import com.alipay.common.tracer.core.appender.self.SelfLog; import com.alipay.common.tracer.core.utils.AssertUtils; import com.alipay.common.tracer.core.utils.StringUtils; +import com.alipay.sofa.common.code.LogCode2Description; import com.alipay.sofa.tracer.plugins.datasource.tracer.Endpoint; import java.lang.reflect.Method; @@ -26,6 +28,8 @@ import java.util.Collections; import java.util.List; +import static com.alipay.common.tracer.core.constants.SofaTracerConstant.SPACE_ID; + /** * @author shusong.yss * @author qilong.zql @@ -52,6 +56,8 @@ public class DataSourceUtils { public static final String ORACLE_PREFIX_THIN = "jdbc:oracle:thin:"; + public static final String POSTGRE_PREFIX_THIN = "jdbc:postgresql://"; + public static final int ORACLE_DEFAULT_PORT = 1521; public static boolean isDruidDataSource(Object dataSource) { @@ -172,11 +178,23 @@ public static boolean isTargetDataSource(String className, Object dataSource) { public static List getEndpointsFromConnectionURL(final String connectionURL) { String currentUri = StringUtils.EMPTY_STRING; - List endpoints = null; - if (StringUtils.isNotBlank(connectionURL) && connectionURL.startsWith(ORACLE_PREFIX_THIN)) { - currentUri = connectionURL.substring(ORACLE_PREFIX_THIN.length()); - // parse endpoints by tns name. - endpoints = parseEndpointByTnsName(currentUri); + List endpoints = Collections.emptyList(); + try { + //首先jdbc:oracle:thin: 特殊解析 + if (StringUtils.isNotBlank(connectionURL) + && connectionURL.startsWith(ORACLE_PREFIX_THIN)) { + + currentUri = connectionURL.substring(ORACLE_PREFIX_THIN.length()); + // parse endpoints by tns name. + endpoints = parseEndpointByTnsName(currentUri); + } else if (StringUtils.isNotBlank(connectionURL) + && connectionURL.startsWith(POSTGRE_PREFIX_THIN) + && connectionURL.contains(",")) { + //pg数据库 读写分离的配资 + currentUri = connectionURL.substring(POSTGRE_PREFIX_THIN.length()); + endpoints = parseEndpointByPgMulti(currentUri); + } + //普通解析 兜底 if (endpoints == null || endpoints.size() == 0 || null == endpoints.get(0) || StringUtils.isBlank(endpoints.get(0).getHost())) { // easy tns or others db url be resolve. it's a single endpoint. @@ -186,9 +204,30 @@ public static List getEndpointsFromConnectionURL(final String connecti } endpoints = Collections.singletonList(singleEndpoint); } - return endpoints; + } catch (Exception e) { + //链接配置样式多,捕获异常,不影响启动 + SelfLog.error(LogCode2Description.convert(SPACE_ID, "01-00015"), e); } - return Collections.emptyList(); + return endpoints; + } + + private static List parseEndpointByPgMulti(String currentUri) { + List endpoints = new ArrayList<>(); + String[] urls = currentUri.split(","); + for (String url : urls) { + int hostEnd = url.indexOf(":"); + String host = url.substring(0, hostEnd); + int portEnd = url.indexOf('/'); + if (portEnd == -1) { + portEnd = url.length(); + } + Integer port = Integer.parseInt(url.substring(hostEnd + 1, portEnd)); + Endpoint endpoint = new Endpoint(); + endpoint.setHost(host); + endpoint.setPort(port); + endpoints.add(endpoint); + } + return endpoints; } private static List parseEndpointByTnsName(final String url) { diff --git a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/test/java/com/sofa/tracer/plugins/datasource/DataSourceUtilTest.java b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/test/java/com/sofa/tracer/plugins/datasource/DataSourceUtilTest.java index c79f96356..c5f3afa63 100644 --- a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/test/java/com/sofa/tracer/plugins/datasource/DataSourceUtilTest.java +++ b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/test/java/com/sofa/tracer/plugins/datasource/DataSourceUtilTest.java @@ -17,12 +17,15 @@ package com.sofa.tracer.plugins.datasource; import com.alipay.common.tracer.core.utils.ReflectionUtils; +import com.alipay.sofa.tracer.plugins.datasource.tracer.Endpoint; +import com.alipay.sofa.tracer.plugins.datasource.utils.DataSourceUtils; import com.alipay.sofa.tracer.plugins.datasource.utils.SqlUtils; import com.sofa.tracer.plugins.datasource.bean.ConcreteClassService; import org.junit.Assert; import org.junit.Test; import java.lang.reflect.Method; +import java.util.List; /** * @author qilong.zql @@ -56,4 +59,23 @@ public void testGetSqlEscaped() { Assert.assertTrue(!result.contains("\r")); Assert.assertTrue(result.equals("select app1 %2Capp2 from table where id = a;")); } + + @Test + public void testGetEndpointsFromConnectionURL() { + String mysqlStr = "jdbc:mysql://127.0.0.1:5432"; + List mysqlEndpoints = DataSourceUtils.getEndpointsFromConnectionURL(mysqlStr); + Assert.assertTrue(mysqlEndpoints.size() == 1); + Assert.assertEquals(mysqlEndpoints.get(0).getHost(), "127.0.0.1"); + Assert.assertEquals(mysqlEndpoints.get(0).getPort(), 5432); + + String pgStr = "jdbc:postgresql://pgm-b1j86r7w2287y711.pg.rds.ops.cloudtest.jxnxs.com:3433,pgr-b1jyp8yi35bj7267.pg.rds.ops.cloudtest.jxnxs.com:3306/postgres?serverTimezone=GMT%2B8&allowMultiQueries=true"; + List pgEndpoints = DataSourceUtils.getEndpointsFromConnectionURL(pgStr); + Assert.assertTrue(pgEndpoints.size() == 2); + Assert.assertEquals(pgEndpoints.get(0).getHost(), + "pgm-b1j86r7w2287y711.pg.rds.ops.cloudtest.jxnxs.com"); + Assert.assertEquals(pgEndpoints.get(0).getPort(), 3433); + Assert.assertEquals(pgEndpoints.get(1).getHost(), + "pgr-b1jyp8yi35bj7267.pg.rds.ops.cloudtest.jxnxs.com"); + Assert.assertEquals(pgEndpoints.get(1).getPort(), 3306); + } } \ No newline at end of file diff --git a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/test/java/com/sofa/tracer/plugins/datasource/base/BaseTest.java b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/test/java/com/sofa/tracer/plugins/datasource/base/BaseTest.java index f34ddca8a..ca9a63c54 100644 --- a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/test/java/com/sofa/tracer/plugins/datasource/base/BaseTest.java +++ b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/test/java/com/sofa/tracer/plugins/datasource/base/BaseTest.java @@ -24,7 +24,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.sofa.tracer.plugins.datasource.TestUtil; import org.apache.commons.io.FileUtils; -import org.junit.*; +import org.junit.After; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.mockito.Mock; @@ -33,7 +36,13 @@ import javax.sql.DataSource; import java.io.File; import java.io.IOException; -import java.sql.*; +import java.sql.Connection; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Timestamp; import java.util.Arrays; import java.util.Collections; import java.util.List; diff --git a/sofa-tracer-plugins/sofa-tracer-dubbo-2.6.x-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-dubbo-2.6.x-plugin/pom.xml index f54f70363..ce4493cbb 100644 --- a/sofa-tracer-plugins/sofa-tracer-dubbo-2.6.x-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-dubbo-2.6.x-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/pom.xml index 67902f5ec..496e8fa49 100644 --- a/sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo26x/DubboSofaTracerFilter.java b/sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo26x/DubboSofaTracerFilter.java index 991a1c909..075b255df 100644 --- a/sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo26x/DubboSofaTracerFilter.java +++ b/sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo26x/DubboSofaTracerFilter.java @@ -45,7 +45,6 @@ import com.alipay.sofa.tracer.plugins.dubbo.constants.AttachmentKeyConstants; import com.alipay.sofa.tracer.plugins.dubbo.tracer.DubboConsumerSofaTracer; import com.alipay.sofa.tracer.plugins.dubbo.tracer.DubboProviderSofaTracer; - import io.opentracing.tag.Tags; import java.util.HashMap; diff --git a/sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo27x/DubboSofaTracerFilter.java b/sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo27x/DubboSofaTracerFilter.java index 7b2513683..82280abbf 100644 --- a/sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo27x/DubboSofaTracerFilter.java +++ b/sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo27x/DubboSofaTracerFilter.java @@ -31,10 +31,7 @@ import com.alipay.sofa.tracer.plugins.dubbo.constants.AttachmentKeyConstants; import com.alipay.sofa.tracer.plugins.dubbo.tracer.DubboConsumerSofaTracer; import com.alipay.sofa.tracer.plugins.dubbo.tracer.DubboProviderSofaTracer; - -import io.opentracing.SpanContext; import io.opentracing.tag.Tags; - import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.remoting.TimeoutException; diff --git a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/pom.xml index 637c04bd5..dd69975f6 100644 --- a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerFilter.java b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerFilter.java index 9068e3d4b..cb9d76fb9 100644 --- a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerFilter.java +++ b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerFilter.java @@ -42,6 +42,7 @@ import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.support.RpcUtils; + import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletableFuture; diff --git a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/encoder/DubboServerDigestEncoder.java b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/encoder/DubboServerDigestEncoder.java index a6747b5cc..58685e44c 100644 --- a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/encoder/DubboServerDigestEncoder.java +++ b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/encoder/DubboServerDigestEncoder.java @@ -18,9 +18,6 @@ import com.alipay.common.tracer.core.appender.builder.JsonStringBuilder; import com.alipay.common.tracer.core.appender.builder.XStringBuilder; -import com.alipay.common.tracer.core.appender.self.Timestamp; -import com.alipay.common.tracer.core.constants.SofaTracerConstant; -import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext; import com.alipay.common.tracer.core.middleware.parent.AbstractDigestSpanEncoder; import com.alipay.common.tracer.core.span.CommonSpanTags; import com.alipay.common.tracer.core.span.SofaTracerSpan; @@ -28,7 +25,6 @@ import com.alipay.sofa.tracer.plugins.dubbo.constants.AttachmentKeyConstants; import io.opentracing.tag.Tags; -import java.io.IOException; import java.util.Map; /** diff --git a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/wrapper/DataSizeCodecWrapper.java b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/wrapper/DataSizeCodecWrapper.java index 16ee24e92..3384d1071 100644 --- a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/wrapper/DataSizeCodecWrapper.java +++ b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/wrapper/DataSizeCodecWrapper.java @@ -24,6 +24,7 @@ import org.apache.dubbo.remoting.exchange.Response; import org.apache.dubbo.rpc.AppResponse; import org.apache.dubbo.rpc.RpcInvocation; + import java.io.IOException; /** diff --git a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/test/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerTest.java b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/test/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerTest.java index 481b3742b..516dcfc5a 100644 --- a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/test/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerTest.java +++ b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/test/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerTest.java @@ -25,11 +25,16 @@ import com.alipay.sofa.tracer.plugins.dubbo.service.DubboService; import org.apache.commons.io.FileUtils; import org.apache.dubbo.common.URL; -import org.apache.dubbo.config.*; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ProtocolConfig; +import org.apache.dubbo.config.ReferenceConfig; +import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.config.ServiceConfig; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; + import java.io.File; import java.util.List; diff --git a/sofa-tracer-plugins/sofa-tracer-flexible-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-flexible-plugin/pom.xml index c6c2acb8b..24f2f3e8a 100644 --- a/sofa-tracer-plugins/sofa-tracer-flexible-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-flexible-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/pom.xml index d3e129a73..218a4fa68 100644 --- a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/interceptor/SofaTracerAsyncHttpInterceptor.java b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/interceptor/SofaTracerAsyncHttpInterceptor.java index 277c10972..3d5130d02 100644 --- a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/interceptor/SofaTracerAsyncHttpInterceptor.java +++ b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/interceptor/SofaTracerAsyncHttpInterceptor.java @@ -20,7 +20,12 @@ import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; import com.alipay.common.tracer.core.span.SofaTracerSpan; import com.alipay.common.tracer.core.tracer.AbstractTracer; -import org.apache.http.*; +import org.apache.http.HttpException; +import org.apache.http.HttpRequest; +import org.apache.http.HttpRequestInterceptor; +import org.apache.http.HttpResponse; +import org.apache.http.HttpResponseInterceptor; +import org.apache.http.RequestLine; import org.apache.http.protocol.HttpContext; import java.io.IOException; diff --git a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/interceptor/SofaTracerHttpInterceptor.java b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/interceptor/SofaTracerHttpInterceptor.java index 83a907285..7433d38b1 100644 --- a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/interceptor/SofaTracerHttpInterceptor.java +++ b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/interceptor/SofaTracerHttpInterceptor.java @@ -20,7 +20,12 @@ import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; import com.alipay.common.tracer.core.span.SofaTracerSpan; import com.alipay.common.tracer.core.tracer.AbstractTracer; -import org.apache.http.*; +import org.apache.http.HttpException; +import org.apache.http.HttpRequest; +import org.apache.http.HttpRequestInterceptor; +import org.apache.http.HttpResponse; +import org.apache.http.HttpResponseInterceptor; +import org.apache.http.RequestLine; import org.apache.http.protocol.HttpContext; import java.io.IOException; diff --git a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/test/java/com/alipay/sofa/tracer/plugins/httpclient/NonJsonTest.java b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/test/java/com/alipay/sofa/tracer/plugins/httpclient/NonJsonTest.java index afd9efa29..3d68a2530 100644 --- a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/test/java/com/alipay/sofa/tracer/plugins/httpclient/NonJsonTest.java +++ b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/test/java/com/alipay/sofa/tracer/plugins/httpclient/NonJsonTest.java @@ -37,9 +37,7 @@ import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * @author: guolei.sgl (guolei.sgl@antfin.com) 2019/9/1 7:59 PM diff --git a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/test/java/com/alipay/sofa/tracer/plugins/httpclient/base/client/HttpClientInstance.java b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/test/java/com/alipay/sofa/tracer/plugins/httpclient/base/client/HttpClientInstance.java index bd443852c..94925fcdf 100644 --- a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/test/java/com/alipay/sofa/tracer/plugins/httpclient/base/client/HttpClientInstance.java +++ b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/test/java/com/alipay/sofa/tracer/plugins/httpclient/base/client/HttpClientInstance.java @@ -22,7 +22,11 @@ import org.apache.http.HttpHeaders; import org.apache.http.HttpStatus; import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.*; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpHead; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; diff --git a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/test/java/com/alipay/sofa/tracer/plugins/httpclient/base/controller/SampleRestController.java b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/test/java/com/alipay/sofa/tracer/plugins/httpclient/base/controller/SampleRestController.java index 0bb949f46..360da8148 100644 --- a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/test/java/com/alipay/sofa/tracer/plugins/httpclient/base/controller/SampleRestController.java +++ b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/test/java/com/alipay/sofa/tracer/plugins/httpclient/base/controller/SampleRestController.java @@ -16,7 +16,12 @@ */ package com.alipay.sofa.tracer.plugins.httpclient.base.controller; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; import java.util.Map; diff --git a/sofa-tracer-plugins/sofa-tracer-kafkamq-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-kafkamq-plugin/pom.xml index 297e6e2cd..8f66b8b6b 100644 --- a/sofa-tracer-plugins/sofa-tracer-kafkamq-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-kafkamq-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-mongodb-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-mongodb-plugin/pom.xml index 88a172a48..2e3073a12 100644 --- a/sofa-tracer-plugins/sofa-tracer-mongodb-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-mongodb-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-mongodb-plugin/src/main/java/com/alipay/sofa/tracer/plugins/mongodb/SofaTracerCommandListener.java b/sofa-tracer-plugins/sofa-tracer-mongodb-plugin/src/main/java/com/alipay/sofa/tracer/plugins/mongodb/SofaTracerCommandListener.java index af3be5cd9..814611bb8 100644 --- a/sofa-tracer-plugins/sofa-tracer-mongodb-plugin/src/main/java/com/alipay/sofa/tracer/plugins/mongodb/SofaTracerCommandListener.java +++ b/sofa-tracer-plugins/sofa-tracer-mongodb-plugin/src/main/java/com/alipay/sofa/tracer/plugins/mongodb/SofaTracerCommandListener.java @@ -26,6 +26,7 @@ import com.mongodb.event.CommandStartedEvent; import com.mongodb.event.CommandSucceededEvent; import io.opentracing.tag.Tags; + import java.io.PrintWriter; import java.io.StringWriter; import java.net.InetSocketAddress; diff --git a/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/pom.xml index ddb8e8e41..3fb2bf72d 100644 --- a/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/src/test/java/com/alipay/sofa/tracer/plugins/okhttp/base/controller/SampleRestController.java b/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/src/test/java/com/alipay/sofa/tracer/plugins/okhttp/base/controller/SampleRestController.java index e0b6d20ad..b479d2340 100644 --- a/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/src/test/java/com/alipay/sofa/tracer/plugins/okhttp/base/controller/SampleRestController.java +++ b/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/src/test/java/com/alipay/sofa/tracer/plugins/okhttp/base/controller/SampleRestController.java @@ -16,7 +16,12 @@ */ package com.alipay.sofa.tracer.plugins.okhttp.base.controller; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; import java.util.Map; diff --git a/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/pom.xml index 88e81200e..cb2e69787 100644 --- a/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/aspect/SofaTracerSendMessageAspect.java b/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/aspect/SofaTracerSendMessageAspect.java index adb9c8b8e..b16136eea 100644 --- a/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/aspect/SofaTracerSendMessageAspect.java +++ b/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/aspect/SofaTracerSendMessageAspect.java @@ -16,7 +16,6 @@ */ package com.sofa.alipay.tracer.plugins.rabbitmq.aspect; -import com.alipay.common.tracer.core.configuration.SofaTracerConfiguration; import com.sofa.alipay.tracer.plugins.rabbitmq.holder.RabbitMqSofaTracerHolder; import com.sofa.alipay.tracer.plugins.rabbitmq.tracers.RabbitMQSendTracer; import org.aspectj.lang.ProceedingJoinPoint; diff --git a/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/holder/RabbitMqSofaTracerHolder.java b/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/holder/RabbitMqSofaTracerHolder.java index e82ed05d2..a7ba6884c 100644 --- a/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/holder/RabbitMqSofaTracerHolder.java +++ b/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/holder/RabbitMqSofaTracerHolder.java @@ -36,7 +36,6 @@ import org.springframework.util.ReflectionUtils; import java.lang.reflect.Field; -import java.util.Map; /** * RabbitMqSofaTracerHolder. diff --git a/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/interceptor/SofaTracerConsumeInterceptor.java b/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/interceptor/SofaTracerConsumeInterceptor.java index ebcbdcf38..1abe0596f 100644 --- a/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/interceptor/SofaTracerConsumeInterceptor.java +++ b/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/interceptor/SofaTracerConsumeInterceptor.java @@ -23,12 +23,8 @@ import com.alipay.common.tracer.core.registry.ExtendFormat; import com.alipay.common.tracer.core.span.CommonSpanTags; import com.alipay.common.tracer.core.span.SofaTracerSpan; -import com.alipay.common.tracer.core.utils.StringUtils; import com.sofa.alipay.tracer.plugins.rabbitmq.carrier.RabbitMqExtractCarrier; -import com.sofa.alipay.tracer.plugins.rabbitmq.carrier.RabbitMqInjectCarrier; import com.sofa.alipay.tracer.plugins.rabbitmq.tracers.RabbitMQConsumeTracer; -import com.sofa.alipay.tracer.plugins.rabbitmq.tracers.RabbitMQSendTracer; -import io.opentracing.SpanContext; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.springframework.amqp.core.Message; diff --git a/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/tracers/RabbitMQSendTracer.java b/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/tracers/RabbitMQSendTracer.java index 900181b6c..f6091a61f 100644 --- a/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/tracers/RabbitMQSendTracer.java +++ b/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rabbitmq/tracers/RabbitMQSendTracer.java @@ -22,13 +22,9 @@ import com.alipay.common.tracer.core.reporter.stat.AbstractSofaTracerStatisticReporter; import com.alipay.common.tracer.core.span.SofaTracerSpan; import com.alipay.common.tracer.core.tracer.AbstractClientTracer; -import com.sofa.alipay.tracer.plugins.rabbitmq.encoders.RabbitMQConsumeDigestEncoder; -import com.sofa.alipay.tracer.plugins.rabbitmq.encoders.RabbitMQConsumeDigestJsonEncoder; import com.sofa.alipay.tracer.plugins.rabbitmq.encoders.RabbitMQSendDigestEncoder; import com.sofa.alipay.tracer.plugins.rabbitmq.encoders.RabbitMQSendDigestJsonEncoder; import com.sofa.alipay.tracer.plugins.rabbitmq.enums.RabbitMqLogEnum; -import com.sofa.alipay.tracer.plugins.rabbitmq.repoters.RabbitMQConsumeStatJsonReporter; -import com.sofa.alipay.tracer.plugins.rabbitmq.repoters.RabbitMQConsumeStatReporter; import com.sofa.alipay.tracer.plugins.rabbitmq.repoters.RabbitMQSendStatJsonReporter; import com.sofa.alipay.tracer.plugins.rabbitmq.repoters.RabbitMQSendStatReporter; diff --git a/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/test/java/com/sofa/tracer/plugins/rabbitmq/base/MockRabbitMqExtractCarrier.java b/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/test/java/com/sofa/tracer/plugins/rabbitmq/base/MockRabbitMqExtractCarrier.java index 88f3bac97..3624c3c2e 100644 --- a/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/test/java/com/sofa/tracer/plugins/rabbitmq/base/MockRabbitMqExtractCarrier.java +++ b/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/test/java/com/sofa/tracer/plugins/rabbitmq/base/MockRabbitMqExtractCarrier.java @@ -17,7 +17,7 @@ package com.sofa.tracer.plugins.rabbitmq.base; import com.sofa.alipay.tracer.plugins.rabbitmq.carrier.RabbitMqExtractCarrier; -import org.junit.*; +import org.junit.Test; import java.util.Collections; import java.util.Iterator; diff --git a/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/test/java/com/sofa/tracer/plugins/rabbitmq/base/MockSofaTracerConsumeInterceptor.java b/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/test/java/com/sofa/tracer/plugins/rabbitmq/base/MockSofaTracerConsumeInterceptor.java index 84147565b..48da73c2a 100644 --- a/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/test/java/com/sofa/tracer/plugins/rabbitmq/base/MockSofaTracerConsumeInterceptor.java +++ b/sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/src/test/java/com/sofa/tracer/plugins/rabbitmq/base/MockSofaTracerConsumeInterceptor.java @@ -21,10 +21,10 @@ import com.alipay.common.tracer.core.registry.AbstractTextB3Formatter; import com.alipay.common.tracer.core.registry.ExtendFormat; import com.alipay.common.tracer.core.span.SofaTracerSpan; -import org.aopalliance.intercept.MethodInvocation; import com.sofa.alipay.tracer.plugins.rabbitmq.carrier.RabbitMqExtractCarrier; import com.sofa.alipay.tracer.plugins.rabbitmq.interceptor.SofaTracerConsumeInterceptor; import com.sofa.alipay.tracer.plugins.rabbitmq.tracers.RabbitMQConsumeTracer; +import org.aopalliance.intercept.MethodInvocation; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.amqp.core.Message; diff --git a/sofa-tracer-plugins/sofa-tracer-redis-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-redis-plugin/pom.xml index 6211b6f53..4077a2137 100644 --- a/sofa-tracer-plugins/sofa-tracer-redis-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-redis-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/SofaTracerRCFBeanPostProcessor.java b/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/SofaTracerRCFBeanPostProcessor.java index 0755372c3..c0c7d4cae 100644 --- a/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/SofaTracerRCFBeanPostProcessor.java +++ b/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/SofaTracerRCFBeanPostProcessor.java @@ -17,7 +17,6 @@ package com.sofa.alipay.tracer.plugins.spring.redis; import com.sofa.alipay.tracer.plugins.spring.redis.common.RedisActionWrapperHelper; - import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.data.redis.connection.RedisConnectionFactory; diff --git a/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/common/RedisActionWrapperHelper.java b/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/common/RedisActionWrapperHelper.java index cd03fed5b..e1950e3cc 100644 --- a/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/common/RedisActionWrapperHelper.java +++ b/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/common/RedisActionWrapperHelper.java @@ -22,6 +22,9 @@ import com.alipay.common.tracer.core.span.CommonSpanTags; import com.alipay.common.tracer.core.span.SofaTracerSpan; import com.sofa.alipay.tracer.plugins.spring.redis.tracer.RedisSofaTracer; +import io.opentracing.Span; +import io.opentracing.Tracer; +import io.opentracing.tag.Tags; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -29,10 +32,6 @@ import java.util.List; import java.util.function.Supplier; -import io.opentracing.Span; -import io.opentracing.Tracer; -import io.opentracing.tag.Tags; - /** * @author: guolei.sgl (guolei.sgl@antfin.com) 2019/11/18 9:15 PM * @since: diff --git a/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingReactiveRedisClusterConnection.java b/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingReactiveRedisClusterConnection.java index ec223a86f..d0c4438b2 100644 --- a/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingReactiveRedisClusterConnection.java +++ b/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingReactiveRedisClusterConnection.java @@ -16,8 +16,8 @@ */ package com.sofa.alipay.tracer.plugins.spring.redis.connections; -import com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand; import com.sofa.alipay.tracer.plugins.spring.redis.common.RedisActionWrapperHelper; +import com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand; import org.springframework.data.redis.connection.ReactiveClusterGeoCommands; import org.springframework.data.redis.connection.ReactiveClusterHashCommands; import org.springframework.data.redis.connection.ReactiveClusterHyperLogLogCommands; diff --git a/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingReactiveRedisConnection.java b/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingReactiveRedisConnection.java index 105073756..10d14c719 100644 --- a/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingReactiveRedisConnection.java +++ b/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingReactiveRedisConnection.java @@ -16,8 +16,8 @@ */ package com.sofa.alipay.tracer.plugins.spring.redis.connections; -import com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand; import com.sofa.alipay.tracer.plugins.spring.redis.common.RedisActionWrapperHelper; +import com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand; import org.springframework.data.redis.connection.ReactiveGeoCommands; import org.springframework.data.redis.connection.ReactiveHashCommands; import org.springframework.data.redis.connection.ReactiveHyperLogLogCommands; diff --git a/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingRedisClusterConnection.java b/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingRedisClusterConnection.java index 8a6234cff..d99e8fe88 100644 --- a/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingRedisClusterConnection.java +++ b/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingRedisClusterConnection.java @@ -32,40 +32,7 @@ import java.util.Properties; import java.util.Set; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.BGREWRITEAOF; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.BGSAVE; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLIENT_LIST; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_ADDSLOTS; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_COUNTKEYSINSLOT; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_DELSLOTS; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_FORGET; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_GETKEYSINSLOT; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_INFO; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_KEYSLOT; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_MASTER_SLAVE_MAP; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_MEET; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_NODES; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_NODE_FOR_KEY; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_NODE_FOR_SLOT; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_REPLICATE; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_SETSLOT; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CLUSTER_SLAVES; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CONFIG_GET; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CONFIG_RESETSTAT; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.CONFIG_SET; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.DBSIZE; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.EXECUTE; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.FLUSHALL; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.FLUSHDB; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.INFO; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.KEYS; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.LASTSAVE; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.PING; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.RANDOMKEY; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.SAVE; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.SCAN; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.SHUTDOWN; -import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.TIME; +import static com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand.*; /** * OpenTracing instrumentation of a {@link RedisClusterConnection}. diff --git a/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingRedisConnection.java b/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingRedisConnection.java index fa784df46..31d97a525 100644 --- a/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingRedisConnection.java +++ b/sofa-tracer-plugins/sofa-tracer-redis-plugin/src/main/java/com/sofa/alipay/tracer/plugins/spring/redis/connections/TracingRedisConnection.java @@ -16,8 +16,8 @@ */ package com.sofa.alipay.tracer.plugins.spring.redis.connections; -import com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand; import com.sofa.alipay.tracer.plugins.spring.redis.common.RedisActionWrapperHelper; +import com.sofa.alipay.tracer.plugins.spring.redis.common.RedisCommand; import org.springframework.dao.DataAccessException; import org.springframework.data.geo.Circle; import org.springframework.data.geo.Distance; diff --git a/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/pom.xml index b405cee93..69df742bd 100644 --- a/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/interceptor/AsyncRestTemplateRequestInterceptor.java b/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/interceptor/AsyncRestTemplateRequestInterceptor.java index fad2d149c..87ec1731f 100644 --- a/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/interceptor/AsyncRestTemplateRequestInterceptor.java +++ b/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/interceptor/AsyncRestTemplateRequestInterceptor.java @@ -33,6 +33,7 @@ import org.springframework.http.client.ClientHttpResponse; import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFutureCallback; + import java.io.IOException; import java.util.List; diff --git a/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/test/java/com/sofa/tracer/plugins/resttemplate/AsyncRestTemplateTest.java b/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/test/java/com/sofa/tracer/plugins/resttemplate/AsyncRestTemplateTest.java index 3dcfbdcf8..a7c334807 100644 --- a/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/test/java/com/sofa/tracer/plugins/resttemplate/AsyncRestTemplateTest.java +++ b/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/test/java/com/sofa/tracer/plugins/resttemplate/AsyncRestTemplateTest.java @@ -31,6 +31,7 @@ import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFutureCallback; import org.springframework.web.client.AsyncRestTemplate; + import java.io.File; import java.io.IOException; import java.util.List; diff --git a/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/test/java/com/sofa/tracer/plugins/resttemplate/base/AbstractTestBase.java b/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/test/java/com/sofa/tracer/plugins/resttemplate/base/AbstractTestBase.java index abdd6dc48..50c932c7d 100644 --- a/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/test/java/com/sofa/tracer/plugins/resttemplate/base/AbstractTestBase.java +++ b/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/test/java/com/sofa/tracer/plugins/resttemplate/base/AbstractTestBase.java @@ -27,6 +27,7 @@ import org.springframework.boot.web.server.LocalServerPort; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + import java.io.File; import java.io.IOException; import java.lang.reflect.Field; diff --git a/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/test/java/com/sofa/tracer/plugins/resttemplate/base/SampleRestController.java b/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/test/java/com/sofa/tracer/plugins/resttemplate/base/SampleRestController.java index 6129623c7..5e01ddafe 100644 --- a/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/test/java/com/sofa/tracer/plugins/resttemplate/base/SampleRestController.java +++ b/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/test/java/com/sofa/tracer/plugins/resttemplate/base/SampleRestController.java @@ -16,7 +16,10 @@ */ package com.sofa.tracer.plugins.resttemplate.base; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; import java.util.Map; diff --git a/sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/pom.xml index ceb1fdc41..fa6a9e415 100644 --- a/sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/src/main/java/com/alipay/sofa/tracer/plugins/rocketmq/interceptor/SofaTracerConsumeMessageHook.java b/sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/src/main/java/com/alipay/sofa/tracer/plugins/rocketmq/interceptor/SofaTracerConsumeMessageHook.java index 574e60cdd..fc1b82af9 100644 --- a/sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/src/main/java/com/alipay/sofa/tracer/plugins/rocketmq/interceptor/SofaTracerConsumeMessageHook.java +++ b/sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/src/main/java/com/alipay/sofa/tracer/plugins/rocketmq/interceptor/SofaTracerConsumeMessageHook.java @@ -16,17 +16,16 @@ */ package com.alipay.sofa.tracer.plugins.rocketmq.interceptor; -import org.apache.rocketmq.client.hook.ConsumeMessageContext; -import org.apache.rocketmq.client.hook.ConsumeMessageHook; -import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.common.message.MessageQueue; - import com.alipay.common.tracer.core.appender.self.SelfLog; import com.alipay.common.tracer.core.constants.SofaTracerConstant; import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext; import com.alipay.common.tracer.core.span.CommonSpanTags; import com.alipay.common.tracer.core.span.SofaTracerSpan; import com.alipay.sofa.tracer.plugins.rocketmq.tracers.RocketMQConsumeTracer; +import org.apache.rocketmq.client.hook.ConsumeMessageContext; +import org.apache.rocketmq.client.hook.ConsumeMessageHook; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageQueue; /** * @author: guolei.sgl (guolei.sgl@antfin.com) 2019/12/12 8:22 PM diff --git a/sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/src/main/java/com/alipay/sofa/tracer/plugins/rocketmq/interceptor/SofaTracerSendMessageHook.java b/sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/src/main/java/com/alipay/sofa/tracer/plugins/rocketmq/interceptor/SofaTracerSendMessageHook.java index 4aed666ea..b43b2cfb0 100644 --- a/sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/src/main/java/com/alipay/sofa/tracer/plugins/rocketmq/interceptor/SofaTracerSendMessageHook.java +++ b/sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/src/main/java/com/alipay/sofa/tracer/plugins/rocketmq/interceptor/SofaTracerSendMessageHook.java @@ -21,7 +21,7 @@ import com.alipay.common.tracer.core.span.CommonSpanTags; import com.alipay.common.tracer.core.span.SofaTracerSpan; import com.alipay.sofa.tracer.plugins.rocketmq.tracers.RocketMQSendTracer; - +import io.opentracing.tag.Tags; import org.apache.rocketmq.client.hook.SendMessageContext; import org.apache.rocketmq.client.hook.SendMessageHook; import org.apache.rocketmq.client.producer.SendResult; @@ -32,8 +32,6 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import io.opentracing.tag.Tags; - /** * @author: guolei.sgl (guolei.sgl@antfin.com) 2019/12/12 8:22 PM * @since: diff --git a/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/pom.xml index d31a13255..89fa40c45 100644 --- a/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springcloud/carriers/FeignRequestCarrier.java b/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springcloud/carriers/FeignRequestCarrier.java index a5fb69a14..9c19f2303 100644 --- a/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springcloud/carriers/FeignRequestCarrier.java +++ b/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springcloud/carriers/FeignRequestCarrier.java @@ -18,6 +18,7 @@ import feign.Request; import io.opentracing.propagation.TextMap; + import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; diff --git a/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springcloud/instruments/feign/SofaTracerFeignContext.java b/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springcloud/instruments/feign/SofaTracerFeignContext.java index 60df1636f..ae7c70e02 100644 --- a/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springcloud/instruments/feign/SofaTracerFeignContext.java +++ b/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springcloud/instruments/feign/SofaTracerFeignContext.java @@ -22,6 +22,7 @@ import org.springframework.cloud.openfeign.FeignContext; import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory; import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient; + import java.util.HashMap; import java.util.Map; diff --git a/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springcloud/tracers/FeignClientTracer.java b/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springcloud/tracers/FeignClientTracer.java index 10c43f6a9..a6d934401 100644 --- a/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springcloud/tracers/FeignClientTracer.java +++ b/sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springcloud/tracers/FeignClientTracer.java @@ -23,9 +23,9 @@ import com.alipay.common.tracer.core.span.SofaTracerSpan; import com.alipay.common.tracer.core.tracer.AbstractClientTracer; import com.alipay.sofa.tracer.plugins.springcloud.encodes.OpenFeignDigestEncoder; -import com.alipay.sofa.tracer.plugins.springcloud.repoters.OpenFeignStatJsonReporter; import com.alipay.sofa.tracer.plugins.springcloud.encodes.OpenFeignDigestJsonEncoder; import com.alipay.sofa.tracer.plugins.springcloud.enums.FeignClientLogEnum; +import com.alipay.sofa.tracer.plugins.springcloud.repoters.OpenFeignStatJsonReporter; import com.alipay.sofa.tracer.plugins.springcloud.repoters.OpenFeignStatReporter; /** diff --git a/sofa-tracer-plugins/sofa-tracer-springmessage-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-springmessage-plugin/pom.xml index ef319296c..ea7fa4448 100644 --- a/sofa-tracer-plugins/sofa-tracer-springmessage-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-springmessage-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/pom.xml index 4ed71289e..247f7a1d3 100644 --- a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/pom.xml @@ -4,7 +4,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml diff --git a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcSofaTracerFilter.java b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcSofaTracerFilter.java index 31e687f9d..a6d43e196 100644 --- a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcSofaTracerFilter.java +++ b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcSofaTracerFilter.java @@ -26,7 +26,12 @@ import com.alipay.common.tracer.core.utils.StringUtils; import io.opentracing.tag.Tags; -import javax.servlet.*; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; diff --git a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/webflux/WebfluxSofaTracerFilter.java b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/webflux/WebfluxSofaTracerFilter.java index 32ddf664e..db88fe886 100644 --- a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/webflux/WebfluxSofaTracerFilter.java +++ b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/webflux/WebfluxSofaTracerFilter.java @@ -38,7 +38,7 @@ import reactor.core.publisher.Mono; import java.net.URI; -import java.util.*; +import java.util.HashMap; /** * @author qilong.zql diff --git a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/pom.xml b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/pom.xml index 32ce18805..08ff31b42 100644 --- a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/pom.xml +++ b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml 4.0.0 diff --git a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinSofaTracerRestTemplateCustomizer.java b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinSofaTracerRestTemplateCustomizer.java index 85571d177..5fc876d83 100644 --- a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinSofaTracerRestTemplateCustomizer.java +++ b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinSofaTracerRestTemplateCustomizer.java @@ -21,6 +21,7 @@ import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.client.RestTemplate; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.GZIPOutputStream; diff --git a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinSofaTracerSpanRemoteReporter.java b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinSofaTracerSpanRemoteReporter.java index 062ab3ee5..18c02ecb4 100644 --- a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinSofaTracerSpanRemoteReporter.java +++ b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinSofaTracerSpanRemoteReporter.java @@ -25,6 +25,7 @@ import org.springframework.web.client.RestTemplate; import zipkin2.Span; import zipkin2.reporter.AsyncReporter; + import java.io.Closeable; import java.io.Flushable; diff --git a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/adapter/NetUtils.java b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/adapter/NetUtils.java index e2c7adb28..3d533bc41 100644 --- a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/adapter/NetUtils.java +++ b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/adapter/NetUtils.java @@ -17,7 +17,6 @@ package com.alipay.sofa.tracer.plugins.zipkin.adapter; import com.alipay.common.tracer.core.utils.StringUtils; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/adapter/ZipkinV2SpanAdapter.java b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/adapter/ZipkinV2SpanAdapter.java index c5f38d1ce..3f415ba81 100644 --- a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/adapter/ZipkinV2SpanAdapter.java +++ b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/adapter/ZipkinV2SpanAdapter.java @@ -21,14 +21,13 @@ import com.alipay.common.tracer.core.span.LogData; import com.alipay.common.tracer.core.span.SofaTracerSpan; import com.alipay.common.tracer.core.utils.StringUtils; - -import java.net.InetAddress; -import java.util.Map; - import io.opentracing.tag.Tags; import zipkin2.Endpoint; import zipkin2.Span; +import java.net.InetAddress; +import java.util.Map; + /*** * ZipkinV2SpanAdapter : convent sofaTracer span model to zipkin span model * @author guolei.sgl 05/09/2018 diff --git a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/initialize/ZipkinReportRegisterBean.java b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/initialize/ZipkinReportRegisterBean.java index fb88d62c4..dd3bcf057 100644 --- a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/initialize/ZipkinReportRegisterBean.java +++ b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/initialize/ZipkinReportRegisterBean.java @@ -20,9 +20,9 @@ import com.alipay.common.tracer.core.listener.SpanReportListener; import com.alipay.common.tracer.core.listener.SpanReportListenerHolder; import com.alipay.common.tracer.core.utils.StringUtils; -import com.alipay.sofa.tracer.plugins.zipkin.properties.ZipkinProperties; import com.alipay.sofa.tracer.plugins.zipkin.ZipkinSofaTracerRestTemplateCustomizer; import com.alipay.sofa.tracer.plugins.zipkin.ZipkinSofaTracerSpanRemoteReporter; +import com.alipay.sofa.tracer.plugins.zipkin.properties.ZipkinProperties; import org.springframework.beans.factory.InitializingBean; import org.springframework.web.client.RestTemplate; diff --git a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/sender/ZipkinRestTemplateSender.java b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/sender/ZipkinRestTemplateSender.java index dd1c07701..ce800c4c6 100644 --- a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/sender/ZipkinRestTemplateSender.java +++ b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/sender/ZipkinRestTemplateSender.java @@ -26,6 +26,7 @@ import zipkin2.codec.Encoding; import zipkin2.reporter.BytesMessageEncoder; import zipkin2.reporter.Sender; + import java.net.URI; import java.util.List; diff --git a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/test/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinV2SpanAdapterTest.java b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/test/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinV2SpanAdapterTest.java index e81e02b53..b1ccd382d 100644 --- a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/test/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinV2SpanAdapterTest.java +++ b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/test/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinV2SpanAdapterTest.java @@ -25,6 +25,7 @@ import org.junit.Before; import org.junit.Test; import zipkin2.Span; + import java.util.HashMap; import java.util.Map; diff --git a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/test/resources/spring-bean.xml b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/test/resources/spring-bean.xml index cf4900015..2b84719e1 100644 --- a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/test/resources/spring-bean.xml +++ b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/test/resources/spring-bean.xml @@ -1,15 +1,12 @@ diff --git a/tracer-all/pom.xml b/tracer-all/pom.xml index 7c76acecb..01aeb3629 100644 --- a/tracer-all/pom.xml +++ b/tracer-all/pom.xml @@ -5,12 +5,12 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 4.0.0 tracer-all - 3.1.0 + 3.1.1 jar SOFATracer in one without SOFABoot starter diff --git a/tracer-core/pom.xml b/tracer-core/pom.xml index b17e0cf79..1a35800e6 100644 --- a/tracer-core/pom.xml +++ b/tracer-core/pom.xml @@ -4,7 +4,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../pom.xml diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/SofaTracer.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/SofaTracer.java index d834e394d..68f8cb331 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/SofaTracer.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/SofaTracer.java @@ -133,7 +133,7 @@ public void reportSpan(SofaTracerSpan span) { return; } // //sampler is support & current span is root span - if (sampler != null && span.getParentSofaTracerSpan() == null) { + if (sampler != null && (span.isClient() && span.getParentSofaTracerSpan() == null)) { span.getSofaTracerSpanContext().setSampled(sampler.sample(span).isSampled()); } //invoke listener diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemon.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemon.java index 7376028b3..8817faf1a 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemon.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemon.java @@ -16,14 +16,14 @@ */ package com.alipay.common.tracer.core.appender; -import java.io.File; -import java.nio.charset.Charset; - import com.alipay.common.tracer.core.appender.self.SelfLog; import com.alipay.common.tracer.core.appender.self.TracerDaemon; import com.alipay.common.tracer.core.utils.StringUtils; import com.alipay.common.tracer.core.utils.TracerUtils; +import java.io.File; +import java.nio.charset.Charset; + /** * TracerLogRootDaemon *

@@ -64,6 +64,11 @@ public class TracerLogRootDaemon { if (StringUtils.isBlank(loggingRoot)) { loggingRoot = System.getProperty("logging.path"); } + // adapter to springboot 2.4.x + if (StringUtils.isBlank(loggingRoot)) { + loggingRoot = System.getProperty("logging.file.path"); + } + if (StringUtils.isBlank(loggingRoot)) { loggingRoot = System.getProperty("user.home") + File.separator + "logs"; } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppender.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppender.java index b6f82c6c0..a13941e85 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppender.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppender.java @@ -28,7 +28,11 @@ import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Locale; +import java.util.TimeZone; import static com.alipay.common.tracer.core.constants.SofaTracerConstant.SPACE_ID; diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/SelfLog.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/SelfLog.java index 592facc8b..7f5556e38 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/SelfLog.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/SelfLog.java @@ -50,13 +50,28 @@ public class SelfLog { * @param e */ public static void error(String log, Throwable e) { + logWithException(ERROR_PREFIX, log, e); + } + + /** + * Warn with exception + * @param log + * @param e + */ + public static void warn(String log, Throwable e) { + logWithException(WARN_PREFIX, log, e); + } + + public static void logWithException(String prefix, String log, Throwable e) { try { String timestamp = Timestamp.currentTime(); StringWriter sw = new StringWriter(4096); PrintWriter pw = new PrintWriter(sw, false); - pw.append(timestamp).append(ERROR_PREFIX).append(log).append(StringUtils.NEWLINE); - e.printStackTrace(pw); - pw.println(); + pw.append(timestamp).append(prefix).append(log).append(StringUtils.NEWLINE); + if (e != null) { + e.printStackTrace(pw); + pw.println(); + } pw.flush(); selfLogAppenderManager.append(sw.toString()); } catch (Throwable t) { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/FunctionalAsyncSupport.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/FunctionalAsyncSupport.java new file mode 100644 index 000000000..dd91f24f5 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/FunctionalAsyncSupport.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.context.trace.SofaTraceContext; +import com.alipay.common.tracer.core.extensions.SpanExtensionFactory; +import com.alipay.common.tracer.core.span.SofaTracerSpan; + +/** + * @author khotyn + * @version FunctionalAsyncSupport.java, v 0.1 2021年02月17日 11:02 下午 khotyn + */ +public class FunctionalAsyncSupport { + private final long tid = Thread.currentThread().getId(); + protected final SofaTraceContext traceContext; + private final SofaTracerSpan currentSpan; + + public FunctionalAsyncSupport(SofaTraceContext traceContext) { + this.traceContext = traceContext; + if (!traceContext.isEmpty()) { + this.currentSpan = traceContext.getCurrentSpan(); + } else { + this.currentSpan = null; + } + } + + public void doBefore() { + if (Thread.currentThread().getId() != tid) { + if (currentSpan != null) { + traceContext.push(currentSpan); + SpanExtensionFactory.logStartedSpan(currentSpan); + } + } + } + + public void doFinally() { + if (Thread.currentThread().getId() != tid) { + if (currentSpan != null) { + traceContext.pop(); + } + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerBiConsumer.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerBiConsumer.java new file mode 100644 index 000000000..b7c5892d2 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerBiConsumer.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.BiConsumer; + +/** + * @author khotyn + * @version SofaTracerBiConsumer.java, v 0.1 2021年02月17日 11:04 下午 khotyn + */ +public class SofaTracerBiConsumer implements BiConsumer { + private final BiConsumer wrappedBiConsumer; + private final FunctionalAsyncSupport functionalAsyncSupport; + + public SofaTracerBiConsumer(BiConsumer wrappedBiConsumer) { + this.wrappedBiConsumer = wrappedBiConsumer; + this.functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public void accept(T t, U u) { + functionalAsyncSupport.doBefore(); + try { + wrappedBiConsumer.accept(t, u); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerBiFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerBiFunction.java new file mode 100644 index 000000000..516bf8fb0 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerBiFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.BiFunction; + +/** + * @author khotyn + * @version SofaTracerBiFunction.java, v 0.1 2021年02月17日 11:04 下午 khotyn + */ +public class SofaTracerBiFunction implements BiFunction { + private final BiFunction wrappedBiFunction; + private final FunctionalAsyncSupport functionalAsyncSupport; + + public SofaTracerBiFunction(BiFunction wrappedBiFunction) { + this.wrappedBiFunction = wrappedBiFunction; + this.functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public R apply(T t, U u) { + functionalAsyncSupport.doBefore(); + try { + return wrappedBiFunction.apply(t, u); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerBiPredicate.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerBiPredicate.java new file mode 100644 index 000000000..404ef756e --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerBiPredicate.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.BiPredicate; + +/** + * @author khotyn + * @version SofaTracerBiPredicate.java, v 0.1 2021年02月17日 11:05 下午 khotyn + */ +public class SofaTracerBiPredicate implements BiPredicate { + private final BiPredicate wrappedBiPredicate; + private final FunctionalAsyncSupport functionalAsyncSupport; + + public SofaTracerBiPredicate(BiPredicate wrappedBiPredicate) { + this.wrappedBiPredicate = wrappedBiPredicate; + this.functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public boolean test(T t, U u) { + functionalAsyncSupport.doBefore(); + try { + return wrappedBiPredicate.test(t, u); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerBooleanSupplier.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerBooleanSupplier.java new file mode 100644 index 000000000..5979850d6 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerBooleanSupplier.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.BooleanSupplier; + +/** + * @author khotyn + * @version SofaTracerBooleanSupplier.java, v 0.1 2021年02月17日 11:05 下午 khotyn + */ +public class SofaTracerBooleanSupplier implements BooleanSupplier { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final BooleanSupplier wrappedBooleanSupplier; + + public SofaTracerBooleanSupplier(BooleanSupplier wrappedBooleanSupplier) { + this.wrappedBooleanSupplier = wrappedBooleanSupplier; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public boolean getAsBoolean() { + functionalAsyncSupport.doBefore(); + try { + return wrappedBooleanSupplier.getAsBoolean(); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerCallable.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerCallable.java index e04a8fde8..229c75595 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerCallable.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerCallable.java @@ -17,9 +17,7 @@ package com.alipay.common.tracer.core.async; import com.alipay.common.tracer.core.context.trace.SofaTraceContext; -import com.alipay.common.tracer.core.extensions.SpanExtensionFactory; import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; -import com.alipay.common.tracer.core.span.SofaTracerSpan; import java.util.concurrent.Callable; @@ -31,11 +29,8 @@ * @version $Id: Callable.java, v 0.1 June 19, 2017 5:52 PM luoguimu123 Exp $ */ public class SofaTracerCallable implements Callable { - - private long tid = Thread.currentThread().getId(); - private Callable wrappedCallable; - private SofaTraceContext traceContext; - private SofaTracerSpan currentSpan; + private Callable wrappedCallable; + private FunctionalAsyncSupport functionalAsyncSupport; public SofaTracerCallable(Callable wrappedCallable) { this.initCallable(wrappedCallable, SofaTraceContextHolder.getSofaTraceContext()); @@ -47,30 +42,16 @@ public SofaTracerCallable(Callable wrappedCallable, SofaTraceContext traceCon private void initCallable(Callable wrappedCallable, SofaTraceContext traceContext) { this.wrappedCallable = wrappedCallable; - this.traceContext = traceContext; - if (!traceContext.isEmpty()) { - this.currentSpan = traceContext.getCurrentSpan(); - } else { - this.currentSpan = null; - } + this.functionalAsyncSupport = new FunctionalAsyncSupport(traceContext); } @Override public T call() throws Exception { - if (Thread.currentThread().getId() != tid) { - if (currentSpan != null) { - traceContext.push(currentSpan); - SpanExtensionFactory.logStartedSpan(currentSpan); - } - } + functionalAsyncSupport.doBefore(); try { return wrappedCallable.call(); } finally { - if (Thread.currentThread().getId() != tid) { - if (currentSpan != null) { - traceContext.pop(); - } - } + functionalAsyncSupport.doFinally(); } } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerConsumer.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerConsumer.java new file mode 100644 index 000000000..d7ca88712 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerConsumer.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.Consumer; + +/** + * @author khotyn + * @version SofaTracerConsumer.java, v 0.1 2021年02月07日 10:57 下午 khotyn + */ +public class SofaTracerConsumer implements Consumer { + private final Consumer wrappedConsumer; + private final FunctionalAsyncSupport functionalAsyncSupport; + + public SofaTracerConsumer(Consumer wrappedConsumer) { + this.wrappedConsumer = wrappedConsumer; + this.functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public void accept(T t) { + functionalAsyncSupport.doBefore(); + try { + wrappedConsumer.accept(t); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleBinaryOperator.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleBinaryOperator.java new file mode 100644 index 000000000..549d562c2 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleBinaryOperator.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.DoubleBinaryOperator; + +/** + * @author khotyn + * @version SofaTracerDoubleBinaryOperator.java, v 0.1 2021年02月07日 11:21 下午 khotyn + */ +public class SofaTracerDoubleBinaryOperator implements DoubleBinaryOperator { + private final DoubleBinaryOperator wrappedDoubleBinaryOperator; + private final FunctionalAsyncSupport functionalAsyncSupport; + + public SofaTracerDoubleBinaryOperator(DoubleBinaryOperator wrappedDoubleBinaryOperator) { + this.wrappedDoubleBinaryOperator = wrappedDoubleBinaryOperator; + this.functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public double applyAsDouble(double left, double right) { + functionalAsyncSupport.doBefore(); + try { + return wrappedDoubleBinaryOperator.applyAsDouble(left, right); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleConsumer.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleConsumer.java new file mode 100644 index 000000000..32a89e329 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleConsumer.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.DoubleConsumer; + +/** + * @author khotyn + * @version SofaTracerDoubleConsumer.java, v 0.1 2021年02月07日 11:23 下午 khotyn + */ +public class SofaTracerDoubleConsumer implements DoubleConsumer { + private final DoubleConsumer wrappedDoubleConsumer; + private final FunctionalAsyncSupport functionalAsyncSupport; + + public SofaTracerDoubleConsumer(DoubleConsumer wrappedDoubleConsumer) { + this.wrappedDoubleConsumer = wrappedDoubleConsumer; + this.functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public void accept(double value) { + functionalAsyncSupport.doBefore(); + try { + wrappedDoubleConsumer.accept(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleFunction.java new file mode 100644 index 000000000..9641d7279 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.DoubleFunction; + +/** + * @author khotyn + * @version SofaTracerDoubleFunction.java, v 0.1 2021年02月07日 11:24 下午 khotyn + */ +public class SofaTracerDoubleFunction implements DoubleFunction { + private final DoubleFunction wrappedDoubleFunction; + private final FunctionalAsyncSupport functionalAsyncSupport; + + public SofaTracerDoubleFunction(DoubleFunction wrappedDoubleFunction) { + this.wrappedDoubleFunction = wrappedDoubleFunction; + this.functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public R apply(double value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedDoubleFunction.apply(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoublePredicate.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoublePredicate.java new file mode 100644 index 000000000..d065b62c4 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoublePredicate.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.DoublePredicate; + +/** + * @author khotyn + * @version SofaTracer.java, v 0.1 2021年02月18日 11:54 上午 khotyn + */ +public class SofaTracerDoublePredicate implements DoublePredicate { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final DoublePredicate wrappedDoublePredicate; + + public SofaTracerDoublePredicate(DoublePredicate wrappedDoublePredicate) { + this.wrappedDoublePredicate = wrappedDoublePredicate; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public boolean test(double value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedDoublePredicate.test(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleSupplier.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleSupplier.java new file mode 100644 index 000000000..b6ad472cb --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleSupplier.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.DoubleSupplier; + +/** + * @author khotyn + * @version SofaTracerDoubleSupplier.java, v 0.1 2021年02月07日 10:53 下午 khotyn + */ +public class SofaTracerDoubleSupplier implements DoubleSupplier { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final DoubleSupplier wrappedDoubleSupplier; + + public SofaTracerDoubleSupplier(DoubleSupplier wrappedDoubleSupplier) { + this.wrappedDoubleSupplier = wrappedDoubleSupplier; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public double getAsDouble() { + functionalAsyncSupport.doBefore(); + try { + return wrappedDoubleSupplier.getAsDouble(); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleToIntFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleToIntFunction.java new file mode 100644 index 000000000..1a08d6d70 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleToIntFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.DoubleToIntFunction; + +/** + * @author khotyn + * @version SofaTracerDoubleToIntFunction.java, v 0.1 2021年02月18日 11:53 上午 khotyn + */ +public class SofaTracerDoubleToIntFunction implements DoubleToIntFunction { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final DoubleToIntFunction wrappedDoubleToIntFunction; + + public SofaTracerDoubleToIntFunction(DoubleToIntFunction wrappedDoubleToIntFunction) { + this.wrappedDoubleToIntFunction = wrappedDoubleToIntFunction; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public int applyAsInt(double value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedDoubleToIntFunction.applyAsInt(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleToLongFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleToLongFunction.java new file mode 100644 index 000000000..b22155620 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleToLongFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.DoubleToLongFunction; + +/** + * @author khotyn + * @version SofaTracerDoubleToLongFunction.java, v 0.1 2021年02月18日 11:56 上午 khotyn + */ +public class SofaTracerDoubleToLongFunction implements DoubleToLongFunction { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final DoubleToLongFunction wrappedDoubleToLongFunction; + + public SofaTracerDoubleToLongFunction(DoubleToLongFunction wrappedDoubleToLongFunction) { + this.wrappedDoubleToLongFunction = wrappedDoubleToLongFunction; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public long applyAsLong(double value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedDoubleToLongFunction.applyAsLong(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleUnaryOperator.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleUnaryOperator.java new file mode 100644 index 000000000..f637c51d2 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerDoubleUnaryOperator.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.DoubleUnaryOperator; + +/** + * @author khotyn + * @version SofaTracerDoubleUnaryOperator.java, v 0.1 2021年02月18日 11:57 上午 khotyn + */ +public class SofaTracerDoubleUnaryOperator implements DoubleUnaryOperator { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final DoubleUnaryOperator wrappedDoubleUnaryOperator; + + public SofaTracerDoubleUnaryOperator(DoubleUnaryOperator wrappedDoubleUnaryOperator) { + this.wrappedDoubleUnaryOperator = wrappedDoubleUnaryOperator; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public double applyAsDouble(double operand) { + functionalAsyncSupport.doBefore(); + try { + return wrappedDoubleUnaryOperator.applyAsDouble(operand); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerFunction.java new file mode 100644 index 000000000..4fb2fae92 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.Function; + +/** + * @author khotyn + * @version SofaTracerFunction.java, v 0.1 2021年02月07日 9:56 下午 khotyn + */ +public class SofaTracerFunction implements Function { + private final Function wrappedFunction; + private final FunctionalAsyncSupport functionalAsyncSupport; + + public SofaTracerFunction(Function wrappedFunction) { + this.wrappedFunction = wrappedFunction; + this.functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public R apply(T t) { + functionalAsyncSupport.doBefore(); + try { + return wrappedFunction.apply(t); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntBinaryOperator.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntBinaryOperator.java new file mode 100644 index 000000000..dd6aa5441 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntBinaryOperator.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.IntBinaryOperator; + +/** + * @author khotyn + * @version SofaTracerIntBinaryOperator.java, v 0.1 2021年02月18日 11:58 上午 khotyn + */ +public class SofaTracerIntBinaryOperator implements IntBinaryOperator { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final IntBinaryOperator wrappedIntBinaryOperator; + + public SofaTracerIntBinaryOperator(IntBinaryOperator wrappedIntBinaryOperator) { + this.wrappedIntBinaryOperator = wrappedIntBinaryOperator; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public int applyAsInt(int left, int right) { + functionalAsyncSupport.doBefore(); + try { + return wrappedIntBinaryOperator.applyAsInt(left, right); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntConsumer.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntConsumer.java new file mode 100644 index 000000000..cd5af1b30 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntConsumer.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.IntConsumer; + +/** + * @author khotyn + * @version SofaTracerIntConsumer.java, v 0.1 2021年02月18日 12:00 下午 khotyn + */ +public class SofaTracerIntConsumer implements IntConsumer { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final IntConsumer wrappedIntConsumer; + + public SofaTracerIntConsumer(IntConsumer wrappedIntConsumer) { + this.wrappedIntConsumer = wrappedIntConsumer; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public void accept(int value) { + functionalAsyncSupport.doBefore(); + try { + wrappedIntConsumer.accept(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntFunction.java new file mode 100644 index 000000000..9200df89e --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.IntFunction; + +/** + * @author khotyn + * @version SofaTracerIntFunction.java, v 0.1 2021年02月18日 12:01 下午 khotyn + */ +public class SofaTracerIntFunction implements IntFunction { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final IntFunction wrappedIntFunction; + + public SofaTracerIntFunction(IntFunction wrappedIntFunction) { + this.wrappedIntFunction = wrappedIntFunction; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public R apply(int value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedIntFunction.apply(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntPredicate.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntPredicate.java new file mode 100644 index 000000000..54652db7b --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntPredicate.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.IntPredicate; + +/** + * @author khotyn + * @version v0.1 + */ +public class SofaTracerIntPredicate implements IntPredicate { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final IntPredicate wrappedIntPredicate; + + public SofaTracerIntPredicate(IntPredicate wrappedIntPredicate) { + this.wrappedIntPredicate = wrappedIntPredicate; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public boolean test(int value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedIntPredicate.test(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntSupplier.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntSupplier.java new file mode 100644 index 000000000..f2ba7dad5 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntSupplier.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.IntSupplier; + +/** + * @author khotyn + * @version SofaTracerIntSupplier.java, v 0.1 2021年02月07日 10:41 下午 khotyn + */ +public class SofaTracerIntSupplier implements IntSupplier { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final IntSupplier wrappedSupplier; + + public SofaTracerIntSupplier(IntSupplier wrappedSupplier) { + this.wrappedSupplier = wrappedSupplier; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public int getAsInt() { + functionalAsyncSupport.doBefore(); + try { + return wrappedSupplier.getAsInt(); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntToDoubleFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntToDoubleFunction.java new file mode 100644 index 000000000..8623c4c31 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntToDoubleFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.IntToDoubleFunction; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerIntToDoubleFunction implements IntToDoubleFunction { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final IntToDoubleFunction wrappedIntToDoubleFunction; + + public SofaTracerIntToDoubleFunction(IntToDoubleFunction wrappedIntToDoubleFunction) { + this.wrappedIntToDoubleFunction = wrappedIntToDoubleFunction; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public double applyAsDouble(int value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedIntToDoubleFunction.applyAsDouble(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntToLongFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntToLongFunction.java new file mode 100644 index 000000000..61a223fc1 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntToLongFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.IntToLongFunction; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerIntToLongFunction implements IntToLongFunction { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final IntToLongFunction wrappedIntToLongFunction; + + public SofaTracerIntToLongFunction(IntToLongFunction wrappedIntToLongFunction) { + this.wrappedIntToLongFunction = wrappedIntToLongFunction; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public long applyAsLong(int value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedIntToLongFunction.applyAsLong(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntUnaryOperator.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntUnaryOperator.java new file mode 100644 index 000000000..57ea4e434 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerIntUnaryOperator.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.IntUnaryOperator; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerIntUnaryOperator implements IntUnaryOperator { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final IntUnaryOperator wrappedIntUnaryOperator; + + public SofaTracerIntUnaryOperator(IntUnaryOperator wrappedIntUnaryOperator) { + this.wrappedIntUnaryOperator = wrappedIntUnaryOperator; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public int applyAsInt(int operand) { + functionalAsyncSupport.doBefore(); + try { + return wrappedIntUnaryOperator.applyAsInt(operand); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongBinaryOperator.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongBinaryOperator.java new file mode 100644 index 000000000..6d7940495 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongBinaryOperator.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.LongBinaryOperator; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerLongBinaryOperator implements LongBinaryOperator { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final LongBinaryOperator wrappedLongBinaryOperator; + + public SofaTracerLongBinaryOperator(LongBinaryOperator wrappedLongBinaryOperator) { + this.wrappedLongBinaryOperator = wrappedLongBinaryOperator; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public long applyAsLong(long left, long right) { + functionalAsyncSupport.doBefore(); + try { + return wrappedLongBinaryOperator.applyAsLong(left, right); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongConsumer.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongConsumer.java new file mode 100644 index 000000000..91496e329 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongConsumer.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.LongConsumer; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerLongConsumer implements LongConsumer { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final LongConsumer wrappedLongConsumer; + + public SofaTracerLongConsumer(LongConsumer wrappedLongConsumer) { + this.wrappedLongConsumer = wrappedLongConsumer; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public void accept(long value) { + functionalAsyncSupport.doBefore(); + try { + wrappedLongConsumer.accept(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongFunction.java new file mode 100644 index 000000000..ffcc18498 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.LongFunction; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerLongFunction implements LongFunction { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final LongFunction wrappedLongFunction; + + public SofaTracerLongFunction(LongFunction wrappedLongFunction) { + this.wrappedLongFunction = wrappedLongFunction; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public R apply(long value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedLongFunction.apply(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongPredicate.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongPredicate.java new file mode 100644 index 000000000..ce7dd8fa7 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongPredicate.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.LongPredicate; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerLongPredicate implements LongPredicate { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final LongPredicate wrappedLongPredicate; + + public SofaTracerLongPredicate(LongPredicate wrappedLongPredicate) { + this.wrappedLongPredicate = wrappedLongPredicate; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public boolean test(long value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedLongPredicate.test(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongSupplier.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongSupplier.java new file mode 100644 index 000000000..b431526b3 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongSupplier.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.LongSupplier; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerLongSupplier implements LongSupplier { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final LongSupplier wrappedLongSupplier; + + public SofaTracerLongSupplier(LongSupplier wrappedLongSupplier) { + this.wrappedLongSupplier = wrappedLongSupplier; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public long getAsLong() { + functionalAsyncSupport.doBefore(); + try { + return wrappedLongSupplier.getAsLong(); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongToDoubleFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongToDoubleFunction.java new file mode 100644 index 000000000..4ae1d0137 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongToDoubleFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.LongToDoubleFunction; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerLongToDoubleFunction implements LongToDoubleFunction { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final LongToDoubleFunction wrappedLongToDoubleFunction; + + public SofaTracerLongToDoubleFunction(LongToDoubleFunction wrappedLongToDoubleFunction) { + this.wrappedLongToDoubleFunction = wrappedLongToDoubleFunction; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public double applyAsDouble(long value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedLongToDoubleFunction.applyAsDouble(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongToIntFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongToIntFunction.java new file mode 100644 index 000000000..5f40ab536 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongToIntFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.LongToIntFunction; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerLongToIntFunction implements LongToIntFunction { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final LongToIntFunction wrappedLongToIntFunction; + + public SofaTracerLongToIntFunction(LongToIntFunction wrappedLongToIntFunction) { + this.wrappedLongToIntFunction = wrappedLongToIntFunction; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public int applyAsInt(long value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedLongToIntFunction.applyAsInt(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongUnaryOperator.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongUnaryOperator.java new file mode 100644 index 000000000..c824b9141 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerLongUnaryOperator.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.LongUnaryOperator; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerLongUnaryOperator implements LongUnaryOperator { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final LongUnaryOperator wrappedLongUnaryOperator; + + public SofaTracerLongUnaryOperator(LongUnaryOperator wrappedLongUnaryOperator) { + this.wrappedLongUnaryOperator = wrappedLongUnaryOperator; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public long applyAsLong(long operand) { + functionalAsyncSupport.doBefore(); + try { + return wrappedLongUnaryOperator.applyAsLong(operand); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerObjDoubleConsumer.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerObjDoubleConsumer.java new file mode 100644 index 000000000..0ac08bf9d --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerObjDoubleConsumer.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.ObjDoubleConsumer; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerObjDoubleConsumer implements ObjDoubleConsumer { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final ObjDoubleConsumer wrappedObjDoubleConsumer; + + public SofaTracerObjDoubleConsumer(ObjDoubleConsumer wrappedObjDoubleConsumer) { + this.wrappedObjDoubleConsumer = wrappedObjDoubleConsumer; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public void accept(T t, double value) { + functionalAsyncSupport.doBefore(); + try { + wrappedObjDoubleConsumer.accept(t, value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerObjIntConsumer.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerObjIntConsumer.java new file mode 100644 index 000000000..44153387f --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerObjIntConsumer.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.ObjIntConsumer; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerObjIntConsumer implements ObjIntConsumer { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final ObjIntConsumer wrappedDoubleSupplier; + + public SofaTracerObjIntConsumer(ObjIntConsumer wrappedDoubleSupplier) { + this.wrappedDoubleSupplier = wrappedDoubleSupplier; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public void accept(T t, int value) { + functionalAsyncSupport.doBefore(); + try { + wrappedDoubleSupplier.accept(t, value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerObjLongConsumer.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerObjLongConsumer.java new file mode 100644 index 000000000..95f2739c8 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerObjLongConsumer.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.ObjLongConsumer; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerObjLongConsumer implements ObjLongConsumer { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final ObjLongConsumer wrappedObjLongConsumer; + + public SofaTracerObjLongConsumer(ObjLongConsumer wrappedObjLongConsumer) { + this.wrappedObjLongConsumer = wrappedObjLongConsumer; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public void accept(T t, long value) { + functionalAsyncSupport.doBefore(); + try { + wrappedObjLongConsumer.accept(t, value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerPredicate.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerPredicate.java new file mode 100644 index 000000000..b105be092 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerPredicate.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.Predicate; + +/** + * @author khotyn + * @version SofaTracerPredicate.java, v 0.1 2021年02月07日 10:54 下午 khotyn + */ +public class SofaTracerPredicate implements Predicate { + private final Predicate wrappedPredicate; + private final FunctionalAsyncSupport functionalAsyncSupport; + + public SofaTracerPredicate(Predicate wrappedPredicate) { + this.wrappedPredicate = wrappedPredicate; + this.functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public boolean test(T t) { + functionalAsyncSupport.doBefore(); + try { + return wrappedPredicate.test(t); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerRunnable.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerRunnable.java index 6dbb71a72..039e06251 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerRunnable.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerRunnable.java @@ -17,9 +17,8 @@ package com.alipay.common.tracer.core.async; import com.alipay.common.tracer.core.context.trace.SofaTraceContext; -import com.alipay.common.tracer.core.extensions.SpanExtensionFactory; import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; -import com.alipay.common.tracer.core.span.SofaTracerSpan; + import java.lang.Runnable; /** @@ -30,11 +29,8 @@ * @version $Id: Runnable.java, v 0.1 June 19, 2017 5:54 PM luoguimu123 Exp $ */ public class SofaTracerRunnable implements Runnable { - - private long tid = Thread.currentThread().getId(); - private Runnable wrappedRunnable; - private SofaTraceContext traceContext; - private SofaTracerSpan currentSpan; + private Runnable wrappedRunnable; + protected FunctionalAsyncSupport functionalAsyncSupport; public SofaTracerRunnable(Runnable wrappedRunnable) { this.initRunnable(wrappedRunnable, SofaTraceContextHolder.getSofaTraceContext()); @@ -46,30 +42,16 @@ public SofaTracerRunnable(Runnable wrappedRunnable, SofaTraceContext traceContex private void initRunnable(Runnable wrappedRunnable, SofaTraceContext traceContext) { this.wrappedRunnable = wrappedRunnable; - this.traceContext = traceContext; - if (!traceContext.isEmpty()) { - this.currentSpan = traceContext.getCurrentSpan(); - } else { - this.currentSpan = null; - } + this.functionalAsyncSupport = new FunctionalAsyncSupport(traceContext); } @Override public void run() { - if (Thread.currentThread().getId() != tid) { - if (currentSpan != null) { - traceContext.push(currentSpan); - SpanExtensionFactory.logStartedSpan(currentSpan); - } - } + functionalAsyncSupport.doBefore(); try { wrappedRunnable.run(); } finally { - if (Thread.currentThread().getId() != tid) { - if (currentSpan != null) { - traceContext.pop(); - } - } + functionalAsyncSupport.doFinally(); } } } \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerSupplier.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerSupplier.java new file mode 100644 index 000000000..1ccce16f8 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerSupplier.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.Supplier; + +/** + * @author khotyn + * @version SofaTracerSupplier.java, v 0.1 2021年02月07日 2:02 下午 khotyn + */ +public class SofaTracerSupplier implements Supplier { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final Supplier wrappedSupplier; + + public SofaTracerSupplier(Supplier wrappedSupplier) { + this.wrappedSupplier = wrappedSupplier; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public T get() { + functionalAsyncSupport.doBefore(); + try { + return wrappedSupplier.get(); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToDoubleBiFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToDoubleBiFunction.java new file mode 100644 index 000000000..be489099d --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToDoubleBiFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.ToDoubleBiFunction; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerToDoubleBiFunction implements ToDoubleBiFunction { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final ToDoubleBiFunction wrappedToDoubleBiFunction; + + public SofaTracerToDoubleBiFunction(ToDoubleBiFunction wrappedToDoubleBiFunction) { + this.wrappedToDoubleBiFunction = wrappedToDoubleBiFunction; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public double applyAsDouble(T t, U u) { + functionalAsyncSupport.doBefore(); + try { + return wrappedToDoubleBiFunction.applyAsDouble(t, u); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToDoubleFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToDoubleFunction.java new file mode 100644 index 000000000..28f8ab612 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToDoubleFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.ToDoubleFunction; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerToDoubleFunction implements ToDoubleFunction { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final ToDoubleFunction wrappedToDoubleFunction; + + public SofaTracerToDoubleFunction(ToDoubleFunction wrappedToDoubleFunction) { + this.wrappedToDoubleFunction = wrappedToDoubleFunction; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public double applyAsDouble(T value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedToDoubleFunction.applyAsDouble(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToIntBiFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToIntBiFunction.java new file mode 100644 index 000000000..7aa26f2a7 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToIntBiFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.ToIntBiFunction; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerToIntBiFunction implements ToIntBiFunction { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final ToIntBiFunction wrappedToIntBiFunction; + + public SofaTracerToIntBiFunction(ToIntBiFunction wrappedToIntBiFunction) { + this.wrappedToIntBiFunction = wrappedToIntBiFunction; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public int applyAsInt(T t, U u) { + functionalAsyncSupport.doBefore(); + try { + return wrappedToIntBiFunction.applyAsInt(t, u); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToIntFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToIntFunction.java new file mode 100644 index 000000000..da1f9571b --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToIntFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.ToIntFunction; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerToIntFunction implements ToIntFunction { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final ToIntFunction wrappedToIntFunction; + + public SofaTracerToIntFunction(ToIntFunction wrappedToIntFunction) { + this.wrappedToIntFunction = wrappedToIntFunction; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public int applyAsInt(T value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedToIntFunction.applyAsInt(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToLongBiFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToLongBiFunction.java new file mode 100644 index 000000000..14aee8bb3 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToLongBiFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.ToLongBiFunction; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerToLongBiFunction implements ToLongBiFunction { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final ToLongBiFunction wrappedToLongBiFunction; + + public SofaTracerToLongBiFunction(ToLongBiFunction wrappedToLongBiFunction) { + this.wrappedToLongBiFunction = wrappedToLongBiFunction; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public long applyAsLong(T t, U u) { + functionalAsyncSupport.doBefore(); + try { + return wrappedToLongBiFunction.applyAsLong(t, u); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToLongFunction.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToLongFunction.java new file mode 100644 index 000000000..98ad01682 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerToLongFunction.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; + +import java.util.function.ToLongFunction; + +/** + * @author khotyn + * @version v0.1 2021.02.18 + */ +public class SofaTracerToLongFunction implements ToLongFunction { + private final FunctionalAsyncSupport functionalAsyncSupport; + private final ToLongFunction wrappedToLongFunction; + + public SofaTracerToLongFunction(ToLongFunction wrappedToLongFunction) { + this.wrappedToLongFunction = wrappedToLongFunction; + functionalAsyncSupport = new FunctionalAsyncSupport( + SofaTraceContextHolder.getSofaTraceContext()); + } + + @Override + public long applyAsLong(T value) { + functionalAsyncSupport.doBefore(); + try { + return wrappedToLongFunction.applyAsLong(value); + } finally { + functionalAsyncSupport.doFinally(); + } + } +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/TracedExecutorService.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/TracedExecutorService.java index b2f2cfe29..ffc0be40d 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/TracedExecutorService.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/TracedExecutorService.java @@ -22,8 +22,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.concurrent.*; -import java.lang.Runnable; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; public class TracedExecutorService implements ExecutorService { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/configuration/SofaTracerConfiguration.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/configuration/SofaTracerConfiguration.java index 9dea4f964..2fa4553f7 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/configuration/SofaTracerConfiguration.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/configuration/SofaTracerConfiguration.java @@ -83,6 +83,8 @@ public class SofaTracerConfiguration { */ public static final String STAT_LOG_INTERVAL = "stat_log_interval"; + public static final String FILL_MINUTE_SWITCH = "fill_minute_switch"; + /***************** Asynchronous queue configuration item start ***************/ /** @@ -172,6 +174,14 @@ public static void setProperty(String key, Map value) { properties.put(key, value); } + /** + * Remove property by key + * @param key + */ + public static void removeProperty(String key) { + properties.remove(key); + } + /** * get property by key * diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContext.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContext.java index eead22581..5b3da3a5b 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContext.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContext.java @@ -22,6 +22,7 @@ import com.alipay.common.tracer.core.utils.StringUtils; import com.alipay.common.tracer.core.utils.TracerUtils; import io.opentracing.SpanContext; + import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -62,7 +63,7 @@ public class SofaTracerSpanContext implements SpanContext { /** * Default will not be sampled */ - private boolean isSampled = false; + private boolean isSampled = true; /** * The system transparently transmits data, @@ -96,17 +97,17 @@ public SofaTracerSpanContext cloneInstance() { public SofaTracerSpanContext() { //Default will not be sampled - this(StringUtils.EMPTY_STRING, StringUtils.EMPTY_STRING, null, false); + this(StringUtils.EMPTY_STRING, StringUtils.EMPTY_STRING, null, true); } public SofaTracerSpanContext(String traceId, String spanId) { //Default will not be sampled - this(traceId, spanId, null, false); + this(traceId, spanId, null, true); } public SofaTracerSpanContext(String traceId, String spanId, String parentId) { //Default will not be sampled - this(traceId, spanId, parentId, false); + this(traceId, spanId, parentId, true); } public SofaTracerSpanContext(String traceId, String spanId, String parentId, boolean isSampled) { @@ -242,7 +243,7 @@ public static SofaTracerSpanContext deserializeFromString(String deserializeValu String spanId = SofaTracer.ROOT_SPAN_ID; String parentId = StringUtils.EMPTY_STRING; //sampled default is false - boolean sampled = false; + boolean sampled = true; //sys bizBaggage Map sysBaggage = new HashMap(); //bizBaggage @@ -302,7 +303,7 @@ public static SofaTracerSpanContext deserializeFromString(String deserializeValu * @return root node */ public static SofaTracerSpanContext rootStart() { - return rootStart(false); + return rootStart(true); } public static SofaTracerSpanContext rootStart(boolean isSampled) { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/middleware/parent/AbstractDigestSpanEncoder.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/middleware/parent/AbstractDigestSpanEncoder.java index a8c433cdf..da9491d66 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/middleware/parent/AbstractDigestSpanEncoder.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/middleware/parent/AbstractDigestSpanEncoder.java @@ -25,11 +25,15 @@ import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext; import com.alipay.common.tracer.core.span.CommonSpanTags; import com.alipay.common.tracer.core.span.SofaTracerSpan; +import com.alipay.common.tracer.util.DesensitizationHelper; + import io.opentracing.tag.Tags; import java.io.IOException; import java.util.Map; +import static com.alipay.common.tracer.util.DesensitizationHelper.desensitize; + /** * * @author luoguimu123 @@ -101,7 +105,7 @@ protected void appendComponentSlot(XStringBuilder xsb, JsonStringBuilder jsb, * @return String */ protected String baggageSystemSerialized(SofaTracerSpanContext spanContext) { - return spanContext.getSysSerializedBaggage(); + return desensitize(spanContext.getSysSerializedBaggage()); } /** @@ -110,7 +114,7 @@ protected String baggageSystemSerialized(SofaTracerSpanContext spanContext) { * @return */ protected String baggageSerialized(SofaTracerSpanContext spanContext) { - return spanContext.getBizSerializedBaggage(); + return desensitize(spanContext.getBizSerializedBaggage()); } /** diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/AbstractTextB3Formatter.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/AbstractTextB3Formatter.java index 904ebd343..eb090516a 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/AbstractTextB3Formatter.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/AbstractTextB3Formatter.java @@ -20,6 +20,7 @@ import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext; import com.alipay.common.tracer.core.utils.StringUtils; import io.opentracing.propagation.TextMap; + import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -64,7 +65,7 @@ public SofaTracerSpanContext extract(TextMap carrier) { String traceId = null; String spanId = null; String parentId = null; - boolean sampled = false; + boolean sampled = true; boolean isGetSampled = false; //sysBaggage Map sysBaggage = new ConcurrentHashMap(); diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImpl.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImpl.java index f9d9d03e2..35907634e 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImpl.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImpl.java @@ -61,7 +61,6 @@ public class DiskReporterImpl extends AbstractDiskReporter { private SofaTracerStatisticReporter statReporter; public DiskReporterImpl(String digestLogType, SpanEncoder contextEncoder) { - this(digestLogType, StringUtils.EMPTY_STRING, StringUtils.EMPTY_STRING, contextEncoder, null); } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/manager/SofaTracerStatisticReporterManager.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/manager/SofaTracerStatisticReporterManager.java index aec7bd52d..ca3eadd4d 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/manager/SofaTracerStatisticReporterManager.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/manager/SofaTracerStatisticReporterManager.java @@ -17,13 +17,20 @@ package com.alipay.common.tracer.core.reporter.stat.manager; import com.alipay.common.tracer.core.appender.self.SelfLog; +import com.alipay.common.tracer.core.configuration.SofaTracerConfiguration; import com.alipay.common.tracer.core.reporter.stat.SofaTracerStatisticReporter; import com.alipay.common.tracer.core.reporter.stat.model.StatKey; import com.alipay.common.tracer.core.reporter.stat.model.StatValues; +import com.alipay.common.tracer.core.utils.DateUtils; import com.alipay.common.tracer.core.utils.StringUtils; +import java.util.Date; import java.util.Map; -import java.util.concurrent.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; /** @@ -83,7 +90,15 @@ public Thread newThread(Runnable r) { } private void start() { - executor.scheduleAtFixedRate(new StatReporterPrinter(), 0, cycleTime, TimeUnit.SECONDS); + //是否补齐分钟 + long initialDelay = 0L; + //默认关闭 + if ("true".equals(SofaTracerConfiguration + .getProperty(SofaTracerConfiguration.FILL_MINUTE_SWITCH))) { + initialDelay = DateUtils.diffNextMinute(new Date()); + } + executor.scheduleAtFixedRate(new StatReporterPrinter(), initialDelay, cycleTime * 1000, + TimeUnit.MILLISECONDS); } /** diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/SofaTracerPercentageBasedSampler.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/SofaTracerPercentageBasedSampler.java index 8724d5212..d91952779 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/SofaTracerPercentageBasedSampler.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/SofaTracerPercentageBasedSampler.java @@ -19,7 +19,11 @@ import com.alipay.common.tracer.core.constants.SofaTracerConstant; import com.alipay.common.tracer.core.span.SofaTracerSpan; -import java.util.*; +import java.util.BitSet; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; import java.util.concurrent.atomic.AtomicLong; /** diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/DateUtils.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/DateUtils.java new file mode 100644 index 000000000..f38787701 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/DateUtils.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.utils; + +import java.util.Date; + +/** + * @author zhile + * @version : DateUtils.java, v 0.1 2021年09月23日 下午3:55 zhile Exp $ + */ +public class DateUtils { + + /** + * 获取离下一分钟的毫秒数 + */ + public static long diffNextMinute(Date date) { + long now = date.getTime(); + long nextMinute = (now / (60 * 1000) + 1) * 60 * 1000; + return nextMinute - now; + } + +} \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/util/CoolDown.java b/tracer-core/src/main/java/com/alipay/common/tracer/util/CoolDown.java new file mode 100644 index 000000000..fe2861500 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/util/CoolDown.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.util; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * A tool to reduce execution frequency of some unimportant operation(such as log duplicated error logs). + * + *

created at 2021/4/7 + * + * @author xiangfeng.xzc + */ +class CoolDown { + final long intervalMills; + final int times; + final AtomicInteger counter = new AtomicInteger(0); + final AtomicInteger wip = new AtomicInteger(0); + volatile long nextResetTime; + + CoolDown(long resetIntervalMills, int times) { + this.intervalMills = resetIntervalMills; + this.times = times; + this.nextResetTime = System.currentTimeMillis() + resetIntervalMills; + } + + boolean tryAcquire() { + while (true) { + int c = counter.get(); + if (c < times) { + if (counter.compareAndSet(c, c + 1)) { + return true; + } + // CAS fail: retry loop + } else { + // Counter full in this period: + long now = System.currentTimeMillis(); + if (now > nextResetTime) { + // wip acts like a SpinLock: only one thread can update 'nextResetTime' and 'counter' + if (wip.compareAndSet(0, 1)) { + if (now > nextResetTime) { + nextResetTime = now + intervalMills; + counter.set(0); + } + wip.set(0); + } + } else { + return false; + } + } + } + } +} diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/util/DesensitizationHelper.java b/tracer-core/src/main/java/com/alipay/common/tracer/util/DesensitizationHelper.java new file mode 100644 index 000000000..fa72485d3 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/util/DesensitizationHelper.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.util; + +import com.alipay.common.tracer.core.appender.self.SelfLog; +import com.alipay.common.tracer.core.configuration.SofaTracerConfiguration; + +import java.util.ServiceLoader; + +/** + * Desensitization Helper. + *

+ * {@link DesensitizationHelper#desensitize(String)} can only reach 7000 OPS (1 thread) measured by JMH in my + * Mac Pro. + *

All our {@link com.alipay.common.tracer.core.appender.encoder.SpanEncoder}s are running in the same single thread. + * Thus performance is seriously damaged. Developers should only enable desensitization with this concern. + *

If you want to enable desensitization, you need to add antmasking-scan dependency with compile + * scope manually. + *

created at 2021/3/26 + * + * @author xiangfeng.xzc + */ +public class DesensitizationHelper { + public static final String ENABLED_KEY = "tracer_desens_enabled"; + public static final String ENABLED_DEFAULT_VALUE = "false"; + /** + * Cool down log + */ + private static final CoolDown COOL_DOWN = new CoolDown(60000L, 10); + static volatile Desensitizer desensitizer; + + static { + try { + ServiceLoader loader = ServiceLoader.load(Desensitizer.class, + DesensitizationHelper.class.getClassLoader()); + + Desensitizer first = null; + for (Desensitizer d : loader) { + if (first == null) { + first = d; + } + String msg = String.format("Find Desensitizer impl: %s %s", d.getClass(), + d.toString()); + SelfLog.info(msg); + } + + // use first + desensitizer = first; + } catch (Throwable e) { + SelfLog.warn("Fail to find class ScanAndDesensUtil, desensitization is disabled", e); + } + } + + /** + * Set a user defined desensitizer. + * + * @param desensitizer + */ + public static void setDesensitizer(Desensitizer desensitizer) { + DesensitizationHelper.desensitizer = desensitizer; + } + + /** + * Desensitize str + * + * @param str + * @return + */ + public static String desensitize(String str) { + // disabled return original str + if (!enabled()) { + return str; + } + Desensitizer desensitizer = DesensitizationHelper.desensitizer; + if (desensitizer == null) { + return str; + } + + try { + return desensitizer.desensitize(str); + } catch (Throwable e) { + if (COOL_DOWN.tryAcquire()) { + SelfLog.error("fail to desensitize: " + str, e); + } + return str; + } + } + + private static boolean enabled() { + // This property may change at runtime. So we have to check every time. + return desensitizer != null && // + "true".equals(SofaTracerConfiguration + .getProperty(ENABLED_KEY, ENABLED_DEFAULT_VALUE)); + } + +} diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/util/Desensitizer.java b/tracer-core/src/main/java/com/alipay/common/tracer/util/Desensitizer.java new file mode 100644 index 000000000..6d17611e7 --- /dev/null +++ b/tracer-core/src/main/java/com/alipay/common/tracer/util/Desensitizer.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.util; + +/** + *

created at 2021/3/26 + * + * @author xiangfeng.xzc + */ +public interface Desensitizer { + /** + * Desensitize str + * @param str + * @return + */ + String desensitize(String str); +} diff --git a/tracer-core/src/main/resources/tracer/log-codes.properties b/tracer-core/src/main/resources/tracer/log-codes.properties index 245ce5d60..f41450dc5 100644 --- a/tracer-core/src/main/resources/tracer/log-codes.properties +++ b/tracer-core/src/main/resources/tracer/log-codes.properties @@ -12,3 +12,4 @@ 01-00012=Span tags unsupported type [ %s ]. 01-00013=Current stage has no span exist in SofaTracerContext. 01-00014=Cannot set tag to component. current component is [ %s ]. +01-00015=Parse connnect url error diff --git a/tracer-core/src/main/resources/tracer/log-codes_zh_CN.properties b/tracer-core/src/main/resources/tracer/log-codes_zh_CN.properties index 132bb36ab..dbb9316f3 100644 --- a/tracer-core/src/main/resources/tracer/log-codes_zh_CN.properties +++ b/tracer-core/src/main/resources/tracer/log-codes_zh_CN.properties @@ -11,4 +11,5 @@ 01-00011=Log Type can't be empty when report. 01-00012=Span tags unsupported type [ %s ]. 01-00013=Current stage has no span exist in SofaTracerContext. -01-00014=Cannot set tag to component. current component is [ %s ]. \ No newline at end of file +01-00014=Cannot set tag to component. current component is [ %s ]. +01-00015=Parse connnect url error \ No newline at end of file diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/TestUtil.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/TestUtil.java index b744e6670..2a3ea079e 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/TestUtil.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/TestUtil.java @@ -20,6 +20,8 @@ import java.util.HashMap; import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.function.BooleanSupplier; /** * @author qilong.zql @@ -28,9 +30,9 @@ public class TestUtil { public static boolean compareSlotMap(String a, String b) { - Map aMap = new HashMap(); + Map aMap = new HashMap<>(); StringUtils.stringToMap(a, aMap); - Map bMap = new HashMap(); + Map bMap = new HashMap<>(); StringUtils.stringToMap(b, bMap); if (aMap.size() != bMap.size()) { return false; @@ -43,9 +45,21 @@ public static boolean compareSlotMap(String a, String b) { return true; } - public static void waitForAsyncLog() throws InterruptedException { - // wait flush log to file... (500ms is just expected time) - Thread.sleep(500); + public static void periodicallyAssert(Runnable assertion, long timeout) { + for (int i = 0; i < timeout; i++) { + try { + assertion.run(); + return; + } catch (AssertionError error) { + try { + TimeUnit.MILLISECONDS.sleep(1); + } catch (InterruptedException e) { + // Ignore + } + } + } + + assertion.run(); } } \ No newline at end of file diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonLoggingpathTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonLoggingpathTest.java new file mode 100644 index 000000000..6b624e858 --- /dev/null +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonLoggingpathTest.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.appender; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; + +import static junit.framework.TestCase.assertEquals; + +/** + * TracerLogRootDaemonLoggingpathTest + * @author guolei.sgl + * @since v3.1.1 + */ +public class TracerLogRootDaemonLoggingpathTest { + + @Before + public void before() throws Exception { + System.setProperty(TracerLogRootDaemon.TRACER_APPEND_PID_TO_LOG_PATH_KEY, "false"); + System.setProperty("logging.file.path", System.getProperty("user.home") + File.separator + + "logs"); + } + + @After + public void after() throws Exception { + System.clearProperty(TracerLogRootDaemon.TRACER_APPEND_PID_TO_LOG_PATH_KEY); + System.clearProperty("logging.file.path"); + } + + @Test + public void testLogRoot() { + assertEquals(TracerLogRootDaemon.LOG_FILE_DIR, System.getProperty("user.home") + + File.separator + "logs/tracelog"); + } + +} diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/builder/JsonStringBuilderTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/builder/JsonStringBuilderTest.java index ef04f3f68..1e06d5ee1 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/builder/JsonStringBuilderTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/builder/JsonStringBuilderTest.java @@ -21,9 +21,7 @@ import com.alipay.common.tracer.core.utils.StringUtils; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * JsonStringBuilder Tester. diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/file/CompositeTraceAppenderTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/file/CompositeTraceAppenderTest.java index 8fb852b7e..f670688cf 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/file/CompositeTraceAppenderTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/file/CompositeTraceAppenderTest.java @@ -25,6 +25,7 @@ import org.mockito.Mockito; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; + import java.io.File; import java.io.IOException; diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppenderTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppenderTest.java index ef3c97051..54ea9078f 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppenderTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppenderTest.java @@ -30,13 +30,12 @@ import java.io.IOException; /** - * * @author khotyn 4/8/14 3:56 PM */ public class TimedRollingFileAppenderTest extends AbstractTestBase { - private static final String ROLLING_TEST_FILE_NAME = "rolling-test.log"; - private TimedRollingFileAppender timedRollingFileAppender; - private PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); + private static final String ROLLING_TEST_FILE_NAME = "rolling-test.log"; + private TimedRollingFileAppender timedRollingFileAppender; + private final PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); @Before public void init() { @@ -58,8 +57,8 @@ public void test() throws IOException, InterruptedException { Resource[] resources = resolver.getResources("file:" + TracerLogRootDaemon.LOG_FILE_DIR + File.separator + ROLLING_TEST_FILE_NAME + "*"); - Assert.assertTrue("The number of files is incorrect. The number of files starting with " - + ROLLING_TEST_FILE_NAME + " should be 2", resources.length == 2); + Assert.assertEquals("The number of files is incorrect. The number of files starting with " + + ROLLING_TEST_FILE_NAME + " should be 2", 2, resources.length); for (Resource resource : resources) { String c = FileUtils.readFileToString(resource.getFile()); diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/info/StaticInfoLogTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/info/StaticInfoLogTest.java index 404d3624b..a55c66960 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/info/StaticInfoLogTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/info/StaticInfoLogTest.java @@ -42,29 +42,34 @@ public class StaticInfoLogTest extends AbstractTestBase { @Test - public void testLogStaticInfo() throws IOException, InterruptedException, NoSuchFieldException, - IllegalAccessException { + public void testLogStaticInfo() throws NoSuchFieldException, + IllegalAccessException { //record reflect(); StaticInfoLog.logStaticInfo(); - TestUtil.waitForAsyncLog(); + TestUtil.periodicallyAssert(() -> { + try { - List params = new ArrayList(); - params.add(TracerUtils.getPID()); - params.add(TracerUtils.getInetAddress()); - params.add(TracerUtils.getCurrentZone()); - params.add(TracerUtils.getDefaultTimeZone()); - List contents = FileUtils.readLines(customFileLog("static-info.log")); - Assert.assertFalse("Static information log has no content", contents.isEmpty()); - assertTrue(checkResult(params, contents.get(0))); + List params = new ArrayList<>(); + params.add(TracerUtils.getPID()); + params.add(TracerUtils.getInetAddress()); + params.add(TracerUtils.getCurrentZone()); + params.add(TracerUtils.getDefaultTimeZone()); + List contents = FileUtils.readLines(customFileLog("static-info.log")); + Assert.assertFalse("Static information log has no content", contents.isEmpty()); + assertTrue(checkResult(params, contents.get(0))); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } private static void reflect() throws NoSuchFieldException, IllegalAccessException { Field field = StaticInfoLog.class.getDeclaredField("appender"); field.setAccessible(true); - TraceAppender appender = (TraceAppender) field.get(null); + TraceAppender appender; appender = new TimedRollingFileAppender("static-info.log", true); field.set(null, appender); } diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentConsumerCorrectTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentConsumerCorrectTest.java index b76519c58..51107c9fc 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentConsumerCorrectTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentConsumerCorrectTest.java @@ -16,6 +16,7 @@ */ package com.alipay.common.tracer.core.appender.manager; +import com.alipay.common.tracer.core.TestUtil; import com.alipay.common.tracer.core.appender.TraceAppender; import com.alipay.common.tracer.core.appender.TracerLogRootDaemon; import com.alipay.common.tracer.core.appender.file.LoadTestAwareAppender; @@ -35,7 +36,6 @@ import java.util.concurrent.CountDownLatch; /** - * * @author liangen * @version $Id: ConcurrentConsumerCorrectTest.java, v 0.1 October 23, 2017 3:01 PM liangen Exp $ */ @@ -50,7 +50,6 @@ public class ConcurrentConsumerCorrectTest { @Before public void before() throws Exception { - cleanDir(); } @@ -60,27 +59,27 @@ public void clean() throws Exception { } @Test - public void testConcurrentConsumerCorrect() throws InterruptedException, IOException { - /** Logs are not allowed to be lost, and log loss is avoided to affect the correctness of the result check. */ + public void testConcurrentConsumerCorrect() throws InterruptedException { + /* Logs are not allowed to be lost, and log loss is avoided to affect the correctness of the result check. */ SofaTracerConfiguration.setProperty( - SofaTracerConfiguration.TRACER_ASYNC_APPENDER_ALLOW_DISCARD, "false"); + SofaTracerConfiguration.TRACER_ASYNC_APPENDER_ALLOW_DISCARD, "false"); final AsyncCommonDigestAppenderManager asyncCommonDigestAppenderManager = new AsyncCommonDigestAppenderManager( - 1024); + 1024); asyncCommonDigestAppenderManager.start("ConcurrentConsumerCorrectTest"); ClientSpanEncoder encoder = new ClientSpanEncoder(); TraceAppender traceAppender1 = LoadTestAwareAppender - .createLoadTestAwareTimedRollingFileAppender(fileName1, "", ""); + .createLoadTestAwareTimedRollingFileAppender(fileName1, "", ""); TraceAppender traceAppender2 = LoadTestAwareAppender - .createLoadTestAwareTimedRollingFileAppender(fileName2, "", ""); + .createLoadTestAwareTimedRollingFileAppender(fileName2, "", ""); TraceAppender traceAppender3 = LoadTestAwareAppender - .createLoadTestAwareTimedRollingFileAppender(fileName3, "", ""); + .createLoadTestAwareTimedRollingFileAppender(fileName3, "", ""); TraceAppender traceAppender4 = LoadTestAwareAppender - .createLoadTestAwareTimedRollingFileAppender(fileName4, "", ""); + .createLoadTestAwareTimedRollingFileAppender(fileName4, "", ""); TraceAppender traceAppender5 = LoadTestAwareAppender - .createLoadTestAwareTimedRollingFileAppender(fileName5, "", ""); + .createLoadTestAwareTimedRollingFileAppender(fileName5, "", ""); asyncCommonDigestAppenderManager.addAppender("logType1", traceAppender1, encoder); asyncCommonDigestAppenderManager.addAppender("logType2", traceAppender2, encoder); @@ -90,7 +89,7 @@ public void testConcurrentConsumerCorrect() throws InterruptedException, IOExcep final CountDownLatch countDownLatch = new CountDownLatch(30); for (int i = 0; i < 20; i++) { - new Thread(()->{ + new Thread(() -> { SofaTracerSpan span1 = ManagerTestUtil.createSofaTracerSpan(1); for (int j = 0; j < 30; j++) { asyncCommonDigestAppenderManager.append(span1); @@ -121,7 +120,7 @@ public void testConcurrentConsumerCorrect() throws InterruptedException, IOExcep } for (int i = 0; i < 10; i++) { - new Thread(()->{ + new Thread(() -> { SofaTracerSpan span1 = ManagerTestUtil.createSofaTracerSpan(1); SofaTracerSpan span2 = ManagerTestUtil.createSofaTracerSpan(2); SofaTracerSpan span3 = ManagerTestUtil.createSofaTracerSpan(3); @@ -138,16 +137,19 @@ public void testConcurrentConsumerCorrect() throws InterruptedException, IOExcep }).start(); } - /** check */ + /* check */ countDownLatch.await(); - Thread.sleep(3000); - - assertFile(fileName1, 1000, "traceID1"); - assertFile(fileName2, 1200, "traceID2"); - assertFile(fileName3, 1400, "traceID3"); - assertFile(fileName4, 1600, "traceID4"); - assertFile(fileName5, 1800, "traceID5"); - + TestUtil.periodicallyAssert(() -> { + try { + assertFile(fileName1, 1000, "traceID1"); + assertFile(fileName2, 1200, "traceID2"); + assertFile(fileName3, 1400, "traceID3"); + assertFile(fileName4, 1600, "traceID4"); + assertFile(fileName5, 1800, "traceID5"); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 3000); } public void assertFile(String fileName, int expectedNum, String expectedContent) @@ -157,7 +159,7 @@ public void assertFile(String fileName, int expectedNum, String expectedContent) BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream( fileNameRoot + fileName))); - String line = null; + String line; while ((line = reader.readLine()) != null) { Assert.assertTrue(line.contains(expectedContent)); actualNum++; @@ -167,7 +169,6 @@ public void assertFile(String fileName, int expectedNum, String expectedContent) } private void cleanDir() throws Exception { - Thread.sleep(2000); File file = new File(System.getProperty("user.home") + File.separator + "logs/tracelog" + File.separator + "append-manager.log"); if (file.exists()) { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentDiscardTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentDiscardTest.java index 9395d0c73..615ebcc23 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentDiscardTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentDiscardTest.java @@ -16,6 +16,7 @@ */ package com.alipay.common.tracer.core.appender.manager; +import com.alipay.common.tracer.core.TestUtil; import com.alipay.common.tracer.core.appender.TraceAppender; import com.alipay.common.tracer.core.appender.TracerLogRootDaemon; import com.alipay.common.tracer.core.appender.file.LoadTestAwareAppender; @@ -38,7 +39,6 @@ import java.util.concurrent.atomic.AtomicInteger; /** - * * @author liangen * @version $Id: ConcurrentDiscardTest.java, v 0.1 October 23, 2017 8:22 PM liangen Exp $ */ @@ -83,32 +83,32 @@ private void cleanDir() throws Exception { } @Test - public void testConcurrentDiscard() throws InterruptedException, IOException { + public void testConcurrentDiscard() throws InterruptedException { SofaTracerConfiguration.setProperty( - SofaTracerConfiguration.TRACER_ASYNC_APPENDER_ALLOW_DISCARD, "true"); + SofaTracerConfiguration.TRACER_ASYNC_APPENDER_ALLOW_DISCARD, "true"); SofaTracerConfiguration.setProperty( - SofaTracerConfiguration.TRACER_ASYNC_APPENDER_IS_OUT_DISCARD_NUMBER, "true"); + SofaTracerConfiguration.TRACER_ASYNC_APPENDER_IS_OUT_DISCARD_NUMBER, "true"); SofaTracerConfiguration.setProperty( - SofaTracerConfiguration.TRACER_ASYNC_APPENDER_IS_OUT_DISCARD_ID, "true"); + SofaTracerConfiguration.TRACER_ASYNC_APPENDER_IS_OUT_DISCARD_ID, "true"); SofaTracerConfiguration.setProperty( - SofaTracerConfiguration.TRACER_ASYNC_APPENDER_DISCARD_OUT_THRESHOLD, "500"); + SofaTracerConfiguration.TRACER_ASYNC_APPENDER_DISCARD_OUT_THRESHOLD, "500"); final AsyncCommonDigestAppenderManager asyncCommonDigestAppenderManager = new AsyncCommonDigestAppenderManager( - 1024); + 1024); asyncCommonDigestAppenderManager.start("ConcurrentDiscardTest"); ClientSpanEncoder encoder = new ClientSpanEncoder(); TraceAppender traceAppender1 = LoadTestAwareAppender - .createLoadTestAwareTimedRollingFileAppender(fileName1, "", ""); + .createLoadTestAwareTimedRollingFileAppender(fileName1, "", ""); TraceAppender traceAppender2 = LoadTestAwareAppender - .createLoadTestAwareTimedRollingFileAppender(fileName2, "", ""); + .createLoadTestAwareTimedRollingFileAppender(fileName2, "", ""); TraceAppender traceAppender3 = LoadTestAwareAppender - .createLoadTestAwareTimedRollingFileAppender(fileName3, "", ""); + .createLoadTestAwareTimedRollingFileAppender(fileName3, "", ""); TraceAppender traceAppender4 = LoadTestAwareAppender - .createLoadTestAwareTimedRollingFileAppender(fileName4, "", ""); + .createLoadTestAwareTimedRollingFileAppender(fileName4, "", ""); TraceAppender traceAppender5 = LoadTestAwareAppender - .createLoadTestAwareTimedRollingFileAppender(fileName5, "", ""); + .createLoadTestAwareTimedRollingFileAppender(fileName5, "", ""); asyncCommonDigestAppenderManager.addAppender("logType1", traceAppender1, encoder); asyncCommonDigestAppenderManager.addAppender("logType2", traceAppender2, encoder); @@ -120,7 +120,7 @@ public void testConcurrentDiscard() throws InterruptedException, IOException { final CountDownLatch countDownLatch = new CountDownLatch(50); for (int i = 0; i < 50; i++) { - new Thread(()-> { + new Thread(() -> { SofaTracerSpan span1 = ManagerTestUtil.createSofaTracerSpan(1); SofaTracerSpan span2 = ManagerTestUtil.createSofaTracerSpan(2); SofaTracerSpan span3 = ManagerTestUtil.createSofaTracerSpan(3); @@ -153,32 +153,36 @@ public void testConcurrentDiscard() throws InterruptedException, IOException { } countDownLatch.await(); - Thread.sleep(3000); - SynchronizingSelfLog.flush(); - - /**check*/ - int log1Num = getLineNum(fileName1); - int log2Num = getLineNum(fileName2); - int log3Num = getLineNum(fileName3); - int log4Num = getLineNum(fileName4); - int log5Num = getLineNum(fileName5); - int allNum = log1Num + log2Num + log3Num + log4Num + log5Num; - - /**Landing log + Lost log = Print log*/ - SelfLog.info("Landing log:" + allNum); - SelfLog.info("Lost log:" + discardNum.get()); - Assert.assertEquals(25000, allNum + discardNum.get()); - /** Sync.log lost log data is less than the actual number of lost */ - int logDiscard = getDiscardNumFromTracerSelfLog(); - SelfLog.info("Sync.log records the number of lost logs:" + logDiscard); - Assert.assertTrue(logDiscard <= discardNum.get()); - /** Accuracy of the specific lost log data recorded by sync.log: the difference from the true lost number should be less than 500 */ - int allTraceIdDiscard = traceId1Discard + traceId2Discard + traceId3Discard - + traceId4Discard + traceId5Discard; - SelfLog.info("The number of specific lost log data with traceId recorded by sync.log:" + allTraceIdDiscard); - Assert.assertTrue((discardNum.get() == allTraceIdDiscard) - || (discardNum.get() - allTraceIdDiscard) < 500); - + TestUtil.periodicallyAssert(() -> { + try { + SynchronizingSelfLog.flush(); + + /*check*/ + int log1Num = getLineNum(fileName1); + int log2Num = getLineNum(fileName2); + int log3Num = getLineNum(fileName3); + int log4Num = getLineNum(fileName4); + int log5Num = getLineNum(fileName5); + int allNum = log1Num + log2Num + log3Num + log4Num + log5Num; + + /*Landing log + Lost log = Print log*/ + SelfLog.info("Landing log:" + allNum); + SelfLog.info("Lost log:" + discardNum.get()); + Assert.assertEquals(25000, allNum + discardNum.get()); + /* Sync.log lost log data is less than the actual number of lost */ + int logDiscard = getDiscardNumFromTracerSelfLog(); + SelfLog.info("Sync.log records the number of lost logs:" + logDiscard); + Assert.assertTrue(logDiscard <= discardNum.get()); + /* Accuracy of the specific lost log data recorded by sync.log: the difference from the true lost number should be less than 500 */ + int allTraceIdDiscard = traceId1Discard + traceId2Discard + traceId3Discard + + traceId4Discard + traceId5Discard; + SelfLog.info("The number of specific lost log data with traceId recorded by sync.log:" + allTraceIdDiscard); + Assert.assertTrue((discardNum.get() == allTraceIdDiscard) + || (discardNum.get() - allTraceIdDiscard) < 500); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 3000); } public int getLineNum(String fileName) throws IOException { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConsumerExceptionHandlerTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConsumerExceptionHandlerTest.java index 1f1d2452f..aaf185b43 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConsumerExceptionHandlerTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConsumerExceptionHandlerTest.java @@ -33,34 +33,33 @@ import java.io.IOException; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; /** - * @description: [test unit for ConsumerExceptionHandler] - * @email: - * @author: guolei.sgl - * @date: 18/7/27 + * @author guolei.sgl + * @description [test unit for ConsumerExceptionHandler] + * @email + * @date 18/7/27 */ public class ConsumerExceptionHandlerTest extends AbstractTestBase { private ConsumerExceptionHandler consumerExceptionHandler; private SofaTracerSpanEvent sofaTracerSpanEvent; private SofaTracerSpan sofaTracerSpan; - private SofaTracer sofaTracer; - private final String tracerType = "SofaTracerSpanTest"; - private final String clientLogType = "client-log-test.log"; - private final String serverLogType = "server-log-test.log"; @Before public void init() { consumerExceptionHandler = new ConsumerExceptionHandler(); sofaTracerSpanEvent = new SofaTracerSpanEvent(); + String clientLogType = "client-log-test.log"; Reporter clientReporter = new DiskReporterImpl(clientLogType, new ClientSpanEncoder()); + String serverLogType = "server-log-test.log"; Reporter serverReporter = new DiskReporterImpl(serverLogType, new ServerSpanEncoder()); - sofaTracer = new SofaTracer.Builder(tracerType) + String tracerType = "SofaTracerSpanTest"; + SofaTracer sofaTracer = new SofaTracer.Builder(tracerType) .withTag("tracer", "SofaTraceContextHolderTest").withClientReporter(clientReporter) .withServerReporter(serverReporter).build(); - sofaTracerSpan = (SofaTracerSpan) this.sofaTracer.buildSpan("SofaTracerSpanTest").start(); + sofaTracerSpan = (SofaTracerSpan) sofaTracer.buildSpan("SofaTracerSpanTest").start(); } @After @@ -72,47 +71,59 @@ public void afterClean() throws IOException { } @Test - public void handleEventExceptionWithEventNull() throws IOException, InterruptedException { + public void handleEventExceptionWithEventNull() { consumerExceptionHandler.handleEventException(new Throwable(), 1, null); - - TestUtil.waitForAsyncLog(); - - File log = customFileLog("sync.log"); - List logs = FileUtils.readLines(log); - assertTrue(logs.toString(), logs.get(0).contains("[ERROR]")); + TestUtil.periodicallyAssert(() -> { + try { + File log = customFileLog("sync.log"); + List logs = FileUtils.readLines(log); + assertTrue(logs.toString(), logs.get(0).contains("[ERROR]")); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } @Test - public void handleEventExceptionWithEventNotNull() throws IOException, InterruptedException { + public void handleEventExceptionWithEventNotNull() { sofaTracerSpanEvent.setSofaTracerSpan(sofaTracerSpan); consumerExceptionHandler.handleEventException(new Throwable(), 1, sofaTracerSpanEvent); - - TestUtil.waitForAsyncLog(); - - File log = customFileLog("sync.log"); - List logs = FileUtils.readLines(log); - assertTrue(logs.toString(), logs.get(0).contains("[ERROR]")); + TestUtil.periodicallyAssert(() -> { + try { + File log = customFileLog("sync.log"); + List logs = FileUtils.readLines(log); + assertTrue(logs.toString(), logs.get(0).contains("[ERROR]")); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } @Test - public void handleOnStartException() throws IOException, InterruptedException { + public void handleOnStartException() { consumerExceptionHandler.handleOnStartException(new Throwable()); - - TestUtil.waitForAsyncLog(); - - File log = customFileLog("sync.log"); - List logs = FileUtils.readLines(log); - assertTrue(logs.toString(), logs.get(0).contains("[ERROR]")); + TestUtil.periodicallyAssert(() -> { + try { + File log = customFileLog("sync.log"); + List logs = FileUtils.readLines(log); + assertTrue(logs.toString(), logs.get(0).contains("[ERROR]")); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } @Test - public void handleOnShutdownException() throws IOException, InterruptedException { + public void handleOnShutdownException() { consumerExceptionHandler.handleOnShutdownException(new Throwable()); - - TestUtil.waitForAsyncLog(); - - File log = customFileLog("sync.log"); - List logs = FileUtils.readLines(log); - assertTrue(logs.toString(), logs.get(0).contains("[ERROR]")); + TestUtil.periodicallyAssert(() -> { + try { + File log = customFileLog("sync.log"); + List logs = FileUtils.readLines(log); + assertTrue(logs.toString(), logs.get(0).contains("[ERROR]")); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } } \ No newline at end of file diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ManagerTestUtil.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ManagerTestUtil.java index f0066f550..454ae236c 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ManagerTestUtil.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ManagerTestUtil.java @@ -19,7 +19,6 @@ import com.alipay.common.tracer.core.SofaTracer; import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext; import com.alipay.common.tracer.core.span.SofaTracerSpan; -import java.io.File; /** * diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/StringConsumerExceptionHandlerTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/StringConsumerExceptionHandlerTest.java index 50f47b33d..a76894bb4 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/StringConsumerExceptionHandlerTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/StringConsumerExceptionHandlerTest.java @@ -23,15 +23,16 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; + import java.io.File; import java.io.IOException; import java.util.List; /** - * @description: [test unit for StringConsumerExceptionHandler] - * @email: - * @author: guolei.sgl - * @date: 18/7/27 + * @author guolei.sgl + * @description [test unit for StringConsumerExceptionHandler] + * @email + * @date 18/7/27 */ public class StringConsumerExceptionHandlerTest extends AbstractTestBase { @@ -55,32 +56,54 @@ public void clean() throws IOException { } @Test - public void handleEventExceptionWithEventNull() throws IOException, InterruptedException { + public void handleEventExceptionWithEventNull() { stringConsumerExceptionHandler.handleEventException(new Throwable(), 2, null); - Assert.assertTrue(checkFileContainError()); + TestUtil.periodicallyAssert(() -> { + try { + Assert.assertTrue(checkFileContainError()); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } @Test - public void handleEventExceptionWithEventNotNull() throws IOException, InterruptedException { + public void handleEventExceptionWithEventNotNull() { stringConsumerExceptionHandler.handleEventException(new Throwable(), 2, stringEvent); - Assert.assertTrue(checkFileContainError()); + TestUtil.periodicallyAssert(() -> { + try { + Assert.assertTrue(checkFileContainError()); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } @Test - public void handleOnStartException() throws IOException, InterruptedException { + public void handleOnStartException() { stringConsumerExceptionHandler.handleOnStartException(new Throwable()); - Assert.assertTrue(checkFileContainError()); + TestUtil.periodicallyAssert(() -> { + try { + Assert.assertTrue(checkFileContainError()); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } @Test - public void handleOnShutdownException() throws IOException, InterruptedException { + public void handleOnShutdownException() { stringConsumerExceptionHandler.handleOnShutdownException(new Throwable()); - Assert.assertTrue(checkFileContainError()); + TestUtil.periodicallyAssert(() -> { + try { + Assert.assertTrue(checkFileContainError()); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } - private boolean checkFileContainError() throws IOException, InterruptedException { - TestUtil.waitForAsyncLog(); - + private boolean checkFileContainError() throws IOException { File log = customFileLog("sync.log"); List logs = FileUtils.readLines(log); return logs.get(0).contains("[ERROR]"); diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/self/SelfLogTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/self/SelfLogTest.java index f2afc729e..351bd09c3 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/self/SelfLogTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/self/SelfLogTest.java @@ -25,10 +25,11 @@ import org.junit.Test; import java.io.File; +import java.io.IOException; import java.lang.reflect.Field; import java.util.List; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; /** * SelfLog Tester. @@ -48,6 +49,7 @@ public void before() throws Exception { public void after() throws Exception { File file = tracerSelfLog(); if (file.exists()) { + //noinspection ResultOfMethodCallIgnored file.createNewFile(); } } @@ -56,53 +58,93 @@ public void after() throws Exception { * Method: error(String log, Throwable e) */ @Test - public void testErrorForLogE() throws Exception { + public void testErrorForLogE() { SelfLog.error("Error info", new RuntimeException("RunTimeException")); - - TestUtil.waitForAsyncLog(); - - List logs = FileUtils.readLines(tracerSelfLog()); - assertTrue(!logs.isEmpty()); + TestUtil.periodicallyAssert(() -> { + try { + List logs = FileUtils.readLines(tracerSelfLog()); + assertFalse(logs.isEmpty()); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } /** * out Method: errorWithTraceId(String log, Throwable e) */ @Test - public void testErrorWithTraceIdForLogE() throws Exception { + public void testErrorWithTraceIdForLogE() { SelfLog.errorWithTraceId("error Info ", "traceid"); - - TestUtil.waitForAsyncLog(); - - List logs = FileUtils.readLines(tracerSelfLog()); - assertTrue(!logs.isEmpty()); + TestUtil.periodicallyAssert(() -> { + try { + List logs = FileUtils.readLines(tracerSelfLog()); + assertFalse(logs.isEmpty()); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } /** * Method: errorWithTraceId(String log, Throwable e) */ @Test - public void testErrorWithTraceIdForLogErrorThrowable() throws Exception { + public void testErrorWithTraceIdForLogErrorThrowable() { SelfLog.errorWithTraceId("error Info ", new Throwable()); - - TestUtil.waitForAsyncLog(); - - List logs = FileUtils.readLines(tracerSelfLog()); - assertTrue(!logs.isEmpty()); + TestUtil.periodicallyAssert(() -> { + try { + List logs = FileUtils.readLines(tracerSelfLog()); + assertFalse(logs.isEmpty()); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } /** * Method: error(String log) */ @Test - public void testErrorLog() throws Exception { + public void testErrorLog() { SelfLog.error("Error info"); SelfLog.error("Error", new RuntimeException("error")); + TestUtil.periodicallyAssert(() -> { + try { + List logs = FileUtils.readLines(tracerSelfLog()); + assertFalse(logs.isEmpty()); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); + } - TestUtil.waitForAsyncLog(); + @Test + public void testWarnWithExceptionLog() throws Exception { + SelfLog.warn("warn", new RuntimeException("warn!!!")); + + TestUtil.periodicallyAssert(() -> { + try { + List logs = FileUtils.readLines(tracerSelfLog()); + assertFalse(logs.isEmpty()); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 2); + } - List logs = FileUtils.readLines(tracerSelfLog()); - assertTrue(!logs.isEmpty()); + @Test + public void testWarnWithNullExceptionLog() throws Exception { + SelfLog.warn("warn", null); + + TestUtil.periodicallyAssert(() -> { + try { + List logs = FileUtils.readLines(tracerSelfLog()); + assertFalse(logs.isEmpty()); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 2); } private static void reflectSelfLog() throws NoSuchFieldException, IllegalAccessException { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/self/SynchronizingSelfLogTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/self/SynchronizingSelfLogTest.java index 61ccf558b..2b9224412 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/self/SynchronizingSelfLogTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/self/SynchronizingSelfLogTest.java @@ -20,9 +20,11 @@ import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Test; + import java.io.File; import java.io.IOException; import java.util.List; + import static org.junit.Assert.assertTrue; /** diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerFunctionalTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerFunctionalTest.java new file mode 100644 index 000000000..f88bd648b --- /dev/null +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerFunctionalTest.java @@ -0,0 +1,951 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.async; + +import com.alipay.common.tracer.core.SofaTracer; +import com.alipay.common.tracer.core.context.trace.SofaTraceContext; +import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; +import com.alipay.common.tracer.core.reporter.digest.DiskReporterImpl; +import com.alipay.common.tracer.core.reporter.facade.Reporter; +import com.alipay.common.tracer.core.span.SofaTracerSpan; +import com.alipay.common.tracer.core.tracertest.encoder.ClientSpanEncoder; +import com.alipay.common.tracer.core.tracertest.encoder.ServerSpanEncoder; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.BiPredicate; +import java.util.function.BooleanSupplier; +import java.util.function.Consumer; +import java.util.function.DoubleBinaryOperator; +import java.util.function.DoubleConsumer; +import java.util.function.DoubleFunction; +import java.util.function.DoublePredicate; +import java.util.function.DoubleSupplier; +import java.util.function.DoubleToIntFunction; +import java.util.function.DoubleToLongFunction; +import java.util.function.DoubleUnaryOperator; +import java.util.function.Function; +import java.util.function.IntBinaryOperator; +import java.util.function.IntConsumer; +import java.util.function.IntFunction; +import java.util.function.IntPredicate; +import java.util.function.IntSupplier; +import java.util.function.IntToDoubleFunction; +import java.util.function.IntToLongFunction; +import java.util.function.IntUnaryOperator; +import java.util.function.LongBinaryOperator; +import java.util.function.LongConsumer; +import java.util.function.LongFunction; +import java.util.function.LongPredicate; +import java.util.function.LongSupplier; +import java.util.function.LongToDoubleFunction; +import java.util.function.LongToIntFunction; +import java.util.function.LongUnaryOperator; +import java.util.function.ObjDoubleConsumer; +import java.util.function.ObjIntConsumer; +import java.util.function.ObjLongConsumer; +import java.util.function.Predicate; +import java.util.function.ToDoubleBiFunction; +import java.util.function.ToDoubleFunction; +import java.util.function.ToIntBiFunction; +import java.util.function.ToIntFunction; +import java.util.function.ToLongBiFunction; +import java.util.function.ToLongFunction; + +/** + * @author khotyn + * @version v0.1 + */ +public class SofaTracerFunctionalTest { + private static SofaTracerSpan sofaTracerSpan; + + @BeforeClass + public static void setup() { + String clientLogType = "client-log-test.log"; + Reporter clientReporter = new DiskReporterImpl(clientLogType, new ClientSpanEncoder()); + String serverLogType = "server-log-test.log"; + Reporter serverReporter = new DiskReporterImpl(serverLogType, new ServerSpanEncoder()); + String tracerType = "SofaTracerSpanTest"; + SofaTracer sofaTracer = new SofaTracer.Builder(tracerType) + .withTag("tracer", "SofaTraceContextHolderTest").withClientReporter(clientReporter) + .withServerReporter(serverReporter).build(); + sofaTracerSpan = (SofaTracerSpan) sofaTracer.buildSpan("SofaTracerSpanTest").start(); + } + + @Before + public void pushSpan() { + SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext(); + sofaTraceContext.push(sofaTracerSpan); + } + + @Test + public void testWrappedBiConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + BiConsumer biConsumer = new SofaTracerBiConsumer<>((s, s2) -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan()); + useThreadToRun(() -> biConsumer.accept("", "")); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawBiConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + BiConsumer biConsumer = (s, s2) -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + useThreadToRun(() -> biConsumer.accept("", "")); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedBiFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + BiFunction biFunction = new SofaTracerBiFunction<>((s, s2) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return ""; + }); + useThreadToRun(() -> biFunction.apply("", "")); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawBiFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + BiFunction biFunction = (s, s2) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return ""; + }; + useThreadToRun(() -> biFunction.apply("", "")); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedBiPredicate() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + BiPredicate biPredicate = new SofaTracerBiPredicate<>((s, s2) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return false; + }); + useThreadToRun(() -> biPredicate.test("", "")); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawBiPredicate() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + BiPredicate biPredicate = (s, s2) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return false; + }; + useThreadToRun(() -> biPredicate.test("", "")); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedBooleanSupplier() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + BooleanSupplier booleanSupplier = new SofaTracerBooleanSupplier(() -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return false; + }); + useThreadToRun(booleanSupplier::getAsBoolean); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawBooleanSupplier() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + BooleanSupplier booleanSupplier = () -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return false; + }; + useThreadToRun(booleanSupplier::getAsBoolean); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + Consumer consumer = new SofaTracerConsumer<>(s -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan()); + useThreadToRun(() -> consumer.accept("")); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + Consumer consumer = s -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + useThreadToRun(() -> consumer.accept("")); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedDoubleBinaryOperator() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoubleBinaryOperator doubleBinaryOperator = new SofaTracerDoubleBinaryOperator((left, right) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> doubleBinaryOperator.applyAsDouble(0, 0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawDoubleBinaryOperator() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoubleBinaryOperator doubleBinaryOperator = (left, right) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> doubleBinaryOperator.applyAsDouble(0, 0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedDoubleConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoubleConsumer doubleConsumer = new SofaTracerDoubleConsumer(value -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan()); + useThreadToRun(() -> doubleConsumer.accept(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawDoubleConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoubleConsumer doubleConsumer = value -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + useThreadToRun(() -> doubleConsumer.accept(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedDoubleFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoubleFunction doubleFunction = new SofaTracerDoubleFunction<>(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return null; + }); + useThreadToRun(() -> doubleFunction.apply(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRowDoubleFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoubleFunction doubleFunction = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return null; + }; + useThreadToRun(() -> doubleFunction.apply(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedDoublePredicate() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoublePredicate doublePredicate = new SofaTracerDoublePredicate(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return false; + }); + + useThreadToRun(() -> doublePredicate.test(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawDoublePredicate() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoublePredicate doublePredicate = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return false; + }; + useThreadToRun(() -> doublePredicate.test(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedDoubleSupplier() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoubleSupplier doubleSupplier = new SofaTracerDoubleSupplier(() -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(doubleSupplier::getAsDouble); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawDoubleSupplier() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoubleSupplier doubleSupplier = () -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(doubleSupplier::getAsDouble); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedDoubleToIntFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoubleToIntFunction doubleToIntFunction = new SofaTracerDoubleToIntFunction(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> doubleToIntFunction.applyAsInt(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawDoubleToIntFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoubleToIntFunction doubleToIntFunction = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> doubleToIntFunction.applyAsInt(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedDoubleToLongFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoubleToLongFunction doubleToLongFunction = new SofaTracerDoubleToLongFunction(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> doubleToLongFunction.applyAsLong(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawDoubleToLongFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoubleToLongFunction doubleToLongFunction = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> doubleToLongFunction.applyAsLong(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedDoubleUnaryOperator() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoubleUnaryOperator doubleUnaryOperator = new SofaTracerDoubleUnaryOperator(operand -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> doubleUnaryOperator.applyAsDouble(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawDoubleUnaryOperator() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + DoubleUnaryOperator doubleUnaryOperator = operand -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> doubleUnaryOperator.applyAsDouble(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + Function function = new SofaTracerFunction<>(s -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return ""; + }); + useThreadToRun(() -> function.apply("")); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + Function function = s -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return ""; + }; + useThreadToRun(() -> function.apply("")); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedIntBinaryOperator() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntBinaryOperator intBinaryOperator = new SofaTracerIntBinaryOperator((left, right) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> intBinaryOperator.applyAsInt(0, 0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawIntBinaryOperator() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntBinaryOperator intBinaryOperator = (left, right) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> intBinaryOperator.applyAsInt(0, 0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedIntConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntConsumer intConsumer = new SofaTracerIntConsumer(value -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan()); + useThreadToRun(() -> intConsumer.accept(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawIntConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntConsumer intConsumer = value -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + useThreadToRun(() -> intConsumer.accept(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedIntFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntFunction intFunction = new SofaTracerIntFunction<>(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return null; + }); + useThreadToRun(() -> intFunction.apply(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawIntFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntFunction intFunction = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return null; + }; + useThreadToRun(() -> intFunction.apply(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedIntPredicate() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntPredicate intPredicate = new SofaTracerIntPredicate(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return false; + }); + useThreadToRun(() -> intPredicate.test(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawIntPredicate() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntPredicate intPredicate = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return false; + }; + useThreadToRun(() -> intPredicate.test(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedIntSupplier() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntSupplier intSupplier = new SofaTracerIntSupplier(() -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(intSupplier::getAsInt); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawIntSupplier() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntSupplier intSupplier = () -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(intSupplier::getAsInt); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedIntToDoubleFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntToDoubleFunction intToDoubleFunction = new SofaTracerIntToDoubleFunction(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> intToDoubleFunction.applyAsDouble(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawIntToDoubleFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntToDoubleFunction intToDoubleFunction = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> intToDoubleFunction.applyAsDouble(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedIntToLongFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntToLongFunction intToLongFunction = new SofaTracerIntToLongFunction(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> intToLongFunction.applyAsLong(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawIntToLongFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntToLongFunction intToLongFunction = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> intToLongFunction.applyAsLong(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedIntUnaryOperator() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntUnaryOperator intUnaryOperator = new SofaTracerIntUnaryOperator(operand -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> intUnaryOperator.applyAsInt(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawIntUnaryOperator() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + IntUnaryOperator intUnaryOperator = operand -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> intUnaryOperator.applyAsInt(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedLongBinaryOperator() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongBinaryOperator longBinaryOperator = new SofaTracerLongBinaryOperator((left, right) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> longBinaryOperator.applyAsLong(0, 0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawLongBinaryOperator() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongBinaryOperator longBinaryOperator = (left, right) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> longBinaryOperator.applyAsLong(0, 0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedLongConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongConsumer longConsumer = new SofaTracerLongConsumer(value -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan()); + useThreadToRun(() -> longConsumer.accept(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawLongConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongConsumer longConsumer = value -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + useThreadToRun(() -> longConsumer.accept(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedLongFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongFunction longFunction = new SofaTracerLongFunction<>(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return null; + }); + useThreadToRun(() -> longFunction.apply(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawLongFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongFunction longFunction = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return null; + }; + useThreadToRun(() -> longFunction.apply(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedLongPredicate() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongPredicate longPredicate = new SofaTracerLongPredicate(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return false; + }); + useThreadToRun(() -> longPredicate.test(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawLongPredicate() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongPredicate longPredicate = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return false; + }; + useThreadToRun(() -> longPredicate.test(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedLongSupplier() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongSupplier longSupplier = new SofaTracerLongSupplier(() -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(longSupplier::getAsLong); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawLongSupplier() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongSupplier longSupplier = () -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(longSupplier::getAsLong); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedLongToDoubleFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongToDoubleFunction longToDoubleFunction = new SofaTracerLongToDoubleFunction(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> longToDoubleFunction.applyAsDouble(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawLongToDoubleFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongToDoubleFunction longToDoubleFunction = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> longToDoubleFunction.applyAsDouble(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedLongToIntFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongToIntFunction longToIntFunction = new SofaTracerLongToIntFunction(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> longToIntFunction.applyAsInt(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawLongToIntFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongToIntFunction longToIntFunction = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> longToIntFunction.applyAsInt(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedLongUnaryOperator() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongUnaryOperator longUnaryOperator = new SofaTracerLongUnaryOperator(operand -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> longUnaryOperator.applyAsLong(0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawLongUnaryOperator() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + LongUnaryOperator longUnaryOperator = operand -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> longUnaryOperator.applyAsLong(0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedObjDoubleConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ObjDoubleConsumer objDoubleConsumer = new SofaTracerObjDoubleConsumer<>((s, value) -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan()); + useThreadToRun(() -> objDoubleConsumer.accept("", 0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawObjDoubleConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ObjDoubleConsumer objDoubleConsumer = (s, value) -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + useThreadToRun(() -> objDoubleConsumer.accept("", 0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedObjIntConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ObjIntConsumer objIntConsumer = new SofaTracerObjIntConsumer<>((s, value) -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan()); + useThreadToRun(() -> objIntConsumer.accept("", 0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawObjIntConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ObjIntConsumer objIntConsumer = (s, value) -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + useThreadToRun(() -> objIntConsumer.accept("", 0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedObjLongConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ObjLongConsumer objLongConsumer = new SofaTracerObjLongConsumer<>((s, value) -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan()); + useThreadToRun(() -> objLongConsumer.accept("", 0)); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawObjLongConsumer() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ObjLongConsumer objLongConsumer = (s, value) -> spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + useThreadToRun(() -> objLongConsumer.accept("", 0)); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedPredicate() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + Predicate predicate = new SofaTracerPredicate<>(s -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return false; + }); + useThreadToRun(() -> predicate.test("")); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawPredicate() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + Predicate predicate = s -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return false; + }; + useThreadToRun(() -> predicate.test("")); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedSupplier() throws ExecutionException, InterruptedException { + CompletableFuture future = CompletableFuture.supplyAsync(new SofaTracerSupplier<>(() -> SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan())); + Assert.assertEquals(sofaTracerSpan, future.get()); + } + + @Test + public void testRawSupplier() throws ExecutionException, InterruptedException { + CompletableFuture future = CompletableFuture.supplyAsync(() -> SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan()); + Assert.assertNull(future.get()); + } + + @Test + public void testWrappedToDoubleBiFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ToDoubleBiFunction toDoubleBiFunction = new SofaTracerToDoubleBiFunction<>((s, s2) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> toDoubleBiFunction.applyAsDouble("", "")); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawToDoubleBiFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ToDoubleBiFunction toDoubleBiFunction = (s, s2) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> toDoubleBiFunction.applyAsDouble("", "")); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedToDoubleFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ToDoubleFunction toDoubleFunction = new SofaTracerToDoubleFunction<>(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> toDoubleFunction.applyAsDouble("")); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawToDoubleFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ToDoubleFunction toDoubleFunction = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> toDoubleFunction.applyAsDouble("")); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedToIntBiFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ToIntBiFunction toIntBiFunction = new SofaTracerToIntBiFunction<>((s, s2) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> toIntBiFunction.applyAsInt("", "")); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawToIntBiFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ToIntBiFunction toIntBiFunction = (s, s2) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> toIntBiFunction.applyAsInt("", "")); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedToIntFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ToIntFunction toIntFunction = new SofaTracerToIntFunction<>(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> toIntFunction.applyAsInt("")); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawToIntFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ToIntFunction toIntFunction = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> toIntFunction.applyAsInt("")); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedToLongBiFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ToLongBiFunction toLongBiFunction = new SofaTracerToLongBiFunction<>((s, s2) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> toLongBiFunction.applyAsLong("", "")); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawToLongBiFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ToLongBiFunction toLongBiFunction = (s, s2) -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> toLongBiFunction.applyAsLong("", "")); + Assert.assertNull(spanInFunction[0]); + } + + @Test + public void testWrappedToLongFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ToLongFunction toLongFunction = new SofaTracerToLongFunction<>(value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }); + useThreadToRun(() -> toLongFunction.applyAsLong("")); + Assert.assertEquals(sofaTracerSpan, spanInFunction[0]); + } + + @Test + public void testRawToLongFunction() throws InterruptedException { + final SofaTracerSpan[] spanInFunction = {null}; + ToLongFunction toLongFunction = value -> { + spanInFunction[0] = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); + return 0; + }; + useThreadToRun(() -> toLongFunction.applyAsLong("")); + Assert.assertNull(spanInFunction[0]); + } + + private void useThreadToRun(Runnable runnable) throws InterruptedException { + Thread thread = new Thread(runnable); + thread.start(); + thread.join(); + } +} \ No newline at end of file diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerRunnableTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerRunnableTest.java index 2d7f86a2e..070a2d55c 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerRunnableTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerRunnableTest.java @@ -90,22 +90,19 @@ public void sofaTracerRunnableSamples() throws InterruptedException { thread.start(); Thread.sleep(3 * 1000); assertEquals(1, sofaTraceContext.getThreadLocalSpanSize()); - assertEquals(2, runnableTread.atomicLong.get()); + assertEquals(2, RunnableTread.atomicLong.get()); assertNotEquals(Thread.currentThread().getId(), runnableTread.getThreadId()); assertNotEquals(Thread.currentThread().getName(), runnableTread.getThreadName()); } @Test - public void samples() throws Exception { + public void samples() { SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext(); SofaTracerSpan sofaTracerSpan = mock((SofaTracerSpan.class)); sofaTraceContext.push(sofaTracerSpan); - Thread thread = new Thread(new SofaTracerRunnable(new Runnable() { - @Override - public void run() { - //do something your business code - } + Thread thread = new Thread(new SofaTracerRunnable(() -> { + //do something your business code })); thread.start(); assertEquals(1, sofaTraceContext.getThreadLocalSpanSize()); diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/async/TracerScheduleExecutorServiceTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/async/TracerScheduleExecutorServiceTest.java index 9283fcf3f..ab3751075 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/async/TracerScheduleExecutorServiceTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/async/TracerScheduleExecutorServiceTest.java @@ -27,88 +27,76 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import java.lang.reflect.Field; + import java.util.HashMap; import java.util.Map; -import java.util.concurrent.*; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; /** - * @description: [test for TracerScheduleExecutorService] - * @email: - * @author: guolei.sgl - * @date: 18/7/30 + * @author guolei.sgl + * @description [test for TracerScheduleExecutorService] + * @email + * @date 18/7/30 */ public class TracerScheduleExecutorServiceTest { - private static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS; - TracerScheduleExecutorService tracerScheduleExecutorService; - ScheduledExecutorService scheduledExecutorService; - - private final String tracerType = "SofaTracerSpanTest"; - private final String clientLogType = "client-log-test.log"; - private final String serverLogType = "server-log-test.log"; - private SofaTracer sofaTracer; - private SofaTracerSpan sofaTracerSpan; + private static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS; + private TracerScheduleExecutorService tracerScheduleExecutorService; + private SofaTracerSpan sofaTracerSpan; @Before public void setUp() { - scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); + ScheduledExecutorService scheduledExecutorService = Executors + .newSingleThreadScheduledExecutor(); tracerScheduleExecutorService = new TracerScheduleExecutorService(scheduledExecutorService); + String clientLogType = "client-log-test.log"; Reporter clientReporter = new DiskReporterImpl(clientLogType, new ClientSpanEncoder()); + String serverLogType = "server-log-test.log"; Reporter serverReporter = new DiskReporterImpl(serverLogType, new ServerSpanEncoder()); - sofaTracer = new SofaTracer.Builder(tracerType) + String tracerType = "SofaTracerSpanTest"; + SofaTracer sofaTracer = new SofaTracer.Builder(tracerType) .withTag("tracer", "SofaTraceContextHolderTest").withClientReporter(clientReporter) .withServerReporter(serverReporter).build(); - sofaTracerSpan = (SofaTracerSpan) this.sofaTracer.buildSpan("SofaTracerSpanTest").start(); + sofaTracerSpan = (SofaTracerSpan) sofaTracer.buildSpan("SofaTracerSpanTest").start(); } @Test public void scheduleRunnable() throws InterruptedException { - final Map taskMap = new HashMap(); + final Map taskMap = new HashMap<>(); taskMap.put("key", 1); - SofaTracerRunnable sofaTracerRunnable = new SofaTracerRunnable(new Runnable() { - @Override - public void run() { - taskMap.put("key", taskMap.get("key") + 1); - } - }); + SofaTracerRunnable sofaTracerRunnable = new SofaTracerRunnable(() -> taskMap.put("key", taskMap.get("key") + 1)); tracerScheduleExecutorService.schedule(sofaTracerRunnable, 1000, TIME_UNIT); Thread.sleep(1100); Integer result = taskMap.get("key"); - Assert.assertTrue(result == 2); + Assert.assertEquals(2, (int) result); } @Test public void scheduleRunnable_with_tracerContext() throws Exception { SofaTraceContext sofaTraceContext = new SofaTracerThreadLocalTraceContext(); sofaTraceContext.push(sofaTracerSpan); - final Map taskMap = new HashMap(); + final Map taskMap = new HashMap<>(); taskMap.put("key", 1); - SofaTracerRunnable sofaTracerRunnable = new SofaTracerRunnable(new Runnable() { - @Override - public void run() { - taskMap.put("key", taskMap.get("key") + 1); - } - }, sofaTraceContext); + SofaTracerRunnable sofaTracerRunnable = new SofaTracerRunnable(() -> taskMap.put("key", taskMap.get("key") + 1), sofaTraceContext); tracerScheduleExecutorService.schedule(sofaTracerRunnable, 1000, TIME_UNIT); Thread.sleep(1100); Integer result = taskMap.get("key"); - Assert.assertTrue(result == 2); + Assert.assertEquals(2, (int) result); //check currentSpan - Field field = sofaTracerRunnable.getClass().getDeclaredField("traceContext"); - field.setAccessible(true); - SofaTraceContext resultSofaTraceContext = (SofaTraceContext) field.get(sofaTracerRunnable); - SofaTracerSpan currentSpan = resultSofaTraceContext.getCurrentSpan(); - Assert.assertTrue(currentSpan.getOperationName().equals("SofaTracerSpanTest")); + SofaTracerSpan currentSpan = sofaTracerRunnable.functionalAsyncSupport.traceContext.getCurrentSpan(); + Assert.assertEquals("SofaTracerSpanTest", currentSpan.getOperationName()); } @Test public void scheduleCallable() throws Exception { final Object testObj = new Object(); - ScheduledFuture schedule = tracerScheduleExecutorService - .schedule(()-> testObj, 1000, TIME_UNIT); + ScheduledFuture schedule = tracerScheduleExecutorService + .schedule(() -> testObj, 1000, TIME_UNIT); Thread.sleep(1100); Object o = schedule.get(); - Assert.assertTrue(testObj == o); + Assert.assertSame(testObj, o); } } \ No newline at end of file diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/configuration/SofaTracerConfigurationTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/configuration/SofaTracerConfigurationTest.java index 4c987b7a0..0b5ef0dcd 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/configuration/SofaTracerConfigurationTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/configuration/SofaTracerConfigurationTest.java @@ -25,6 +25,9 @@ import java.io.File; import java.util.HashMap; import java.util.Map; +import java.util.UUID; + +import static org.junit.Assert.*; /** * @@ -64,34 +67,32 @@ public static void after1() throws Exception { @Test public void testTracerConfiguration() { - Assert.assertEquals(SofaTracerConfiguration.getInteger("nullkey"), null); + assertEquals(SofaTracerConfiguration.getInteger("nullkey"), null); Integer i = new Integer(1); - Assert.assertEquals(SofaTracerConfiguration.getIntegerDefaultIfNull("nullkey", i), i); - Assert.assertEquals(SofaTracerConfiguration.getMapEmptyIfNull("nullkey").size(), 0); - Assert.assertEquals(SofaTracerConfiguration.getMapEmptyIfNull("testProperty1").size(), 0); - Assert.assertEquals(SofaTracerConfiguration.getMapEmptyIfNull("testProperty3").size(), 0); - Assert.assertEquals(SofaTracerConfiguration.getProperty("testProperty1"), "test1"); - Assert.assertEquals(SofaTracerConfiguration.getProperty("testProperty3"), "test3"); + assertEquals(SofaTracerConfiguration.getIntegerDefaultIfNull("nullkey", i), i); + assertEquals(SofaTracerConfiguration.getMapEmptyIfNull("nullkey").size(), 0); + assertEquals(SofaTracerConfiguration.getMapEmptyIfNull("testProperty1").size(), 0); + assertEquals(SofaTracerConfiguration.getMapEmptyIfNull("testProperty3").size(), 0); + assertEquals(SofaTracerConfiguration.getProperty("testProperty1"), "test1"); + assertEquals(SofaTracerConfiguration.getProperty("testProperty3"), "test3"); - Assert.assertEquals(SofaTracerConfiguration.getProperty("notExist", null), null); + assertEquals(SofaTracerConfiguration.getProperty("notExist", null), null); SofaTracerConfiguration.setProperty("testProperty1", "newkey"); - Assert.assertEquals(SofaTracerConfiguration.getProperty("testProperty1"), "newkey"); + assertEquals(SofaTracerConfiguration.getProperty("testProperty1"), "newkey"); SofaTracerConfiguration.setProperty("testProperty3", "newkey"); - Assert.assertEquals(SofaTracerConfiguration.getProperty("testProperty3"), "newkey"); + assertEquals(SofaTracerConfiguration.getProperty("testProperty3"), "newkey"); - Assert.assertEquals(SofaTracerConfiguration.getInteger("testIntegerProperty1").intValue(), - 1); - Assert.assertEquals(SofaTracerConfiguration.getInteger("testIntegerProperty2").intValue(), - 2); + assertEquals(SofaTracerConfiguration.getInteger("testIntegerProperty1").intValue(), 1); + assertEquals(SofaTracerConfiguration.getInteger("testIntegerProperty2").intValue(), 2); HashMap map = new HashMap(); SofaTracerConfiguration.setProperty("map", map); - Assert.assertEquals(SofaTracerConfiguration.getMapEmptyIfNull("map"), map); + assertEquals(SofaTracerConfiguration.getMapEmptyIfNull("map"), map); SofaTracerConfiguration.setProperty("integer1", 1); - Assert.assertEquals(SofaTracerConfiguration.getInteger("integer1").intValue(), 1); + assertEquals(SofaTracerConfiguration.getInteger("integer1").intValue(), 1); } @Test @@ -120,4 +121,12 @@ public boolean contains(String key) { } + @Test + public void test_removeProperty() { + String uuid = UUID.randomUUID().toString(); + SofaTracerConfiguration.setProperty(uuid, "test_removeProperty"); + assertEquals("test_removeProperty", SofaTracerConfiguration.getProperty(uuid)); + SofaTracerConfiguration.removeProperty(uuid); + assertEquals("", SofaTracerConfiguration.getProperty(uuid)); + } } \ No newline at end of file diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContextTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContextTest.java index 3e89db381..7432f9039 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContextTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContextTest.java @@ -274,7 +274,7 @@ public void testRootStart() throws Exception { SofaTracerSpanContext sofaTracerSpanContext = SofaTracerSpanContext.rootStart(); assertEquals(SofaTracer.ROOT_SPAN_ID, sofaTracerSpanContext.getSpanId()); assertTrue(StringUtils.isBlank(sofaTracerSpanContext.getParentId())); - assertTrue(!sofaTracerSpanContext.isSampled()); + assertTrue(sofaTracerSpanContext.isSampled()); } /** diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/exception/SofaTracerRuntimeExceptionTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/exception/SofaTracerRuntimeExceptionTest.java index 9ede6ad20..8b3603625 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/exception/SofaTracerRuntimeExceptionTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/exception/SofaTracerRuntimeExceptionTest.java @@ -27,6 +27,7 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; + import java.util.HashMap; import java.util.Iterator; import java.util.Map; diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/holder/SofaTraceContextHolderTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/holder/SofaTraceContextHolderTest.java index be90d9830..b43788432 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/holder/SofaTraceContextHolderTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/holder/SofaTraceContextHolderTest.java @@ -25,9 +25,7 @@ import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * SofaTraceContextHolder Tester. diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/listener/SpanReportListenerHolderTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/listener/SpanReportListenerHolderTest.java index 193b814e5..6abbac4e2 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/listener/SpanReportListenerHolderTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/listener/SpanReportListenerHolderTest.java @@ -19,6 +19,7 @@ import com.alipay.common.tracer.core.span.SofaTracerSpan; import org.junit.Before; import org.junit.Test; + import java.util.ArrayList; import java.util.List; diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/mock/MockSofaTracerTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/mock/MockSofaTracerTest.java index e5dd45434..41f583cb7 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/mock/MockSofaTracerTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/mock/MockSofaTracerTest.java @@ -18,9 +18,9 @@ import com.alipay.common.tracer.core.SofaTracer; import com.alipay.common.tracer.core.base.AbstractTestBase; -import org.junit.Test; -import org.junit.Before; import org.junit.After; +import org.junit.Before; +import org.junit.Test; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonSpanEncoderTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonSpanEncoderTest.java index cd693a312..3aaeb503e 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonSpanEncoderTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonSpanEncoderTest.java @@ -33,12 +33,14 @@ import org.junit.Test; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import static com.alipay.common.tracer.core.span.SofaTracerSpan.ARRAY_SEPARATOR; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** @@ -50,11 +52,9 @@ */ public class CommonSpanEncoderTest extends AbstractTestBase { - private SofaTracer sofaTracer; + private SofaTracer sofaTracer; - private String clientLogType = "clientLog.log"; - - private String appName = "appName"; + private final String clientLogType = "clientLog.log"; @Before public void setup() throws Exception { @@ -68,17 +68,18 @@ public void setup() throws Exception { * Method: encode(SofaTracerSpan span) */ @Test - public void testEncode() throws Exception { + public void testEncode() { + String appName = "appName"; SofaTracerSpan sofaTracerSpan = (SofaTracerSpan) this.sofaTracer - .buildSpan("spanOperationName").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT) - .withTag(SpanTags.CURR_APP_TAG.getKey(), appName).start(); + .buildSpan("spanOperationName").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT) + .withTag(SpanTags.CURR_APP_TAG.getKey(), appName).start(); SofaTracerSpanContext sofaTracerSpanContext = sofaTracerSpan.getSofaTracerSpanContext(); Exception exception = new RuntimeException("CommonSpanEncoderTest"); String errorType = "timeout_error"; - String[] errorSources = new String[] { "trade", "rpc" }; + String[] errorSources = new String[]{"trade", "rpc"}; - Map context = new HashMap(); + Map context = new HashMap<>(); context.put("serviceName", "service"); context.put("methodName", "methodCall"); @@ -91,37 +92,40 @@ public void testEncode() throws Exception { //Record a client log sofaTracerSpan.finish(); - TestUtil.waitForAsyncLog(); - - //Check client logs - List clientDigestContents = FileUtils.readLines(new File(logDirectoryPath - + File.separator - + clientLogType)); - assertTrue(clientDigestContents.size() == 1); - assertTrue(clientDigestContents.get(0).contains(sofaTracerSpanContext.getTraceId())); - - //error log - List errorContents = FileUtils - .readLines(customFileLog(TracerSystemLogEnum.MIDDLEWARE_ERROR.getDefaultLogName())); - //Error stack - assertTrue(errorContents.size() > 1); - assertTrue(errorContents.get(0).contains(sofaTracerSpanContext.getTraceId())); - //remove head - String fileContent = errorContents.get(0).substring(errorContents.get(0).indexOf(",") + 1); - //remove end - fileContent = fileContent.substring(0, fileContent.lastIndexOf(",")); - //construct result - List params = new ArrayList<>(); - params.add(sofaTracerSpan.getTagsWithStr().get(SpanTags.CURR_APP_TAG.getKey())); - params.add(sofaTracerSpanContext.getTraceId()); - params.add(sofaTracerSpanContext.getSpanId()); - params.add(Thread.currentThread().getName()); - params.add(errorType); - params.add(StringUtils.arrayToString(errorSources, ARRAY_SEPARATOR, "", "")); - params.add(MAP_PREFIX + StringUtils.mapToString(context)); - params.add(MAP_PREFIX + StringUtils.mapToString(sofaTracerSpanContext.getBizBaggage())); - - Assert.assertTrue("Content Checkout error", checkResult(params, fileContent)); + TestUtil.periodicallyAssert(() -> { + try { + //Check client logs + List clientDigestContents = FileUtils.readLines(new File(logDirectoryPath + + File.separator + + clientLogType)); + assertEquals(1, clientDigestContents.size()); + assertTrue(clientDigestContents.get(0).contains(sofaTracerSpanContext.getTraceId())); + + //error log + List errorContents = FileUtils + .readLines(customFileLog(TracerSystemLogEnum.MIDDLEWARE_ERROR.getDefaultLogName())); + //Error stack + assertTrue(errorContents.size() > 1); + assertTrue(errorContents.get(0).contains(sofaTracerSpanContext.getTraceId())); + //remove head + String fileContent = errorContents.get(0).substring(errorContents.get(0).indexOf(",") + 1); + //remove end + fileContent = fileContent.substring(0, fileContent.lastIndexOf(",")); + //construct result + List params = new ArrayList<>(); + params.add(sofaTracerSpan.getTagsWithStr().get(SpanTags.CURR_APP_TAG.getKey())); + params.add(sofaTracerSpanContext.getTraceId()); + params.add(sofaTracerSpanContext.getSpanId()); + params.add(Thread.currentThread().getName()); + params.add(errorType); + params.add(StringUtils.arrayToString(errorSources, ARRAY_SEPARATOR, "", "")); + params.add(MAP_PREFIX + StringUtils.mapToString(context)); + params.add(MAP_PREFIX + StringUtils.mapToString(sofaTracerSpanContext.getBizBaggage())); + + Assert.assertTrue("Content Checkout error", checkResult(params, fileContent)); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } - } diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonTracerManagerTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonTracerManagerTest.java index 3edb4575b..6851868d9 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonTracerManagerTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonTracerManagerTest.java @@ -27,8 +27,10 @@ import org.junit.Test; import java.io.File; +import java.io.IOException; import java.util.List; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** @@ -53,39 +55,43 @@ public void before() { * Method: reportCommonSpan(CommonLogSpan commonLogSpan) */ @Test - public void testRegisterAndReportCommonSpan() throws Exception { + public void testRegisterAndReportCommonSpan() { String logType = "test-register.log"; CommonTracerManager.register(logType, "", ""); CommonLogSpan commonLogSpan = new CommonLogSpan(this.sofaTracer, - System.currentTimeMillis(), "testReportProfile", SofaTracerSpanContext.rootStart(), - null); + System.currentTimeMillis(), "testReportProfile", SofaTracerSpanContext.rootStart(), + null); assertTrue(CommonTracerManager.isAppenderExist(logType)); //Note: Be sure to set the log type for commonSpan commonLogSpan.setLogType(logType); CommonTracerManager.reportCommonSpan(commonLogSpan); - TestUtil.waitForAsyncLog(); - - File file = customFileLog(logType); - assertTrue(file.exists()); - - List errorContents = FileUtils.readLines(file); - assertTrue(errorContents.toString(), errorContents.size() == 1); + TestUtil.periodicallyAssert(() -> { + try { + File file = customFileLog(logType); + assertTrue(file.exists()); + + List errorContents = FileUtils.readLines(file); + assertEquals(errorContents.toString(), 1, errorContents.size()); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } - /*** + /** * com.alipay.common.tracer.core.reporter.common.CommonTracerManager#register(char, java.lang.String, java.lang.String, java.lang.String) - * @throws Exception */ @Test - public void testRegisterAndReportCommonSpanChar() throws Exception { + public void testRegisterAndReportCommonSpanChar() { char logType = '3'; String logTypeStr = String.valueOf(logType); String fileName = "test.log.char"; + //noinspection deprecation CommonTracerManager.register(logType, fileName, "", ""); CommonLogSpan commonLogSpan = new CommonLogSpan(this.sofaTracer, - System.currentTimeMillis(), "testReportProfile", SofaTracerSpanContext.rootStart(), - null); + System.currentTimeMillis(), "testReportProfile", SofaTracerSpanContext.rootStart(), + null); assertTrue(CommonTracerManager.isAppenderExist(logTypeStr)); //Note: Be sure to set the log type for commonSpan commonLogSpan.setLogType(logTypeStr); @@ -93,52 +99,61 @@ public void testRegisterAndReportCommonSpanChar() throws Exception { commonLogSpan.addSlot("word"); CommonTracerManager.reportCommonSpan(commonLogSpan); - TestUtil.waitForAsyncLog(); - - File file = customFileLog(fileName); - assertTrue(file.exists()); - - List contents = FileUtils.readLines(file); - assertTrue(contents.toString(), contents.size() == 1); - assertTrue(contents.get(0).contains("hello") && contents.get(0).contains("word")); - + TestUtil.periodicallyAssert(() -> { + try { + File file = customFileLog(fileName); + assertTrue(file.exists()); + + List contents = FileUtils.readLines(file); + assertEquals(contents.toString(), 1, contents.size()); + assertTrue(contents.get(0).contains("hello") && contents.get(0).contains("word")); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } /** * Method: reportProfile(CommonLogSpan sofaTracerSpan) */ @Test - public void testReportProfile() throws Exception { + public void testReportProfile() { String logType = TracerSystemLogEnum.MIDDLEWARE_ERROR.getDefaultLogName(); CommonTracerManager.reportError(new CommonLogSpan(this.sofaTracer, System - .currentTimeMillis(), "testReportProfile", SofaTracerSpanContext.rootStart(), null)); - - TestUtil.waitForAsyncLog(); - - File file = customFileLog(logType); - assertTrue(file.exists()); - - List errorContents = FileUtils.readLines(file); - assertTrue(errorContents.toString(), errorContents.size() == 1); + .currentTimeMillis(), "testReportProfile", SofaTracerSpanContext.rootStart(), null)); + + TestUtil.periodicallyAssert(() -> { + try { + File file = customFileLog(logType); + assertTrue(file.exists()); + List errorContents = FileUtils.readLines(file); + assertEquals(errorContents.toString(), 1, errorContents.size()); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } /** * Method: reportError(CommonLogSpan sofaTracerSpan) */ @Test - public void testReportError() throws Exception { + public void testReportError() { CommonTracerManager.reportProfile(new CommonLogSpan(this.sofaTracer, System - .currentTimeMillis(), "testReportProfile", SofaTracerSpanContext.rootStart(), null)); + .currentTimeMillis(), "testReportProfile", SofaTracerSpanContext.rootStart(), null)); String logType = TracerSystemLogEnum.RPC_PROFILE.getDefaultLogName(); - TestUtil.waitForAsyncLog(); - - File file = customFileLog(logType); - assertTrue(file.exists()); - - List profileContents = FileUtils.readLines(file); - assertTrue(profileContents.toString(), profileContents.size() == 1); + TestUtil.periodicallyAssert(() -> { + try { + File file = customFileLog(logType); + assertTrue(file.exists()); + + List profileContents = FileUtils.readLines(file); + assertEquals(profileContents.toString(), 1, profileContents.size()); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } - } diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImplTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImplTest.java index aa6b52a74..8339b045c 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImplTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImplTest.java @@ -21,6 +21,7 @@ import com.alipay.common.tracer.core.base.AbstractTestBase; import com.alipay.common.tracer.core.configuration.SofaTracerConfiguration; import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext; +import com.alipay.common.tracer.core.reporter.stat.AbstractSofaTracerStatisticReporter; import com.alipay.common.tracer.core.reporter.stat.SofaTracerStatisticReporter; import com.alipay.common.tracer.core.span.SofaTracerSpan; import com.alipay.common.tracer.core.tracertest.encoder.ClientSpanEncoder; @@ -28,11 +29,13 @@ import com.alipay.common.tracer.core.utils.StringUtils; import io.opentracing.tag.Tags; import org.apache.commons.io.FileUtils; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import java.io.File; +import java.util.HashMap; import java.util.List; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; @@ -51,21 +54,21 @@ */ public class DiskReporterImplTest extends AbstractTestBase { - private String clientLogType = "client-log-disk-report.log"; + private final String clientLogType = "client-log-disk-report.log"; - private String expectRollingPolicy = SofaTracerConfiguration - .getRollingPolicy(TracerTestLogEnum.RPC_CLIENT - .getRollingKey()); + private final String expectRollingPolicy = SofaTracerConfiguration + .getRollingPolicy(TracerTestLogEnum.RPC_CLIENT + .getRollingKey()); - private String expectLogReserveConfig = SofaTracerConfiguration - .getLogReserveConfig(TracerTestLogEnum.RPC_CLIENT - .getLogReverseKey()); + private final String expectLogReserveConfig = SofaTracerConfiguration + .getLogReserveConfig(TracerTestLogEnum.RPC_CLIENT + .getLogReverseKey()); - private ClientSpanEncoder expectedClientSpanEncoder = new ClientSpanEncoder(); + private final ClientSpanEncoder expectedClientSpanEncoder = new ClientSpanEncoder(); - private DiskReporterImpl clientReporter; + private DiskReporterImpl clientReporter; - private SofaTracerSpan sofaTracerSpan; + private SofaTracerSpan sofaTracerSpan; @Before public void before() { @@ -100,13 +103,45 @@ public void testGetStatReporterType() { assertTrue(StringUtils.isBlank(this.clientReporter.getStatReporterType())); } + @Test + public void testGetStatReporterTypeNotNull() { + AbstractDiskReporter diskReporter = new DiskReporterImpl(clientLogType, + expectRollingPolicy, expectLogReserveConfig, expectedClientSpanEncoder, + new AbstractSofaTracerStatisticReporter("testTracer", "", "") { + @Override + public void doReportStat(SofaTracerSpan sofaTracerSpan) { + + } + }); + Assert.assertNotNull(diskReporter.getStatReporterType()); + } + + @Test + public void testStatisticReport() { + final String[] str = { "" }; + AbstractDiskReporter diskReporter = new DiskReporterImpl(clientLogType, + expectRollingPolicy, expectLogReserveConfig, expectedClientSpanEncoder, + new AbstractSofaTracerStatisticReporter("testTracer", "", "") { + @Override + public void doReportStat(SofaTracerSpan sofaTracerSpan) { + str[0] = "hello"; + } + }); + SofaTracer sofaTracer = mock(SofaTracer.class); + SofaTracerSpanContext sofaTracerSpanContext = new SofaTracerSpanContext(); + SofaTracerSpan sofaTracerSpan = new SofaTracerSpan(sofaTracer, System.currentTimeMillis(), + "mock", sofaTracerSpanContext, new HashMap<>()); + diskReporter.statisticReport(sofaTracerSpan); + Assert.assertEquals("hello", str[0]); + } + /** * Method: digestReport(SofaTracerSpan span) */ @Test public void testDigestReport() { this.clientReporter.digestReport(this.sofaTracerSpan); - assertEquals(true, this.clientReporter.getIsDigestFileInited().get()); + assertTrue(this.clientReporter.getIsDigestFileInited().get()); } /** @@ -156,32 +191,35 @@ public void testFixInitDigestFile() throws Exception { SelfLog.warn("SelfLog init success!!!"); int nThreads = 30; ExecutorService executor = new ThreadPoolExecutor(nThreads, nThreads, 0L, - TimeUnit.MILLISECONDS, new LinkedBlockingQueue()); + TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>()); + CountDownLatch countDownLatch = new CountDownLatch(nThreads); for (int i = 0; i < nThreads; i++) { - Runnable worker = new WorkerInitThread(this.clientReporter, "" + i); + Runnable worker = new WorkerInitThread(this.clientReporter, "" + i, countDownLatch); executor.execute(worker); } - Thread.sleep(3 * 1000); + //noinspection ResultOfMethodCallIgnored + countDownLatch.await(3, TimeUnit.SECONDS); // When there is no control for concurrent initialization, report span will get an error; // when the repair method is initialized,other threads need to wait for initialization to complete. List contents = FileUtils.readLines(tracerSelfLog()); - assertTrue("Actual concurrent init file size = " + contents.size(), contents.size() == 1); + assertEquals("Actual concurrent init file size = " + contents.size(), 1, contents.size()); } - class WorkerInitThread implements Runnable { - - private DiskReporterImpl reporter; - - private String command; + static class WorkerInitThread implements Runnable { + private final DiskReporterImpl reporter; + private final String command; + private final CountDownLatch countDownLatch; - public WorkerInitThread(DiskReporterImpl reporter, String s) { + public WorkerInitThread(DiskReporterImpl reporter, String s, CountDownLatch countDownLatch) { this.command = s; this.reporter = reporter; + this.countDownLatch = countDownLatch; } @Override public void run() { processCommand(); + countDownLatch.countDown(); } private void processCommand() { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/SofaTracerDigestReporterAsyncManagerTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/SofaTracerDigestReporterAsyncManagerTest.java index ec99b6620..4271b9410 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/SofaTracerDigestReporterAsyncManagerTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/SofaTracerDigestReporterAsyncManagerTest.java @@ -22,6 +22,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; + import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/stat/SofaTracerStatisticReporterImplTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/stat/SofaTracerStatisticReporterImplTest.java index 3b4259b23..fa40e9833 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/stat/SofaTracerStatisticReporterImplTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/stat/SofaTracerStatisticReporterImplTest.java @@ -21,7 +21,10 @@ import com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager; import com.alipay.common.tracer.core.reporter.stat.model.StatKey; import com.alipay.common.tracer.core.span.SofaTracerSpan; -import org.junit.*; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import java.util.Date; diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/samplers/SamplingStatusTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/samplers/SamplingStatusTest.java index ad54bc75d..a002eda0c 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/samplers/SamplingStatusTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/samplers/SamplingStatusTest.java @@ -19,6 +19,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; + import java.util.HashMap; import java.util.Map; diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java index f9e8b0aef..5819ccb57 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java @@ -27,9 +27,13 @@ import com.alipay.common.tracer.core.tracertest.encoder.ServerSpanEncoder; import com.alipay.common.tracer.core.utils.StringUtils; import io.opentracing.tag.Tags; -import org.junit.*; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -46,8 +50,6 @@ */ public class SofaTracerSpanTest extends AbstractTestBase { - private final String tracerType = "SofaTracerSpanTest"; - private final String clientLogType = "client-log-test.log"; private final String serverLogType = "server-log-test.log"; @@ -62,6 +64,7 @@ public void setup() { Reporter serverReporter = new DiskReporterImpl(serverLogType, new ServerSpanEncoder()); + String tracerType = "SofaTracerSpanTest"; sofaTracer = new SofaTracer.Builder(tracerType) .withTag("tracer", "SofaTraceContextHolderTest").withClientReporter(clientReporter) .withServerReporter(serverReporter).build(); @@ -73,6 +76,7 @@ public void setup() { public void afterMethod() throws Exception { File file = tracerSelfLog(); if (file.exists()) { + //noinspection ResultOfMethodCallIgnored file.createNewFile(); } @@ -110,7 +114,7 @@ public void testConstructSpan() { String spanId = "spanId"; SofaTracerSpanContext sofaTracerSpanContext = new SofaTracerSpanContext(traceId, spanId, null); - Map tags = new HashMap(); + Map tags = new HashMap<>(); tags.put("key", "value"); SofaTracerSpan sofaTracerSpan = new SofaTracerSpan(this.sofaTracer, startTime, "testConstructSpan", sofaTracerSpanContext, tags); @@ -147,11 +151,10 @@ public void testSetAndGetBaggageItem() { @Test public void testSetBooleanTag() { - Boolean expected = true; String key = "tag.key"; - sofaTracerSpan.setTag(key, expected); - assertEquals(expected, sofaTracerSpan.getTagsWithBool().get(key)); + sofaTracerSpan.setTag(key, true); + assertEquals(true, sofaTracerSpan.getTagsWithBool().get(key)); } @Test @@ -200,7 +203,7 @@ public void testWithTimestampDurationEndTimeMinusStartTime() { * Method: finish() */ @Test - public void testFinish() throws Exception { + public void testFinish() { SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testWithTimestamp") .withStartTimestamp(111).start(); long endTime = System.currentTimeMillis(); @@ -213,7 +216,7 @@ public void testFinish() throws Exception { * Method: close() */ @Test - public void testClose() throws Exception { + public void testClose() { SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testWithTimestamp") .withStartTimestamp(111).start(); //close @@ -227,29 +230,28 @@ public void testClose() throws Exception { * Method: log(String eventType) */ @Test - public void testLogEventType() throws Exception { + public void testLogEventType() { List valueStr = Arrays.asList("value0", "value1", "value2"); long beginTime = System.currentTimeMillis(); sofaTracerSpan.log(valueStr.get(0)); sofaTracerSpan.log(valueStr.get(1)); sofaTracerSpan.log(valueStr.get(2)); List logDataList = sofaTracerSpan.getLogs(); - assertTrue(logDataList.size() == 3); + assertEquals(3, logDataList.size()); for (LogData logData : logDataList) { - Object value = logData.getFields().get(LogData.EVENT_TYPE_KEY); + String value = (String) logData.getFields().get(LogData.EVENT_TYPE_KEY); assertTrue(valueStr.contains(value)); long time = logData.getTime(); assertTrue(beginTime <= time && time <= System.currentTimeMillis()); } logDataList.clear(); - assertTrue(logDataList.size() == 0); } /** * Method: log(long currentTime, String eventType) */ @Test - public void testLogForCurrentTimeEventType() throws Exception { + public void testLogForCurrentTimeEventType() { List valueStr = Arrays.asList("value0", "value1", "value2"); SofaTracerSpan sofaTracerSpan1 = (SofaTracerSpan) this.sofaTracer .buildSpan("testLogForCurrentTimeEventType").withStartTimestamp(110).start(); @@ -258,31 +260,30 @@ public void testLogForCurrentTimeEventType() throws Exception { sofaTracerSpan1.log(111, valueStr.get(1)); sofaTracerSpan1.log(111, valueStr.get(2)); List logDataList = sofaTracerSpan1.getLogs(); - assertTrue(logDataList.size() == 3); + assertEquals(3, logDataList.size()); for (LogData logData : logDataList) { - Object value = logData.getFields().get(LogData.EVENT_TYPE_KEY); + String value = (String) logData.getFields().get(LogData.EVENT_TYPE_KEY); long time = logData.getTime(); assertTrue(valueStr.contains(value)); - assertTrue(time == 111); + assertEquals(111, time); } logDataList.clear(); - assertTrue(logDataList.size() == 0); } /** * Method: log(long currentTime, Map map) */ @Test - public void testLogForCurrentTimeMap() throws Exception { + public void testLogForCurrentTimeMap() { SofaTracerSpan testLogForCurrentTimeMapSpan = (SofaTracerSpan) this.sofaTracer .buildSpan("testLogForCurrentTimeMap").withStartTimestamp(111).start(); - Map fields = new HashMap(); + Map fields = new HashMap<>(); fields.put("key", "value"); - Map fields1 = new HashMap(); + Map fields1 = new HashMap<>(); fields1.put("key1", "value1"); - Map fields2 = new HashMap(); + Map fields2 = new HashMap<>(); fields2.put("key2", "value2"); - Map fields3 = new HashMap(); + Map fields3 = new HashMap<>(); fields3.put("key3", "value3"); testLogForCurrentTimeMapSpan.log(222, fields); @@ -290,17 +291,17 @@ public void testLogForCurrentTimeMap() throws Exception { testLogForCurrentTimeMapSpan.log(222, fields2); testLogForCurrentTimeMapSpan.log(222, fields3); List logDataList = testLogForCurrentTimeMapSpan.getLogs(); - assertTrue(logDataList.size() == 4); - assertTrue(logDataList.get(0).getTime() == 222); + assertEquals(4, logDataList.size()); + assertEquals(222, logDataList.get(0).getTime()); assertTrue(logDataList.get(0).getFields().containsKey("key") && logDataList.get(0).getFields().containsValue("value")); - assertTrue(logDataList.get(1).getTime() == 222); + assertEquals(222, logDataList.get(1).getTime()); assertTrue(logDataList.get(1).getFields().containsKey("key1") && logDataList.get(1).getFields().containsValue("value1")); - assertTrue(logDataList.get(2).getTime() == 222); + assertEquals(222, logDataList.get(2).getTime()); assertTrue(logDataList.get(2).getFields().containsKey("key2") && logDataList.get(2).getFields().containsValue("value2")); - assertTrue(logDataList.get(3).getTime() == 222); + assertEquals(222, logDataList.get(3).getTime()); assertTrue(logDataList.get(3).getFields().containsKey("key3") && logDataList.get(3).getFields().containsValue("value3")); @@ -310,14 +311,14 @@ public void testLogForCurrentTimeMap() throws Exception { * Method: log(Map map) */ @Test - public void testLogMap() throws Exception { + public void testLogMap() { SofaTracerSpan testLogMap = (SofaTracerSpan) this.sofaTracer.buildSpan("testLogMap") .withStartTimestamp(111).start(); - Map fields = new HashMap(); + Map fields = new HashMap<>(); fields.put("key", "value"); testLogMap.log(222, fields); List logDataList = testLogMap.getLogs(); - assertTrue(logDataList.size() == 1); + assertEquals(1, logDataList.size()); assertTrue(logDataList.get(0).getFields().containsKey("key") && logDataList.get(0).getFields().containsValue("value")); } @@ -326,7 +327,7 @@ public void testLogMap() throws Exception { * Method: log(String eventName, Object payload) */ @Test - public void testLogForEventNamePayload() throws Exception { + public void testLogForEventNamePayload() { SofaTracerSpan testLogForEventNamePayloadSpan = (SofaTracerSpan) this.sofaTracer .buildSpan("testLogForEventNamePayload").withStartTimestamp(111).start(); Object payload = new Object(); @@ -334,14 +335,14 @@ public void testLogForEventNamePayload() throws Exception { testLogForEventNamePayloadSpan.log("eventName", payload); // Object load = testLogForEventNamePayloadSpan.getLogs().get(0).getFields().get("eventName"); - assertTrue(load == payload); + assertSame(load, payload); } /** * Method: log(long currentTime, String eventName, Object payload) */ @Test - public void testLogForCurrentTimeEventNamePayload() throws Exception { + public void testLogForCurrentTimeEventNamePayload() { SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer .buildSpan("testLogForEventNamePayload").withStartTimestamp(111).start(); span.log(222, "eventName222", "value222"); @@ -350,7 +351,7 @@ public void testLogForCurrentTimeEventNamePayload() throws Exception { List logDataList = span.getLogs(); assertEquals(3, logDataList.size()); assertEquals(222, logDataList.get(0).getTime()); - assertTrue(logDataList.get(0).getFields().size() == 1); + assertEquals(1, logDataList.get(0).getFields().size()); assertTrue(logDataList.get(0).getFields().containsKey("eventName222") && logDataList.get(0).getFields().containsValue("value222")); assertEquals(333, logDataList.get(1).getTime()); @@ -361,7 +362,7 @@ public void testLogForCurrentTimeEventNamePayload() throws Exception { * Method: getTagsWithStr() */ @Test - public void testGetTagsWithStr() throws Exception { + public void testGetTagsWithStr() { SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testGetTagsWithStr") .withStartTimestamp(111).start(); //str @@ -374,7 +375,7 @@ public void testGetTagsWithStr() throws Exception { * Method: getTagsWithBool() */ @Test - public void testGetTagsWithBool() throws Exception { + public void testGetTagsWithBool() { SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testGetTagsWithStr") .withStartTimestamp(111).start(); //bool @@ -387,7 +388,7 @@ public void testGetTagsWithBool() throws Exception { * Method: getTagsWithNumber() */ @Test - public void testGetTagsWithNumber() throws Exception { + public void testGetTagsWithNumber() { SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testGetTagsWithNumber") .withStartTimestamp(111).start(); span.setTag("key", 100); @@ -402,7 +403,7 @@ public void testGetTagsWithNumber() throws Exception { * Method: getLogType() */ @Test - public void testGetLogType() throws Exception { + public void testGetLogType() { //client SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testGetLogTypeClient") .withStartTimestamp(111).start(); @@ -412,30 +413,30 @@ public void testGetLogType() throws Exception { assertFalse(span.isServer()); //logtype String logType = span.getLogType(); - assertTrue(clientLogType.equals(logType)); + assertEquals(clientLogType, logType); //server SofaTracerSpan serverSpan = (SofaTracerSpan) this.sofaTracer .buildSpan("testGetLogTypeServer").withStartTimestamp(111).start(); serverSpan.setTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); - assertTrue(serverLogType.equals(serverSpan.getLogType())); + assertEquals(serverLogType, serverSpan.getLogType()); } /** * Method: setLogType(String logType) */ @Test - public void testSetLogType() throws Exception { + public void testSetLogType() { SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testSetLogType") .withStartTimestamp(111).start(); span.setLogType("client"); - assertTrue("client".equals(span.getLogType())); + assertEquals("client", span.getLogType()); } /** * Method: getParentSofaTracerSpan() */ @Test - public void testGetParentSofaTracerSpan() throws Exception { + public void testGetParentSofaTracerSpan() { SofaTracerSpan parentSpan = (SofaTracerSpan) this.sofaTracer.buildSpan("parent") .withStartTimestamp(111).start(); @@ -449,7 +450,7 @@ public void testGetParentSofaTracerSpan() throws Exception { * Method: isServer() */ @Test - public void testIsServer() throws Exception { + public void testIsServer() { SofaTracerSpan clientSpan = (SofaTracerSpan) this.sofaTracer.buildSpan("testIsClient") .withStartTimestamp(111).start(); clientSpan.setTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT); @@ -466,7 +467,7 @@ public void testIsServer() throws Exception { * Method: toString() */ @Test - public void testToString() throws Exception { + public void testToString() { String str = sofaTracerSpan.toString(); assertTrue(str, StringUtils.isNotBlank(str)); } @@ -475,40 +476,44 @@ public void testToString() throws Exception { * Method: getThisAsParentWhenExceedLayer() */ @Test - public void testGetThisAsParentWhenExceedLayer() throws Exception { + public void testGetThisAsParentWhenExceedLayer() { StringBuilder spanIdBuilder = new StringBuilder("0").append("."); int i = 1; for (; i < 150; i++) { spanIdBuilder.append(i).append("."); } spanIdBuilder.append(i); - Map baggage = new HashMap(); + Map baggage = new HashMap<>(); baggage.put("key", "value"); baggage.put("key1", "value1"); baggage.put("key2", "value2"); String traceId = TraceIdGenerator.generate(); SofaTracerSpanContext sofaTracerSpanContext = new SofaTracerSpanContext(traceId, - spanIdBuilder.toString(), ""); + spanIdBuilder.toString(), ""); sofaTracerSpanContext.addBizBaggage(baggage); SofaTracerSpan sofaTracerSpan = new SofaTracerSpan(this.sofaTracer, - System.currentTimeMillis(), "open", sofaTracerSpanContext, null); + System.currentTimeMillis(), "open", sofaTracerSpanContext, null); // SofaTracerSpan thisAsParentSpan = sofaTracerSpan.getThisAsParentWhenExceedLayer(); assertEquals("\n" + sofaTracerSpanContext, SofaTracer.ROOT_SPAN_ID, thisAsParentSpan - .getSofaTracerSpanContext().getSpanId()); + .getSofaTracerSpanContext().getSpanId()); assertNotEquals(traceId, thisAsParentSpan.getSofaTracerSpanContext().getTraceId()); assertEquals(baggage, sofaTracerSpanContext.getBizBaggage()); - TestUtil.waitForAsyncLog(); - - Assert.assertTrue(checkSelfLogContainsError()); + TestUtil.periodicallyAssert(() -> { + try { + Assert.assertTrue(checkSelfLogContainsError()); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } @Test - public void testTags() throws Exception { + public void testTags() { SofaTracerSpan sofaTracerSpan = new SofaTracerSpan(this.sofaTracer, System.currentTimeMillis(), "open", SofaTracerSpanContext.rootStart(), null); sofaTracerSpan.setTag("key", ""); - assertTrue(sofaTracerSpan.getTagsWithStr().size() == 0); + assertEquals(0, sofaTracerSpan.getTagsWithStr().size()); } } \ No newline at end of file diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/tracer/AbstractServerTracerTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/tracer/AbstractServerTracerTest.java index 4123bff84..03d213477 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/tracer/AbstractServerTracerTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/tracer/AbstractServerTracerTest.java @@ -87,7 +87,7 @@ public void testServerReceive_sofaTracerSpanContext() { // sofaTracerSpanContext's sampler is false SofaTracerSpanContext sofaTracerSpanContext = new SofaTracerSpanContext("123", "0"); SofaTracerSpan sofaTracerSpan = serverTracer.serverReceive(sofaTracerSpanContext); - Assert.assertTrue(!sofaTracerSpan.getSofaTracerSpanContext().isSampled()); + Assert.assertTrue(sofaTracerSpan.getSofaTracerSpanContext().isSampled()); } @Test diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java index 6375ffa9a..f3d4900f9 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java @@ -38,8 +38,13 @@ import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Test; + import java.io.IOException; -import java.util.*; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -54,16 +59,12 @@ public class SofaTracerTest extends AbstractTestBase { private final String tracerType = "TracerTestService"; - - private SofaTracer sofaTracer; - private final String tracerGlobalTagKey = "tracerkey"; - private final String tracerGlobalTagValue = "tracervalue"; + private SofaTracer sofaTracer; @Before - public void beforeInstance() throws IOException { - + public void beforeInstance() { SofaTracerConfiguration.setProperty(SofaTracerConfiguration.SAMPLER_STRATEGY_NAME_KEY, SofaTracerPercentageBasedSampler.TYPE); SofaTracerConfiguration.setProperty( @@ -100,7 +101,7 @@ public void testInject() { SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testInjectSpan").start(); TextMap carrier = new TextMap() { - Map map = new HashMap(); + final Map map = new HashMap<>(); @Override public Iterator> iterator() { @@ -120,29 +121,32 @@ public void put(String key, String value) { Format.Builtin.TEXT_MAP, carrier); assertTrue("Origin Context : " + originContext.toString(), StringUtils.isBlank(extractSpanContext.getParentId())); - assertTrue("Extract Context : " + extractSpanContext, - originContext.equals(extractSpanContext)); + assertEquals("Extract Context : " + extractSpanContext, originContext, extractSpanContext); } /** * Method: reportSpan(SofaTracerSpan span) */ @Test - public void testReportSpan() throws Exception { + public void testReportSpan() { SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testInjectSpan") - .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start(); + .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start(); //Report Do not prohibit writing span.finish(); - TestUtil.waitForAsyncLog(); - - List contents = FileUtils.readLines(customFileLog(TracerTestLogEnum.RPC_CLIENT - .getDefaultLogName())); - assertTrue(contents.get(0), contents.size() == 1); - String contextStr = contents.get(0); - //Test print one only put one tag - assertTrue(contextStr.contains(Tags.SPAN_KIND.getKey()) - && contextStr.contains(Tags.SPAN_KIND_CLIENT)); + TestUtil.periodicallyAssert(() -> { + try { + List contents = FileUtils.readLines(customFileLog(TracerTestLogEnum.RPC_CLIENT + .getDefaultLogName())); + assertEquals(contents.get(0), 1, contents.size()); + String contextStr = contents.get(0); + //Test print one only put one tag + assertTrue(contextStr.contains(Tags.SPAN_KIND.getKey()) + && contextStr.contains(Tags.SPAN_KIND_CLIENT)); + } catch (IOException e) { + throw new AssertionError(e); + } + }, 500); } /** @@ -157,7 +161,7 @@ public void testIsDisableAllDigestLog() { .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start(); //report span.finish(); - assertTrue(!customFileLog(TracerTestLogEnum.RPC_CLIENT.getDefaultLogName()).exists()); + assertFalse(customFileLog(TracerTestLogEnum.RPC_CLIENT.getDefaultLogName()).exists()); // reset SofaTracerConfiguration.setProperty( SofaTracerConfiguration.DISABLE_MIDDLEWARE_DIGEST_LOG_KEY, ""); @@ -168,7 +172,7 @@ public void testIsDisableClientDigestLog() { //Close the client digest log String clientLogTypeName = TracerTestLogEnum.RPC_CLIENT.getDefaultLogName(); - Map prop = new HashMap(); + Map prop = new HashMap<>(); prop.put(clientLogTypeName, "true"); SofaTracerConfiguration.setProperty(SofaTracerConfiguration.DISABLE_DIGEST_LOG_KEY, prop); //create @@ -176,7 +180,7 @@ public void testIsDisableClientDigestLog() { .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start(); //report span.finish(); - assertTrue(!customFileLog(clientLogTypeName).exists()); + assertFalse(customFileLog(clientLogTypeName).exists()); SofaTracerConfiguration.setProperty(SofaTracerConfiguration.DISABLE_DIGEST_LOG_KEY, new HashMap<>()); } @@ -193,7 +197,7 @@ public void testClose() { //report span.finish(); String clientLogTypeName = TracerTestLogEnum.RPC_CLIENT.getDefaultLogName(); - assertTrue(!customFileLog(clientLogTypeName).exists()); + assertFalse(customFileLog(clientLogTypeName).exists()); } @Test @@ -214,7 +218,7 @@ public void testTracerClose() { @Test public void testGetTracerType() { String tracerType = this.sofaTracer.getTracerType(); - assertTrue(tracerType.equals(this.tracerType)); + assertEquals(tracerType, this.tracerType); } /** @@ -222,7 +226,7 @@ public void testGetTracerType() { */ @Test public void testGetSofaTracerDigestReporter() { - assertTrue(this.sofaTracer.getClientReporter() != null); + assertNotNull(this.sofaTracer.getClientReporter()); } /** @@ -230,11 +234,11 @@ public void testGetSofaTracerDigestReporter() { */ @Test public void testGetSofaTracerStatisticReporter() { - assertTrue(this.sofaTracer.getClientReporter() != null); + assertNotNull(this.sofaTracer.getClientReporter()); assertTrue(this.sofaTracer.getClientReporter() instanceof DiskReporterImpl); DiskReporterImpl clientReporter = (DiskReporterImpl) this.sofaTracer.getClientReporter(); assertTrue(StringUtils.isBlank(clientReporter.getStatReporterType())); - assertTrue(clientReporter.getStatReporter() == null); + assertNull(clientReporter.getStatReporter()); } /** @@ -243,13 +247,13 @@ public void testGetSofaTracerStatisticReporter() { @Test public void testGetTracerTags() { Map tags = this.sofaTracer.getTracerTags(); - assertTrue(tags.keySet().contains(this.tracerGlobalTagKey)); + assertTrue(tags.containsKey(this.tracerGlobalTagKey)); for (Map.Entry entry : tags.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (this.tracerGlobalTagKey.equals(key)) { - assertTrue("tracer tags : key=" + key + ",value = " + value, - this.tracerGlobalTagValue.equals(value)); + assertEquals("tracer tags : key=" + key + ",value = " + value, + this.tracerGlobalTagValue, value); } } } @@ -260,11 +264,11 @@ public void testGetTracerTags() { @Test public void testAsChildOfParent() { //create - Map bizBaggage = new HashMap(); + Map bizBaggage = new HashMap<>(); bizBaggage.put("biz", "value"); bizBaggage.put("biz1", "value1"); bizBaggage.put("biz2", "value2"); - Map sysBaggage = new HashMap(); + Map sysBaggage = new HashMap<>(); sysBaggage.put("sys", "value"); sysBaggage.put("sys1", "value1"); sysBaggage.put("sys2", "value2"); @@ -274,8 +278,8 @@ public void testAsChildOfParent() { spanParent.getSofaTracerSpanContext().addSysBaggage(sysBaggage); String parentTraceId = spanParent.getSofaTracerSpanContext().getTraceId(); SofaTracerSpanContext parentSpanContext = (SofaTracerSpanContext) spanParent.context(); - assertTrue("\nroot spanId : " + parentSpanContext.getSpanId(), parentSpanContext - .getSpanId().equals(SofaTracer.ROOT_SPAN_ID)); + assertEquals("\nroot spanId : " + parentSpanContext.getSpanId(), + parentSpanContext.getSpanId(), SofaTracer.ROOT_SPAN_ID); //child SofaTracerSpan spanChild = (SofaTracerSpan) this.sofaTracer.buildSpan("spanChild") .asChildOf(spanParent).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start(); @@ -304,7 +308,7 @@ public void testAsChildOfParentTestBizBaggageAndSysBaggage() { .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).start(); String parentTraceId = spanParent.getSofaTracerSpanContext().getTraceId(); SofaTracerSpanContext parentSpanContext = (SofaTracerSpanContext) spanParent.context(); - assertTrue(parentSpanContext.getSpanId().equals(SofaTracer.ROOT_SPAN_ID)); + assertEquals(parentSpanContext.getSpanId(), SofaTracer.ROOT_SPAN_ID); //child SofaTracerSpan spanChild = (SofaTracerSpan) this.sofaTracer.buildSpan("spanChild") .asChildOf(spanParent).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start(); @@ -341,8 +345,8 @@ public void testAsChildOfMultiParentSpan() { assertTrue("Parent1 --> TraceId : " + p1TraceId + ", spanId : " + p1SpanId, SofaTracer.ROOT_SPAN_ID.equals(parentSpanId) && parentSpanId.equals(followSpanId) && followSpanId.equals(p1SpanId)); - assertFalse(parentTraceID.equals(followTraceId)); - assertFalse(followTraceId.equals(p1TraceId)); + assertNotEquals(parentTraceID, followTraceId); + assertNotEquals(followTraceId, p1TraceId); //child SofaTracerSpan childSpan = (SofaTracerSpan) this.sofaTracer.buildSpan("childFollow") //parent @@ -354,11 +358,10 @@ public void testAsChildOfMultiParentSpan() { .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start(); String childTraceid = childSpan.getSofaTracerSpanContext().getTraceId(); String childSpanId = childSpan.getSofaTracerSpanContext().getSpanId(); - assertFalse("Child --> TraceId : " + childTraceid + ", spanId :" + childSpanId, - p1TraceId.equals(childTraceid)); + assertNotEquals("Child --> TraceId : " + childTraceid + ", spanId :" + childSpanId, + p1TraceId, childTraceid); //child context - SofaTracerSpanContext sofaTracerSpanContext = childSpan.getSofaTracerSpanContext(); - assertTrue(childTraceid.equals(parentTraceID)); + assertEquals(childTraceid, parentTraceID); //grandson SofaTracerSpan grandsonSpan = (SofaTracerSpan) this.sofaTracer.buildSpan("grandson") //parent @@ -367,14 +370,14 @@ public void testAsChildOfMultiParentSpan() { String grandsonTraceid = grandsonSpan.getSofaTracerSpanContext().getTraceId(); String grandsonSpanId = grandsonSpan.getSofaTracerSpanContext().getSpanId(); //check traceId - assertTrue("Grandson --> TraceId : " + grandsonTraceid + ", Grandson spanId :" - + grandsonSpanId, childTraceid.equals(parentTraceID)); - assertTrue(childTraceid.equals(grandsonTraceid)); + assertEquals("Grandson --> TraceId : " + grandsonTraceid + ", Grandson spanId :" + + grandsonSpanId, childTraceid, parentTraceID); + assertEquals(childTraceid, grandsonTraceid); //check spanId - assertTrue(grandsonSpan.getSofaTracerSpanContext().getParentId() - .equals(childSpan.getSofaTracerSpanContext().getSpanId())); - assertTrue(childSpan.getSofaTracerSpanContext().getParentId() - .equals(spanParent.getSofaTracerSpanContext().getSpanId())); + assertEquals(grandsonSpan.getSofaTracerSpanContext().getParentId(), childSpan + .getSofaTracerSpanContext().getSpanId()); + assertEquals(childSpan.getSofaTracerSpanContext().getParentId(), spanParent + .getSofaTracerSpanContext().getSpanId()); } /** @@ -393,7 +396,6 @@ public void testAddReferenceForReferenceTypeReferencedContextAndBaggageMultipleR spanParent.setBaggageItem(parBagKey, parBagValue); String parentTraceID = spanParent.getSofaTracerSpanContext().getTraceId(); - String parentSpanId = spanParent.getSofaTracerSpanContext().getSpanId(); //follow SofaTracerSpan spanFollow1 = (SofaTracerSpan) this.sofaTracer.buildSpan("spanFollow1") .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).start(); @@ -420,11 +422,11 @@ public void testAddReferenceForReferenceTypeReferencedContextAndBaggageMultipleR .addReference(References.FOLLOWS_FROM, spanFollow2.context()) .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start(); //check traceId - assertTrue("Follow --> TraceId : " + followTraceId2 + ", spanId : " + followSpanId2, - parentTraceID.equals(childSpan.getSofaTracerSpanContext().getTraceId())); + assertEquals("Follow --> TraceId : " + followTraceId2 + ", spanId : " + followSpanId2, + parentTraceID, childSpan.getSofaTracerSpanContext().getTraceId()); //check spanId - assertTrue(childSpan.getSofaTracerSpanContext().getParentId() - .equals(spanParent.getSofaTracerSpanContext().getSpanId())); + assertEquals(childSpan.getSofaTracerSpanContext().getParentId(), spanParent + .getSofaTracerSpanContext().getSpanId()); //baggage assertEquals("Child Baggage : " + childSpan.getSofaTracerSpanContext().getBizBaggage(), parBagValue, childSpan.getBaggageItem(parBagKey)); @@ -449,21 +451,21 @@ public void testWithTagForKeyValue() { Map tagsStr = spanParent.getTagsWithStr(); //string - assertTrue("tagsStr : " + tagsStr, tagsStr.keySet().contains("tagkey") - && tagsStr.values().contains("tagvalue")); - assertTrue(tagsStr.keySet().contains("tag1") && tagsStr.values().contains("value")); + assertTrue("tagsStr : " + tagsStr, + tagsStr.containsKey("tagkey") && tagsStr.containsValue("tagvalue")); + assertTrue(tagsStr.containsKey("tag1") && tagsStr.containsValue("value")); //bool spanParent.setTag("bool", Boolean.TRUE); spanParent.setTag("bool1", Boolean.FALSE); - assertTrue(spanParent.getTagsWithBool().get("bool").equals(Boolean.TRUE)); - assertTrue(spanParent.getTagsWithBool().get("bool1").equals(Boolean.FALSE)); + assertEquals(spanParent.getTagsWithBool().get("bool"), Boolean.TRUE); + assertEquals(spanParent.getTagsWithBool().get("bool1"), Boolean.FALSE); //number - spanParent.setTag("num1", new Integer(10)); + spanParent.setTag("num1", 10); spanParent.setTag("num2", 20); spanParent.setTag("num3", 2.22); - assertTrue(spanParent.getTagsWithNumber().get("num1").equals(10)); - assertTrue(spanParent.getTagsWithNumber().get("num2").equals(20)); - assertTrue(spanParent.getTagsWithNumber().get("num3").equals(2.22)); + assertEquals(10, spanParent.getTagsWithNumber().get("num1")); + assertEquals(20, spanParent.getTagsWithNumber().get("num2")); + assertEquals(2.22, spanParent.getTagsWithNumber().get("num3")); } /** @@ -486,15 +488,15 @@ public void testWithStartTimestampMicroseconds() { */ @Test public void testWithStatsReporterSofaTracerDigestReporter() { - assertTrue(this.sofaTracer.getServerReporter() != null); + assertNotNull(this.sofaTracer.getServerReporter()); } /** * Method: withSampler(Sampler sampler) */ @Test - public void testWithSampler() throws Exception { - assertTrue(this.sofaTracer.getSampler() != null); + public void testWithSampler() { + assertNotNull(this.sofaTracer.getSampler()); } } diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/utils/DateUtilsTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/utils/DateUtilsTest.java new file mode 100644 index 000000000..0ecb90acc --- /dev/null +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/utils/DateUtilsTest.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.core.utils; + +import org.junit.Test; + +import java.util.Date; + +import static junit.framework.TestCase.assertTrue; + +/** + * @author zhile + * @version : DateUtilsTest.java, v 0.1 2021年10月08日 下午3:47 zhile Exp $ + */ +public class DateUtilsTest { + + @Test + public void testDiffNextMinute() { + long diff = DateUtils.diffNextMinute(new Date()); + assertTrue(diff > 0); + } +} \ No newline at end of file diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/util/CoolDownTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/util/CoolDownTest.java new file mode 100644 index 000000000..f9beb25fc --- /dev/null +++ b/tracer-core/src/test/java/com/alipay/common/tracer/util/CoolDownTest.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.util; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.*; + +/** + *

created at 2021/4/7 + * + * @author xiangfeng.xzc + */ +public class CoolDownTest { + @Test + public void test() throws Throwable { + int times = 5; + int periods = 3; + final CoolDown coolDown = new CoolDown(1000, times); + ExecutorService es = Executors.newFixedThreadPool(4); + List> futures = new ArrayList>(); + + final AtomicInteger counter = new AtomicInteger(); + long start = System.currentTimeMillis(); + // CoolDown will reset at 1000ms and 2000ms + // with 500ms buffer to thread init. + final long end = start + (periods - 1) * 1000 + 500; + + for (int i = 0; i < 4; i++) { + futures.add(es.submit(new Runnable() { + @Override + public void run() { + while (System.currentTimeMillis() < end) { + if (coolDown.tryAcquire()) { + counter.incrementAndGet(); + } + } + } + })); + } + for (Future f : futures) { + f.get(); + } + es.shutdown(); + assertEquals(times * periods, counter.get()); + } +} \ No newline at end of file diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/util/DesensitizationHelperTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/util/DesensitizationHelperTest.java new file mode 100644 index 000000000..b8fef90b1 --- /dev/null +++ b/tracer-core/src/test/java/com/alipay/common/tracer/util/DesensitizationHelperTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.util; + +import com.alipay.common.tracer.core.configuration.SofaTracerConfiguration; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + *

created at 2021/4/12 + * + * @author xiangfeng.xzc + */ +public class DesensitizationHelperTest { + @Before + public void before() { + SofaTracerConfiguration.setProperty(DesensitizationHelper.ENABLED_KEY, "true"); + } + + @After + public void after() { + SofaTracerConfiguration.removeProperty(DesensitizationHelper.ENABLED_KEY); + DesensitizationHelper.setDesensitizer(null); + } + + @Test + public void test() { + DesensitizationHelper.setDesensitizer(new MockDesensitizer()); + assertEquals("mocked", DesensitizationHelper.desensitize("aa")); + } + + @Test + public void test_exception() { + DesensitizationHelper.setDesensitizer(new MockDesensitizer(true)); + assertEquals("aa", DesensitizationHelper.desensitize("aa")); + } +} \ No newline at end of file diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/util/MockDesensitizer.java b/tracer-core/src/test/java/com/alipay/common/tracer/util/MockDesensitizer.java new file mode 100644 index 000000000..8091af1df --- /dev/null +++ b/tracer-core/src/test/java/com/alipay/common/tracer/util/MockDesensitizer.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.common.tracer.util; + +/** + *

created at 2021/4/12 + * + * @author xiangfeng.xzc + */ +class MockDesensitizer implements Desensitizer { + private final boolean exception; + + MockDesensitizer() { + this(false); + } + + MockDesensitizer(boolean exception) { + this.exception = exception; + } + + @Override + public String desensitize(String str) { + if (exception) { + throw new IllegalStateException("exception is true"); + } + return "mocked"; + } +} diff --git a/tracer-core/src/test/java/com/alipay/disruptor/AggregateEventHandlerTest.java b/tracer-core/src/test/java/com/alipay/disruptor/AggregateEventHandlerTest.java index 33609830b..aeeb3b562 100644 --- a/tracer-core/src/test/java/com/alipay/disruptor/AggregateEventHandlerTest.java +++ b/tracer-core/src/test/java/com/alipay/disruptor/AggregateEventHandlerTest.java @@ -18,8 +18,9 @@ import com.alipay.disruptor.support.DummyEventHandler; import org.junit.Test; + import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.junit.Assert.assertThat; /** * @description: [test for AggregateEventHandler] diff --git a/tracer-core/src/test/java/com/alipay/disruptor/BusySpinWaitStrategyTest.java b/tracer-core/src/test/java/com/alipay/disruptor/BusySpinWaitStrategyTest.java index 6357e0891..d9ce91872 100644 --- a/tracer-core/src/test/java/com/alipay/disruptor/BusySpinWaitStrategyTest.java +++ b/tracer-core/src/test/java/com/alipay/disruptor/BusySpinWaitStrategyTest.java @@ -17,6 +17,7 @@ package com.alipay.disruptor; import org.junit.Test; + import static com.alipay.disruptor.support.WaitStrategyTestUtil.assertWaitForWithDelayOf; /** diff --git a/tracer-core/src/test/java/com/alipay/disruptor/EventPollerTest.java b/tracer-core/src/test/java/com/alipay/disruptor/EventPollerTest.java index 83799c140..c658e20a2 100644 --- a/tracer-core/src/test/java/com/alipay/disruptor/EventPollerTest.java +++ b/tracer-core/src/test/java/com/alipay/disruptor/EventPollerTest.java @@ -17,7 +17,9 @@ package com.alipay.disruptor; import org.junit.Test; + import java.util.ArrayList; + import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; diff --git a/tracer-core/src/test/java/com/alipay/disruptor/FixedSequenceGroupTest.java b/tracer-core/src/test/java/com/alipay/disruptor/FixedSequenceGroupTest.java index 3d4da4fd4..37d8d6c96 100644 --- a/tracer-core/src/test/java/com/alipay/disruptor/FixedSequenceGroupTest.java +++ b/tracer-core/src/test/java/com/alipay/disruptor/FixedSequenceGroupTest.java @@ -19,7 +19,7 @@ import org.junit.Test; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.junit.Assert.assertThat; /** * @description: [test for FixedSequenceGroup] diff --git a/tracer-core/src/test/java/com/alipay/disruptor/LiteTimeoutBlockingWaitStrategyTest.java b/tracer-core/src/test/java/com/alipay/disruptor/LiteTimeoutBlockingWaitStrategyTest.java index 8516c1d3a..ae7284089 100644 --- a/tracer-core/src/test/java/com/alipay/disruptor/LiteTimeoutBlockingWaitStrategyTest.java +++ b/tracer-core/src/test/java/com/alipay/disruptor/LiteTimeoutBlockingWaitStrategyTest.java @@ -20,6 +20,7 @@ import org.junit.Test; import java.util.concurrent.TimeUnit; + import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; diff --git a/tracer-core/src/test/java/com/alipay/disruptor/TimeoutBlockingWaitStrategyTest.java b/tracer-core/src/test/java/com/alipay/disruptor/TimeoutBlockingWaitStrategyTest.java index 9ac10d792..f2d2fbb7c 100644 --- a/tracer-core/src/test/java/com/alipay/disruptor/TimeoutBlockingWaitStrategyTest.java +++ b/tracer-core/src/test/java/com/alipay/disruptor/TimeoutBlockingWaitStrategyTest.java @@ -18,8 +18,11 @@ import com.alipay.disruptor.support.DummySequenceBarrier; import org.junit.Test; + import java.util.concurrent.TimeUnit; -import static org.junit.Assert.*; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @description: [test for TimeoutBlockingWaitStrategy] diff --git a/tracer-core/src/test/java/com/alipay/disruptor/WorkerPoolTest.java b/tracer-core/src/test/java/com/alipay/disruptor/WorkerPoolTest.java index f2cb32627..244b798bc 100644 --- a/tracer-core/src/test/java/com/alipay/disruptor/WorkerPoolTest.java +++ b/tracer-core/src/test/java/com/alipay/disruptor/WorkerPoolTest.java @@ -23,6 +23,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicLong; + import static org.hamcrest.CoreMatchers.is; /** diff --git a/tracer-core/src/test/java/com/alipay/disruptor/YieldingWaitStrategyTest.java b/tracer-core/src/test/java/com/alipay/disruptor/YieldingWaitStrategyTest.java index 975da9984..2867bb47a 100644 --- a/tracer-core/src/test/java/com/alipay/disruptor/YieldingWaitStrategyTest.java +++ b/tracer-core/src/test/java/com/alipay/disruptor/YieldingWaitStrategyTest.java @@ -17,6 +17,7 @@ package com.alipay.disruptor; import org.junit.Test; + import static com.alipay.disruptor.support.WaitStrategyTestUtil.assertWaitForWithDelayOf; /** diff --git a/tracer-core/src/test/java/com/alipay/disruptor/dsl/WorkerPoolInfoTest.java b/tracer-core/src/test/java/com/alipay/disruptor/dsl/WorkerPoolInfoTest.java index d8de5f6c1..8085ef96e 100644 --- a/tracer-core/src/test/java/com/alipay/disruptor/dsl/WorkerPoolInfoTest.java +++ b/tracer-core/src/test/java/com/alipay/disruptor/dsl/WorkerPoolInfoTest.java @@ -19,11 +19,19 @@ import com.alipay.common.tracer.core.appender.manager.ConsumerThreadFactory; import com.alipay.common.tracer.core.appender.manager.StringEvent; import com.alipay.common.tracer.core.appender.manager.StringEventFactory; -import com.alipay.disruptor.*; +import com.alipay.disruptor.BlockingWaitStrategy; +import com.alipay.disruptor.EventFactory; +import com.alipay.disruptor.FatalExceptionHandler; +import com.alipay.disruptor.RingBuffer; +import com.alipay.disruptor.Sequence; +import com.alipay.disruptor.SequenceBarrier; +import com.alipay.disruptor.WorkHandler; +import com.alipay.disruptor.WorkerPool; import com.alipay.disruptor.util.DaemonThreadFactory; import org.junit.Assert; import org.junit.Before; import org.junit.Test; + import java.util.concurrent.Executor; import java.util.concurrent.Executors; diff --git a/tracer-extensions/pom.xml b/tracer-extensions/pom.xml index e1af65f88..ade326f61 100644 --- a/tracer-extensions/pom.xml +++ b/tracer-extensions/pom.xml @@ -4,7 +4,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 tracer-extensions diff --git a/tracer-sofa-boot-starter/pom.xml b/tracer-sofa-boot-starter/pom.xml index d11c55599..4af66ef6e 100644 --- a/tracer-sofa-boot-starter/pom.xml +++ b/tracer-sofa-boot-starter/pom.xml @@ -5,7 +5,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../pom.xml diff --git a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/datasource/processor/DataSourceBeanPostProcessor.java b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/datasource/processor/DataSourceBeanPostProcessor.java index 4a041bcce..f2eacfd9b 100644 --- a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/datasource/processor/DataSourceBeanPostProcessor.java +++ b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/datasource/processor/DataSourceBeanPostProcessor.java @@ -29,7 +29,6 @@ import org.springframework.util.Assert; import javax.sql.DataSource; - import java.lang.reflect.Method; import static com.alipay.common.tracer.core.configuration.SofaTracerConfiguration.TRACER_APPNAME_KEY; diff --git a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/flexible/configuration/TracerAnnotationConfiguration.java b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/flexible/configuration/TracerAnnotationConfiguration.java index 5c6117bf1..b85a19ad3 100644 --- a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/flexible/configuration/TracerAnnotationConfiguration.java +++ b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/flexible/configuration/TracerAnnotationConfiguration.java @@ -17,10 +17,10 @@ package com.alipay.sofa.tracer.boot.flexible.configuration; import com.alipay.sofa.tracer.boot.configuration.SofaTracerAutoConfiguration; +import com.alipay.sofa.tracer.boot.flexible.aop.SofaTracerAdvisingBeanPostProcessor; import com.alipay.sofa.tracer.boot.flexible.processor.MethodInvocationProcessor; import com.alipay.sofa.tracer.boot.flexible.processor.SofaTracerIntroductionInterceptor; import com.alipay.sofa.tracer.boot.flexible.processor.SofaTracerMethodInvocationProcessor; -import com.alipay.sofa.tracer.boot.flexible.aop.SofaTracerAdvisingBeanPostProcessor; import io.opentracing.Tracer; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; diff --git a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/kafka/configuration/SofaTracerKafkaAutoConfiguration.java b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/kafka/configuration/SofaTracerKafkaAutoConfiguration.java index 2e98a8036..0e8f4e7f2 100644 --- a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/kafka/configuration/SofaTracerKafkaAutoConfiguration.java +++ b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/kafka/configuration/SofaTracerKafkaAutoConfiguration.java @@ -19,23 +19,15 @@ import com.alipay.sofa.tracer.boot.kafka.processor.KafkaConsumerFactoryPostProcessor; import com.alipay.sofa.tracer.boot.kafka.processor.KafkaProducerFactoryPostProcessor; import com.sofa.alipay.tracer.plugins.kafkamq.aspect.KafkaListenerSofaTracerAspect; -import org.apache.kafka.clients.consumer.KafkaConsumer; -import org.apache.kafka.clients.producer.KafkaProducer; -import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration; -import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; -import org.springframework.context.annotation.Lazy; import org.springframework.kafka.core.ConsumerFactory; -import org.springframework.kafka.core.DefaultKafkaConsumerFactory; -import org.springframework.kafka.core.DefaultKafkaProducerFactory; import org.springframework.kafka.core.ProducerFactory; /** diff --git a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/listener/SofaTracerConfigurationListener.java b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/listener/SofaTracerConfigurationListener.java index 054814569..2719849f9 100644 --- a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/listener/SofaTracerConfigurationListener.java +++ b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/listener/SofaTracerConfigurationListener.java @@ -16,6 +16,9 @@ */ package com.alipay.sofa.tracer.boot.listener; +import com.alipay.common.tracer.core.configuration.SofaTracerConfiguration; +import com.alipay.common.tracer.core.utils.StringUtils; +import com.alipay.sofa.tracer.boot.properties.SofaTracerProperties; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.bind.Bindable; @@ -26,10 +29,6 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; import org.springframework.util.Assert; - -import com.alipay.common.tracer.core.configuration.SofaTracerConfiguration; -import com.alipay.common.tracer.core.utils.StringUtils; -import com.alipay.sofa.tracer.boot.properties.SofaTracerProperties; import org.springframework.util.ClassUtils; /** @@ -81,6 +80,8 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { //stat log interval SofaTracerConfiguration.setProperty(SofaTracerConfiguration.STAT_LOG_INTERVAL, tempTarget.getStatLogInterval()); + SofaTracerConfiguration.setProperty(SofaTracerConfiguration.FILL_MINUTE_SWITCH, + String.valueOf(tempTarget.isFillMinuteSwitch())); //baggage length SofaTracerConfiguration.setProperty( SofaTracerConfiguration.TRACER_PENETRATE_ATTRIBUTE_MAX_LENGTH, diff --git a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/properties/SofaTracerProperties.java b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/properties/SofaTracerProperties.java index 48a9abb7c..2af59f55c 100644 --- a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/properties/SofaTracerProperties.java +++ b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/properties/SofaTracerProperties.java @@ -66,6 +66,11 @@ public class SofaTracerProperties { private String statLogInterval = String .valueOf(SofaTracerStatisticReporterManager.DEFAULT_CYCLE_SECONDS); + /*** + * com.alipay.sofa.tracer.fillMinuteSwitch + */ + private boolean fillMinuteSwitch = false; + /*** * com.alipay.sofa.tracer.baggageMaxLength */ @@ -170,4 +175,22 @@ public boolean isJsonOutput() { public void setJsonOutput(boolean jsonOutput) { this.jsonOutput = jsonOutput; } + + /** + * Getter method for property fillMinuteSwitch. + * + * @return property value of fillMinuteSwitch + */ + public boolean isFillMinuteSwitch() { + return fillMinuteSwitch; + } + + /** + * Setter method for property fillMinuteSwitch. + * + * @param fillMinuteSwitch value to be assigned to property fillMinuteSwitch + */ + public void setFillMinuteSwitch(boolean fillMinuteSwitch) { + this.fillMinuteSwitch = fillMinuteSwitch; + } } \ No newline at end of file diff --git a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/rabbitmq/configuration/SofaTracerRabbitMqConfiguration.java b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/rabbitmq/configuration/SofaTracerRabbitMqConfiguration.java index 29fb3b0ac..895871d0d 100644 --- a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/rabbitmq/configuration/SofaTracerRabbitMqConfiguration.java +++ b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/rabbitmq/configuration/SofaTracerRabbitMqConfiguration.java @@ -18,7 +18,6 @@ import com.alipay.sofa.tracer.boot.rabbitmq.processor.SofaTracerRabbitMqBeanPostProcessor; import com.sofa.alipay.tracer.plugins.rabbitmq.aspect.SofaTracerSendMessageAspect; -import com.sofa.alipay.tracer.plugins.rabbitmq.interceptor.SofaTracerConsumeInterceptor; import org.springframework.amqp.core.Message; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.boot.autoconfigure.AutoConfigureAfter; diff --git a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/rabbitmq/processor/SofaTracerRabbitMqBeanPostProcessor.java b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/rabbitmq/processor/SofaTracerRabbitMqBeanPostProcessor.java index e3bd70412..e69db6322 100644 --- a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/rabbitmq/processor/SofaTracerRabbitMqBeanPostProcessor.java +++ b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/rabbitmq/processor/SofaTracerRabbitMqBeanPostProcessor.java @@ -26,9 +26,7 @@ import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.context.EnvironmentAware; import org.springframework.core.PriorityOrdered; -import org.springframework.core.env.Environment; import org.springframework.util.ReflectionUtils; import java.lang.reflect.Field; diff --git a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/redis/configuration/SofaTracerRedisConfiguration.java b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/redis/configuration/SofaTracerRedisConfiguration.java index 51951a424..365d5e4fa 100644 --- a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/redis/configuration/SofaTracerRedisConfiguration.java +++ b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/redis/configuration/SofaTracerRedisConfiguration.java @@ -19,7 +19,6 @@ import com.alipay.sofa.tracer.boot.configuration.SofaTracerAutoConfiguration; import com.sofa.alipay.tracer.plugins.spring.redis.SofaTracerRCFBeanPostProcessor; import com.sofa.alipay.tracer.plugins.spring.redis.common.RedisActionWrapperHelper; - import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; diff --git a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/springcloud/configuration/SofaTracerFeignClientAutoConfiguration.java b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/springcloud/configuration/SofaTracerFeignClientAutoConfiguration.java index 6e49b6d75..e738eff97 100644 --- a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/springcloud/configuration/SofaTracerFeignClientAutoConfiguration.java +++ b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/springcloud/configuration/SofaTracerFeignClientAutoConfiguration.java @@ -16,6 +16,7 @@ */ package com.alipay.sofa.tracer.boot.springcloud.configuration; +import com.alipay.sofa.tracer.boot.springcloud.processor.SofaTracerFeignContextBeanPostProcessor; import feign.Client; import org.springframework.beans.factory.BeanFactory; import org.springframework.boot.autoconfigure.AutoConfigureBefore; @@ -24,7 +25,6 @@ import org.springframework.cloud.openfeign.FeignAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alipay.sofa.tracer.boot.springcloud.processor.SofaTracerFeignContextBeanPostProcessor; /** * @author: guolei.sgl (guolei.sgl@antfin.com) 2019/3/13 6:04 PM diff --git a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/config/ConfigurationTest.java b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/config/ConfigurationTest.java index 83939f2eb..0e760784d 100644 --- a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/config/ConfigurationTest.java +++ b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/config/ConfigurationTest.java @@ -16,9 +16,10 @@ */ package com.alipay.sofa.tracer.boot.config; -import java.io.File; -import java.util.Map; - +import com.alipay.common.tracer.core.appender.file.TimedRollingFileAppender; +import com.alipay.sofa.tracer.boot.base.ConfigurationHolder; +import com.alipay.sofa.tracer.boot.base.SpringBootWebApplication; +import com.alipay.sofa.tracer.boot.properties.SofaTracerProperties; import org.apache.commons.io.FileUtils; import org.junit.Assert; import org.junit.BeforeClass; @@ -28,10 +29,8 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.alipay.common.tracer.core.appender.file.TimedRollingFileAppender; -import com.alipay.sofa.tracer.boot.base.ConfigurationHolder; -import com.alipay.sofa.tracer.boot.base.SpringBootWebApplication; -import com.alipay.sofa.tracer.boot.properties.SofaTracerProperties; +import java.io.File; +import java.util.Map; /** * @author qilong.zql diff --git a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/flexible/FlexibleTracerTest.java b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/flexible/FlexibleTracerTest.java index 656c7f869..e7ff27eb9 100644 --- a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/flexible/FlexibleTracerTest.java +++ b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/flexible/FlexibleTracerTest.java @@ -31,9 +31,7 @@ import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * @author: guolei.sgl (guolei.sgl@antfin.com) 2019/8/3 10:59 AM diff --git a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/opentracing/profiles/tracer/OpenTracingTest.java b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/opentracing/profiles/tracer/OpenTracingTest.java index 4cb37434b..7eac09159 100644 --- a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/opentracing/profiles/tracer/OpenTracingTest.java +++ b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/opentracing/profiles/tracer/OpenTracingTest.java @@ -29,7 +29,8 @@ import java.util.Map; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * OpenTracingTest diff --git a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/redis/SofaTracerRedisConnectionTest.java b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/redis/SofaTracerRedisConnectionTest.java index 72c11ad99..fa1aaabc9 100644 --- a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/redis/SofaTracerRedisConnectionTest.java +++ b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/redis/SofaTracerRedisConnectionTest.java @@ -23,10 +23,10 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import redis.embedded.RedisServer; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import redis.embedded.RedisServer; import static org.junit.Assert.assertEquals; diff --git a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/springmvc/SpringMvcFilterJsonOutputTest.java b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/springmvc/SpringMvcFilterJsonOutputTest.java index c1df0e504..d9d6c7379 100644 --- a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/springmvc/SpringMvcFilterJsonOutputTest.java +++ b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/springmvc/SpringMvcFilterJsonOutputTest.java @@ -41,7 +41,8 @@ import java.util.List; import java.util.Map; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * SpringMvcFilterTest diff --git a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/springmvc/SpringMvcFilterTest.java b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/springmvc/SpringMvcFilterTest.java index 6a64515d6..1b0947b9e 100644 --- a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/springmvc/SpringMvcFilterTest.java +++ b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/springmvc/SpringMvcFilterTest.java @@ -45,9 +45,7 @@ import java.util.List; import java.util.concurrent.ConcurrentHashMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * SpringMvcFilterTest diff --git a/tracer-test/core-test/pom.xml b/tracer-test/core-test/pom.xml index 1557d4674..db32ddbc3 100644 --- a/tracer-test/core-test/pom.xml +++ b/tracer-test/core-test/pom.xml @@ -4,7 +4,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml diff --git a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/base/AbstractTestBase.java b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/base/AbstractTestBase.java index 39c51d710..9dff4cb6b 100644 --- a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/base/AbstractTestBase.java +++ b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/base/AbstractTestBase.java @@ -32,7 +32,6 @@ import com.alipay.common.tracer.core.span.SofaTracerSpan; import com.alipay.common.tracer.core.utils.StringUtils; import com.alipay.common.tracer.core.utils.TracerUtils; - import com.alipay.common.tracer.test.core.sofatracer.encoder.ClientSpanEncoder; import com.alipay.common.tracer.test.core.sofatracer.encoder.ServerSpanEncoder; import com.alipay.common.tracer.test.core.sofatracer.type.TracerTestLogEnum; diff --git a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerDemoTest.java b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerDemoTest.java index 52b396c9e..87b0979ae 100644 --- a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerDemoTest.java +++ b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerDemoTest.java @@ -18,13 +18,11 @@ import com.alipay.common.tracer.core.context.trace.SofaTraceContext; import com.alipay.common.tracer.core.holder.SofaTraceContextHolder; - import com.alipay.common.tracer.core.span.SofaTracerSpan; import com.alipay.common.tracer.test.TestUtil; import com.alipay.common.tracer.test.base.AbstractTestBase; import com.alipay.common.tracer.test.core.sofatracer.type.TracerTestLogEnum; import org.apache.commons.io.FileUtils; - import org.junit.Before; import org.junit.Test; diff --git a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerStatisticsDemoTest.java b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerStatisticsDemoTest.java index 33834159d..f1cb6a05b 100644 --- a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerStatisticsDemoTest.java +++ b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerStatisticsDemoTest.java @@ -29,6 +29,7 @@ import java.io.File; import java.util.List; + import static org.junit.Assert.*; /** diff --git a/tracer-test/log4j-test/pom.xml b/tracer-test/log4j-test/pom.xml index 6f737d7fa..01883cf59 100644 --- a/tracer-test/log4j-test/pom.xml +++ b/tracer-test/log4j-test/pom.xml @@ -4,7 +4,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml diff --git a/tracer-test/log4j2-test/pom.xml b/tracer-test/log4j2-test/pom.xml index 870e56542..4caa3a67f 100644 --- a/tracer-test/log4j2-test/pom.xml +++ b/tracer-test/log4j2-test/pom.xml @@ -4,7 +4,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml diff --git a/tracer-test/logback-test/pom.xml b/tracer-test/logback-test/pom.xml index 42b407f5e..c0f883e9f 100644 --- a/tracer-test/logback-test/pom.xml +++ b/tracer-test/logback-test/pom.xml @@ -4,7 +4,7 @@ tracer-all-parent com.alipay.sofa - 3.1.0 + 3.1.1 ../../pom.xml