Skip to content

Commit 82e28bf

Browse files
author
Marius Posta
authored
java-cdk: fix LoggingInvocationInterceptor for dynamic tests (#38073)
1 parent b421453 commit 82e28bf

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

airbyte-cdk/java/airbyte-cdk/core/src/testFixtures/kotlin/io/airbyte/cdk/extensions/LoggingInvocationInterceptor.kt

+17-11
Original file line numberDiff line numberDiff line change
@@ -36,39 +36,45 @@ class LoggingInvocationInterceptor : InvocationInterceptor {
3636
private class LoggingInvocationInterceptorHandler : InvocationHandler {
3737
@Throws(Throwable::class)
3838
override fun invoke(proxy: Any, method: Method, args: Array<Any>): Any? {
39-
if (
39+
val methodName = method.name
40+
val invocationContextClass: Class<*> =
41+
when (methodName) {
42+
"interceptDynamicTest" -> DynamicTestInvocationContext::class.java
43+
else -> ReflectiveInvocationContext::class.java
44+
}
45+
try {
4046
LoggingInvocationInterceptor::class
4147
.java
4248
.getDeclaredMethod(
4349
method.name,
4450
InvocationInterceptor.Invocation::class.java,
45-
ReflectiveInvocationContext::class.java,
51+
invocationContextClass,
4652
ExtensionContext::class.java
47-
) == null
48-
) {
53+
)
54+
} catch (_: NoSuchMethodException) {
4955
LOGGER.error(
5056
"Junit LoggingInvocationInterceptor executing unknown interception point {}",
5157
method.name
5258
)
5359
return method.invoke(proxy, *(args))
5460
}
5561
val invocation = args[0] as InvocationInterceptor.Invocation<*>?
56-
val invocationContext = args[1] as ReflectiveInvocationContext<*>
62+
val reflectiveInvocationContext = args[1] as? ReflectiveInvocationContext<*>
5763
val extensionContext = args[2] as ExtensionContext?
58-
val methodName = method.name
5964
val logLineSuffix: String
6065
val methodMatcher = methodPattern.matcher(methodName)
6166
if (methodName == "interceptDynamicTest") {
6267
logLineSuffix =
6368
"execution of DynamicTest %s".formatted(extensionContext!!.displayName)
6469
} else if (methodName == "interceptTestClassConstructor") {
6570
logLineSuffix =
66-
"instance creation for %s".formatted(invocationContext!!.targetClass)
71+
"instance creation for %s".formatted(reflectiveInvocationContext!!.targetClass)
6772
} else if (methodMatcher.matches()) {
6873
val interceptedEvent = methodMatcher.group(1)
69-
val methodRealClassName = invocationContext!!.executable!!.declaringClass.simpleName
70-
val methodName = invocationContext.executable!!.name
71-
val targetClassName = invocationContext!!.targetClass.simpleName
74+
val methodRealClassName =
75+
reflectiveInvocationContext!!.executable!!.declaringClass.simpleName
76+
val methodName = reflectiveInvocationContext.executable!!.name
77+
val targetClassName = reflectiveInvocationContext.targetClass.simpleName
7278
val methodDisplayName =
7379
if (targetClassName == methodRealClassName) methodName
7480
else "$methodName($methodRealClassName)"
@@ -86,7 +92,7 @@ class LoggingInvocationInterceptor : InvocationInterceptor {
8692
val timeoutTask = TimeoutInteruptor(currentThread)
8793
val start = Instant.now()
8894
try {
89-
val timeout = getTimeout(invocationContext)
95+
val timeout = reflectiveInvocationContext?.let(::getTimeout)
9096
if (timeout != null) {
9197
LOGGER.info(
9298
"Junit starting {} with timeout of {}",

0 commit comments

Comments
 (0)