-
Notifications
You must be signed in to change notification settings - Fork 287
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
Add FhirEngine interface method 'withTransaction' #2535
base: master
Are you sure you want to change the base?
Conversation
To support performing FhirEngine actions as a single atomic transaction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some suggestions for the api.
13b83cb
to
bf90f8c
Compare
bf90f8c
to
72be126
Compare
engine/src/test/java/com/google/android/fhir/impl/FhirEngineImplTest.kt
Outdated
Show resolved
Hide resolved
to better reflect need for atomic transactions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. @jingtang10
Note: Sync APIs are deprecated now and once removed we probably dont need the CRUDEngine interface. |
happy to merge once jajoo's comment's resolved. discussed with @aditya-07 who's also ok with this. |
FORK - With unmerged PR #9 - WUP #13 SDK - WUP google#2178 - WUP google#2650 - WUP google#2663 PERF - WUP google#2669 - WUP google#2565 - WUP google#2561 - WUP google#2535
FORK - With unmerged PR #9 - WUP #13 SDK - WUP google#2178 - WUP google#2650 - WUP google#2663 PERF - WUP google#2669 - WUP google#2565 - WUP google#2561 - WUP google#2535
and removed the CRUDEngine interface
3af9d14
to
b520d30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @LZRS!
engine/src/main/java/com/google/android/fhir/impl/FhirEngineImpl.kt
Outdated
Show resolved
Hide resolved
@@ -783,6 +788,132 @@ class FhirEngineImplTest { | |||
assertThat(services.database.getLocalChangesCount()).isEqualTo(0) | |||
} | |||
|
|||
@Test | |||
fun `withTransaction saves all changes successfully in order`() = runTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you simplify this test case?
I think you should keep this test case to use at most 2 resources. For example a patient and an observation. this is because when you add more resources to reference each other it's not really testing anything new.
Even just create a patient and then an observation that references the patient in my opinion is enough.
The point of the transation API isn't that things happen in order.... things will be executed in order without transation. The point is really that a transaction is atomic and will be reverted as a whole. So this test case should just be simply testing that the transation api runs multiple operations. the next test case is more important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense...I've updated the changes
} | ||
|
||
@Test | ||
fun `withTransaction reverts all changes when an error occurs`() = runTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test case can be done using 2 resources.
before transation:
create a patient
in a transation:
create an encoutner for the patient, update the encouter to reference a non-existent patient.
check that the encounter is also rolled back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I've updated the changes
IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).
Fixes #2531
Description
Support performing FhirEngine actions as a single atomic transaction
Alternative(s) considered
Have you considered any alternatives? And if so, why have you chosen the approach in this PR?
Type
Choose one: (Bug fix | Feature | Documentation | Testing | Code health | Builds | Releases | Other)
Screenshots (if applicable)
Checklist
./gradlew spotlessApply
and./gradlew spotlessCheck
to check my code follows the style guide of this project../gradlew check
and./gradlew connectedCheck
to test my changes locally.