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