Skip to content

Commit 65dc96f

Browse files
hej090224Copilot
andauthored
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 9118afd commit 65dc96f

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

operator-framework-core/src/test/kotlin/io/javaoperatorsdk/operator/processing/dependent/workflow/KotlinCheckedExceptionDependentResourceTest.kt

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,25 @@ class KotlinCheckedExceptionDependentResourceTest {
6969

7070
@Suppress("UNCHECKED_CAST")
7171
val context = mock(Context::class.java) as Context<TestCustomResource>
72-
`when`(context.managedWorkflowAndDependentResourceContext())
73-
.thenReturn(mock(ManagedWorkflowAndDependentResourceContext::class.java))
74-
`when`(context.workflowExecutorService).thenReturn(Executors.newCachedThreadPool())
75-
@Suppress("UNCHECKED_CAST")
76-
`when`(context.eventSourceRetriever())
77-
.thenReturn(mock(EventSourceRetriever::class.java) as EventSourceRetriever<TestCustomResource>)
72+
val executorService = Executors.newSingleThreadExecutor()
73+
try {
74+
`when`(context.managedWorkflowAndDependentResourceContext())
75+
.thenReturn(mock(ManagedWorkflowAndDependentResourceContext::class.java))
76+
`when`(context.workflowExecutorService).thenReturn(executorService)
77+
@Suppress("UNCHECKED_CAST")
78+
`when`(context.eventSourceRetriever())
79+
.thenReturn(mock(EventSourceRetriever::class.java) as EventSourceRetriever<TestCustomResource>)
7880

79-
val result = workflow.reconcile(TestCustomResource(), context)
81+
val result = workflow.reconcile(TestCustomResource(), context)
8082

81-
// the checked exception was caught by the workflow executor, not left uncaught, so it is
82-
// reported as an error for the dependent resource, which is what allows JOSDK to retry the
83-
// reconciliation.
84-
assertThat(result.erroredDependents).containsOnlyKeys(dependentResource)
85-
assertThat(result.erroredDependents[dependentResource]).isInstanceOf(CheckedException::class.java)
86-
assertThrows<AggregatedOperatorException> { result.throwAggregateExceptionIfErrorsPresent() }
87-
}
83+
// the checked exception was caught by the workflow executor, not left uncaught, so it is
84+
// reported as an error for the dependent resource, which is what allows JOSDK to retry the
85+
// reconciliation.
86+
assertThat(result.erroredDependents).containsOnlyKeys(dependentResource)
87+
assertThat(result.erroredDependents[dependentResource])
88+
.isInstanceOf(CheckedException::class.java)
89+
assertThrows<AggregatedOperatorException> { result.throwAggregateExceptionIfErrorsPresent() }
90+
} finally {
91+
executorService.shutdownNow()
92+
}
8893
}

0 commit comments

Comments
 (0)