Repository navigation
Make TextFileBasedViolationStore thread-safe under parallel test execution - #1656
Conversation
StefanGraeber
left a comment
There was a problem hiding this comment.
Thanks for contributing 🙂
The code itself looks good, just one minor edge case in the case of a non-existing directory which remains as race condition.
to make the pipeline pass, you must include a Signed-off-by: footer to your commit
https://github.com/TNG/ArchUnit/pull/1656/checks?check_run_id=85373415790
|
you might have a merge conflict with #1655 which will be submitted soon. |
7518e4c to
85656a5
Compare
Thanks for the heads up! It didn't have a conflict, but I rebased anyway and converted the test to JUnit 5.
True, I added a separate test for that. |
|
Oh, these old Java versions, should be fixed. |
StefanGraeber
left a comment
There was a problem hiding this comment.
Please squash at least the last two commits to avoid having an invalid intermediate state.
The other comments are not hugely important to me. If you have an opposing preference, it's also ok for me
e847785 to
0fc0aaa
Compare
|
@StefanGraeber Should all be addressed except for the optional comment on the assertion move. |
…ution Multiple FreezingArchRule instances each create a fresh TextFileBasedViolationStore and load stored.rules into their own private snapshot. Concurrent saves caused a lost-update: the last writer overwrote the file with only its own entries. Fix by sharing one FileSyncedProperties per stored.rules canonical path via a static ConcurrentHashMap, and synchronizing writes with a putIfAbsent method that atomically checks, sets, and flushes to disk under one lock. - Move directory creation into FileSyncedProperties.initializePropertiesFile - Use mkdirs() || isDirectory() to handle the race where a concurrent process creates the directory between mkdirs() returning false and the isDirectory check - Add TextFileBasedViolationStoreConcurrencyTest with separate initialize-race and save-race scenarios - Convert both test classes from JUnit 4 to JUnit 5 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Niklas Keller <niklas@chrono24.com>
0fc0aaa to
48f6118
Compare
# [ArchUnit 1.5.0](https://github.com/TNG/ArchUnit/releases/tag/v1.5.0) ## Enhancements ### Core * Support Java 27 / class file major version 71 (#1618) * Improve descriptions of `JavaAccess.Predicates.originOwner` and `JavaAccess.Predicates.targetOwner` (#1603) * Expose information on sealed classes via `JavaClass`: `isSealed()` and `getPermittedSubclasses()` (#1677) * Consider dependencies from caught exceptions (#1555) * `ImportOption.DoNotIncludeTests` and `OnlyIncludeTests` consider tests in custom Gradle source sets (#1660) ### Lang * `ArchConditions` offers new `ArchCondition<JavaClass> haveAnyDependenciesThat(DescribedPredicate<Dependency>)` (#1580) ### Library * `ArchitectureMetrics.lakosMetrics` is computed much more performantly (#1629) * `TextFileBasedViolationStore` is now thread-safe under parallel test execution (#1656) * `ModuleDependency` now provides stable descriptions (#1648) ### JUnit * `archunit-junit6` supports ArchUnit with JUnit 6 (~#1556~, ~#1658~, #1659) * `AnalyzeClasses` supports individual classes (#1569) * (`archunit-junit:0.9.0` (which was renamed with [ArchUnit 0.9.0](https://github.com/TNG/ArchUnit/releases/tag/v0.9.0)) now relocates to `archunit-junit4:0.9.0` (#1673)) * will only be published after #1684 🙈 ### Documentation * Document `Priority` (#1671) * Document Package Identifiers in User Guide (#1672) ## Internal Improvements * Text files now use UNIX line breaks (#1602, #1611) * Update Gradle from 8 to 9; build & test with JDK 25 (#1550, and also #1612, #1619) * Separate integration tests by JUnit version (#1636) * Replace `junit-dataprovider` with `junit-jupiter-params` (#1655) * ArchUnit releases now update Maven examples (and Gradle wrapper) of [ArchUnit-Examples](https://github.com/TNG/ArchUnit-Examples) (#1450) * Avoid managing hamcrest dependency (#1467)
Multiple FreezingArchRule instances each create a fresh TextFileBasedViolationStore and load stored.rules into their own private snapshot. Concurrent saves caused a lost-update: the last writer overwrote the file with only its own entries.
Fix by sharing one FileSyncedProperties per stored.rules canonical path via a static ConcurrentHashMap, and synchronizing writes with a putIfAbsent method that atomically checks, sets, and flushes to disk under one lock.
Fixes #1654.