Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refacto csr logic to context source caller #1311

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

thomasBousselin
Copy link
Contributor

No description provided.

@thomasBousselin thomasBousselin self-assigned this Jan 9, 2025
@thomasBousselin thomasBousselin linked an issue Jan 9, 2025 that may be closed by this pull request
@thomasBousselin thomasBousselin force-pushed the refacto/migrate-csr-logic branch from 7428f65 to 975dcc6 Compare January 10, 2025 12:42
Copy link
Contributor

github-actions bot commented Jan 10, 2025

Test Results

   70 files  ±0     70 suites  ±0   1m 24s ⏱️ -2s
1 140 tests +2  1 140 ✅ +2  0 💤 ±0  0 ❌ ±0 
1 179 runs  +2  1 179 ✅ +2  0 💤 ±0  0 ❌ ±0 

Results for commit 3ba9204. ± Comparison against base commit a6b8b37.

This pull request removes 193 and adds 41 tests. Note that renamed tests count towards both.
                           …, withTemporalValues=true, withAudit=false, expectation={
                      "@id": "https://uri…
                      "@type": "@json",
                      …
                    "@value": "/A/B"
                    "@value": "/C/D"
                    "@value": 20
                    "…
                    {
                  "@type": "https://uri.etsi.org/ngsi-ld/DateTime",
…
com.egm.stellio.search.csr.service.ContextSourceCallerTests ‑ queryEntities ContextSource should return a RevalidationFailedWarning when receiving bad payload()
com.egm.stellio.search.csr.service.ContextSourceCallerTests ‑ queryEntitiesFromAllSources should return the warnings sent by the CSRs and update the statuses()
com.egm.stellio.search.csr.service.ContextSourceCallerTests ‑ queryEntitiesFromContextSource should return the count and the entities when the request succeed()
com.egm.stellio.search.csr.service.ContextSourceCallerTests ‑ retrieveEntityContextSource should return a RevalidationFailedWarning when receiving bad payload()
com.egm.stellio.search.csr.service.ContextSourceCallerTests ‑ retrieveEntityFromAllSources should return the warnings sent by the CSRs and update the statuses()
com.egm.stellio.search.csr.service.ContextSourceCallerTests ‑ retrieveEntityFromContextSource should return the entity when the request succeeds()
com.egm.stellio.search.entity.util.PatchAttributeTests ‑ [1] source={
    "attribute": {
        "type": "Property",
        "value": 12.0,
        "observedAt": "2024-04-14T12:34:56Z"
    }
}, target={
    "attribute": {
        "type": "Property",
        "value": 12.2,
        "unitCode": "GRM"
    }
}, expected={
    "attribute": {
        "type": "Property",
        "value": 12.2,
        "unitCode": "GRM",
        "observedAt": "2024-04-14T12:34:56Z"
    }
}
com.egm.stellio.search.entity.util.PatchAttributeTests ‑ [1] source={
    "attribute": {
        "type": "Property",
        "value": 12.0,
        "observedAt": "2024-04-14T12:34:56Z",
        "subAttribute": {
            "type": "Property",
            "value": "subAttribute"
        }
    }
}, target={
    "attribute": {
        "type": "Property",
        "value": 12.2,
        "unitCode": "GRM",
        "subAttribute": {
            "type": "Property",
            "value": "newSubAttributeValue"
        }
    }
}, expected={
    "attribute": {
        "type": "Property",
        "value": 12.2,
        "unitCode": "GRM",
        "observedAt": "2024-04-14T12:34:56Z",
        "subAttribute": {
            "type": "Property",
            "value": "newSubAttributeValue"
        }
    }
}
com.egm.stellio.search.entity.util.PatchAttributeTests ‑ [2] source={
    "attribute": {
        "type": "Property",
        "value": { "en": "car", "fr": "voiture" }
    }
}, target={
    "attribute": {
        "type": "Property",
        "value": { "fr": "vélo", "es": "bicicleta" }
    }
}, expected={
    "attribute": {
        "type": "Property",
        "value": { "en": "car", "fr": "vélo", "es": "bicicleta" }
    }
}
com.egm.stellio.search.entity.util.PatchAttributeTests ‑ [2] source={
    "incoming": {
        "type": "JsonProperty",
        "json": { "id": 1, "b": null, "c": 12.4 },
        "observedAt": "2022-12-24T14:01:22.066Z",
        "subAttribute": {
            "type": "Property",
            "value": "subAttribute"
        }
    }
}, target={
    "incoming": {
        "type": "JsonProperty",
        "json": { "id": 2, "b": "something" },
        "observedAt": "2023-12-24T14:01:22.066Z"
    }
}, expected={
    "incoming": {
        "type": "JsonProperty",
        "json": { "id": 2, "b": "something" },
        "observedAt": "2023-12-24T14:01:22.066Z",
        "subAttribute": {
            "type": "Property",
            "value": "subAttribute"
        }
    }
}
…

♻️ This comment has been updated with latest results.

@thomasBousselin thomasBousselin marked this pull request as ready for review January 10, 2025 12:51
@bobeal
Copy link
Member

bobeal commented Jan 10, 2025

please write "refactor", it's only one more letter and it is a real word

@@ -30,10 +36,48 @@ import java.net.URI

typealias QueryEntitiesResponse = Pair<List<CompactedEntity>, Int?>

object ContextSourceCaller {
@Service
class ContextSourceCaller(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep the convention of suffixing by Service everything that is a service

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be better named something like DistributedOperationService. Or maybe even better DistributedConsumptionOperationService (since having all the dist ops in just one service will not be possible). Even this will end up in 3 services (provision, consumption and subscription) that will quickly be too big. So my final word is DistributedEntityConsumptionOperationService (or DistributedEntityConsumptionService).

val logger: Logger = LoggerFactory.getLogger(javaClass)

suspend fun retrieveContextSourceEntity(
suspend fun retrieveEntityFromAllContextSources(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

distributeRetrieveEntityOperation?

@@ -55,7 +99,45 @@ object ContextSourceCaller {
)
}

suspend fun queryContextSourceEntities(
suspend fun queryEntitiesFromAllContextSources(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

distributeQueryEntitiesOperation?

@@ -100,7 +123,7 @@ class ContextSourceCallerTests {
}

@Test
fun `queryContextSourceEntities should return a RevalidationFailedWarning when receiving bad payload`() = runTest {
fun `queryEntities ContextSource should return a RevalidationFailedWarning when receiving bad payload`() = runTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fun `queryEntities ContextSource should return a RevalidationFailedWarning when receiving bad payload`() = runTest {
fun `queryEntitiesFromContextSource should return a RevalidationFailedWarning when receiving bad payload`() = runTest {

@@ -4,13 +4,8 @@ import arrow.core.getOrElse
import arrow.core.left
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not forget to update Detekt baseline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Isolate ContextSource logic in its own layer.
2 participants