From 553ea49b4991e5f19008c380fcdd01e77f937f7d Mon Sep 17 00:00:00 2001 From: Stephane Geneix Date: Wed, 21 Feb 2024 09:15:06 -0800 Subject: [PATCH] fix junit test error logging --- .../LoggingInvocationInterceptor.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/airbyte-cdk/java/airbyte-cdk/core/src/testFixtures/java/io/airbyte/cdk/extensions/LoggingInvocationInterceptor.java b/airbyte-cdk/java/airbyte-cdk/core/src/testFixtures/java/io/airbyte/cdk/extensions/LoggingInvocationInterceptor.java index 6ccaf15a1255..8957a5928d83 100644 --- a/airbyte-cdk/java/airbyte-cdk/core/src/testFixtures/java/io/airbyte/cdk/extensions/LoggingInvocationInterceptor.java +++ b/airbyte-cdk/java/airbyte-cdk/core/src/testFixtures/java/io/airbyte/cdk/extensions/LoggingInvocationInterceptor.java @@ -10,10 +10,11 @@ import java.lang.reflect.Proxy; import java.time.Duration; import java.time.Instant; -import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.junit.jupiter.api.extension.DynamicTestInvocationContext; import org.junit.jupiter.api.extension.ExtensionContext; @@ -71,8 +72,21 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl LOGGER.info("Junit completed {} in {} ms", logLineSuffix, elapsedMs); return retVal; } catch (Throwable t) { - String stackTrace = Arrays.stream(ExceptionUtils.getStackFrames(t)).takeWhile(s -> !s.startsWith("\tat org.junit")).collect( - Collectors.joining("\n ")); + boolean belowCurrentCall = false; + List stackToDisplay = new LinkedList(); + for (String stackString : ExceptionUtils.getStackFrames(t)) { + if (stackString.startsWith("\tat ")) { + if (!belowCurrentCall && stackString.contains(LoggingInvocationInterceptor.class.getCanonicalName())) { + belowCurrentCall = true; + } + } else { + belowCurrentCall = false; + } + if (!belowCurrentCall) { + stackToDisplay.add(stackString); + } + } + String stackTrace = StringUtils.join(stackToDisplay, "\n "); LOGGER.warn("Junit exception throw during {}:\n{}", logLineSuffix, stackTrace); throw t; }