From 755c7b73b06e7acf5974a9d26b4f660e1a80c52f Mon Sep 17 00:00:00 2001 From: Shams Asari Date: Wed, 6 Dec 2023 09:55:35 +0000 Subject: [PATCH] ENT-11111: Reverted exposure of internal ConcurrencyUtils method (#7586) --- .ci/api-current.txt | 4 ---- .../net/corda/core/concurrent/ConcurrencyUtils.kt | 9 ++++----- .../corda/core/concurrent/ConcurrencyUtilsTest.kt | 12 ++++++------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.ci/api-current.txt b/.ci/api-current.txt index 617e6e82bf..a2703c32b2 100644 --- a/.ci/api-current.txt +++ b/.ci/api-current.txt @@ -83,11 +83,7 @@ public final class net.corda.core.Utils extends java.lang.Object public final class net.corda.core.concurrent.ConcurrencyUtils extends java.lang.Object @NotNull public static final net.corda.core.concurrent.CordaFuture firstOf(net.corda.core.concurrent.CordaFuture[], kotlin.jvm.functions.Function1) - @NotNull - public static final net.corda.core.concurrent.CordaFuture firstOf(net.corda.core.concurrent.CordaFuture[], org.slf4j.Logger, kotlin.jvm.functions.Function1) public static final W match(java.util.concurrent.Future, kotlin.jvm.functions.Function1, kotlin.jvm.functions.Function1) - @NotNull - public static final String shortCircuitedTaskFailedMessage = "Short-circuited task failed:" ## public interface net.corda.core.concurrent.CordaFuture extends java.util.concurrent.Future public abstract void then(kotlin.jvm.functions.Function1) diff --git a/core/src/main/kotlin/net/corda/core/concurrent/ConcurrencyUtils.kt b/core/src/main/kotlin/net/corda/core/concurrent/ConcurrencyUtils.kt index 51e3a1243d..cd5c338d9f 100644 --- a/core/src/main/kotlin/net/corda/core/concurrent/ConcurrencyUtils.kt +++ b/core/src/main/kotlin/net/corda/core/concurrent/ConcurrencyUtils.kt @@ -1,7 +1,7 @@ @file:JvmName("ConcurrencyUtils") package net.corda.core.concurrent -import net.corda.core.internal.VisibleForTesting +import net.corda.core.CordaInternal import net.corda.core.internal.concurrent.openFuture import net.corda.core.utilities.getOrThrow import org.slf4j.Logger @@ -27,10 +27,9 @@ fun Future.match(success: (V) -> W, failure: (Throwable) -> W): W { fun firstOf(vararg futures: CordaFuture, handler: (CordaFuture) -> W) = firstOf(futures, defaultLog, handler) private val defaultLog = LoggerFactory.getLogger("net.corda.core.concurrent") -@VisibleForTesting -const val shortCircuitedTaskFailedMessage = "Short-circuited task failed:" -fun firstOf(futures: Array>, log: Logger, handler: (CordaFuture) -> W): CordaFuture { +@CordaInternal +internal fun firstOf(futures: Array>, log: Logger, handler: (CordaFuture) -> W): CordaFuture { val resultFuture = openFuture() val winnerChosen = AtomicBoolean() futures.forEach { @@ -40,7 +39,7 @@ fun firstOf(futures: Array>, log: Logger, handler: it.isCancelled -> { // Do nothing. } - else -> it.match({}, { log.error(shortCircuitedTaskFailedMessage, it) }) + else -> it.match({}, { log.error("Short-circuited task failed:", it) }) } } } diff --git a/core/src/test/kotlin/net/corda/core/concurrent/ConcurrencyUtilsTest.kt b/core/src/test/kotlin/net/corda/core/concurrent/ConcurrencyUtilsTest.kt index a7b2238da4..59c790f8a8 100644 --- a/core/src/test/kotlin/net/corda/core/concurrent/ConcurrencyUtilsTest.kt +++ b/core/src/test/kotlin/net/corda/core/concurrent/ConcurrencyUtilsTest.kt @@ -34,7 +34,7 @@ class ConcurrencyUtilsTest { val throwable = EOFException("log me") f2.setException(throwable) assertEquals(1, invocations) // Least astonishing to skip handler side-effects. - verify(log).error(eq(shortCircuitedTaskFailedMessage), same(throwable)) + verify(log).error(eq("Short-circuited task failed:"), same(throwable)) verifyNoMoreInteractions(log) } @@ -68,7 +68,7 @@ class ConcurrencyUtilsTest { f1.set(100) assertEquals(100, g.getOrThrow()) assertEquals(1, invocations) // Handler didn't run as g was already done. - verify(log).error(eq(shortCircuitedTaskFailedMessage), same(nonCancel)) + verify(log).error(eq("Short-circuited task failed:"), same(nonCancel)) verifyNoMoreInteractions(log) assertThatThrownBy { f2.getOrThrow() }.isSameAs(nonCancel) } @@ -98,7 +98,7 @@ class ConcurrencyUtilsTest { }, failures::add) }.isSameAs(x) assertEquals(listOf(100), successes) - assertEquals(emptyList(), failures) + assertEquals(emptyList(), failures) } @Test(timeout=300_000) @@ -109,12 +109,12 @@ class ConcurrencyUtilsTest { val failures = mutableListOf() val x = Throwable() assertThatThrownBy { - f.match(successes::add, { + f.match(successes::add) { failures.add(it) throw x - }) + } }.isSameAs(x) - assertEquals(emptyList(), successes) + assertEquals(emptyList(), successes) assertEquals(listOf(e), failures) } }