generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
16140: manually populate poison queue when a step encounters an error (…
…#16258) * 16140: manually populate poison queue when a step encounters an error * fixup! 16140: manually populate poison queue when a step encounters an error
- Loading branch information
Showing
17 changed files
with
183 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
119 changes: 119 additions & 0 deletions
119
prime-router/src/test/kotlin/azure/FHIRFunctionsTests.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package gov.cdc.prime.router.azure | ||
|
||
import gov.cdc.prime.reportstream.shared.QueueMessage | ||
import gov.cdc.prime.router.FileSettings | ||
import gov.cdc.prime.router.azure.db.enums.TaskAction | ||
import gov.cdc.prime.router.azure.db.tables.pojos.ReportFile | ||
import gov.cdc.prime.router.azure.observability.event.IReportStreamEventService | ||
import gov.cdc.prime.router.azure.observability.event.ReportStreamEventName | ||
import gov.cdc.prime.router.azure.observability.event.ReportStreamReportProcessingErrorEventBuilder | ||
import gov.cdc.prime.router.common.UniversalPipelineTestUtils | ||
import gov.cdc.prime.router.common.UniversalPipelineTestUtils.createFHIRFunctionsInstance | ||
import gov.cdc.prime.router.fhirengine.azure.FHIRFunctions | ||
import gov.cdc.prime.router.fhirengine.engine.FHIRConverter | ||
import gov.cdc.prime.router.metadata.LookupTable | ||
import gov.cdc.prime.router.unittest.UnitTestUtils | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.mockkConstructor | ||
import io.mockk.mockkObject | ||
import io.mockk.slot | ||
import io.mockk.spyk | ||
import io.mockk.verify | ||
import org.jooq.exception.DataAccessException | ||
import org.jooq.tools.jdbc.MockConnection | ||
import org.jooq.tools.jdbc.MockDataProvider | ||
import org.jooq.tools.jdbc.MockResult | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import java.util.UUID | ||
|
||
class FHIRFunctionsTests { | ||
|
||
val queueMessage = """ | ||
{ | ||
"type": "convert", | ||
"reportId": "${UUID.randomUUID()}", | ||
"blobURL": "", | ||
"digest": "", | ||
"blobSubFolderName": "ignore.full-elr", | ||
"topic": "full-elr", | ||
"schemaName": "" | ||
} | ||
""" | ||
|
||
@BeforeEach | ||
fun beforeEach() { | ||
mockkObject(QueueAccess) | ||
every { QueueAccess.sendMessage(any(), any()) } returns "poison-123" | ||
mockkObject(BlobAccess) | ||
mockkConstructor(DatabaseLookupTableAccess::class) | ||
} | ||
|
||
private fun createFHIRFunctionsInstance(): FHIRFunctions { | ||
val settings = FileSettings().loadOrganizations(UniversalPipelineTestUtils.universalPipelineOrganization) | ||
val metadata = UnitTestUtils.simpleMetadata | ||
metadata.lookupTableStore += mapOf( | ||
"observation-mapping" to LookupTable("observation-mapping", emptyList()) | ||
) | ||
val dataProvider = MockDataProvider { emptyArray<MockResult>() } | ||
val connection = MockConnection(dataProvider) | ||
val accessSpy = spyk(DatabaseAccess(connection)) | ||
val workflowEngine = WorkflowEngine.Builder() | ||
.metadata(metadata) | ||
.settingsProvider(settings) | ||
.databaseAccess(accessSpy) | ||
.build() | ||
every { accessSpy.fetchReportFile(any()) } returns mockk<ReportFile>(relaxed = true) | ||
return FHIRFunctions(workflowEngine, databaseAccess = accessSpy) | ||
} | ||
|
||
@Test | ||
fun `test should add to the poison queue and catch an unexpected exception`() { | ||
val fhirFunctions = createFHIRFunctionsInstance() | ||
|
||
val mockReportEventService = mockk<IReportStreamEventService>(relaxed = true) | ||
val init = slot<ReportStreamReportProcessingErrorEventBuilder.() -> Unit>() | ||
every { | ||
mockReportEventService.sendReportProcessingError(any(), any<ReportFile>(), any(), any(), capture(init)) | ||
} returns Unit | ||
val mockFHIRConverter = mockk<FHIRConverter>(relaxed = true) | ||
every { mockFHIRConverter.run(any(), any(), any(), any()) } throws RuntimeException("Error") | ||
every { mockFHIRConverter.reportEventService } returns mockReportEventService | ||
every { mockFHIRConverter.taskAction } returns TaskAction.convert | ||
fhirFunctions.process(queueMessage, 1, mockFHIRConverter, ActionHistory(TaskAction.convert)) | ||
|
||
verify(exactly = 1) { | ||
QueueAccess.sendMessage( | ||
"${QueueMessage.elrConvertQueueName}-poison", | ||
queueMessage | ||
) | ||
mockReportEventService.sendReportProcessingError( | ||
ReportStreamEventName.PIPELINE_EXCEPTION, | ||
any<ReportFile>(), | ||
TaskAction.convert, | ||
"Error", | ||
init.captured | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun `test should not add to the poison queue and throw a data access exception`() { | ||
val fhirFunctions = createFHIRFunctionsInstance() | ||
|
||
val mockFHIRConverter = mockk<FHIRConverter>(relaxed = true) | ||
every { mockFHIRConverter.run(any(), any(), any(), any()) } throws DataAccessException("Error") | ||
assertThrows<DataAccessException> { | ||
fhirFunctions.process(queueMessage, 1, mockFHIRConverter, ActionHistory(TaskAction.convert)) | ||
} | ||
|
||
verify(exactly = 0) { | ||
QueueAccess.sendMessage( | ||
"${QueueMessage.elrConvertQueueName}-poison", | ||
queueMessage | ||
) | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.