@@ -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