test: add Kotlin verification smoke test#3513
Open
hej090224 wants to merge 1 commit into
Open
Conversation
Adds a Maven-compiled Kotlin test source set to operator-framework-core and a smoke test verifying that a checked (non-RuntimeException) Exception thrown from a Kotlin DependentResource is properly caught and reported by the workflow executor, so that retries are triggered as expected. Kotlin does not have checked exceptions, so Kotlin code can throw a checked Exception from an overridden method without declaring it, even though the Java DependentResource#reconcile signature does not declare `throws Exception`. Before operator-framework#2965 this exception would not have been caught by NodeExecutor, since it only handled RuntimeException, silently swallowing the error and preventing retries. Closes operator-framework#2967
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Kotlin-based test coverage to ensure the workflow executor correctly captures non-RuntimeException failures thrown from Kotlin-implemented DependentResources, preventing silent bypass of retry/error aggregation logic.
Changes:
- Introduces a Kotlin smoke test that throws a checked
ExceptionfromDependentResource.reconcileand asserts it is surfaced viaerroredDependentsand aggregated exceptions. - Updates
operator-framework-corebuild to compilesrc/test/kotlinviakotlin-maven-pluginand adds Kotlin stdlib as a test-scoped dependency.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| operator-framework-core/src/test/kotlin/io/javaoperatorsdk/operator/processing/dependent/workflow/KotlinCheckedExceptionDependentResourceTest.kt | Adds Kotlin smoke test validating workflow error capture/aggregation for checked exceptions thrown from Kotlin dependents |
| operator-framework-core/pom.xml | Adds Kotlin test compilation support and Kotlin stdlib dependency (test scope) to enable the new Kotlin test |
Comment on lines
+72
to
+87
| `when`(context.managedWorkflowAndDependentResourceContext()) | ||
| .thenReturn(mock(ManagedWorkflowAndDependentResourceContext::class.java)) | ||
| `when`(context.workflowExecutorService).thenReturn(Executors.newCachedThreadPool()) | ||
| @Suppress("UNCHECKED_CAST") | ||
| `when`(context.eventSourceRetriever()) | ||
| .thenReturn(mock(EventSourceRetriever::class.java) as EventSourceRetriever<TestCustomResource>) | ||
|
|
||
| val result = workflow.reconcile(TestCustomResource(), context) | ||
|
|
||
| // the checked exception was caught by the workflow executor, not left uncaught, so it is | ||
| // reported as an error for the dependent resource, which is what allows JOSDK to retry the | ||
| // reconciliation. | ||
| assertThat(result.erroredDependents).containsOnlyKeys(dependentResource) | ||
| assertThat(result.erroredDependents[dependentResource]).isInstanceOf(CheckedException::class.java) | ||
| assertThrows<AggregatedOperatorException> { result.throwAggregateExceptionIfErrorsPresent() } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2967
What this does
Adds a Kotlin-based smoke test to
operator-framework-coreverifying that JOSDK behaves correctly when aDependentResourceis implemented in Kotlin.Kotlin has no concept of checked vs. unchecked exceptions, so Kotlin code can throw a plain
Exceptionfrom an overridden method (e.g.DependentResource#reconcile) without declaring it — even though the Java-declared method signature doesn't includethrows Exception. Before #2965,NodeExecutoronly caughtRuntimeException, so such an exception thrown from Kotlin would silently bypass the workflow's error handling and not trigger a retry.The new test (
KotlinCheckedExceptionDependentResourceTest.kt):DependentResourcewhosereconcilethrows a custom checkedException.Workflow/WorkflowReconcileExecutor/NodeExecutor(no mocked cluster needed).WorkflowReconcileResult#getErroredDependents()and thatthrowAggregateExceptionIfErrorsPresent()throwsAggregatedOperatorException, confirming a retry would be triggered.I verified this test actually exercises the fix: temporarily reverting
NodeExecutor'scatch (Exception e)back tocatch (RuntimeException e)(the pre-#2965 behavior) makes the test fail, since the checked exception is then silently swallowed andgetErroredDependents()stays empty.Build changes
kotlin-maven-plugin(test scope only,2.4.10) tooperator-framework-core/pom.xml, compiling sources undersrc/test/kotlin. No other module is affected, and no Kotlin dependency is added to the main/runtime classpath.Relation to #2965
#2965 fixed
NodeExecutor,AbstractWorkflowExecutor, andPollingEventSourceto catchExceptioninstead ofRuntimeException(with// Exception is required because of Kotlincomments already in place), and opened #2967 as a follow-up to add tests validating this behavior with actual Kotlin code. I also grepped the codebase for any remainingcatch (RuntimeExceptionin main sources and found none left to fix.I scoped this PR to a unit-test-level smoke test (no real Kubernetes cluster required) so it's fast and fully verifiable in CI; a full Kotlin-based
*IT.java-style integration test againstLocallyRunOperatorExtensioncould be a good follow-up if maintainers want broader coverage.Test plan
./mvnw -pl operator-framework-core -am test— 646 tests passcatch (RuntimeException)behavior, and passes against currentcatch (Exception)behavior