From 6e921d03730a67e2c24e1c3b3067887de89dbfd6 Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 1 Dec 2022 15:04:41 +0300 Subject: [PATCH] review fix --- .../yegor256/tojos/MnSynchronizedTest.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/yegor256/tojos/MnSynchronizedTest.java b/src/test/java/com/yegor256/tojos/MnSynchronizedTest.java index 7e9495e..d601d2a 100644 --- a/src/test/java/com/yegor256/tojos/MnSynchronizedTest.java +++ b/src/test/java/com/yegor256/tojos/MnSynchronizedTest.java @@ -68,14 +68,14 @@ class MnSynchronizedTest { @BeforeEach final void setUp(@TempDir final Path temp) { - this.shared = new MnSynchronized(new MnJson(temp.resolve("/bar/baz/a.json"))); + this.shared = new MnSynchronized(new MnJson(temp.resolve("bar/baz/a.json"))); this.executor = Executors.newFixedThreadPool(MnSynchronizedTest.THREADS); this.latch = new CountDownLatch(1); this.additional = rowsByThreads(); } @Test - final void concurrentScenario() throws InterruptedException { + final void writesConcurrently() throws InterruptedException { for (int trds = 1; trds <= MnSynchronizedTest.THREADS; ++trds) { this.executor.submit( () -> { @@ -92,7 +92,9 @@ final void concurrentScenario() throws InterruptedException { assert this.executor.awaitTermination(1, TimeUnit.MINUTES); MatcherAssert.assertThat( this.shared.read().size(), - Matchers.equalTo(25) + Matchers.equalTo( + MnSynchronizedTest.THREADS * MnSynchronizedTest.THREADS + ) ); } @@ -102,12 +104,12 @@ final void concurrentScenario() throws InterruptedException { * @return Collection of rows */ private static Collection> rowsByThreads() { - final Map row = new HashMap<>(0); - row.put(Tojos.KEY, String.valueOf(MnSynchronizedTest.THREADS)); - final Collection> res = new ArrayList<>(MnSynchronizedTest.THREADS); - for (int idx = 0; idx < MnSynchronizedTest.THREADS; ++idx) { - res.add(row); - } - return res; + return Collections.nCopies( + MnSynchronizedTest.THREADS, + Collections.singletonMap( + Tojos.KEY, + String.valueOf(MnSynchronizedTest.THREADS) + ) + ); } }