From 22561763666c04b1145c43765065fddc900cf577 Mon Sep 17 00:00:00 2001 From: sunmisc Date: Thu, 2 Jan 2025 18:36:24 +0300 Subject: [PATCH 1/9] add AtRhoTest --- .../src/test/java/org/eolang/AtRhoTest.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 eo-runtime/src/test/java/org/eolang/AtRhoTest.java diff --git a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java new file mode 100644 index 00000000000..edb29201aca --- /dev/null +++ b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java @@ -0,0 +1,42 @@ +package org.eolang; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicInteger; + +final class AtRhoTest { + + @ParameterizedTest + @ValueSource(ints = {1, 4, 32}) + void threadSafeAtRho(final int threads) throws InterruptedException { + final Attr atRho = new AtRho(); + final CountDownLatch startLatch = new CountDownLatch(1); + final CountDownLatch endLatch = new CountDownLatch(threads); + final AtomicInteger count = new AtomicInteger(0); + for (int i = 0; i < threads; i++) { + new Thread(() -> { + try { + startLatch.await(); + atRho.put(new Phi.ToPhi(count.incrementAndGet())); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } finally { + endLatch.countDown(); + } + }).start(); + } + startLatch.countDown(); + endLatch.await(); + MatcherAssert.assertThat( + "The object must be equal to 1", + new BytesOf( + atRho.get().delta() + ).asNumber(), + Matchers.equalTo(1.0) + ); + } +} From 2a7df07fab871ce43c27c7cb006a97c3b9828c18 Mon Sep 17 00:00:00 2001 From: sunmisc Date: Thu, 2 Jan 2025 18:55:11 +0300 Subject: [PATCH 2/9] added copyright --- .../src/test/java/org/eolang/AtRhoTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java index edb29201aca..0deb0251dcf 100644 --- a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java +++ b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java @@ -1,3 +1,26 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2025 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package org.eolang; import org.hamcrest.MatcherAssert; @@ -8,6 +31,11 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; +/** + * Test for {@link AtRho}. + * + * @since 0.50.0 + */ final class AtRhoTest { @ParameterizedTest From 3bb9bfcf3d63e4b1e91f810588720e1ee2a2fd3a Mon Sep 17 00:00:00 2001 From: sunmisc Date: Thu, 2 Jan 2025 19:01:11 +0300 Subject: [PATCH 3/9] updated --- eo-runtime/src/test/java/org/eolang/AtRhoTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java index 0deb0251dcf..da3e6d14f9e 100644 --- a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java +++ b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java @@ -40,7 +40,7 @@ final class AtRhoTest { @ParameterizedTest @ValueSource(ints = {1, 4, 32}) - void threadSafeAtRho(final int threads) throws InterruptedException { + void worksAsExpected(final int threads) throws InterruptedException { final Attr atRho = new AtRho(); final CountDownLatch startLatch = new CountDownLatch(1); final CountDownLatch endLatch = new CountDownLatch(threads); From 9003dab1bf84c592c3cf7ee7c4b666470c4b645a Mon Sep 17 00:00:00 2001 From: sunmisc Date: Thu, 2 Jan 2025 21:54:30 +0300 Subject: [PATCH 4/9] updated year in copyright --- eo-runtime/src/test/java/org/eolang/AtRhoTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java index da3e6d14f9e..fded7068aa6 100644 --- a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java +++ b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2016-2025 Objectionary.com + * Copyright (c) 2016-2024 Objectionary.com * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal From 7b24c045120922d83c1afeb32fbc1c1512a4b922 Mon Sep 17 00:00:00 2001 From: sunmisc Date: Thu, 2 Jan 2025 22:06:11 +0300 Subject: [PATCH 5/9] updated --- .../src/test/java/org/eolang/AtRhoTest.java | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java index fded7068aa6..5540567e093 100644 --- a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java +++ b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java @@ -41,29 +41,31 @@ final class AtRhoTest { @ParameterizedTest @ValueSource(ints = {1, 4, 32}) void worksAsExpected(final int threads) throws InterruptedException { - final Attr atRho = new AtRho(); - final CountDownLatch startLatch = new CountDownLatch(1); - final CountDownLatch endLatch = new CountDownLatch(threads); + final Attr rho = new AtRho(); + final CountDownLatch start = new CountDownLatch(1); + final CountDownLatch end = new CountDownLatch(threads); final AtomicInteger count = new AtomicInteger(0); - for (int i = 0; i < threads; i++) { - new Thread(() -> { - try { - startLatch.await(); - atRho.put(new Phi.ToPhi(count.incrementAndGet())); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - endLatch.countDown(); - } - }).start(); + for (int idx = 0; idx < threads; ++idx) { + final Thread thread = new Thread( + () -> { + try { + start.await(); + final Phi phi = new Phi.ToPhi(count.incrementAndGet()); + rho.put(phi); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } finally { + end.countDown(); + } + } + ); + thread.start(); } - startLatch.countDown(); - endLatch.await(); + start.countDown(); + end.await(); MatcherAssert.assertThat( "The object must be equal to 1", - new BytesOf( - atRho.get().delta() - ).asNumber(), + new BytesOf(rho.get().delta()).asNumber(), Matchers.equalTo(1.0) ); } From d9192d32b1ad10279b2033dffa6afd1a0466c2e1 Mon Sep 17 00:00:00 2001 From: sunmisc Date: Thu, 2 Jan 2025 22:06:47 +0300 Subject: [PATCH 6/9] updated --- eo-runtime/src/test/java/org/eolang/AtRhoTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java index 5540567e093..21cacb03b0e 100644 --- a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java +++ b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java @@ -52,7 +52,7 @@ void worksAsExpected(final int threads) throws InterruptedException { start.await(); final Phi phi = new Phi.ToPhi(count.incrementAndGet()); rho.put(phi); - } catch (InterruptedException e) { + } catch (final InterruptedException ex) { Thread.currentThread().interrupt(); } finally { end.countDown(); From 8dc6536e2bafb8f6156c501652d41402ea48eab3 Mon Sep 17 00:00:00 2001 From: sunmisc Date: Thu, 2 Jan 2025 22:16:11 +0300 Subject: [PATCH 7/9] updated --- .../src/test/java/org/eolang/AtRhoTest.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java index 21cacb03b0e..16dc6ac751c 100644 --- a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java +++ b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java @@ -47,26 +47,26 @@ void worksAsExpected(final int threads) throws InterruptedException { final AtomicInteger count = new AtomicInteger(0); for (int idx = 0; idx < threads; ++idx) { final Thread thread = new Thread( - () -> { - try { - start.await(); - final Phi phi = new Phi.ToPhi(count.incrementAndGet()); - rho.put(phi); - } catch (final InterruptedException ex) { - Thread.currentThread().interrupt(); - } finally { - end.countDown(); - } + () -> { + try { + start.await(); + final Phi phi = new Phi.ToPhi(count.incrementAndGet()); + rho.put(phi); + } catch (final InterruptedException ex) { + Thread.currentThread().interrupt(); + } finally { + end.countDown(); } + } ); thread.start(); } start.countDown(); end.await(); MatcherAssert.assertThat( - "The object must be equal to 1", - new BytesOf(rho.get().delta()).asNumber(), - Matchers.equalTo(1.0) + "The object must be equal to 1", + new BytesOf(rho.get().delta()).asNumber(), + Matchers.equalTo(1.0) ); } } From 041348727187f2805edcfb2b988dc8d678da4aa4 Mon Sep 17 00:00:00 2001 From: sunmisc Date: Thu, 2 Jan 2025 22:16:22 +0300 Subject: [PATCH 8/9] updated --- eo-runtime/src/test/java/org/eolang/AtRhoTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java index 16dc6ac751c..ebf5198e84d 100644 --- a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java +++ b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java @@ -27,7 +27,6 @@ import org.hamcrest.Matchers; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; - import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; From 122aa6458d7a1d0cfe0efc6b03ec871e0721d6e8 Mon Sep 17 00:00:00 2001 From: sunmisc Date: Thu, 2 Jan 2025 22:23:37 +0300 Subject: [PATCH 9/9] fix order import --- eo-runtime/src/test/java/org/eolang/AtRhoTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java index ebf5198e84d..de71233ff4a 100644 --- a/eo-runtime/src/test/java/org/eolang/AtRhoTest.java +++ b/eo-runtime/src/test/java/org/eolang/AtRhoTest.java @@ -23,12 +23,12 @@ */ package org.eolang; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicInteger; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicInteger; /** * Test for {@link AtRho}.