Skip to content

Commit

Permalink
Merge pull request #16257 from CDCgov/refactor/azure_event_service
Browse files Browse the repository at this point in the history
unifying local and in memory azure event service classes into one
  • Loading branch information
kant777 authored Oct 21, 2024
2 parents 1956fe0 + 8eef145 commit b96d657
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,22 @@ class AzureEventServiceImpl(
}
}

// TODO: https://github.com/CDCgov/prime-reportstream/issues/15337
/**
* Local storage of azure events (only used for testing)
*/
class LocalAzureEventServiceImpl(
val events: MutableList<AzureCustomEvent> = mutableListOf(),
val reportStreamEvents: MutableMap<ReportStreamEventName, MutableList<AzureCustomEvent>> = mutableMapOf(),
) : AzureEventService, Logging {
class InMemoryAzureEventService : AzureEventService, Logging {

val events: MutableList<AzureCustomEvent> = mutableListOf()
val reportStreamEvents = mutableMapOf<ReportStreamEventName, MutableList<AzureCustomEvent>>()

/**
* Send event to Azure AppInsights using the Azure TelemetryClient
*/
override fun trackEvent(event: AzureCustomEvent) {
val name = event.javaClass.simpleName
logger.debug("Recording'$name' event in memory.")
logger.debug("Recording '$name' event in memory.")
events.add(event)
}

override fun trackEvent(eventName: ReportStreamEventName, event: AzureCustomEvent) {
logger.debug("Recording '$eventName' event in memory.")
reportStreamEvents.getOrPut(eventName) {
mutableListOf()
mutableListOf()
}.add(event)
events.add(event)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ReportEventServiceTest {

val reportEventService = ReportStreamEventService(
ReportStreamTestDatabaseContainer.testDatabaseAccess,
LocalAzureEventServiceImpl(),
InMemoryAzureEventService(),
ReportService(
ReportGraph(ReportStreamTestDatabaseContainer.testDatabaseAccess),
ReportStreamTestDatabaseContainer.testDatabaseAccess
Expand Down Expand Up @@ -115,7 +115,7 @@ class ReportEventServiceTest {

val reportEventService = ReportStreamEventService(
ReportStreamTestDatabaseContainer.testDatabaseAccess,
LocalAzureEventServiceImpl(),
InMemoryAzureEventService(),
ReportService(
ReportGraph(ReportStreamTestDatabaseContainer.testDatabaseAccess),
ReportStreamTestDatabaseContainer.testDatabaseAccess
Expand Down Expand Up @@ -193,7 +193,7 @@ class ReportEventServiceTest {

val reportEventService = ReportStreamEventService(
ReportStreamTestDatabaseContainer.testDatabaseAccess,
LocalAzureEventServiceImpl(),
InMemoryAzureEventService(),
ReportService(
ReportGraph(ReportStreamTestDatabaseContainer.testDatabaseAccess),
ReportStreamTestDatabaseContainer.testDatabaseAccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import gov.cdc.prime.router.azure.db.tables.pojos.Action
import gov.cdc.prime.router.azure.db.tables.pojos.ReportFile
import gov.cdc.prime.router.azure.observability.bundleDigest.BundleDigestLabResult
import gov.cdc.prime.router.azure.observability.event.AzureEventUtils
import gov.cdc.prime.router.azure.observability.event.InMemoryAzureEventService
import gov.cdc.prime.router.azure.observability.event.ItemEventData
import gov.cdc.prime.router.azure.observability.event.LocalAzureEventServiceImpl
import gov.cdc.prime.router.azure.observability.event.ReportEventData
import gov.cdc.prime.router.azure.observability.event.ReportStreamEventName
import gov.cdc.prime.router.azure.observability.event.ReportStreamEventProperties
Expand Down Expand Up @@ -100,7 +100,7 @@ class FHIRConverterIntegrationTests {
)
)

val azureEventService = LocalAzureEventServiceImpl()
val azureEventService = InMemoryAzureEventService()

private fun createFHIRFunctionsInstance(): FHIRFunctions {
val settings = FileSettings().loadOrganizations(universalPipelineOrganization)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import gov.cdc.prime.router.azure.db.enums.TaskAction
import gov.cdc.prime.router.azure.observability.bundleDigest.BundleDigestLabResult
import gov.cdc.prime.router.azure.observability.event.AzureEventService
import gov.cdc.prime.router.azure.observability.event.AzureEventUtils
import gov.cdc.prime.router.azure.observability.event.InMemoryAzureEventService
import gov.cdc.prime.router.azure.observability.event.ItemEventData
import gov.cdc.prime.router.azure.observability.event.LocalAzureEventServiceImpl
import gov.cdc.prime.router.azure.observability.event.ReportEventData
import gov.cdc.prime.router.azure.observability.event.ReportStreamEventName
import gov.cdc.prime.router.azure.observability.event.ReportStreamEventProperties
Expand Down Expand Up @@ -84,7 +84,7 @@ class FHIRDestinationFilterIntegrationTests : Logging {
)
)

val azureEventsService = LocalAzureEventServiceImpl()
val azureEventsService = InMemoryAzureEventService()

@BeforeEach
fun beforeEach() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import gov.cdc.prime.router.azure.db.enums.TaskAction
import gov.cdc.prime.router.azure.observability.bundleDigest.BundleDigestLabResult
import gov.cdc.prime.router.azure.observability.event.AzureEventService
import gov.cdc.prime.router.azure.observability.event.AzureEventUtils
import gov.cdc.prime.router.azure.observability.event.InMemoryAzureEventService
import gov.cdc.prime.router.azure.observability.event.ItemEventData
import gov.cdc.prime.router.azure.observability.event.LocalAzureEventServiceImpl
import gov.cdc.prime.router.azure.observability.event.ReportEventData
import gov.cdc.prime.router.azure.observability.event.ReportStreamEventName
import gov.cdc.prime.router.azure.observability.event.ReportStreamEventProperties
Expand Down Expand Up @@ -174,7 +174,7 @@ class FHIRReceiverFilterIntegrationTests : Logging {
)
)

val azureEventService = LocalAzureEventServiceImpl()
val azureEventService = InMemoryAzureEventService()

@BeforeEach
fun beforeEach() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import gov.cdc.prime.router.azure.db.Tables
import gov.cdc.prime.router.azure.db.enums.ActionLogType
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.LocalAzureEventServiceImpl
import gov.cdc.prime.router.azure.observability.event.InMemoryAzureEventService
import gov.cdc.prime.router.azure.observability.event.ReportEventData
import gov.cdc.prime.router.azure.observability.event.ReportStreamEventName
import gov.cdc.prime.router.azure.observability.event.ReportStreamEventProperties
Expand Down Expand Up @@ -71,7 +71,7 @@ class FHIRReceiverIntegrationTests {
)
)

private val azureEventService = LocalAzureEventServiceImpl()
private val azureEventService = InMemoryAzureEventService()
private lateinit var submissionTableService: SubmissionTableService

private fun createFHIRFunctionsInstance(): FHIRFunctions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import gov.cdc.prime.router.azure.QueueAccess
import gov.cdc.prime.router.azure.db.enums.TaskAction
import gov.cdc.prime.router.azure.db.tables.Task
import gov.cdc.prime.router.azure.observability.event.AzureEventService
import gov.cdc.prime.router.azure.observability.event.LocalAzureEventServiceImpl
import gov.cdc.prime.router.azure.observability.event.InMemoryAzureEventService
import gov.cdc.prime.router.cli.tests.CompareData
import gov.cdc.prime.router.common.TestcontainersUtils
import gov.cdc.prime.router.common.UniversalPipelineTestUtils
Expand Down Expand Up @@ -65,7 +65,7 @@ class FHIRTranslatorIntegrationTests : Logging {
)
)

val azureEventService = LocalAzureEventServiceImpl()
val azureEventService = InMemoryAzureEventService()

@BeforeEach
fun beforeEach() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class FhirDestinationFilterTests {
actionHistory.reportsIn.clear()
actionHistory.reportsOut.clear()
actionHistory.actionLogs.clear()
azureEventService.clear()
azureEventService.events.clear()
clearAllMocks()
}

Expand Down Expand Up @@ -325,7 +325,7 @@ class FhirDestinationFilterTests {
assertThat(actionHistory.reportsIn).hasSize(1)
assertThat(actionHistory.reportsOut).hasSize(1)

val azureEvents = azureEventService.getEvents()
val azureEvents = azureEventService.events

assertThat(azureEvents).hasSize(1)
assertThat(azureEvents.first())
Expand Down Expand Up @@ -491,7 +491,7 @@ class FhirDestinationFilterTests {
assertThat(actionHistory.reportsIn).hasSize(1)
assertThat(actionHistory.reportsOut).hasSize(1)

val azureEvents = azureEventService.getEvents()
val azureEvents = azureEventService.events
assertThat(azureEvents).hasSize(1)
assertThat(azureEvents.first())
.isInstanceOf(ReportStreamItemEvent::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class FhirReceiverFilterTests {
actionHistory.reportsOut.clear()
actionHistory.reportsReceived.clear()
actionHistory.actionLogs.clear()
azureEventService.clear()
azureEventService.events.clear()
mockkObject(BlobAccess)
clearAllMocks()
}
Expand Down Expand Up @@ -225,7 +225,7 @@ class FhirReceiverFilterTests {
}

// assert
azureEventService.getEvents().forEach { event ->
azureEventService.events.forEach { event ->
assertThat(event)
.isInstanceOf<ReportStreamItemEvent>()
.matchesPredicate {
Expand Down Expand Up @@ -284,7 +284,7 @@ class FhirReceiverFilterTests {
}
}

azureEventService.getEvents().forEach { event ->
azureEventService.events.forEach { event ->
assertThat(event)
.isInstanceOf<ReportStreamItemEvent>()
.matchesPredicate {
Expand Down Expand Up @@ -346,7 +346,7 @@ class FhirReceiverFilterTests {
}

// assert
azureEventService.getEvents().forEach { event ->
azureEventService.events.forEach { event ->
assertThat(event)
.isInstanceOf<ReportStreamItemEvent>()
.matchesPredicate {
Expand Down Expand Up @@ -408,7 +408,7 @@ class FhirReceiverFilterTests {
}

// assert
azureEventService.getEvents().forEach { event ->
azureEventService.events.forEach { event ->
assertThat(event)
.isInstanceOf<ReportStreamItemEvent>()
.matchesPredicate {
Expand Down Expand Up @@ -463,7 +463,7 @@ class FhirReceiverFilterTests {
val messages = engine.run(message, actionLogger, actionHistory, txn)
assertThat(messages).isEmpty()

azureEventService.getEvents().forEach { event ->
azureEventService.events.forEach { event ->
assertThat(event)
.isInstanceOf<ReportStreamItemEvent>()
.matchesPredicate {
Expand Down Expand Up @@ -706,7 +706,7 @@ class FhirReceiverFilterTests {
assertThat(actionHistory.reportsIn).hasSize(1)
assertThat(actionHistory.reportsOut).hasSize(1)

val actualEvents = azureEventService.getEvents()
val actualEvents = azureEventService.events
assertThat(actualEvents).hasSize(0)
}

Expand Down Expand Up @@ -798,7 +798,7 @@ class FhirReceiverFilterTests {
val messages = engine.run(message, actionLogger, actionHistory, txn)
assertThat(messages).isEmpty()

azureEventService.getEvents().forEach { event ->
azureEventService.events.forEach { event ->
assertThat(event)
.isInstanceOf<ReportStreamItemEvent>()
.matchesPredicate {
Expand Down Expand Up @@ -871,7 +871,7 @@ class FhirReceiverFilterTests {
}

// assert
azureEventService.getEvents().forEach { event ->
azureEventService.events.forEach { event ->
assertThat(event)
.isInstanceOf<ReportStreamItemEvent>()
.matchesPredicate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data class Submission(
val bodyURL: String,
@JsonIgnore
val detail: String? = null,
val timestamp: OffsetDateTime? = null
val timestamp: OffsetDateTime? = null,
) {
companion object {
/**
Expand Down

0 comments on commit b96d657

Please sign in to comment.