mirror of
https://github.com/corda/corda.git
synced 2024-12-19 21:17:58 +00:00
ENT-11111: Reverted exposure of internal ConcurrencyUtils method (#7586)
This commit is contained in:
parent
1b3ea01fc9
commit
755c7b73b0
@ -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<? extends V>[], kotlin.jvm.functions.Function1)
|
||||
@NotNull
|
||||
public static final net.corda.core.concurrent.CordaFuture firstOf(net.corda.core.concurrent.CordaFuture<? extends V>[], 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)
|
||||
|
@ -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 <V, W> Future<V>.match(success: (V) -> W, failure: (Throwable) -> W): W {
|
||||
fun <V, W> firstOf(vararg futures: CordaFuture<out V>, handler: (CordaFuture<out V>) -> W) = firstOf(futures, defaultLog, handler)
|
||||
|
||||
private val defaultLog = LoggerFactory.getLogger("net.corda.core.concurrent")
|
||||
@VisibleForTesting
|
||||
const val shortCircuitedTaskFailedMessage = "Short-circuited task failed:"
|
||||
|
||||
fun <V, W> firstOf(futures: Array<out CordaFuture<out V>>, log: Logger, handler: (CordaFuture<out V>) -> W): CordaFuture<W> {
|
||||
@CordaInternal
|
||||
internal fun <V, W> firstOf(futures: Array<out CordaFuture<out V>>, log: Logger, handler: (CordaFuture<out V>) -> W): CordaFuture<W> {
|
||||
val resultFuture = openFuture<W>()
|
||||
val winnerChosen = AtomicBoolean()
|
||||
futures.forEach {
|
||||
@ -40,7 +39,7 @@ fun <V, W> firstOf(futures: Array<out CordaFuture<out V>>, log: Logger, handler:
|
||||
it.isCancelled -> {
|
||||
// Do nothing.
|
||||
}
|
||||
else -> it.match({}, { log.error(shortCircuitedTaskFailedMessage, it) })
|
||||
else -> it.match({}, { log.error("Short-circuited task failed:", it) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Any?>(100), successes)
|
||||
assertEquals(emptyList<Any?>(), failures)
|
||||
assertEquals(emptyList(), failures)
|
||||
}
|
||||
|
||||
@Test(timeout=300_000)
|
||||
@ -109,12 +109,12 @@ class ConcurrencyUtilsTest {
|
||||
val failures = mutableListOf<Any?>()
|
||||
val x = Throwable()
|
||||
assertThatThrownBy {
|
||||
f.match(successes::add, {
|
||||
f.match(successes::add) {
|
||||
failures.add(it)
|
||||
throw x
|
||||
})
|
||||
}
|
||||
}.isSameAs(x)
|
||||
assertEquals(emptyList<Any?>(), successes)
|
||||
assertEquals(emptyList(), successes)
|
||||
assertEquals(listOf<Any?>(e), failures)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user