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

Core: shared clock #1416

Merged
merged 17 commits into from
Jun 9, 2022
Merged

Conversation

algattik
Copy link
Contributor

@algattik algattik commented Jun 3, 2022

What this PR changes/adds

Use a mockable Clock to get the time.

Removes calls to Instant.now(), new Date(), System.currentTimeMillis() from production code.

Why it does that

  • Make access to system time consistent in code base.
  • Make time mockable for testing.
  • Make tests simple and reliable (avoid approximate time comparisons, etc.).

Further notes

  • Moved convenience method implementations from DefaultServiceExtensionContext to the interface
  • Changed DataPlaneInstance contract to return null instead of 0 for empty lastActive time.
  • nbf: in discussion with Ben
  • Removed rollbackState method in ContractNegotiation and TransferProcess, as it's unused and violates state machine contract.
  • Consistently inject services in ContractServiceExtension

Linked Issue(s)

Contributes to #1364 (a decision record will also be provided)

Checklist

  • added appropriate tests?
  • performed checkstyle check locally?
  • added/updated copyright headers?
  • documented public classes/methods?
  • added/updated relevant documentation?
  • added relevant details to the changelog? (skip with label no-changelog)
  • formatted title correctly? (take a look at the CONTRIBUTING and styleguide for details)

@algattik algattik changed the title Feature/1364/284 clock (#286) Core: shared clock Jun 3, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jun 8, 2022

Codecov Report

Merging #1416 (e218c47) into main (c03f7d9) will decrease coverage by 57.52%.
The diff coverage is 9.52%.

❗ Current head e218c47 differs from pull request most recent head a115110. Consider uploading reports for the commit a115110 to get more accurate results

@@              Coverage Diff              @@
##               main    #1416       +/-   ##
=============================================
- Coverage     67.61%   10.08%   -57.53%     
- Complexity        0      452      +452     
=============================================
  Files           719      719               
  Lines         15936    15957       +21     
  Branches       1043     1044        +1     
=============================================
- Hits          10775     1610     -9165     
- Misses         4687    14260     +9573     
+ Partials        474       87      -387     
Impacted Files Coverage Δ
...dataspaceconnector/core/CoreServicesExtension.java 0.00% <ø> (-91.49%) ⬇️
...or/boot/system/DefaultServiceExtensionContext.java 0.00% <0.00%> (-82.50%) ⬇️
...ceconnector/contract/ContractServiceExtension.java 0.00% <0.00%> (-95.09%) ⬇️
...egotiation/AbstractContractNegotiationManager.java 0.00% <0.00%> (-100.00%) ⬇️
...iation/ConsumerContractNegotiationManagerImpl.java 0.00% <0.00%> (-87.79%) ⬇️
...iation/ProviderContractNegotiationManagerImpl.java 0.00% <0.00%> (-90.87%) ⬇️
...ract/validation/ContractValidationServiceImpl.java 0.00% <0.00%> (-60.79%) ⬇️
...connector/transfer/core/CoreTransferExtension.java 0.00% <0.00%> (ø)
...core/transfer/TransferProcessSendRetryManager.java 0.00% <0.00%> (-89.48%) ⬇️
...onnector/azure/cosmos/LeaseableCosmosDocument.java 0.00% <0.00%> (-100.00%) ⬇️
... and 511 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c03f7d9...a115110. Read the comment docs.

@algattik algattik marked this pull request as ready for review June 8, 2022 06:35
@@ -47,28 +48,14 @@ public DefaultServiceExtensionContext(TypeManager typeManager, Monitor monitor,
registerService(TypeManager.class, typeManager);
registerService(Monitor.class, monitor);
registerService(Telemetry.class, telemetry);
registerService(Clock.class, Clock.systemUTC());
Copy link
Member

Choose a reason for hiding this comment

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

Unless there is a good reason to the contrary we should provide the clock with a @Provider(isDefault=true)-annotated factory method in the DefaultServicesExtension.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reasons for this are:

  • to provide a utility method ServiceExtensionContext#getClock so that extensions don't need to inject a clock service. If we move the default clock to DefaultServicesExtension, we can't have such a utility method, since we need the dependency resolver to start extensions in the right order.
  • that the clock is a common service just like TypeManager, Monitor and Telemetry, and there's no obvious reason to manage it differently

@juliapampus
Copy link
Contributor

Does this also resolve issue #341? @algattik

Copy link
Contributor

@jimmarino jimmarino left a comment

Choose a reason for hiding this comment

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

Great stuff @algattik. I'd like to have a Decision Record since it is important to have this approach documented and everyone aware across the codebase.

Given the conflict issue, that could be done in a subsequent PR, even though it would have been better to commit the DR first.

@algattik
Copy link
Contributor Author

algattik commented Jun 8, 2022

Does this also resolve issue #341? @algattik

@juliapampus no, this is a pure "internal utils" change and does not affect any contracts or behaviours

@algattik
Copy link
Contributor Author

algattik commented Jun 8, 2022

Great stuff @algattik. I'd like to have a Decision Record since it is important to have this approach documented and everyone aware across the codebase.

Given the conflict issue, that could be done in a subsequent PR, even though it would have been better to commit the DR first.

Great point, I've updated the parent issue to add the need for a DR, and removed the "Closes" comment from this PR. I'll do a DR next.

@algattik algattik force-pushed the feature/1364-clock branch from 6c93f72 to e218c47 Compare June 9, 2022 06:01
@paullatzelsperger paullatzelsperger merged commit 63e4596 into eclipse-edc:main Jun 9, 2022
diegogomez-zf pushed a commit to diegogomez-zf/DataSpaceConnector that referenced this pull request Jun 10, 2022
* Feature/1364/284 clock (#286)

* Checkstyle

* Update CHANGELOG.md

* Moved default clock to DefaultServicesExtension

* Update DefaultServiceExtensionContext.java

* Update SqlContractNegotiationStoreExtensionTest.java

* Update AbstractMultipartDispatcherIntegrationTest.java

* Revert "Update AbstractMultipartDispatcherIntegrationTest.java"

This reverts commit 1ebb12f.

* Revert "Update SqlContractNegotiationStoreExtensionTest.java"

This reverts commit af4613b.

* Revert "Update DefaultServiceExtensionContext.java"

This reverts commit 3798770.

* Revert "Moved default clock to DefaultServicesExtension"

This reverts commit 7a9fa08.

* Update ContractNegotiationIntegrationTest.java

* Update ContractNegotiationIntegrationTest.java
@algattik algattik mentioned this pull request Jun 10, 2022
7 tasks
@algattik algattik deleted the feature/1364-clock branch June 22, 2022 04:28
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.

5 participants