mirror of
https://github.com/corda/corda.git
synced 2025-01-26 22:29:28 +00:00
Introducing Future.getOrThrow() which throws the cause of the ExecutionException
This commit is contained in:
parent
a26ca37168
commit
38876e3984
@ -1,6 +1,7 @@
|
||||
package net.corda.client
|
||||
|
||||
import net.corda.core.contracts.DOLLARS
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.random63BitValue
|
||||
import net.corda.core.serialization.OpaqueBytes
|
||||
@ -35,7 +36,7 @@ class CordaRPCClientTest {
|
||||
val driverStarted = CountDownLatch(1)
|
||||
driverThread = thread {
|
||||
driver(isDebug = true) {
|
||||
driverInfo = startNode(rpcUsers = listOf(rpcUser), advertisedServices = setOf(ServiceInfo(ValidatingNotaryService.type))).get()
|
||||
driverInfo = startNode(rpcUsers = listOf(rpcUser), advertisedServices = setOf(ServiceInfo(ValidatingNotaryService.type))).getOrThrow()
|
||||
client = CordaRPCClient(toHostAndPort(driverInfo.nodeInfo.address), configureTestSSL())
|
||||
driverStarted.countDown()
|
||||
stopDriver.await()
|
||||
|
@ -8,6 +8,7 @@ import net.corda.core.contracts.Issued
|
||||
import net.corda.core.contracts.PartyAndReference
|
||||
import net.corda.core.contracts.USD
|
||||
import net.corda.core.flows.StateMachineRunId
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.NodeInfo
|
||||
import net.corda.core.node.services.NetworkMapCache
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
@ -60,9 +61,9 @@ class NodeMonitorModelTest {
|
||||
val aliceNodeFuture = startNode("Alice", rpcUsers = listOf(cashUser))
|
||||
val notaryNodeFuture = startNode("Notary", advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type)))
|
||||
|
||||
aliceNode = aliceNodeFuture.get().nodeInfo
|
||||
notaryNode = notaryNodeFuture.get().nodeInfo
|
||||
newNode = { nodeName -> startNode(nodeName).get().nodeInfo }
|
||||
aliceNode = aliceNodeFuture.getOrThrow().nodeInfo
|
||||
notaryNode = notaryNodeFuture.getOrThrow().nodeInfo
|
||||
newNode = { nodeName -> startNode(nodeName).getOrThrow().nodeInfo }
|
||||
val monitor = NodeMonitorModel()
|
||||
|
||||
stateMachineTransactionMapping = monitor.stateMachineTransactionMapping.bufferUntilSubscribed()
|
||||
|
@ -27,6 +27,7 @@ import java.util.concurrent.ExecutionException
|
||||
import java.util.concurrent.Executor
|
||||
import java.util.concurrent.Future
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import java.util.function.BiConsumer
|
||||
import java.util.stream.Stream
|
||||
import java.util.zip.ZipInputStream
|
||||
import kotlin.concurrent.withLock
|
||||
@ -60,8 +61,22 @@ infix fun Long.checkedAdd(b: Long) = Math.addExact(this, b)
|
||||
*/
|
||||
fun random63BitValue(): Long = Math.abs(newSecureRandom().nextLong())
|
||||
|
||||
// TODO Convert the CompletableFuture into a ListenableFuture
|
||||
fun <T> future(block: () -> T): Future<T> = CompletableFuture.supplyAsync(block)
|
||||
/** Same as [Future.get] but with a more descriptive name, and doesn't throw [ExecutionException], instead throwing its cause */
|
||||
fun <T> Future<T>.getOrThrow(): T {
|
||||
try {
|
||||
return get()
|
||||
} catch (e: ExecutionException) {
|
||||
throw e.cause!!
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> future(block: () -> T): ListenableFuture<T> = CompletableToListenable(CompletableFuture.supplyAsync(block))
|
||||
|
||||
private class CompletableToListenable<T>(private val base: CompletableFuture<T>) : Future<T> by base, ListenableFuture<T> {
|
||||
override fun addListener(listener: Runnable, executor: Executor) {
|
||||
base.whenCompleteAsync(BiConsumer { result, exception -> listener.run() }, executor)
|
||||
}
|
||||
}
|
||||
|
||||
// Some utilities for working with Guava listenable futures.
|
||||
fun <T> ListenableFuture<T>.then(executor: Executor, body: () -> Unit) = addListener(Runnable(body), executor)
|
||||
@ -77,9 +92,7 @@ fun <T> ListenableFuture<T>.success(executor: Executor, body: (T) -> Unit) = the
|
||||
|
||||
fun <T> ListenableFuture<T>.failure(executor: Executor, body: (Throwable) -> Unit) = then(executor) {
|
||||
try {
|
||||
get()
|
||||
} catch (e: ExecutionException) {
|
||||
body(e.cause!!)
|
||||
getOrThrow()
|
||||
} catch (t: Throwable) {
|
||||
body(t)
|
||||
}
|
||||
@ -101,15 +114,11 @@ inline fun <T> SettableFuture<T>.catch(block: () -> T) {
|
||||
|
||||
fun <A> ListenableFuture<A>.toObservable(): Observable<A> {
|
||||
return Observable.create { subscriber ->
|
||||
then {
|
||||
try {
|
||||
subscriber.onNext(get())
|
||||
subscriber.onCompleted()
|
||||
} catch (e: ExecutionException) {
|
||||
subscriber.onError(e.cause!!)
|
||||
} catch (t: Throwable) {
|
||||
subscriber.onError(t)
|
||||
}
|
||||
success {
|
||||
subscriber.onNext(it)
|
||||
subscriber.onCompleted()
|
||||
} failure {
|
||||
subscriber.onError(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -186,7 +195,7 @@ fun <T> List<T>.randomOrNull(): T? {
|
||||
fun <T> List<T>.randomOrNull(predicate: (T) -> Boolean) = filter(predicate).randomOrNull()
|
||||
|
||||
// An alias that can sometimes make code clearer to read.
|
||||
val RunOnCallerThread = MoreExecutors.directExecutor()
|
||||
val RunOnCallerThread: Executor = MoreExecutors.directExecutor()
|
||||
|
||||
// TODO: Add inline back when a new Kotlin version is released and check if the java.lang.VerifyError
|
||||
// returns in the IRSSimulationTest. If not, commit the inline back.
|
||||
@ -342,6 +351,4 @@ fun <T> Observable<T>.bufferUntilSubscribed(): Observable<T> {
|
||||
}
|
||||
|
||||
/** Allows summing big decimals that are in iterable collections */
|
||||
fun Iterable<BigDecimal>.sum(): BigDecimal {
|
||||
return this.fold(BigDecimal.valueOf(0)) { a: BigDecimal, b: BigDecimal -> a + b }
|
||||
}
|
||||
fun Iterable<BigDecimal>.sum(): BigDecimal = fold(BigDecimal.ZERO) { a, b -> a + b }
|
||||
|
@ -4,6 +4,7 @@ import net.corda.core.contracts.DummyContract
|
||||
import net.corda.core.crypto.NullSignature
|
||||
import net.corda.core.crypto.Party
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.recordTransactions
|
||||
import net.corda.core.serialization.opaque
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
@ -14,7 +15,6 @@ import net.corda.testing.MEGA_CORP
|
||||
import net.corda.testing.MEGA_CORP_KEY
|
||||
import net.corda.testing.MINI_CORP_PUBKEY
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import net.corda.testing.rootCauseExceptions
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
@ -52,7 +52,7 @@ class ResolveTransactionsFlowTest {
|
||||
val p = ResolveTransactionsFlow(setOf(stx2.id), a.info.legalIdentity)
|
||||
val future = b.services.startFlow(p).resultFuture
|
||||
net.runNetwork()
|
||||
val results = future.get()
|
||||
val results = future.getOrThrow()
|
||||
assertEquals(listOf(stx1.id, stx2.id), results.map { it.id })
|
||||
databaseTransaction(b.database) {
|
||||
assertEquals(stx1, b.storage.validatedTransactions.getTransaction(stx1.id))
|
||||
@ -67,9 +67,7 @@ class ResolveTransactionsFlowTest {
|
||||
val p = ResolveTransactionsFlow(setOf(stx.id), a.info.legalIdentity)
|
||||
val future = b.services.startFlow(p).resultFuture
|
||||
net.runNetwork()
|
||||
assertFailsWith(SignatureException::class) {
|
||||
rootCauseExceptions { future.get() }
|
||||
}
|
||||
assertFailsWith(SignatureException::class) { future.getOrThrow() }
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -78,7 +76,7 @@ class ResolveTransactionsFlowTest {
|
||||
val p = ResolveTransactionsFlow(stx2, a.info.legalIdentity)
|
||||
val future = b.services.startFlow(p).resultFuture
|
||||
net.runNetwork()
|
||||
future.get()
|
||||
future.getOrThrow()
|
||||
databaseTransaction(b.database) {
|
||||
assertEquals(stx1, b.storage.validatedTransactions.getTransaction(stx1.id))
|
||||
// But stx2 wasn't inserted, just stx1.
|
||||
@ -105,9 +103,7 @@ class ResolveTransactionsFlowTest {
|
||||
p.transactionCountLimit = 40
|
||||
val future = b.services.startFlow(p).resultFuture
|
||||
net.runNetwork()
|
||||
assertFailsWith<ResolveTransactionsFlow.ExcessivelyLargeTransactionGraph> {
|
||||
rootCauseExceptions { future.get() }
|
||||
}
|
||||
assertFailsWith<ResolveTransactionsFlow.ExcessivelyLargeTransactionGraph> { future.getOrThrow() }
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -133,7 +129,7 @@ class ResolveTransactionsFlowTest {
|
||||
val p = ResolveTransactionsFlow(setOf(stx3.id), a.info.legalIdentity)
|
||||
val future = b.services.startFlow(p).resultFuture
|
||||
net.runNetwork()
|
||||
future.get()
|
||||
future.getOrThrow()
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -143,7 +139,7 @@ class ResolveTransactionsFlowTest {
|
||||
val p = ResolveTransactionsFlow(stx2, a.info.legalIdentity)
|
||||
val future = b.services.startFlow(p).resultFuture
|
||||
net.runNetwork()
|
||||
future.get()
|
||||
future.getOrThrow()
|
||||
assertNotNull(b.services.storageService.attachments.openAttachment(id))
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.corda.node.driver
|
||||
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.NodeInfo
|
||||
import net.corda.core.node.services.NetworkMapCache
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.node.services.api.RegulatorService
|
||||
import net.corda.node.services.messaging.ArtemisMessagingComponent
|
||||
@ -30,9 +30,9 @@ class DriverTests {
|
||||
val notary = startNode("TestNotary", setOf(ServiceInfo(SimpleNotaryService.type)))
|
||||
val regulator = startNode("Regulator", setOf(ServiceInfo(RegulatorService.type)))
|
||||
|
||||
nodeMustBeUp(notary.get().nodeInfo, "TestNotary")
|
||||
nodeMustBeUp(regulator.get().nodeInfo, "Regulator")
|
||||
Pair(notary.get(), regulator.get())
|
||||
nodeMustBeUp(notary.getOrThrow().nodeInfo, "TestNotary")
|
||||
nodeMustBeUp(regulator.getOrThrow().nodeInfo, "Regulator")
|
||||
Pair(notary.getOrThrow(), regulator.getOrThrow())
|
||||
}
|
||||
nodeMustBeDown(notary.nodeInfo)
|
||||
nodeMustBeDown(regulator.nodeInfo)
|
||||
@ -42,8 +42,8 @@ class DriverTests {
|
||||
fun startingNodeWithNoServicesWorks() {
|
||||
val noService = driver {
|
||||
val noService = startNode("NoService")
|
||||
nodeMustBeUp(noService.get().nodeInfo, "NoService")
|
||||
noService.get()
|
||||
nodeMustBeUp(noService.getOrThrow().nodeInfo, "NoService")
|
||||
noService.getOrThrow()
|
||||
}
|
||||
nodeMustBeDown(noService.nodeInfo)
|
||||
}
|
||||
@ -52,8 +52,8 @@ class DriverTests {
|
||||
fun randomFreePortAllocationWorks() {
|
||||
val nodeInfo = driver(portAllocation = PortAllocation.RandomFree()) {
|
||||
val nodeInfo = startNode("NoService")
|
||||
nodeMustBeUp(nodeInfo.get().nodeInfo, "NoService")
|
||||
nodeInfo.get()
|
||||
nodeMustBeUp(nodeInfo.getOrThrow().nodeInfo, "NoService")
|
||||
nodeInfo.getOrThrow()
|
||||
}
|
||||
nodeMustBeDown(nodeInfo.nodeInfo)
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import net.corda.core.crypto.CompositeKey
|
||||
import net.corda.core.crypto.Party
|
||||
import net.corda.core.crypto.composite
|
||||
import net.corda.core.crypto.generateKeyPair
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.messaging.SingleMessageRecipient
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.random63BitValue
|
||||
@ -34,7 +35,6 @@ import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.security.KeyPair
|
||||
import java.util.*
|
||||
import java.util.concurrent.ExecutionException
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
@ -79,12 +79,12 @@ class DistributedNotaryTests {
|
||||
val buildFlow = { NotaryFlow.Client(stx) }
|
||||
|
||||
val firstSpend = alice.services.startFlow(buildFlow())
|
||||
firstSpend.resultFuture.get()
|
||||
firstSpend.resultFuture.getOrThrow()
|
||||
|
||||
val secondSpend = alice.services.startFlow(buildFlow())
|
||||
|
||||
val ex = assertFailsWith(ExecutionException::class) { secondSpend.resultFuture.get() }
|
||||
val error = (ex.cause as NotaryException).error as NotaryError.Conflict
|
||||
val ex = assertFailsWith(NotaryException::class) { secondSpend.resultFuture.getOrThrow() }
|
||||
val error = ex.error as NotaryError.Conflict
|
||||
assertEquals(error.tx, stx.tx)
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ class DistributedNotaryTests {
|
||||
|
||||
notaryNode.setup().start()
|
||||
thread { notaryNode.run() }
|
||||
notaryNode.networkMapRegistrationFuture.get()
|
||||
notaryNode.networkMapRegistrationFuture.getOrThrow()
|
||||
return notaryNode
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@ class DistributedNotaryTests {
|
||||
networkMapAddress = networkMapAddress)
|
||||
alice.setup().start()
|
||||
thread { alice.run() }
|
||||
alice.networkMapRegistrationFuture.get()
|
||||
alice.networkMapRegistrationFuture.getOrThrow()
|
||||
return alice
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package net.corda.node.messaging
|
||||
import net.corda.core.contracts.Attachment
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.crypto.sha256
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.messaging.SingleMessageRecipient
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.write
|
||||
@ -13,7 +14,6 @@ import net.corda.node.services.network.NetworkMapService
|
||||
import net.corda.node.services.persistence.NodeAttachmentService
|
||||
import net.corda.node.services.transactions.SimpleNotaryService
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import net.corda.testing.rootCauseExceptions
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.io.ByteArrayInputStream
|
||||
@ -53,7 +53,7 @@ class AttachmentTests {
|
||||
network.runNetwork()
|
||||
val f1 = n1.services.startFlow(FetchAttachmentsFlow(setOf(id), n0.info.legalIdentity))
|
||||
network.runNetwork()
|
||||
assertEquals(0, f1.resultFuture.get().fromDisk.size)
|
||||
assertEquals(0, f1.resultFuture.getOrThrow().fromDisk.size)
|
||||
|
||||
// Verify it was inserted into node one's store.
|
||||
val attachment = n1.storage.attachments.openAttachment(id)!!
|
||||
@ -62,7 +62,7 @@ class AttachmentTests {
|
||||
// Shut down node zero and ensure node one can still resolve the attachment.
|
||||
n0.stop()
|
||||
|
||||
val response: FetchDataFlow.Result<Attachment> = n1.services.startFlow(FetchAttachmentsFlow(setOf(id), n0.info.legalIdentity)).resultFuture.get()
|
||||
val response: FetchDataFlow.Result<Attachment> = n1.services.startFlow(FetchAttachmentsFlow(setOf(id), n0.info.legalIdentity)).resultFuture.getOrThrow()
|
||||
assertEquals(attachment, response.fromDisk[0])
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ class AttachmentTests {
|
||||
network.runNetwork()
|
||||
val f1 = n1.services.startFlow(FetchAttachmentsFlow(setOf(hash), n0.info.legalIdentity))
|
||||
network.runNetwork()
|
||||
val e = assertFailsWith<FetchDataFlow.HashNotFound> { rootCauseExceptions { f1.resultFuture.get() } }
|
||||
val e = assertFailsWith<FetchDataFlow.HashNotFound> { f1.resultFuture.getOrThrow() }
|
||||
assertEquals(hash, e.requested)
|
||||
}
|
||||
|
||||
@ -106,8 +106,6 @@ class AttachmentTests {
|
||||
network.runNetwork()
|
||||
val f1 = n1.services.startFlow(FetchAttachmentsFlow(setOf(id), n0.info.legalIdentity))
|
||||
network.runNetwork()
|
||||
assertFailsWith<FetchDataFlow.DownloadedVsRequestedDataMismatch> {
|
||||
rootCauseExceptions { f1.resultFuture.get() }
|
||||
}
|
||||
assertFailsWith<FetchDataFlow.DownloadedVsRequestedDataMismatch> { f1.resultFuture.getOrThrow() }
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,11 @@ import net.corda.core.crypto.composite
|
||||
import net.corda.core.days
|
||||
import net.corda.core.flows.FlowStateMachine
|
||||
import net.corda.core.flows.StateMachineRunId
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.map
|
||||
import net.corda.core.messaging.SingleMessageRecipient
|
||||
import net.corda.core.node.services.*
|
||||
import net.corda.core.rootCause
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.core.transactions.TransactionBuilder
|
||||
import net.corda.core.transactions.WireTransaction
|
||||
@ -43,13 +45,11 @@ import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.security.KeyPair
|
||||
import java.util.*
|
||||
import java.util.concurrent.ExecutionException
|
||||
import java.util.concurrent.Future
|
||||
import java.util.jar.JarOutputStream
|
||||
import java.util.zip.ZipEntry
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
@ -102,11 +102,11 @@ class TwoPartyTradeFlowTests {
|
||||
|
||||
insertFakeTransactions(alicesFakePaper, aliceNode, aliceKey, notaryKey)
|
||||
|
||||
val (bobPsm, aliceResult) = runBuyerAndSeller("alice's paper".outputStateAndRef())
|
||||
val (bobStateMachine, aliceResult) = runBuyerAndSeller("alice's paper".outputStateAndRef())
|
||||
|
||||
// TODO: Verify that the result was inserted into the transaction database.
|
||||
// assertEquals(bobResult.get(), aliceNode.storage.validatedTransactions[aliceResult.get().id])
|
||||
assertEquals(aliceResult.get(), bobPsm.get().resultFuture.get())
|
||||
assertEquals(aliceResult.getOrThrow(), bobStateMachine.getOrThrow().resultFuture.getOrThrow())
|
||||
|
||||
aliceNode.stop()
|
||||
bobNode.stop()
|
||||
@ -192,7 +192,7 @@ class TwoPartyTradeFlowTests {
|
||||
net.runNetwork()
|
||||
|
||||
// Bob is now finished and has the same transaction as Alice.
|
||||
assertThat(bobFuture.get()).isEqualTo(aliceFuture.get())
|
||||
assertThat(bobFuture.getOrThrow()).isEqualTo(aliceFuture.getOrThrow())
|
||||
|
||||
assertThat(bobNode.smm.findStateMachines(Buyer::class.java)).isEmpty()
|
||||
databaseTransaction(bobNode.database) {
|
||||
@ -443,23 +443,18 @@ class TwoPartyTradeFlowTests {
|
||||
|
||||
net.runNetwork() // Clear network map registration messages
|
||||
|
||||
val (bobPsm, aliceResult) = runBuyerAndSeller("alice's paper".outputStateAndRef())
|
||||
val (bobStateMachine, aliceResult) = runBuyerAndSeller("alice's paper".outputStateAndRef())
|
||||
|
||||
net.runNetwork()
|
||||
|
||||
val e = assertFailsWith<ExecutionException> {
|
||||
val e = assertFailsWith<TransactionVerificationException> {
|
||||
if (bobError)
|
||||
aliceResult.get()
|
||||
aliceResult.getOrThrow()
|
||||
else
|
||||
bobPsm.get().resultFuture.get()
|
||||
bobStateMachine.getOrThrow().resultFuture.getOrThrow()
|
||||
}
|
||||
assertTrue(e.cause is TransactionVerificationException)
|
||||
assertNotNull(e.cause!!.cause)
|
||||
assertNotNull(e.cause!!.cause!!.message)
|
||||
val underlyingMessage = e.cause!!.cause!!.message!!
|
||||
if (underlyingMessage.contains(expectedMessageSubstring)) {
|
||||
assertTrue(underlyingMessage.contains(expectedMessageSubstring))
|
||||
} else {
|
||||
val underlyingMessage = e.rootCause.message!!
|
||||
if (expectedMessageSubstring !in underlyingMessage) {
|
||||
assertEquals(expectedMessageSubstring, underlyingMessage)
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import io.atomix.copycat.client.CopycatClient
|
||||
import io.atomix.copycat.server.CopycatServer
|
||||
import io.atomix.copycat.server.storage.Storage
|
||||
import io.atomix.copycat.server.storage.StorageLevel
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.utilities.LogHelper
|
||||
import net.corda.node.services.network.NetworkMapService
|
||||
import net.corda.node.services.transactions.DistributedImmutableMap
|
||||
@ -57,14 +58,14 @@ class DistributedImmutableMapTests {
|
||||
|
||||
val entries = mapOf("key1" to "value1", "key2" to "value2")
|
||||
|
||||
val conflict = client.submit(DistributedImmutableMap.Commands.PutAll(entries)).get()
|
||||
val conflict = client.submit(DistributedImmutableMap.Commands.PutAll(entries)).getOrThrow()
|
||||
assertTrue { conflict.isEmpty() }
|
||||
|
||||
val value1 = client.submit(DistributedImmutableMap.Commands.Get<String, String>("key1"))
|
||||
val value2 = client.submit(DistributedImmutableMap.Commands.Get<String, String>("key2"))
|
||||
|
||||
assertEquals(value1.get(), "value1")
|
||||
assertEquals(value2.get(), "value2")
|
||||
assertEquals(value1.getOrThrow(), "value1")
|
||||
assertEquals(value2.getOrThrow(), "value2")
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -73,9 +74,9 @@ class DistributedImmutableMapTests {
|
||||
|
||||
val entries = mapOf("key1" to "value1", "key2" to "value2")
|
||||
|
||||
var conflict = client.submit(DistributedImmutableMap.Commands.PutAll(entries)).get()
|
||||
var conflict = client.submit(DistributedImmutableMap.Commands.PutAll(entries)).getOrThrow()
|
||||
assertTrue { conflict.isEmpty() }
|
||||
conflict = client.submit(DistributedImmutableMap.Commands.PutAll(entries)).get()
|
||||
conflict = client.submit(DistributedImmutableMap.Commands.PutAll(entries)).getOrThrow()
|
||||
assertTrue { conflict == entries }
|
||||
}
|
||||
|
||||
@ -83,7 +84,7 @@ class DistributedImmutableMapTests {
|
||||
val clusterAddress = freeLocalHostAndPort()
|
||||
val cluster = mutableListOf(createReplica(clusterAddress))
|
||||
for (i in 1..nodeCount) cluster.add(createReplica(freeLocalHostAndPort(), clusterAddress))
|
||||
return cluster.map { it.get() }
|
||||
return cluster.map { it.getOrThrow() }
|
||||
}
|
||||
|
||||
private fun createReplica(myAddress: HostAndPort, clusterAddress: HostAndPort? = null): CompletableFuture<Member> {
|
||||
|
@ -2,29 +2,23 @@ package net.corda.node.services
|
||||
|
||||
import net.corda.core.crypto.composite
|
||||
import net.corda.core.crypto.generateKeyPair
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.node.services.network.NetworkMapService
|
||||
import net.corda.testing.expect
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class InMemoryNetworkMapCacheTest {
|
||||
lateinit var network: MockNetwork
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
network = MockNetwork()
|
||||
}
|
||||
private val network = MockNetwork()
|
||||
|
||||
@Test
|
||||
fun registerWithNetwork() {
|
||||
val (n0, n1) = network.createTwoNodes()
|
||||
|
||||
val future = n1.services.networkMapCache.addMapService(n1.net, n0.info.address, false, null)
|
||||
network.runNetwork()
|
||||
future.get()
|
||||
future.getOrThrow()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.corda.node.services
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.map
|
||||
import net.corda.core.messaging.send
|
||||
import net.corda.core.node.services.DEFAULT_SESSION_ID
|
||||
@ -83,25 +84,25 @@ abstract class AbstractNetworkMapServiceTest {
|
||||
|
||||
// Confirm all nodes have registered themselves
|
||||
network.runNetwork()
|
||||
var fetchPsm = registerNode.fetchMap(mapServiceNode, false)
|
||||
var fetchResult = registerNode.fetchMap(mapServiceNode, false)
|
||||
network.runNetwork()
|
||||
assertEquals(2, fetchPsm.get()?.count())
|
||||
assertEquals(2, fetchResult.getOrThrow()?.count())
|
||||
|
||||
// Forcibly deregister the second node
|
||||
val nodeKey = registerNode.services.legalIdentityKey
|
||||
val instant = Instant.now()
|
||||
val expires = instant + NetworkMapService.DEFAULT_EXPIRATION_PERIOD
|
||||
val reg = NodeRegistration(registerNode.info, instant.toEpochMilli()+1, AddOrRemove.REMOVE, expires)
|
||||
val registerPsm = registerNode.registration(mapServiceNode, reg, nodeKey.private)
|
||||
val registerResult = registerNode.registration(mapServiceNode, reg, nodeKey.private)
|
||||
network.runNetwork()
|
||||
assertTrue(registerPsm.get().success)
|
||||
assertTrue(registerResult.getOrThrow().success)
|
||||
|
||||
swizzle()
|
||||
|
||||
// Now only map service node should be registered
|
||||
fetchPsm = registerNode.fetchMap(mapServiceNode, false)
|
||||
fetchResult = registerNode.fetchMap(mapServiceNode, false)
|
||||
network.runNetwork()
|
||||
assertEquals(mapServiceNode.info, fetchPsm.get()?.filter { it.type == AddOrRemove.ADD }?.map { it.node }?.single())
|
||||
assertEquals(mapServiceNode.info, fetchResult.getOrThrow()?.filter { it.type == AddOrRemove.ADD }?.map { it.node }?.single())
|
||||
}
|
||||
|
||||
protected fun `subscribe with network`(network: MockNetwork,
|
||||
@ -114,9 +115,9 @@ abstract class AbstractNetworkMapServiceTest {
|
||||
|
||||
// Test subscribing to updates
|
||||
network.runNetwork()
|
||||
val subscribePsm = registerNode.subscribe(mapServiceNode, true)
|
||||
val subscribeResult = registerNode.subscribe(mapServiceNode, true)
|
||||
network.runNetwork()
|
||||
subscribePsm.get()
|
||||
subscribeResult.getOrThrow()
|
||||
|
||||
swizzle()
|
||||
|
||||
|
@ -3,6 +3,7 @@ package net.corda.node.services
|
||||
import net.corda.core.contracts.*
|
||||
import net.corda.core.crypto.Party
|
||||
import net.corda.core.crypto.generateKeyPair
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.seconds
|
||||
import net.corda.core.utilities.DUMMY_NOTARY
|
||||
@ -14,14 +15,13 @@ import net.corda.node.internal.AbstractNode
|
||||
import net.corda.node.services.network.NetworkMapService
|
||||
import net.corda.node.services.transactions.SimpleNotaryService
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
import java.util.concurrent.ExecutionException
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class NotaryChangeTests {
|
||||
lateinit var net: MockNetwork
|
||||
@ -53,7 +53,7 @@ class NotaryChangeTests {
|
||||
|
||||
net.runNetwork()
|
||||
|
||||
val newState = future.resultFuture.get()
|
||||
val newState = future.resultFuture.getOrThrow()
|
||||
assertEquals(newState.state.notary, newNotary)
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ class NotaryChangeTests {
|
||||
|
||||
net.runNetwork()
|
||||
|
||||
val newState = future.resultFuture.get()
|
||||
val newState = future.resultFuture.getOrThrow()
|
||||
assertEquals(newState.state.notary, newNotary)
|
||||
val loadedStateA = clientNodeA.services.loadState(newState.ref)
|
||||
val loadedStateB = clientNodeB.services.loadState(newState.ref)
|
||||
@ -82,9 +82,8 @@ class NotaryChangeTests {
|
||||
|
||||
net.runNetwork()
|
||||
|
||||
val ex = assertFailsWith(ExecutionException::class) { future.resultFuture.get() }
|
||||
val error = (ex.cause as StateReplacementException).error
|
||||
assertTrue(error is StateReplacementRefused)
|
||||
val ex = assertFailsWith(StateReplacementException::class) { future.resultFuture.getOrThrow() }
|
||||
assertThat(ex.error).isInstanceOf(StateReplacementRefused::class.java)
|
||||
}
|
||||
|
||||
// TODO: Add more test cases once we have a general flow/service exception handling mechanism:
|
||||
|
@ -6,6 +6,7 @@ import net.corda.core.contracts.StateAndRef
|
||||
import net.corda.core.contracts.StateRef
|
||||
import net.corda.core.contracts.TransactionType
|
||||
import net.corda.core.crypto.DigitalSignature
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.seconds
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
@ -19,14 +20,13 @@ import net.corda.node.services.network.NetworkMapService
|
||||
import net.corda.node.services.transactions.SimpleNotaryService
|
||||
import net.corda.testing.MINI_CORP_KEY
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
import java.util.concurrent.ExecutionException
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class NotaryServiceTests {
|
||||
lateinit var net: MockNetwork
|
||||
@ -53,7 +53,7 @@ class NotaryServiceTests {
|
||||
}
|
||||
|
||||
val future = runNotaryClient(stx)
|
||||
val signature = future.get()
|
||||
val signature = future.getOrThrow()
|
||||
signature.verifyWithECDSA(stx.id)
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ class NotaryServiceTests {
|
||||
}
|
||||
|
||||
val future = runNotaryClient(stx)
|
||||
val signature = future.get()
|
||||
val signature = future.getOrThrow()
|
||||
signature.verifyWithECDSA(stx.id)
|
||||
}
|
||||
|
||||
@ -81,9 +81,8 @@ class NotaryServiceTests {
|
||||
|
||||
val future = runNotaryClient(stx)
|
||||
|
||||
val ex = assertFailsWith(ExecutionException::class) { future.get() }
|
||||
val error = (ex.cause as NotaryException).error
|
||||
assertTrue(error is NotaryError.TimestampInvalid)
|
||||
val ex = assertFailsWith(NotaryException::class) { future.getOrThrow() }
|
||||
assertThat(ex.error).isInstanceOf(NotaryError.TimestampInvalid::class.java)
|
||||
}
|
||||
|
||||
@Test fun `should report conflict for a duplicate transaction`() {
|
||||
@ -101,8 +100,8 @@ class NotaryServiceTests {
|
||||
|
||||
net.runNetwork()
|
||||
|
||||
val ex = assertFailsWith(ExecutionException::class) { future.resultFuture.get() }
|
||||
val notaryError = (ex.cause as NotaryException).error as NotaryError.Conflict
|
||||
val ex = assertFailsWith(NotaryException::class) { future.resultFuture.getOrThrow() }
|
||||
val notaryError = ex.error as NotaryError.Conflict
|
||||
assertEquals(notaryError.tx, stx.tx)
|
||||
notaryError.conflict.verified()
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.google.common.util.concurrent.ListenableFuture
|
||||
import net.corda.core.contracts.*
|
||||
import net.corda.core.crypto.DigitalSignature
|
||||
import net.corda.core.crypto.composite
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.core.utilities.DUMMY_NOTARY
|
||||
@ -21,7 +22,6 @@ import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.util.*
|
||||
import java.util.concurrent.ExecutionException
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
@ -51,9 +51,8 @@ class ValidatingNotaryServiceTests {
|
||||
|
||||
val future = runClient(stx)
|
||||
|
||||
val ex = assertFailsWith(ExecutionException::class) { future.get() }
|
||||
val notaryError = (ex.cause as NotaryException).error
|
||||
assertThat(notaryError).isInstanceOf(NotaryError.TransactionInvalid::class.java)
|
||||
val ex = assertFailsWith(NotaryException::class) { future.getOrThrow() }
|
||||
assertThat(ex.error).isInstanceOf(NotaryError.TransactionInvalid::class.java)
|
||||
}
|
||||
|
||||
@Test fun `should report error for missing signatures`() {
|
||||
@ -67,11 +66,11 @@ class ValidatingNotaryServiceTests {
|
||||
tx.toSignedTransaction(false)
|
||||
}
|
||||
|
||||
val ex = assertFailsWith(ExecutionException::class) {
|
||||
val ex = assertFailsWith(NotaryException::class) {
|
||||
val future = runClient(stx)
|
||||
future.get()
|
||||
future.getOrThrow()
|
||||
}
|
||||
val notaryError = (ex.cause as NotaryException).error
|
||||
val notaryError = ex.error
|
||||
assertThat(notaryError).isInstanceOf(NotaryError.SignaturesMissing::class.java)
|
||||
|
||||
val missingKeys = (notaryError as NotaryError.SignaturesMissing).missingSigners
|
||||
|
@ -6,6 +6,7 @@ import com.google.common.util.concurrent.ListenableFuture
|
||||
import net.corda.core.crypto.Party
|
||||
import net.corda.core.flows.FlowLogic
|
||||
import net.corda.core.flows.FlowSessionException
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.random63BitValue
|
||||
import net.corda.core.serialization.deserialize
|
||||
import net.corda.node.services.persistence.checkpoints
|
||||
@ -162,7 +163,7 @@ class StateMachineManagerTests {
|
||||
// Run the network which will also fire up the second flow. First message should get deduped. So message data stays in sync.
|
||||
net.runNetwork()
|
||||
node2b.smm.executor.flush()
|
||||
fut1.get()
|
||||
fut1.getOrThrow()
|
||||
|
||||
val receivedCount = sessionTransfers.count { it.isPayloadTransfer }
|
||||
// Check flows completed cleanly and didn't get out of phase
|
||||
@ -177,8 +178,8 @@ class StateMachineManagerTests {
|
||||
}
|
||||
assertEquals(payload2, firstAgain.receivedPayload, "Received payload does not match the first value on Node 3")
|
||||
assertEquals(payload2 + 1, firstAgain.receivedPayload2, "Received payload does not match the expected second value on Node 3")
|
||||
assertEquals(payload, secondFlow.get().receivedPayload, "Received payload does not match the (restarted) first value on Node 2")
|
||||
assertEquals(payload + 1, secondFlow.get().receivedPayload2, "Received payload does not match the expected second value on Node 2")
|
||||
assertEquals(payload, secondFlow.getOrThrow().receivedPayload, "Received payload does not match the (restarted) first value on Node 2")
|
||||
assertEquals(payload + 1, secondFlow.getOrThrow().receivedPayload2, "Received payload does not match the expected second value on Node 2")
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -264,7 +265,7 @@ class StateMachineManagerTests {
|
||||
node2.services.registerFlowInitiator(ReceiveThenSuspendFlow::class) { ExceptionFlow }
|
||||
val future = node1.smm.add(ReceiveThenSuspendFlow(node2.info.legalIdentity)).resultFuture
|
||||
net.runNetwork()
|
||||
assertThatThrownBy { future.get() }.hasCauseInstanceOf(FlowSessionException::class.java)
|
||||
assertThatThrownBy { future.getOrThrow() }.isInstanceOf(FlowSessionException::class.java)
|
||||
assertSessionTransfers(
|
||||
node1 sent sessionInit(node1, ReceiveThenSuspendFlow::class) to node2,
|
||||
node2 sent sessionConfirm() to node1,
|
||||
|
@ -5,6 +5,7 @@ import co.paralleluniverse.fibers.FiberExecutorScheduler
|
||||
import co.paralleluniverse.fibers.Suspendable
|
||||
import co.paralleluniverse.strands.Strand
|
||||
import com.google.common.util.concurrent.SettableFuture
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.testing.node.TestClock
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
@ -153,7 +154,7 @@ class ClockUtilsTest {
|
||||
testClock.advanceBy(Duration.ofMinutes(10))
|
||||
}).start()
|
||||
}
|
||||
assertFalse(future.get(), "Should have reached deadline")
|
||||
assertFalse(future.getOrThrow(), "Should have reached deadline")
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -175,7 +176,7 @@ class ClockUtilsTest {
|
||||
testClock.advanceBy(Duration.ofMinutes(10))
|
||||
}).start()
|
||||
}
|
||||
assertFalse(future.get(), "Should have reached deadline")
|
||||
assertFalse(future.getOrThrow(), "Should have reached deadline")
|
||||
}
|
||||
|
||||
@Suspendable
|
||||
|
@ -1,10 +1,10 @@
|
||||
package net.corda.node.utilities
|
||||
|
||||
|
||||
import co.paralleluniverse.fibers.FiberExecutorScheduler
|
||||
import co.paralleluniverse.fibers.Suspendable
|
||||
import co.paralleluniverse.strands.Strand
|
||||
import net.corda.core.RetryableException
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.testing.node.TestClock
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
@ -12,7 +12,6 @@ import org.junit.Test
|
||||
import java.time.Clock
|
||||
import java.time.Duration
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.ExecutionException
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.test.assertEquals
|
||||
@ -120,11 +119,7 @@ class FiberBoxTest {
|
||||
testClock.advanceBy(Duration.ofMinutes(10))
|
||||
}).start()
|
||||
}
|
||||
try {
|
||||
assertEquals(2, future.get())
|
||||
} catch(e: ExecutionException) {
|
||||
throw e.cause!!
|
||||
}
|
||||
assertEquals(2, future.getOrThrow())
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,11 +150,7 @@ class FiberBoxTest {
|
||||
}
|
||||
mutex.write { integer = 1 }
|
||||
}).start()
|
||||
try {
|
||||
assertEquals(1, future.get())
|
||||
} catch(e: ExecutionException) {
|
||||
throw e.cause!!
|
||||
}
|
||||
assertEquals(1, future.getOrThrow())
|
||||
}
|
||||
|
||||
private fun backgroundWrite() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.corda.attachmentdemo
|
||||
|
||||
import net.corda.core.crypto.toBase58String
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.node.driver.driver
|
||||
import net.corda.node.services.transactions.SimpleNotaryService
|
||||
@ -12,9 +12,9 @@ class AttachmentDemoTest {
|
||||
@Test fun `runs attachment demo`() {
|
||||
driver(dsl = {
|
||||
startNode("Notary", setOf(ServiceInfo(SimpleNotaryService.Companion.type)))
|
||||
val nodeA = startNode("Bank A").get()
|
||||
val nodeA = startNode("Bank A").getOrThrow()
|
||||
val nodeAApiAddr = nodeA.config.getHostAndPort("webAddress")
|
||||
val nodeBApiAddr = startNode("Bank B").get().config.getHostAndPort("webAddress")
|
||||
val nodeBApiAddr = startNode("Bank B").getOrThrow().config.getHostAndPort("webAddress")
|
||||
|
||||
var recipientReturn: Boolean? = null
|
||||
var senderReturn: Boolean? = null
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.corda.irs
|
||||
|
||||
import com.google.common.net.HostAndPort
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import com.google.common.util.concurrent.SettableFuture
|
||||
import com.typesafe.config.Config
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.irs.api.NodeInterestRates
|
||||
import net.corda.irs.utilities.postJson
|
||||
@ -10,8 +10,7 @@ import net.corda.irs.utilities.putJson
|
||||
import net.corda.irs.utilities.uploadFile
|
||||
import net.corda.node.driver.driver
|
||||
import net.corda.node.services.transactions.SimpleNotaryService
|
||||
import net.corda.testing.*
|
||||
import com.typesafe.config.Config
|
||||
import net.corda.testing.IntegrationTestCategory
|
||||
import org.apache.commons.io.IOUtils
|
||||
import org.junit.Test
|
||||
import java.net.URL
|
||||
@ -21,9 +20,9 @@ class IRSDemoTest: IntegrationTestCategory {
|
||||
|
||||
@Test fun `runs IRS demo`() {
|
||||
driver(dsl = {
|
||||
val controller = startNode("Notary", setOf(ServiceInfo(SimpleNotaryService.type), ServiceInfo(NodeInterestRates.type))).get()
|
||||
val nodeA = startNode("Bank A").get()
|
||||
val nodeB = startNode("Bank B").get()
|
||||
val controller = startNode("Notary", setOf(ServiceInfo(SimpleNotaryService.type), ServiceInfo(NodeInterestRates.type))).getOrThrow()
|
||||
val nodeA = startNode("Bank A").getOrThrow()
|
||||
val nodeB = startNode("Bank B").getOrThrow()
|
||||
runUploadRates(controller.config.getHostAndPort("webAddress"))
|
||||
runTrade(nodeA.config.getHostAndPort("webAddress"))
|
||||
runDateChange(nodeB.config.getHostAndPort("webAddress"))
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.corda.irs.testing
|
||||
|
||||
import com.google.common.base.Throwables
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.utilities.LogHelper
|
||||
import net.corda.simulation.IRSSimulation
|
||||
import org.junit.Test
|
||||
@ -13,10 +13,6 @@ class IRSSimulationTest {
|
||||
val sim = IRSSimulation(false, false, null)
|
||||
val future = sim.start()
|
||||
while (!future.isDone) sim.iterate()
|
||||
try {
|
||||
future.get()
|
||||
} catch(e: Throwable) {
|
||||
throw Throwables.getRootCause(e)
|
||||
}
|
||||
future.getOrThrow()
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import net.corda.core.contracts.*
|
||||
import net.corda.core.crypto.MerkleTreeException
|
||||
import net.corda.core.crypto.Party
|
||||
import net.corda.core.crypto.generateKeyPair
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.transactions.FilterFuns
|
||||
import net.corda.core.transactions.FilteredTransaction
|
||||
@ -206,7 +207,7 @@ class NodeInterestRatesTest {
|
||||
net.runNetwork()
|
||||
val future = n1.services.startFlow(flow).resultFuture
|
||||
net.runNetwork()
|
||||
future.get()
|
||||
future.getOrThrow()
|
||||
// We should now have a valid signature over our tx from the oracle.
|
||||
val fix = tx.toSignedTransaction(true).tx.commands.map { it.value as Fix }.first()
|
||||
assertEquals(fixOf, fix.of)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.corda.traderdemo
|
||||
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.node.driver.driver
|
||||
import net.corda.node.services.transactions.SimpleNotaryService
|
||||
@ -10,9 +11,9 @@ class TraderDemoTest {
|
||||
@Test fun `runs trader demo`() {
|
||||
driver(dsl = {
|
||||
startNode("Notary", setOf(ServiceInfo(SimpleNotaryService.type)))
|
||||
val nodeA = startNode("Bank A").get()
|
||||
val nodeA = startNode("Bank A").getOrThrow()
|
||||
val nodeAApiAddr = nodeA.config.getHostAndPort("webAddress")
|
||||
val nodeBApiAddr = startNode("Bank B").get().config.getHostAndPort("webAddress")
|
||||
val nodeBApiAddr = startNode("Bank B").getOrThrow().config.getHostAndPort("webAddress")
|
||||
|
||||
assert(TraderDemoClientApi(nodeAApiAddr).runBuyer())
|
||||
assert(TraderDemoClientApi(nodeBApiAddr).runSeller(counterparty = nodeA.nodeInfo.legalIdentity.name))
|
||||
|
@ -2,7 +2,6 @@
|
||||
@file:JvmName("CoreTestUtils")
|
||||
package net.corda.testing
|
||||
|
||||
import com.google.common.base.Throwables
|
||||
import com.google.common.net.HostAndPort
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import com.google.common.util.concurrent.SettableFuture
|
||||
@ -74,15 +73,6 @@ val MOCK_IDENTITY_SERVICE: MockIdentityService get() = MockIdentityService(listO
|
||||
|
||||
fun generateStateRef() = StateRef(SecureHash.randomSHA256(), 0)
|
||||
|
||||
/** If an exception is thrown by the body, rethrows the root cause exception. */
|
||||
inline fun <R> rootCauseExceptions(body: () -> R): R {
|
||||
try {
|
||||
return body()
|
||||
} catch(e: Exception) {
|
||||
throw Throwables.getRootCause(e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a free port.
|
||||
*
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.corda.testing
|
||||
|
||||
import com.google.common.util.concurrent.SettableFuture
|
||||
import net.corda.core.getOrThrow
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import rx.Observable
|
||||
@ -175,7 +176,7 @@ fun <S, E : Any> S.genericExpectEvents(
|
||||
}
|
||||
}
|
||||
}
|
||||
finishFuture.get()
|
||||
finishFuture.getOrThrow()
|
||||
}
|
||||
|
||||
sealed class ExpectCompose<out E> {
|
||||
|
@ -4,6 +4,7 @@ import com.google.common.util.concurrent.Futures
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import com.google.common.util.concurrent.SettableFuture
|
||||
import net.corda.core.ThreadBox
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.messaging.*
|
||||
import net.corda.core.serialization.SingletonSerializeAsToken
|
||||
import net.corda.core.utilities.trace
|
||||
@ -176,7 +177,7 @@ class InMemoryMessagingNetwork(val sendManuallyPumped: Boolean) : SingletonSeria
|
||||
messageSent.set(Unit)
|
||||
}
|
||||
if (block) {
|
||||
messageSent.get()
|
||||
messageSent.getOrThrow()
|
||||
}
|
||||
} else {
|
||||
pumpSendInternal(transfer)
|
||||
|
@ -3,14 +3,11 @@ package net.corda.testing.node
|
||||
import com.google.common.jimfs.Configuration.unix
|
||||
import com.google.common.jimfs.Jimfs
|
||||
import com.google.common.util.concurrent.Futures
|
||||
import net.corda.core.createDirectories
|
||||
import net.corda.core.createDirectory
|
||||
import net.corda.core.*
|
||||
import net.corda.core.crypto.Party
|
||||
import net.corda.core.div
|
||||
import net.corda.core.messaging.SingleMessageRecipient
|
||||
import net.corda.core.node.PhysicalLocation
|
||||
import net.corda.core.node.services.*
|
||||
import net.corda.core.random63BitValue
|
||||
import net.corda.core.utilities.DUMMY_NOTARY_KEY
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import net.corda.node.internal.AbstractNode
|
||||
@ -120,7 +117,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
||||
// through the java.nio API which we are already mocking via Jimfs.
|
||||
override fun makeMessagingService(): MessagingServiceInternal {
|
||||
require(id >= 0) { "Node ID must be zero or positive, was passed: " + id }
|
||||
return mockNet.messagingNetwork.createNodeWithID(!mockNet.threadPerNode, id, serverThread, configuration.myLegalName, database).start().get()
|
||||
return mockNet.messagingNetwork.createNodeWithID(!mockNet.threadPerNode, id, serverThread, configuration.myLegalName, database).start().getOrThrow()
|
||||
}
|
||||
|
||||
override fun makeIdentityService() = MockIdentityService(mockNet.identities)
|
||||
@ -203,7 +200,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
||||
if (start) {
|
||||
node.setup().start()
|
||||
if (threadPerNode && networkMapAddress != null)
|
||||
node.networkMapRegistrationFuture.get() // Block and wait for the node to register in the net map.
|
||||
node.networkMapRegistrationFuture.getOrThrow() // Block and wait for the node to register in the net map.
|
||||
}
|
||||
_nodes.add(node)
|
||||
return node
|
||||
|
Loading…
x
Reference in New Issue
Block a user