Skip to content

Commit 79f4c35

Browse files
authored
Merge pull request #4969 from eshabakhov/#4967
fix(#4967): make Catalogs thread-safe
2 parents 8313b25 + 8c9058a commit 79f4c35

3 files changed

Lines changed: 9 additions & 10 deletions

File tree

eo-maven-plugin/src/main/java/org/eolang/maven/Catalogs.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@
1818
import java.util.Map;
1919
import java.util.concurrent.ConcurrentHashMap;
2020
import org.cactoos.scalar.Sticky;
21+
import org.cactoos.scalar.Synced;
2122
import org.cactoos.scalar.Unchecked;
2223

2324
/**
2425
* All catalogs in one place, to avoid making multiple objects.
2526
*
2627
* @since 0.29
27-
* @todo #4884:30min Use ReentranLock instead of synchronized block in the code.
28-
* It will be more efficient and will not cause deadlocks.
29-
* Don't forget to remove the PMD suppression after that.
3028
*/
31-
@SuppressWarnings("PMD.AvoidSynchronizedStatement")
3229
final class Catalogs {
3330

3431
/**
@@ -40,9 +37,9 @@ final class Catalogs {
4037
* Singleton.
4138
*/
4239
private static final Unchecked<Boolean> TESTING = new Unchecked<>(
43-
new Sticky<>(
44-
() -> {
45-
synchronized (Catalogs.class) {
40+
new Synced<>(
41+
new Sticky<>(
42+
() -> {
4643
boolean tests;
4744
try {
4845
Class.forName("org.junit.jupiter.api.Test");
@@ -52,7 +49,7 @@ final class Catalogs {
5249
}
5350
return tests;
5451
}
55-
}
52+
)
5653
)
5754
);
5855

eo-maven-plugin/src/test/java/org/eolang/maven/CatalogsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java.util.UUID;
1414
import org.hamcrest.MatcherAssert;
1515
import org.hamcrest.Matchers;
16-
import org.junit.jupiter.api.Test;
16+
import org.junit.jupiter.api.RepeatedTest;
1717
import org.junit.jupiter.api.extension.ExtendWith;
1818

1919
/**
@@ -25,7 +25,7 @@
2525
@ExtendWith(MktmpResolver.class)
2626
@SuppressWarnings("PMD.JUnit5TestShouldBePackagePrivate")
2727
public final class CatalogsTest {
28-
@Test
28+
@RepeatedTest(10)
2929
void readsFromTojosConcurrently(@Mktmp final Path tmp) {
3030
final Tojos tojos = Catalogs.INSTANCE.make(tmp.resolve("foreign"), "json");
3131
MatcherAssert.assertThat(

eo-maven-plugin/src/test/resources/junit-platform.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
# SPDX-License-Identifier: MIT
33

44
junit.jupiter.execution.timeout.test.method.default = 3m
5+
junit.jupiter.execution.parallel.enabled = true
6+
junit.jupiter.execution.parallel.mode.default = concurrent

0 commit comments

Comments
 (0)