mirror of
https://github.com/corda/corda.git
synced 2025-06-18 15:18:16 +00:00
Introducing Future.getOrThrow() which throws the cause of the ExecutionException
This commit is contained in:
@ -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() {
|
||||
|
Reference in New Issue
Block a user