mirror of
https://github.com/corda/corda.git
synced 2025-06-21 16:49:45 +00:00
Rename net to network (#773)
* So net no longer interferes with IntelliJ auto-import of net.* packages * Use mockNet for MockNetwork to avoid clashing with Node network
This commit is contained in:
@ -13,28 +13,28 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
|||||||
|
|
||||||
public class FlowsInJavaTest {
|
public class FlowsInJavaTest {
|
||||||
|
|
||||||
private final MockNetwork net = new MockNetwork();
|
private final MockNetwork mockNet = new MockNetwork();
|
||||||
private MockNetwork.MockNode node1;
|
private MockNetwork.MockNode node1;
|
||||||
private MockNetwork.MockNode node2;
|
private MockNetwork.MockNode node2;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockNetwork.BasketOfNodes someNodes = net.createSomeNodes(2);
|
MockNetwork.BasketOfNodes someNodes = mockNet.createSomeNodes(2);
|
||||||
node1 = someNodes.getPartyNodes().get(0);
|
node1 = someNodes.getPartyNodes().get(0);
|
||||||
node2 = someNodes.getPartyNodes().get(1);
|
node2 = someNodes.getPartyNodes().get(1);
|
||||||
net.runNetwork();
|
mockNet.runNetwork();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
net.stopNodes();
|
mockNet.stopNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void suspendableActionInsideUnwrap() throws Exception {
|
public void suspendableActionInsideUnwrap() throws Exception {
|
||||||
node2.registerInitiatedFlow(SendHelloAndThenReceive.class);
|
node2.registerInitiatedFlow(SendHelloAndThenReceive.class);
|
||||||
Future<String> result = node1.getServices().startFlow(new SendInUnwrapFlow(node2.getInfo().getLegalIdentity())).getResultFuture();
|
Future<String> result = node1.getServices().startFlow(new SendInUnwrapFlow(node2.getInfo().getLegalIdentity())).getResultFuture();
|
||||||
net.runNetwork();
|
mockNet.runNetwork();
|
||||||
assertThat(result.get()).isEqualTo("Hello");
|
assertThat(result.get()).isEqualTo("Hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,24 +28,24 @@ import kotlin.test.assertNotNull
|
|||||||
import kotlin.test.assertNull
|
import kotlin.test.assertNull
|
||||||
|
|
||||||
class ResolveTransactionsFlowTest {
|
class ResolveTransactionsFlowTest {
|
||||||
lateinit var net: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
lateinit var a: MockNetwork.MockNode
|
lateinit var a: MockNetwork.MockNode
|
||||||
lateinit var b: MockNetwork.MockNode
|
lateinit var b: MockNetwork.MockNode
|
||||||
lateinit var notary: Party
|
lateinit var notary: Party
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
net = MockNetwork()
|
mockNet = MockNetwork()
|
||||||
val nodes = net.createSomeNodes()
|
val nodes = mockNet.createSomeNodes()
|
||||||
a = nodes.partyNodes[0]
|
a = nodes.partyNodes[0]
|
||||||
b = nodes.partyNodes[1]
|
b = nodes.partyNodes[1]
|
||||||
notary = nodes.notaryNode.info.notaryIdentity
|
notary = nodes.notaryNode.info.notaryIdentity
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
fun tearDown() {
|
fun tearDown() {
|
||||||
net.stopNodes()
|
mockNet.stopNodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
// DOCSTART 1
|
// DOCSTART 1
|
||||||
@ -54,7 +54,7 @@ class ResolveTransactionsFlowTest {
|
|||||||
val (stx1, stx2) = makeTransactions()
|
val (stx1, stx2) = makeTransactions()
|
||||||
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()
|
mockNet.runNetwork()
|
||||||
val results = future.getOrThrow()
|
val results = future.getOrThrow()
|
||||||
assertEquals(listOf(stx1.id, stx2.id), results.map { it.id })
|
assertEquals(listOf(stx1.id, stx2.id), results.map { it.id })
|
||||||
b.database.transaction {
|
b.database.transaction {
|
||||||
@ -69,7 +69,7 @@ class ResolveTransactionsFlowTest {
|
|||||||
val stx = makeTransactions(signFirstTX = false).second
|
val stx = makeTransactions(signFirstTX = false).second
|
||||||
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()
|
mockNet.runNetwork()
|
||||||
assertFailsWith(SignatureException::class) { future.getOrThrow() }
|
assertFailsWith(SignatureException::class) { future.getOrThrow() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ class ResolveTransactionsFlowTest {
|
|||||||
val (stx1, stx2) = makeTransactions()
|
val (stx1, stx2) = makeTransactions()
|
||||||
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()
|
mockNet.runNetwork()
|
||||||
future.getOrThrow()
|
future.getOrThrow()
|
||||||
b.database.transaction {
|
b.database.transaction {
|
||||||
assertEquals(stx1, b.storage.validatedTransactions.getTransaction(stx1.id))
|
assertEquals(stx1, b.storage.validatedTransactions.getTransaction(stx1.id))
|
||||||
@ -105,7 +105,7 @@ class ResolveTransactionsFlowTest {
|
|||||||
val p = ResolveTransactionsFlow(setOf(cursor.id), a.info.legalIdentity)
|
val p = ResolveTransactionsFlow(setOf(cursor.id), a.info.legalIdentity)
|
||||||
p.transactionCountLimit = 40
|
p.transactionCountLimit = 40
|
||||||
val future = b.services.startFlow(p).resultFuture
|
val future = b.services.startFlow(p).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertFailsWith<ResolveTransactionsFlow.ExcessivelyLargeTransactionGraph> { future.getOrThrow() }
|
assertFailsWith<ResolveTransactionsFlow.ExcessivelyLargeTransactionGraph> { future.getOrThrow() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +131,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()
|
mockNet.runNetwork()
|
||||||
future.getOrThrow()
|
future.getOrThrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ class ResolveTransactionsFlowTest {
|
|||||||
val stx2 = makeTransactions(withAttachment = id).second
|
val stx2 = makeTransactions(withAttachment = id).second
|
||||||
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()
|
mockNet.runNetwork()
|
||||||
future.getOrThrow()
|
future.getOrThrow()
|
||||||
|
|
||||||
// TODO: this operation should not require an explicit transaction
|
// TODO: this operation should not require an explicit transaction
|
||||||
|
@ -13,22 +13,22 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertNotEquals
|
import kotlin.test.assertNotEquals
|
||||||
|
|
||||||
class TxKeyFlowTests {
|
class TxKeyFlowTests {
|
||||||
lateinit var net: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun before() {
|
fun before() {
|
||||||
net = MockNetwork(false)
|
mockNet = MockNetwork(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `issue key`() {
|
fun `issue key`() {
|
||||||
// We run this in parallel threads to help catch any race conditions that may exist.
|
// We run this in parallel threads to help catch any race conditions that may exist.
|
||||||
net = MockNetwork(false, true)
|
mockNet = MockNetwork(false, true)
|
||||||
|
|
||||||
// Set up values we'll need
|
// Set up values we'll need
|
||||||
val notaryNode = net.createNotaryNode(null, DUMMY_NOTARY.name)
|
val notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
|
||||||
val aliceNode = net.createPartyNode(notaryNode.info.address, ALICE.name)
|
val aliceNode = mockNet.createPartyNode(notaryNode.info.address, ALICE.name)
|
||||||
val bobNode = net.createPartyNode(notaryNode.info.address, BOB.name)
|
val bobNode = mockNet.createPartyNode(notaryNode.info.address, BOB.name)
|
||||||
val alice: Party = aliceNode.services.myInfo.legalIdentity
|
val alice: Party = aliceNode.services.myInfo.legalIdentity
|
||||||
val bob: Party = bobNode.services.myInfo.legalIdentity
|
val bob: Party = bobNode.services.myInfo.legalIdentity
|
||||||
aliceNode.services.identityService.registerIdentity(bobNode.info.legalIdentityAndCert)
|
aliceNode.services.identityService.registerIdentity(bobNode.info.legalIdentityAndCert)
|
||||||
|
@ -61,22 +61,22 @@ private fun NodeAttachmentService.updateAttachment(attachmentId: SecureHash, dat
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AttachmentSerializationTest {
|
class AttachmentSerializationTest {
|
||||||
private lateinit var network: MockNetwork
|
private lateinit var mockNet: MockNetwork
|
||||||
private lateinit var server: MockNetwork.MockNode
|
private lateinit var server: MockNetwork.MockNode
|
||||||
private lateinit var client: MockNetwork.MockNode
|
private lateinit var client: MockNetwork.MockNode
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
network = MockNetwork()
|
mockNet = MockNetwork()
|
||||||
server = network.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
|
server = mockNet.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
|
||||||
client = network.createNode(server.info.address)
|
client = mockNet.createNode(server.info.address)
|
||||||
client.disableDBCloseOnStop() // Otherwise the in-memory database may disappear (taking the checkpoint with it) while we reboot the client.
|
client.disableDBCloseOnStop() // Otherwise the in-memory database may disappear (taking the checkpoint with it) while we reboot the client.
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
fun tearDown() {
|
fun tearDown() {
|
||||||
network.stopNodes()
|
mockNet.stopNodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ServerLogic(private val client: Party) : FlowLogic<Unit>() {
|
private class ServerLogic(private val client: Party) : FlowLogic<Unit>() {
|
||||||
@ -144,12 +144,12 @@ class AttachmentSerializationTest {
|
|||||||
}
|
}
|
||||||
}, ServerLogic::class.java, track = false)
|
}, ServerLogic::class.java, track = false)
|
||||||
client.services.startFlow(clientLogic)
|
client.services.startFlow(clientLogic)
|
||||||
network.runNetwork(rounds)
|
mockNet.runNetwork(rounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun rebootClientAndGetAttachmentContent(checkAttachmentsOnLoad: Boolean = true): String {
|
private fun rebootClientAndGetAttachmentContent(checkAttachmentsOnLoad: Boolean = true): String {
|
||||||
client.stop()
|
client.stop()
|
||||||
client = network.createNode(server.info.address, client.id, object : MockNetwork.Factory {
|
client = mockNet.createNode(server.info.address, client.id, object : MockNetwork.Factory {
|
||||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?, advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?, entropyRoot: BigInteger): MockNetwork.MockNode {
|
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?, advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?, entropyRoot: BigInteger): MockNetwork.MockNode {
|
||||||
return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {
|
return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {
|
||||||
override fun startMessagingService(rpcOps: RPCOps) {
|
override fun startMessagingService(rpcOps: RPCOps) {
|
||||||
@ -159,7 +159,7 @@ class AttachmentSerializationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return (client.smm.allStateMachines[0].stateMachine.resultFuture.apply { network.runNetwork() }.getOrThrow() as ClientResult).attachmentContent
|
return (client.smm.allStateMachines[0].stateMachine.resultFuture.apply { mockNet.runNetwork() }.getOrThrow() as ClientResult).attachmentContent
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -18,28 +18,28 @@ import org.junit.Test
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class FxTransactionBuildTutorialTest {
|
class FxTransactionBuildTutorialTest {
|
||||||
lateinit var net: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
lateinit var notaryNode: MockNetwork.MockNode
|
lateinit var notaryNode: MockNetwork.MockNode
|
||||||
lateinit var nodeA: MockNetwork.MockNode
|
lateinit var nodeA: MockNetwork.MockNode
|
||||||
lateinit var nodeB: MockNetwork.MockNode
|
lateinit var nodeB: MockNetwork.MockNode
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
net = MockNetwork(threadPerNode = true)
|
mockNet = MockNetwork(threadPerNode = true)
|
||||||
val notaryService = ServiceInfo(ValidatingNotaryService.type)
|
val notaryService = ServiceInfo(ValidatingNotaryService.type)
|
||||||
notaryNode = net.createNode(
|
notaryNode = mockNet.createNode(
|
||||||
legalName = DUMMY_NOTARY.name,
|
legalName = DUMMY_NOTARY.name,
|
||||||
overrideServices = mapOf(notaryService to DUMMY_NOTARY_KEY),
|
overrideServices = mapOf(notaryService to DUMMY_NOTARY_KEY),
|
||||||
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), notaryService))
|
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), notaryService))
|
||||||
nodeA = net.createPartyNode(notaryNode.info.address)
|
nodeA = mockNet.createPartyNode(notaryNode.info.address)
|
||||||
nodeB = net.createPartyNode(notaryNode.info.address)
|
nodeB = mockNet.createPartyNode(notaryNode.info.address)
|
||||||
nodeB.registerInitiatedFlow(ForeignExchangeRemoteFlow::class.java)
|
nodeB.registerInitiatedFlow(ForeignExchangeRemoteFlow::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
fun cleanUp() {
|
fun cleanUp() {
|
||||||
println("Close DB")
|
println("Close DB")
|
||||||
net.stopNodes()
|
mockNet.stopNodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -20,7 +20,7 @@ import org.junit.Test
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class WorkflowTransactionBuildTutorialTest {
|
class WorkflowTransactionBuildTutorialTest {
|
||||||
lateinit var net: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
lateinit var notaryNode: MockNetwork.MockNode
|
lateinit var notaryNode: MockNetwork.MockNode
|
||||||
lateinit var nodeA: MockNetwork.MockNode
|
lateinit var nodeA: MockNetwork.MockNode
|
||||||
lateinit var nodeB: MockNetwork.MockNode
|
lateinit var nodeB: MockNetwork.MockNode
|
||||||
@ -34,21 +34,21 @@ class WorkflowTransactionBuildTutorialTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
net = MockNetwork(threadPerNode = true)
|
mockNet = MockNetwork(threadPerNode = true)
|
||||||
val notaryService = ServiceInfo(ValidatingNotaryService.type)
|
val notaryService = ServiceInfo(ValidatingNotaryService.type)
|
||||||
notaryNode = net.createNode(
|
notaryNode = mockNet.createNode(
|
||||||
legalName = DUMMY_NOTARY.name,
|
legalName = DUMMY_NOTARY.name,
|
||||||
overrideServices = mapOf(Pair(notaryService, DUMMY_NOTARY_KEY)),
|
overrideServices = mapOf(Pair(notaryService, DUMMY_NOTARY_KEY)),
|
||||||
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), notaryService))
|
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), notaryService))
|
||||||
nodeA = net.createPartyNode(notaryNode.info.address)
|
nodeA = mockNet.createPartyNode(notaryNode.info.address)
|
||||||
nodeB = net.createPartyNode(notaryNode.info.address)
|
nodeB = mockNet.createPartyNode(notaryNode.info.address)
|
||||||
nodeA.registerInitiatedFlow(RecordCompletionFlow::class.java)
|
nodeA.registerInitiatedFlow(RecordCompletionFlow::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
fun cleanUp() {
|
fun cleanUp() {
|
||||||
println("Close DB")
|
println("Close DB")
|
||||||
net.stopNodes()
|
mockNet.stopNodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -20,24 +20,24 @@ with this basic skeleton:
|
|||||||
.. sourcecode:: kotlin
|
.. sourcecode:: kotlin
|
||||||
|
|
||||||
class ResolveTransactionsFlowTest {
|
class ResolveTransactionsFlowTest {
|
||||||
lateinit var net: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
lateinit var a: MockNetwork.MockNode
|
lateinit var a: MockNetwork.MockNode
|
||||||
lateinit var b: MockNetwork.MockNode
|
lateinit var b: MockNetwork.MockNode
|
||||||
lateinit var notary: Party
|
lateinit var notary: Party
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
net = MockNetwork()
|
mockNet = MockNetwork()
|
||||||
val nodes = net.createSomeNodes()
|
val nodes = mockNet.createSomeNodes()
|
||||||
a = nodes.partyNodes[0]
|
a = nodes.partyNodes[0]
|
||||||
b = nodes.partyNodes[1]
|
b = nodes.partyNodes[1]
|
||||||
notary = nodes.notaryNode.info.notaryIdentity
|
notary = nodes.notaryNode.info.notaryIdentity
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
fun tearDown() {
|
fun tearDown() {
|
||||||
net.stopNodes()
|
mockNet.stopNodes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ We'll take a look at the ``makeTransactions`` function in a moment. For now, it'
|
|||||||
but not node B.
|
but not node B.
|
||||||
|
|
||||||
The test logic is simple enough: we create the flow, giving it node A's identity as the target to talk to.
|
The test logic is simple enough: we create the flow, giving it node A's identity as the target to talk to.
|
||||||
Then we start it on node B and use the ``net.runNetwork()`` method to bounce messages around until things have
|
Then we start it on node B and use the ``mockNet.runNetwork()`` method to bounce messages around until things have
|
||||||
settled (i.e. there are no more messages waiting to be delivered). All this is done using an in memory message
|
settled (i.e. there are no more messages waiting to be delivered). All this is done using an in memory message
|
||||||
routing implementation that is fast to initialise and use. Finally, we obtain the result of the flow and do
|
routing implementation that is fast to initialise and use. Finally, we obtain the result of the flow and do
|
||||||
some tests on it. We also check the contents of node B's database to see that the flow had the intended effect
|
some tests on it. We also check the contents of node B's database to see that the flow had the intended effect
|
||||||
|
@ -16,7 +16,7 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
class CashExitFlowTests {
|
class CashExitFlowTests {
|
||||||
private val net = MockNetwork(servicePeerAllocationStrategy = RoundRobin())
|
private val mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin())
|
||||||
private val initialBalance = 2000.DOLLARS
|
private val initialBalance = 2000.DOLLARS
|
||||||
private val ref = OpaqueBytes.of(0x01)
|
private val ref = OpaqueBytes.of(0x01)
|
||||||
private lateinit var bankOfCordaNode: MockNode
|
private lateinit var bankOfCordaNode: MockNode
|
||||||
@ -26,23 +26,23 @@ class CashExitFlowTests {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun start() {
|
fun start() {
|
||||||
val nodes = net.createTwoNodes()
|
val nodes = mockNet.createTwoNodes()
|
||||||
notaryNode = nodes.first
|
notaryNode = nodes.first
|
||||||
bankOfCordaNode = nodes.second
|
bankOfCordaNode = nodes.second
|
||||||
notary = notaryNode.info.notaryIdentity
|
notary = notaryNode.info.notaryIdentity
|
||||||
bankOfCorda = bankOfCordaNode.info.legalIdentity
|
bankOfCorda = bankOfCordaNode.info.legalIdentity
|
||||||
|
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
val future = bankOfCordaNode.services.startFlow(CashIssueFlow(initialBalance, ref,
|
val future = bankOfCordaNode.services.startFlow(CashIssueFlow(initialBalance, ref,
|
||||||
bankOfCorda,
|
bankOfCorda,
|
||||||
notary)).resultFuture
|
notary)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
future.getOrThrow()
|
future.getOrThrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
fun cleanUp() {
|
fun cleanUp() {
|
||||||
net.stopNodes()
|
mockNet.stopNodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -50,7 +50,7 @@ class CashExitFlowTests {
|
|||||||
val exitAmount = 500.DOLLARS
|
val exitAmount = 500.DOLLARS
|
||||||
val future = bankOfCordaNode.services.startFlow(CashExitFlow(exitAmount,
|
val future = bankOfCordaNode.services.startFlow(CashExitFlow(exitAmount,
|
||||||
ref)).resultFuture
|
ref)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
val exitTx = future.getOrThrow().tx
|
val exitTx = future.getOrThrow().tx
|
||||||
val expected = (initialBalance - exitAmount).`issued by`(bankOfCorda.ref(ref))
|
val expected = (initialBalance - exitAmount).`issued by`(bankOfCorda.ref(ref))
|
||||||
assertEquals(1, exitTx.inputs.size)
|
assertEquals(1, exitTx.inputs.size)
|
||||||
@ -64,7 +64,7 @@ class CashExitFlowTests {
|
|||||||
val expected = 0.DOLLARS
|
val expected = 0.DOLLARS
|
||||||
val future = bankOfCordaNode.services.startFlow(CashExitFlow(expected,
|
val future = bankOfCordaNode.services.startFlow(CashExitFlow(expected,
|
||||||
ref)).resultFuture
|
ref)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertFailsWith<CashException> {
|
assertFailsWith<CashException> {
|
||||||
future.getOrThrow()
|
future.getOrThrow()
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
class CashIssueFlowTests {
|
class CashIssueFlowTests {
|
||||||
private val net = MockNetwork(servicePeerAllocationStrategy = RoundRobin())
|
private val mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin())
|
||||||
private lateinit var bankOfCordaNode: MockNode
|
private lateinit var bankOfCordaNode: MockNode
|
||||||
private lateinit var bankOfCorda: Party
|
private lateinit var bankOfCorda: Party
|
||||||
private lateinit var notaryNode: MockNode
|
private lateinit var notaryNode: MockNode
|
||||||
@ -24,18 +24,18 @@ class CashIssueFlowTests {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun start() {
|
fun start() {
|
||||||
val nodes = net.createTwoNodes()
|
val nodes = mockNet.createTwoNodes()
|
||||||
notaryNode = nodes.first
|
notaryNode = nodes.first
|
||||||
bankOfCordaNode = nodes.second
|
bankOfCordaNode = nodes.second
|
||||||
notary = notaryNode.info.notaryIdentity
|
notary = notaryNode.info.notaryIdentity
|
||||||
bankOfCorda = bankOfCordaNode.info.legalIdentity
|
bankOfCorda = bankOfCordaNode.info.legalIdentity
|
||||||
|
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
fun cleanUp() {
|
fun cleanUp() {
|
||||||
net.stopNodes()
|
mockNet.stopNodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -45,7 +45,7 @@ class CashIssueFlowTests {
|
|||||||
val future = bankOfCordaNode.services.startFlow(CashIssueFlow(expected, ref,
|
val future = bankOfCordaNode.services.startFlow(CashIssueFlow(expected, ref,
|
||||||
bankOfCorda,
|
bankOfCorda,
|
||||||
notary)).resultFuture
|
notary)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
val issueTx = future.getOrThrow()
|
val issueTx = future.getOrThrow()
|
||||||
val output = issueTx.tx.outputs.single().data as Cash.State
|
val output = issueTx.tx.outputs.single().data as Cash.State
|
||||||
assertEquals(expected.`issued by`(bankOfCorda.ref(ref)), output.amount)
|
assertEquals(expected.`issued by`(bankOfCorda.ref(ref)), output.amount)
|
||||||
@ -57,7 +57,7 @@ class CashIssueFlowTests {
|
|||||||
val future = bankOfCordaNode.services.startFlow(CashIssueFlow(expected, OpaqueBytes.of(0x01),
|
val future = bankOfCordaNode.services.startFlow(CashIssueFlow(expected, OpaqueBytes.of(0x01),
|
||||||
bankOfCorda,
|
bankOfCorda,
|
||||||
notary)).resultFuture
|
notary)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertFailsWith<IllegalArgumentException> {
|
assertFailsWith<IllegalArgumentException> {
|
||||||
future.getOrThrow()
|
future.getOrThrow()
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
class CashPaymentFlowTests {
|
class CashPaymentFlowTests {
|
||||||
private val net = MockNetwork(servicePeerAllocationStrategy = RoundRobin())
|
private val mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin())
|
||||||
private val initialBalance = 2000.DOLLARS
|
private val initialBalance = 2000.DOLLARS
|
||||||
private val ref = OpaqueBytes.of(0x01)
|
private val ref = OpaqueBytes.of(0x01)
|
||||||
private lateinit var bankOfCordaNode: MockNode
|
private lateinit var bankOfCordaNode: MockNode
|
||||||
@ -26,23 +26,23 @@ class CashPaymentFlowTests {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun start() {
|
fun start() {
|
||||||
val nodes = net.createTwoNodes()
|
val nodes = mockNet.createTwoNodes()
|
||||||
notaryNode = nodes.first
|
notaryNode = nodes.first
|
||||||
bankOfCordaNode = nodes.second
|
bankOfCordaNode = nodes.second
|
||||||
notary = notaryNode.info.notaryIdentity
|
notary = notaryNode.info.notaryIdentity
|
||||||
bankOfCorda = bankOfCordaNode.info.legalIdentity
|
bankOfCorda = bankOfCordaNode.info.legalIdentity
|
||||||
|
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
val future = bankOfCordaNode.services.startFlow(CashIssueFlow(initialBalance, ref,
|
val future = bankOfCordaNode.services.startFlow(CashIssueFlow(initialBalance, ref,
|
||||||
bankOfCorda,
|
bankOfCorda,
|
||||||
notary)).resultFuture
|
notary)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
future.getOrThrow()
|
future.getOrThrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
fun cleanUp() {
|
fun cleanUp() {
|
||||||
net.stopNodes()
|
mockNet.stopNodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -51,7 +51,7 @@ class CashPaymentFlowTests {
|
|||||||
val expected = 500.DOLLARS
|
val expected = 500.DOLLARS
|
||||||
val future = bankOfCordaNode.services.startFlow(CashPaymentFlow(expected,
|
val future = bankOfCordaNode.services.startFlow(CashPaymentFlow(expected,
|
||||||
payTo)).resultFuture
|
payTo)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
val paymentTx = future.getOrThrow()
|
val paymentTx = future.getOrThrow()
|
||||||
val states = paymentTx.tx.outputs.map { it.data }.filterIsInstance<Cash.State>()
|
val states = paymentTx.tx.outputs.map { it.data }.filterIsInstance<Cash.State>()
|
||||||
val ourState = states.single { it.owner.owningKey != payTo.owningKey }
|
val ourState = states.single { it.owner.owningKey != payTo.owningKey }
|
||||||
@ -65,7 +65,7 @@ class CashPaymentFlowTests {
|
|||||||
val expected = 4000.DOLLARS
|
val expected = 4000.DOLLARS
|
||||||
val future = bankOfCordaNode.services.startFlow(CashPaymentFlow(expected,
|
val future = bankOfCordaNode.services.startFlow(CashPaymentFlow(expected,
|
||||||
payTo)).resultFuture
|
payTo)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertFailsWith<CashException> {
|
assertFailsWith<CashException> {
|
||||||
future.getOrThrow()
|
future.getOrThrow()
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ class CashPaymentFlowTests {
|
|||||||
val expected = 0.DOLLARS
|
val expected = 0.DOLLARS
|
||||||
val future = bankOfCordaNode.services.startFlow(CashPaymentFlow(expected,
|
val future = bankOfCordaNode.services.startFlow(CashPaymentFlow(expected,
|
||||||
payTo)).resultFuture
|
payTo)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertFailsWith<IllegalArgumentException> {
|
assertFailsWith<IllegalArgumentException> {
|
||||||
future.getOrThrow()
|
future.getOrThrow()
|
||||||
}
|
}
|
||||||
|
@ -27,18 +27,18 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
class IssuerFlowTest {
|
class IssuerFlowTest {
|
||||||
lateinit var net: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
lateinit var notaryNode: MockNode
|
lateinit var notaryNode: MockNode
|
||||||
lateinit var bankOfCordaNode: MockNode
|
lateinit var bankOfCordaNode: MockNode
|
||||||
lateinit var bankClientNode: MockNode
|
lateinit var bankClientNode: MockNode
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test issuer flow`() {
|
fun `test issuer flow`() {
|
||||||
net = MockNetwork(false, true)
|
mockNet = MockNetwork(false, true)
|
||||||
ledger {
|
ledger {
|
||||||
notaryNode = net.createNotaryNode(null, DUMMY_NOTARY.name)
|
notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
|
||||||
bankOfCordaNode = net.createPartyNode(notaryNode.info.address, BOC.name)
|
bankOfCordaNode = mockNet.createPartyNode(notaryNode.info.address, BOC.name)
|
||||||
bankClientNode = net.createPartyNode(notaryNode.info.address, MEGA_CORP.name)
|
bankClientNode = mockNet.createPartyNode(notaryNode.info.address, MEGA_CORP.name)
|
||||||
|
|
||||||
// using default IssueTo Party Reference
|
// using default IssueTo Party Reference
|
||||||
val (issuer, issuerResult) = runIssuerAndIssueRequester(bankOfCordaNode, bankClientNode, 1000000.DOLLARS,
|
val (issuer, issuerResult) = runIssuerAndIssueRequester(bankOfCordaNode, bankClientNode, 1000000.DOLLARS,
|
||||||
@ -58,10 +58,10 @@ class IssuerFlowTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test issue flow to self`() {
|
fun `test issue flow to self`() {
|
||||||
net = MockNetwork(false, true)
|
mockNet = MockNetwork(false, true)
|
||||||
ledger {
|
ledger {
|
||||||
notaryNode = net.createNotaryNode(null, DUMMY_NOTARY.name)
|
notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
|
||||||
bankOfCordaNode = net.createPartyNode(notaryNode.info.address, BOC.name)
|
bankOfCordaNode = mockNet.createPartyNode(notaryNode.info.address, BOC.name)
|
||||||
|
|
||||||
// using default IssueTo Party Reference
|
// using default IssueTo Party Reference
|
||||||
val (issuer, issuerResult) = runIssuerAndIssueRequester(bankOfCordaNode, bankOfCordaNode, 1000000.DOLLARS,
|
val (issuer, issuerResult) = runIssuerAndIssueRequester(bankOfCordaNode, bankOfCordaNode, 1000000.DOLLARS,
|
||||||
@ -74,11 +74,11 @@ class IssuerFlowTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test concurrent issuer flow`() {
|
fun `test concurrent issuer flow`() {
|
||||||
net = MockNetwork(false, true)
|
mockNet = MockNetwork(false, true)
|
||||||
ledger {
|
ledger {
|
||||||
notaryNode = net.createNotaryNode(null, DUMMY_NOTARY.name)
|
notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
|
||||||
bankOfCordaNode = net.createPartyNode(notaryNode.info.address, BOC.name)
|
bankOfCordaNode = mockNet.createPartyNode(notaryNode.info.address, BOC.name)
|
||||||
bankClientNode = net.createPartyNode(notaryNode.info.address, MEGA_CORP.name)
|
bankClientNode = mockNet.createPartyNode(notaryNode.info.address, MEGA_CORP.name)
|
||||||
|
|
||||||
// this test exercises the Cashflow issue and move subflows to ensure consistent spending of issued states
|
// this test exercises the Cashflow issue and move subflows to ensure consistent spending of issued states
|
||||||
val amount = 10000.DOLLARS
|
val amount = 10000.DOLLARS
|
||||||
|
@ -53,7 +53,7 @@ class P2PMessagingTest : NodeBasedTest() {
|
|||||||
networkMapNode.respondWith("Hello")
|
networkMapNode.respondWith("Hello")
|
||||||
val alice = startNode(ALICE.name).getOrThrow()
|
val alice = startNode(ALICE.name).getOrThrow()
|
||||||
val serviceAddress = alice.services.networkMapCache.run {
|
val serviceAddress = alice.services.networkMapCache.run {
|
||||||
alice.net.getAddressOfParty(getPartyInfo(getAnyNotary()!!)!!)
|
alice.network.getAddressOfParty(getPartyInfo(getAnyNotary()!!)!!)
|
||||||
}
|
}
|
||||||
val received = alice.receiveFrom(serviceAddress).getOrThrow(10.seconds)
|
val received = alice.receiveFrom(serviceAddress).getOrThrow(10.seconds)
|
||||||
assertThat(received).isEqualTo("Hello")
|
assertThat(received).isEqualTo("Hello")
|
||||||
@ -98,7 +98,7 @@ class P2PMessagingTest : NodeBasedTest() {
|
|||||||
val distributedServiceNodes = startNotaryCluster(DISTRIBUTED_SERVICE_NAME, 2).getOrThrow()
|
val distributedServiceNodes = startNotaryCluster(DISTRIBUTED_SERVICE_NAME, 2).getOrThrow()
|
||||||
val alice = startNode(ALICE.name, configOverrides = mapOf("messageRedeliveryDelaySeconds" to 1)).getOrThrow()
|
val alice = startNode(ALICE.name, configOverrides = mapOf("messageRedeliveryDelaySeconds" to 1)).getOrThrow()
|
||||||
val serviceAddress = alice.services.networkMapCache.run {
|
val serviceAddress = alice.services.networkMapCache.run {
|
||||||
alice.net.getAddressOfParty(getPartyInfo(getAnyNotary()!!)!!)
|
alice.network.getAddressOfParty(getPartyInfo(getAnyNotary()!!)!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
val dummyTopic = "dummy.topic"
|
val dummyTopic = "dummy.topic"
|
||||||
@ -107,7 +107,7 @@ class P2PMessagingTest : NodeBasedTest() {
|
|||||||
simulateCrashingNode(distributedServiceNodes, dummyTopic, responseMessage)
|
simulateCrashingNode(distributedServiceNodes, dummyTopic, responseMessage)
|
||||||
|
|
||||||
// Send a single request with retry
|
// Send a single request with retry
|
||||||
val response = with(alice.net) {
|
val response = with(alice.network) {
|
||||||
val request = TestRequest(replyTo = myAddress)
|
val request = TestRequest(replyTo = myAddress)
|
||||||
val responseFuture = onNext<Any>(dummyTopic, request.sessionID)
|
val responseFuture = onNext<Any>(dummyTopic, request.sessionID)
|
||||||
val msg = createMessage(TopicSession(dummyTopic), data = request.serialize().bytes)
|
val msg = createMessage(TopicSession(dummyTopic), data = request.serialize().bytes)
|
||||||
@ -123,7 +123,7 @@ class P2PMessagingTest : NodeBasedTest() {
|
|||||||
val distributedServiceNodes = startNotaryCluster(DISTRIBUTED_SERVICE_NAME, 2).getOrThrow()
|
val distributedServiceNodes = startNotaryCluster(DISTRIBUTED_SERVICE_NAME, 2).getOrThrow()
|
||||||
val alice = startNode(ALICE.name, configOverrides = mapOf("messageRedeliveryDelaySeconds" to 1)).getOrThrow()
|
val alice = startNode(ALICE.name, configOverrides = mapOf("messageRedeliveryDelaySeconds" to 1)).getOrThrow()
|
||||||
val serviceAddress = alice.services.networkMapCache.run {
|
val serviceAddress = alice.services.networkMapCache.run {
|
||||||
alice.net.getAddressOfParty(getPartyInfo(getAnyNotary()!!)!!)
|
alice.network.getAddressOfParty(getPartyInfo(getAnyNotary()!!)!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
val dummyTopic = "dummy.topic"
|
val dummyTopic = "dummy.topic"
|
||||||
@ -134,7 +134,7 @@ class P2PMessagingTest : NodeBasedTest() {
|
|||||||
val sessionId = random63BitValue()
|
val sessionId = random63BitValue()
|
||||||
|
|
||||||
// Send a single request with retry
|
// Send a single request with retry
|
||||||
with(alice.net) {
|
with(alice.network) {
|
||||||
val request = TestRequest(sessionId, myAddress)
|
val request = TestRequest(sessionId, myAddress)
|
||||||
val msg = createMessage(TopicSession(dummyTopic), data = request.serialize().bytes)
|
val msg = createMessage(TopicSession(dummyTopic), data = request.serialize().bytes)
|
||||||
send(msg, serviceAddress, retryId = request.sessionID)
|
send(msg, serviceAddress, retryId = request.sessionID)
|
||||||
@ -148,7 +148,7 @@ class P2PMessagingTest : NodeBasedTest() {
|
|||||||
|
|
||||||
// Restart the node and expect a response
|
// Restart the node and expect a response
|
||||||
val aliceRestarted = startNode(ALICE.name, configOverrides = mapOf("messageRedeliveryDelaySeconds" to 1)).getOrThrow()
|
val aliceRestarted = startNode(ALICE.name, configOverrides = mapOf("messageRedeliveryDelaySeconds" to 1)).getOrThrow()
|
||||||
val response = aliceRestarted.net.onNext<Any>(dummyTopic, sessionId).getOrThrow(5.seconds)
|
val response = aliceRestarted.network.onNext<Any>(dummyTopic, sessionId).getOrThrow(5.seconds)
|
||||||
|
|
||||||
assertThat(requestsReceived.get()).isGreaterThanOrEqualTo(2)
|
assertThat(requestsReceived.get()).isGreaterThanOrEqualTo(2)
|
||||||
assertThat(response).isEqualTo(responseMessage)
|
assertThat(response).isEqualTo(responseMessage)
|
||||||
@ -166,7 +166,7 @@ class P2PMessagingTest : NodeBasedTest() {
|
|||||||
distributedServiceNodes.forEach {
|
distributedServiceNodes.forEach {
|
||||||
val nodeName = it.info.legalIdentity.name
|
val nodeName = it.info.legalIdentity.name
|
||||||
var ignoreRequests = false
|
var ignoreRequests = false
|
||||||
it.net.addMessageHandler(dummyTopic, DEFAULT_SESSION_ID) { netMessage, _ ->
|
it.network.addMessageHandler(dummyTopic, DEFAULT_SESSION_ID) { netMessage, _ ->
|
||||||
requestsReceived.incrementAndGet()
|
requestsReceived.incrementAndGet()
|
||||||
firstRequestReceived.countDown()
|
firstRequestReceived.countDown()
|
||||||
// The node which receives the first request will ignore all requests
|
// The node which receives the first request will ignore all requests
|
||||||
@ -179,8 +179,8 @@ class P2PMessagingTest : NodeBasedTest() {
|
|||||||
} else {
|
} else {
|
||||||
println("sending response")
|
println("sending response")
|
||||||
val request = netMessage.data.deserialize<TestRequest>()
|
val request = netMessage.data.deserialize<TestRequest>()
|
||||||
val response = it.net.createMessage(dummyTopic, request.sessionID, responseMessage.serialize().bytes)
|
val response = it.network.createMessage(dummyTopic, request.sessionID, responseMessage.serialize().bytes)
|
||||||
it.net.send(response, request.replyTo)
|
it.network.send(response, request.replyTo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ class P2PMessagingTest : NodeBasedTest() {
|
|||||||
node.respondWith(node.info)
|
node.respondWith(node.info)
|
||||||
}
|
}
|
||||||
val serviceAddress = originatingNode.services.networkMapCache.run {
|
val serviceAddress = originatingNode.services.networkMapCache.run {
|
||||||
originatingNode.net.getAddressOfParty(getPartyInfo(getNotary(serviceName)!!)!!)
|
originatingNode.network.getAddressOfParty(getPartyInfo(getNotary(serviceName)!!)!!)
|
||||||
}
|
}
|
||||||
val participatingNodes = HashSet<Any>()
|
val participatingNodes = HashSet<Any>()
|
||||||
// Try several times so that we can be fairly sure that any node not participating is not due to Artemis' selection
|
// Try several times so that we can be fairly sure that any node not participating is not due to Artemis' selection
|
||||||
@ -209,16 +209,16 @@ class P2PMessagingTest : NodeBasedTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun Node.respondWith(message: Any) {
|
private fun Node.respondWith(message: Any) {
|
||||||
net.addMessageHandler(javaClass.name, DEFAULT_SESSION_ID) { netMessage, _ ->
|
network.addMessageHandler(javaClass.name, DEFAULT_SESSION_ID) { netMessage, _ ->
|
||||||
val request = netMessage.data.deserialize<TestRequest>()
|
val request = netMessage.data.deserialize<TestRequest>()
|
||||||
val response = net.createMessage(javaClass.name, request.sessionID, message.serialize().bytes)
|
val response = network.createMessage(javaClass.name, request.sessionID, message.serialize().bytes)
|
||||||
net.send(response, request.replyTo)
|
network.send(response, request.replyTo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Node.receiveFrom(target: MessageRecipients): ListenableFuture<Any> {
|
private fun Node.receiveFrom(target: MessageRecipients): ListenableFuture<Any> {
|
||||||
val request = TestRequest(replyTo = net.myAddress)
|
val request = TestRequest(replyTo = network.myAddress)
|
||||||
return net.sendRequest<Any>(javaClass.name, request, target)
|
return network.sendRequest<Any>(javaClass.name, request, target)
|
||||||
}
|
}
|
||||||
|
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
|
@ -69,9 +69,9 @@ class P2PSecurityTest : NodeBasedTest() {
|
|||||||
|
|
||||||
private fun SimpleNode.registerWithNetworkMap(registrationName: X500Name): ListenableFuture<NetworkMapService.RegistrationResponse> {
|
private fun SimpleNode.registerWithNetworkMap(registrationName: X500Name): ListenableFuture<NetworkMapService.RegistrationResponse> {
|
||||||
val legalIdentity = getTestPartyAndCertificate(registrationName, identity.public)
|
val legalIdentity = getTestPartyAndCertificate(registrationName, identity.public)
|
||||||
val nodeInfo = NodeInfo(net.myAddress, legalIdentity, MOCK_VERSION_INFO.platformVersion)
|
val nodeInfo = NodeInfo(network.myAddress, legalIdentity, MOCK_VERSION_INFO.platformVersion)
|
||||||
val registration = NodeRegistration(nodeInfo, System.currentTimeMillis(), AddOrRemove.ADD, Instant.MAX)
|
val registration = NodeRegistration(nodeInfo, System.currentTimeMillis(), AddOrRemove.ADD, Instant.MAX)
|
||||||
val request = RegistrationRequest(registration.toWire(keyService, identity.public), net.myAddress)
|
val request = RegistrationRequest(registration.toWire(keyService, identity.public), network.myAddress)
|
||||||
return net.sendRequest<NetworkMapService.RegistrationResponse>(NetworkMapService.REGISTER_TOPIC, request, networkMapNode.net.myAddress)
|
return network.sendRequest<NetworkMapService.RegistrationResponse>(NetworkMapService.REGISTER_TOPIC, request, networkMapNode.network.myAddress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
|||||||
protected val partyKeys = mutableSetOf<KeyPair>()
|
protected val partyKeys = mutableSetOf<KeyPair>()
|
||||||
|
|
||||||
val services = object : ServiceHubInternal() {
|
val services = object : ServiceHubInternal() {
|
||||||
override val networkService: MessagingService get() = net
|
override val networkService: MessagingService get() = network
|
||||||
override val networkMapCache: NetworkMapCacheInternal get() = netMapCache
|
override val networkMapCache: NetworkMapCacheInternal get() = netMapCache
|
||||||
override val storageService: TxWritableStorageService get() = storage
|
override val storageService: TxWritableStorageService get() = storage
|
||||||
override val vaultService: VaultService get() = vault
|
override val vaultService: VaultService get() = vault
|
||||||
@ -167,7 +167,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
|||||||
var inNodeNetworkMapService: NetworkMapService? = null
|
var inNodeNetworkMapService: NetworkMapService? = null
|
||||||
lateinit var txVerifierService: TransactionVerifierService
|
lateinit var txVerifierService: TransactionVerifierService
|
||||||
lateinit var identity: IdentityService
|
lateinit var identity: IdentityService
|
||||||
lateinit var net: MessagingService
|
lateinit var network: MessagingService
|
||||||
lateinit var netMapCache: NetworkMapCacheInternal
|
lateinit var netMapCache: NetworkMapCacheInternal
|
||||||
lateinit var scheduler: NodeSchedulerService
|
lateinit var scheduler: NodeSchedulerService
|
||||||
lateinit var schemas: SchemaService
|
lateinit var schemas: SchemaService
|
||||||
@ -255,7 +255,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
|||||||
|
|
||||||
initUploaders()
|
initUploaders()
|
||||||
|
|
||||||
runOnStop += Runnable { net.stop() }
|
runOnStop += Runnable { network.stop() }
|
||||||
_networkMapRegistrationFuture.setFuture(registerWithNetworkMapIfConfigured())
|
_networkMapRegistrationFuture.setFuture(registerWithNetworkMapIfConfigured())
|
||||||
smm.start(tokenizableServices)
|
smm.start(tokenizableServices)
|
||||||
// Shut down the SMM so no Fibers are scheduled.
|
// Shut down the SMM so no Fibers are scheduled.
|
||||||
@ -437,7 +437,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
|||||||
storage = storageServices.first
|
storage = storageServices.first
|
||||||
checkpointStorage = storageServices.second
|
checkpointStorage = storageServices.second
|
||||||
netMapCache = InMemoryNetworkMapCache()
|
netMapCache = InMemoryNetworkMapCache()
|
||||||
net = makeMessagingService()
|
network = makeMessagingService()
|
||||||
schemas = makeSchemaService()
|
schemas = makeSchemaService()
|
||||||
vault = makeVaultService(configuration.dataSourceProperties)
|
vault = makeVaultService(configuration.dataSourceProperties)
|
||||||
txVerifierService = makeTransactionVerifierService()
|
txVerifierService = makeTransactionVerifierService()
|
||||||
@ -451,7 +451,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
|||||||
keyManagement = makeKeyManagementService(identity)
|
keyManagement = makeKeyManagementService(identity)
|
||||||
scheduler = NodeSchedulerService(services, database, unfinishedSchedules = busyNodeLatch)
|
scheduler = NodeSchedulerService(services, database, unfinishedSchedules = busyNodeLatch)
|
||||||
|
|
||||||
val tokenizableServices = mutableListOf(storage, net, vault, keyManagement, identity, platformClock, scheduler)
|
val tokenizableServices = mutableListOf(storage, network, vault, keyManagement, identity, platformClock, scheduler)
|
||||||
makeAdvertisedServices(tokenizableServices)
|
makeAdvertisedServices(tokenizableServices)
|
||||||
|
|
||||||
return tokenizableServices
|
return tokenizableServices
|
||||||
@ -523,7 +523,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
|||||||
private fun makeInfo(): NodeInfo {
|
private fun makeInfo(): NodeInfo {
|
||||||
val advertisedServiceEntries = makeServiceEntries()
|
val advertisedServiceEntries = makeServiceEntries()
|
||||||
val legalIdentity = obtainLegalIdentity()
|
val legalIdentity = obtainLegalIdentity()
|
||||||
return NodeInfo(net.myAddress, legalIdentity, platformVersion, advertisedServiceEntries, findMyLocation())
|
return NodeInfo(network.myAddress, legalIdentity, platformVersion, advertisedServiceEntries, findMyLocation())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -617,7 +617,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
|||||||
return sendNetworkMapRegistration(address).flatMap { (error) ->
|
return sendNetworkMapRegistration(address).flatMap { (error) ->
|
||||||
check(error == null) { "Unable to register with the network map service: $error" }
|
check(error == null) { "Unable to register with the network map service: $error" }
|
||||||
// The future returned addMapService will complete on the same executor as sendNetworkMapRegistration, namely the one used by net
|
// The future returned addMapService will complete on the same executor as sendNetworkMapRegistration, namely the one used by net
|
||||||
services.networkMapCache.addMapService(net, address, true, null)
|
services.networkMapCache.addMapService(network, address, true, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -627,8 +627,8 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
|||||||
val expires = instant + NetworkMapService.DEFAULT_EXPIRATION_PERIOD
|
val expires = instant + NetworkMapService.DEFAULT_EXPIRATION_PERIOD
|
||||||
val reg = NodeRegistration(info, instant.toEpochMilli(), ADD, expires)
|
val reg = NodeRegistration(info, instant.toEpochMilli(), ADD, expires)
|
||||||
val legalIdentityKey = obtainLegalIdentityKey()
|
val legalIdentityKey = obtainLegalIdentityKey()
|
||||||
val request = NetworkMapService.RegistrationRequest(reg.toWire(keyManagement, legalIdentityKey.public), net.myAddress)
|
val request = NetworkMapService.RegistrationRequest(reg.toWire(keyManagement, legalIdentityKey.public), network.myAddress)
|
||||||
return net.sendRequest(NetworkMapService.REGISTER_TOPIC, request, networkMapAddress)
|
return network.sendRequest(NetworkMapService.REGISTER_TOPIC, request, networkMapAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This is overriden by the mock node implementation to enable operation without any network map service */
|
/** This is overriden by the mock node implementation to enable operation without any network map service */
|
||||||
|
@ -71,7 +71,7 @@ class Node(override val configuration: FullNodeConfiguration,
|
|||||||
override val log: Logger get() = logger
|
override val log: Logger get() = logger
|
||||||
override val platformVersion: Int get() = versionInfo.platformVersion
|
override val platformVersion: Int get() = versionInfo.platformVersion
|
||||||
override val networkMapAddress: NetworkMapAddress? get() = configuration.networkMapService?.address?.let(::NetworkMapAddress)
|
override val networkMapAddress: NetworkMapAddress? get() = configuration.networkMapService?.address?.let(::NetworkMapAddress)
|
||||||
override fun makeTransactionVerifierService() = (net as NodeMessagingClient).verifierService
|
override fun makeTransactionVerifierService() = (network as NodeMessagingClient).verifierService
|
||||||
|
|
||||||
// DISCUSSION
|
// DISCUSSION
|
||||||
//
|
//
|
||||||
@ -232,8 +232,7 @@ class Node(override val configuration: FullNodeConfiguration,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start up the MQ client.
|
// Start up the MQ client.
|
||||||
val net = net as NodeMessagingClient
|
(network as NodeMessagingClient).start(rpcOps, userService)
|
||||||
net.start(rpcOps, userService)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -321,7 +320,7 @@ class Node(override val configuration: FullNodeConfiguration,
|
|||||||
|
|
||||||
/** Starts a blocking event loop for message dispatch. */
|
/** Starts a blocking event loop for message dispatch. */
|
||||||
fun run() {
|
fun run() {
|
||||||
(net as NodeMessagingClient).run(messageBroker!!.serverControl)
|
(network as NodeMessagingClient).run(messageBroker!!.serverControl)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Do we really need setup?
|
// TODO: Do we really need setup?
|
||||||
|
@ -13,7 +13,7 @@ import javax.annotation.concurrent.ThreadSafe
|
|||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
abstract class AbstractNodeService(val services: ServiceHubInternal) : SingletonSerializeAsToken() {
|
abstract class AbstractNodeService(val services: ServiceHubInternal) : SingletonSerializeAsToken() {
|
||||||
|
|
||||||
val net: MessagingService get() = services.networkService
|
val network: MessagingService get() = services.networkService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a handler for a message topic. In comparison to using net.addMessageHandler() this manages a lot of
|
* Register a handler for a message topic. In comparison to using net.addMessageHandler() this manages a lot of
|
||||||
@ -28,14 +28,14 @@ abstract class AbstractNodeService(val services: ServiceHubInternal) : Singleton
|
|||||||
addMessageHandler(topic: String,
|
addMessageHandler(topic: String,
|
||||||
crossinline handler: (Q) -> R,
|
crossinline handler: (Q) -> R,
|
||||||
crossinline exceptionConsumer: (Message, Exception) -> Unit): MessageHandlerRegistration {
|
crossinline exceptionConsumer: (Message, Exception) -> Unit): MessageHandlerRegistration {
|
||||||
return net.addMessageHandler(topic, DEFAULT_SESSION_ID) { message, _ ->
|
return network.addMessageHandler(topic, DEFAULT_SESSION_ID) { message, _ ->
|
||||||
try {
|
try {
|
||||||
val request = message.data.deserialize<Q>()
|
val request = message.data.deserialize<Q>()
|
||||||
val response = handler(request)
|
val response = handler(request)
|
||||||
// If the return type R is Unit, then do not send a response
|
// If the return type R is Unit, then do not send a response
|
||||||
if (response.javaClass != Unit.javaClass) {
|
if (response.javaClass != Unit.javaClass) {
|
||||||
val msg = net.createMessage(topic, request.sessionID, response.serialize().bytes)
|
val msg = network.createMessage(topic, request.sessionID, response.serialize().bytes)
|
||||||
net.send(msg, request.replyTo)
|
network.send(msg, request.replyTo)
|
||||||
}
|
}
|
||||||
} catch(e: Exception) {
|
} catch(e: Exception) {
|
||||||
exceptionConsumer(message, e)
|
exceptionConsumer(message, e)
|
||||||
|
@ -21,21 +21,21 @@ import net.corda.node.services.statemachine.FlowStateMachineImpl
|
|||||||
interface NetworkMapCacheInternal : NetworkMapCache {
|
interface NetworkMapCacheInternal : NetworkMapCache {
|
||||||
/**
|
/**
|
||||||
* Deregister from updates from the given map service.
|
* Deregister from updates from the given map service.
|
||||||
* @param net the network messaging service.
|
* @param network the network messaging service.
|
||||||
* @param service the network map service to fetch current state from.
|
* @param service the network map service to fetch current state from.
|
||||||
*/
|
*/
|
||||||
fun deregisterForUpdates(net: MessagingService, service: NodeInfo): ListenableFuture<Unit>
|
fun deregisterForUpdates(network: MessagingService, service: NodeInfo): ListenableFuture<Unit>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a network map service; fetches a copy of the latest map from the service and subscribes to any further
|
* Add a network map service; fetches a copy of the latest map from the service and subscribes to any further
|
||||||
* updates.
|
* updates.
|
||||||
* @param net the network messaging service.
|
* @param network the network messaging service.
|
||||||
* @param networkMapAddress the network map service to fetch current state from.
|
* @param networkMapAddress the network map service to fetch current state from.
|
||||||
* @param subscribe if the cache should subscribe to updates.
|
* @param subscribe if the cache should subscribe to updates.
|
||||||
* @param ifChangedSinceVer an optional version number to limit updating the map based on. If the latest map
|
* @param ifChangedSinceVer an optional version number to limit updating the map based on. If the latest map
|
||||||
* version is less than or equal to the given version, no update is fetched.
|
* version is less than or equal to the given version, no update is fetched.
|
||||||
*/
|
*/
|
||||||
fun addMapService(net: MessagingService, networkMapAddress: SingleMessageRecipient,
|
fun addMapService(network: MessagingService, networkMapAddress: SingleMessageRecipient,
|
||||||
subscribe: Boolean, ifChangedSinceVer: Int? = null): ListenableFuture<Unit>
|
subscribe: Boolean, ifChangedSinceVer: Int? = null): ListenableFuture<Unit>
|
||||||
|
|
||||||
/** Adds a node to the local cache (generally only used for adding ourselves). */
|
/** Adds a node to the local cache (generally only used for adding ourselves). */
|
||||||
|
@ -77,16 +77,16 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addMapService(net: MessagingService, networkMapAddress: SingleMessageRecipient, subscribe: Boolean,
|
override fun addMapService(network: MessagingService, networkMapAddress: SingleMessageRecipient, subscribe: Boolean,
|
||||||
ifChangedSinceVer: Int?): ListenableFuture<Unit> {
|
ifChangedSinceVer: Int?): ListenableFuture<Unit> {
|
||||||
if (subscribe && !registeredForPush) {
|
if (subscribe && !registeredForPush) {
|
||||||
// Add handler to the network, for updates received from the remote network map service.
|
// Add handler to the network, for updates received from the remote network map service.
|
||||||
net.addMessageHandler(NetworkMapService.PUSH_TOPIC, DEFAULT_SESSION_ID) { message, _ ->
|
network.addMessageHandler(NetworkMapService.PUSH_TOPIC, DEFAULT_SESSION_ID) { message, _ ->
|
||||||
try {
|
try {
|
||||||
val req = message.data.deserialize<NetworkMapService.Update>()
|
val req = message.data.deserialize<NetworkMapService.Update>()
|
||||||
val ackMessage = net.createMessage(NetworkMapService.PUSH_ACK_TOPIC, DEFAULT_SESSION_ID,
|
val ackMessage = network.createMessage(NetworkMapService.PUSH_ACK_TOPIC, DEFAULT_SESSION_ID,
|
||||||
NetworkMapService.UpdateAcknowledge(req.mapVersion, net.myAddress).serialize().bytes)
|
NetworkMapService.UpdateAcknowledge(req.mapVersion, network.myAddress).serialize().bytes)
|
||||||
net.send(ackMessage, req.replyTo)
|
network.send(ackMessage, req.replyTo)
|
||||||
processUpdatePush(req)
|
processUpdatePush(req)
|
||||||
} catch(e: NodeMapError) {
|
} catch(e: NodeMapError) {
|
||||||
logger.warn("Failure during node map update due to bad update: ${e.javaClass.name}")
|
logger.warn("Failure during node map update due to bad update: ${e.javaClass.name}")
|
||||||
@ -98,8 +98,8 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the network map and register for updates at the same time
|
// Fetch the network map and register for updates at the same time
|
||||||
val req = NetworkMapService.FetchMapRequest(subscribe, ifChangedSinceVer, net.myAddress)
|
val req = NetworkMapService.FetchMapRequest(subscribe, ifChangedSinceVer, network.myAddress)
|
||||||
val future = net.sendRequest<FetchMapResponse>(NetworkMapService.FETCH_TOPIC, req, networkMapAddress).map { (nodes) ->
|
val future = network.sendRequest<FetchMapResponse>(NetworkMapService.FETCH_TOPIC, req, networkMapAddress).map { (nodes) ->
|
||||||
// We may not receive any nodes back, if the map hasn't changed since the version specified
|
// We may not receive any nodes back, if the map hasn't changed since the version specified
|
||||||
nodes?.forEach { processRegistration(it) }
|
nodes?.forEach { processRegistration(it) }
|
||||||
Unit
|
Unit
|
||||||
@ -131,10 +131,10 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach
|
|||||||
* Unsubscribes from updates from the given map service.
|
* Unsubscribes from updates from the given map service.
|
||||||
* @param service the network map service to listen to updates from.
|
* @param service the network map service to listen to updates from.
|
||||||
*/
|
*/
|
||||||
override fun deregisterForUpdates(net: MessagingService, service: NodeInfo): ListenableFuture<Unit> {
|
override fun deregisterForUpdates(network: MessagingService, service: NodeInfo): ListenableFuture<Unit> {
|
||||||
// Fetch the network map and register for updates at the same time
|
// Fetch the network map and register for updates at the same time
|
||||||
val req = NetworkMapService.SubscribeRequest(false, net.myAddress)
|
val req = NetworkMapService.SubscribeRequest(false, network.myAddress)
|
||||||
val future = net.sendRequest<SubscribeResponse>(NetworkMapService.SUBSCRIPTION_TOPIC, req, service.address).map {
|
val future = network.sendRequest<SubscribeResponse>(NetworkMapService.SUBSCRIPTION_TOPIC, req, service.address).map {
|
||||||
if (it.confirmed) Unit else throw NetworkCacheError.DeregistrationFailed()
|
if (it.confirmed) Unit else throw NetworkCacheError.DeregistrationFailed()
|
||||||
}
|
}
|
||||||
_registrationFuture.setFuture(future)
|
_registrationFuture.setFuture(future)
|
||||||
|
@ -172,7 +172,7 @@ abstract class AbstractNetworkMapService(services: ServiceHubInternal,
|
|||||||
handlers += addMessageHandler(QUERY_TOPIC) { req: QueryIdentityRequest -> processQueryRequest(req) }
|
handlers += addMessageHandler(QUERY_TOPIC) { req: QueryIdentityRequest -> processQueryRequest(req) }
|
||||||
handlers += addMessageHandler(REGISTER_TOPIC) { req: RegistrationRequest -> processRegistrationRequest(req) }
|
handlers += addMessageHandler(REGISTER_TOPIC) { req: RegistrationRequest -> processRegistrationRequest(req) }
|
||||||
handlers += addMessageHandler(SUBSCRIPTION_TOPIC) { req: SubscribeRequest -> processSubscriptionRequest(req) }
|
handlers += addMessageHandler(SUBSCRIPTION_TOPIC) { req: SubscribeRequest -> processSubscriptionRequest(req) }
|
||||||
handlers += net.addMessageHandler(PUSH_ACK_TOPIC, DEFAULT_SESSION_ID) { message, _ ->
|
handlers += network.addMessageHandler(PUSH_ACK_TOPIC, DEFAULT_SESSION_ID) { message, _ ->
|
||||||
val req = message.data.deserialize<UpdateAcknowledge>()
|
val req = message.data.deserialize<UpdateAcknowledge>()
|
||||||
processAcknowledge(req)
|
processAcknowledge(req)
|
||||||
}
|
}
|
||||||
@ -181,7 +181,7 @@ abstract class AbstractNetworkMapService(services: ServiceHubInternal,
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
fun unregisterNetworkHandlers() {
|
fun unregisterNetworkHandlers() {
|
||||||
for (handler in handlers) {
|
for (handler in handlers) {
|
||||||
net.removeMessageHandler(handler)
|
network.removeMessageHandler(handler)
|
||||||
}
|
}
|
||||||
handlers.clear()
|
handlers.clear()
|
||||||
}
|
}
|
||||||
@ -289,14 +289,14 @@ abstract class AbstractNetworkMapService(services: ServiceHubInternal,
|
|||||||
// TODO: Once we have a better established messaging system, we can probably send
|
// TODO: Once we have a better established messaging system, we can probably send
|
||||||
// to a MessageRecipientGroup that nodes join/leave, rather than the network map
|
// to a MessageRecipientGroup that nodes join/leave, rather than the network map
|
||||||
// service itself managing the group
|
// service itself managing the group
|
||||||
val update = NetworkMapService.Update(wireReg, newMapVersion, net.myAddress).serialize().bytes
|
val update = NetworkMapService.Update(wireReg, newMapVersion, network.myAddress).serialize().bytes
|
||||||
val message = net.createMessage(PUSH_TOPIC, DEFAULT_SESSION_ID, update)
|
val message = network.createMessage(PUSH_TOPIC, DEFAULT_SESSION_ID, update)
|
||||||
|
|
||||||
subscribers.locked {
|
subscribers.locked {
|
||||||
// Remove any stale subscribers
|
// Remove any stale subscribers
|
||||||
values.removeIf { (mapVersion) -> newMapVersion - mapVersion > maxUnacknowledgedUpdates }
|
values.removeIf { (mapVersion) -> newMapVersion - mapVersion > maxUnacknowledgedUpdates }
|
||||||
// TODO: introduce some concept of time in the condition to avoid unsubscribes when there's a message burst.
|
// TODO: introduce some concept of time in the condition to avoid unsubscribes when there's a message burst.
|
||||||
keys.forEach { recipient -> net.send(message, recipient) }
|
keys.forEach { recipient -> network.send(message, recipient) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class CordaRPCOpsImplTest {
|
|||||||
val testJar = "net/corda/node/testing/test.jar"
|
val testJar = "net/corda/node/testing/test.jar"
|
||||||
}
|
}
|
||||||
|
|
||||||
lateinit var network: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
lateinit var aliceNode: MockNode
|
lateinit var aliceNode: MockNode
|
||||||
lateinit var notaryNode: MockNode
|
lateinit var notaryNode: MockNode
|
||||||
lateinit var rpc: CordaRPCOpsImpl
|
lateinit var rpc: CordaRPCOpsImpl
|
||||||
@ -57,10 +57,10 @@ class CordaRPCOpsImplTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
network = MockNetwork()
|
mockNet = MockNetwork()
|
||||||
val networkMap = network.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
|
val networkMap = mockNet.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
|
||||||
aliceNode = network.createNode(networkMapAddress = networkMap.info.address)
|
aliceNode = mockNet.createNode(networkMapAddress = networkMap.info.address)
|
||||||
notaryNode = network.createNode(advertisedServices = ServiceInfo(SimpleNotaryService.type), networkMapAddress = networkMap.info.address)
|
notaryNode = mockNet.createNode(advertisedServices = ServiceInfo(SimpleNotaryService.type), networkMapAddress = networkMap.info.address)
|
||||||
rpc = CordaRPCOpsImpl(aliceNode.services, aliceNode.smm, aliceNode.database)
|
rpc = CordaRPCOpsImpl(aliceNode.services, aliceNode.smm, aliceNode.database)
|
||||||
CURRENT_RPC_CONTEXT.set(RpcContext(User("user", "pwd", permissions = setOf(
|
CURRENT_RPC_CONTEXT.set(RpcContext(User("user", "pwd", permissions = setOf(
|
||||||
startFlowPermission<CashIssueFlow>(),
|
startFlowPermission<CashIssueFlow>(),
|
||||||
@ -87,7 +87,7 @@ class CordaRPCOpsImplTest {
|
|||||||
// Tell the monitoring service node to issue some cash
|
// Tell the monitoring service node to issue some cash
|
||||||
val recipient = aliceNode.info.legalIdentity
|
val recipient = aliceNode.info.legalIdentity
|
||||||
rpc.startFlow(::CashIssueFlow, Amount(quantity, GBP), ref, recipient, notaryNode.info.notaryIdentity)
|
rpc.startFlow(::CashIssueFlow, Amount(quantity, GBP), ref, recipient, notaryNode.info.notaryIdentity)
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
val expectedState = Cash.State(Amount(quantity,
|
val expectedState = Cash.State(Amount(quantity,
|
||||||
Issued(aliceNode.info.legalIdentity.ref(ref), GBP)),
|
Issued(aliceNode.info.legalIdentity.ref(ref), GBP)),
|
||||||
@ -129,11 +129,11 @@ class CordaRPCOpsImplTest {
|
|||||||
notaryNode.info.notaryIdentity
|
notaryNode.info.notaryIdentity
|
||||||
)
|
)
|
||||||
|
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
rpc.startFlow(::CashPaymentFlow, Amount(100, USD), aliceNode.info.legalIdentity)
|
rpc.startFlow(::CashPaymentFlow, Amount(100, USD), aliceNode.info.legalIdentity)
|
||||||
|
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
var issueSmId: StateMachineRunId? = null
|
var issueSmId: StateMachineRunId? = null
|
||||||
var moveSmId: StateMachineRunId? = null
|
var moveSmId: StateMachineRunId? = null
|
||||||
|
@ -31,14 +31,14 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
class AttachmentTests {
|
class AttachmentTests {
|
||||||
lateinit var network: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
lateinit var dataSource: Closeable
|
lateinit var dataSource: Closeable
|
||||||
lateinit var database: Database
|
lateinit var database: Database
|
||||||
lateinit var configuration: RequeryConfiguration
|
lateinit var configuration: RequeryConfiguration
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
network = MockNetwork()
|
mockNet = MockNetwork()
|
||||||
|
|
||||||
val dataSourceProperties = makeTestDataSourceProperties()
|
val dataSourceProperties = makeTestDataSourceProperties()
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ class AttachmentTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `download and store`() {
|
fun `download and store`() {
|
||||||
val (n0, n1) = network.createTwoNodes()
|
val (n0, n1) = mockNet.createTwoNodes()
|
||||||
|
|
||||||
// Insert an attachment into node zero's store directly.
|
// Insert an attachment into node zero's store directly.
|
||||||
val id = n0.database.transaction {
|
val id = n0.database.transaction {
|
||||||
@ -65,9 +65,9 @@ class AttachmentTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get node one to run a flow to fetch it and insert it.
|
// Get node one to run a flow to fetch it and insert it.
|
||||||
network.runNetwork()
|
mockNet.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()
|
mockNet.runNetwork()
|
||||||
assertEquals(0, f1.resultFuture.getOrThrow().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.
|
||||||
@ -86,13 +86,13 @@ class AttachmentTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `missing`() {
|
fun `missing`() {
|
||||||
val (n0, n1) = network.createTwoNodes()
|
val (n0, n1) = mockNet.createTwoNodes()
|
||||||
|
|
||||||
// Get node one to fetch a non-existent attachment.
|
// Get node one to fetch a non-existent attachment.
|
||||||
val hash = SecureHash.randomSHA256()
|
val hash = SecureHash.randomSHA256()
|
||||||
network.runNetwork()
|
mockNet.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()
|
mockNet.runNetwork()
|
||||||
val e = assertFailsWith<FetchDataFlow.HashNotFound> { f1.resultFuture.getOrThrow() }
|
val e = assertFailsWith<FetchDataFlow.HashNotFound> { f1.resultFuture.getOrThrow() }
|
||||||
assertEquals(hash, e.requested)
|
assertEquals(hash, e.requested)
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ class AttachmentTests {
|
|||||||
@Test
|
@Test
|
||||||
fun `malicious response`() {
|
fun `malicious response`() {
|
||||||
// Make a node that doesn't do sanity checking at load time.
|
// Make a node that doesn't do sanity checking at load time.
|
||||||
val n0 = network.createNode(null, -1, object : MockNetwork.Factory {
|
val n0 = mockNet.createNode(null, -1, object : MockNetwork.Factory {
|
||||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceInfo>, id: Int,
|
advertisedServices: Set<ServiceInfo>, id: Int,
|
||||||
overrideServices: Map<ServiceInfo, KeyPair>?,
|
overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||||
@ -114,7 +114,7 @@ class AttachmentTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, true, null, null, ServiceInfo(NetworkMapService.type), ServiceInfo(SimpleNotaryService.type))
|
}, true, null, null, ServiceInfo(NetworkMapService.type), ServiceInfo(SimpleNotaryService.type))
|
||||||
val n1 = network.createNode(n0.info.address)
|
val n1 = mockNet.createNode(n0.info.address)
|
||||||
|
|
||||||
val attachment = fakeAttachment()
|
val attachment = fakeAttachment()
|
||||||
// Insert an attachment into node zero's store directly.
|
// Insert an attachment into node zero's store directly.
|
||||||
@ -135,9 +135,9 @@ class AttachmentTests {
|
|||||||
|
|
||||||
|
|
||||||
// Get n1 to fetch the attachment. Should receive corrupted bytes.
|
// Get n1 to fetch the attachment. Should receive corrupted bytes.
|
||||||
network.runNetwork()
|
mockNet.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()
|
mockNet.runNetwork()
|
||||||
assertFailsWith<FetchDataFlow.DownloadedVsRequestedDataMismatch> { f1.resultFuture.getOrThrow() }
|
assertFailsWith<FetchDataFlow.DownloadedVsRequestedDataMismatch> { f1.resultFuture.getOrThrow() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import kotlin.test.assertFails
|
|||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class InMemoryMessagingTests {
|
class InMemoryMessagingTests {
|
||||||
val network = MockNetwork()
|
val mockNet = MockNetwork()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun topicStringValidation() {
|
fun topicStringValidation() {
|
||||||
@ -33,45 +33,45 @@ class InMemoryMessagingTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun basics() {
|
fun basics() {
|
||||||
val node1 = network.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
|
val node1 = mockNet.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
|
||||||
val node2 = network.createNode(networkMapAddress = node1.info.address)
|
val node2 = mockNet.createNode(networkMapAddress = node1.info.address)
|
||||||
val node3 = network.createNode(networkMapAddress = node1.info.address)
|
val node3 = mockNet.createNode(networkMapAddress = node1.info.address)
|
||||||
|
|
||||||
val bits = "test-content".toByteArray()
|
val bits = "test-content".toByteArray()
|
||||||
var finalDelivery: Message? = null
|
var finalDelivery: Message? = null
|
||||||
|
|
||||||
with(node2) {
|
with(node2) {
|
||||||
node2.net.addMessageHandler { msg, _ ->
|
node2.network.addMessageHandler { msg, _ ->
|
||||||
node2.net.send(msg, node3.info.address)
|
node2.network.send(msg, node3.info.address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
with(node3) {
|
with(node3) {
|
||||||
node2.net.addMessageHandler { msg, _ ->
|
node2.network.addMessageHandler { msg, _ ->
|
||||||
finalDelivery = msg
|
finalDelivery = msg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node 1 sends a message and it should end up in finalDelivery, after we run the network
|
// Node 1 sends a message and it should end up in finalDelivery, after we run the network
|
||||||
node1.net.send(node1.net.createMessage("test.topic", DEFAULT_SESSION_ID, bits), node2.info.address)
|
node1.network.send(node1.network.createMessage("test.topic", DEFAULT_SESSION_ID, bits), node2.info.address)
|
||||||
|
|
||||||
network.runNetwork(rounds = 1)
|
mockNet.runNetwork(rounds = 1)
|
||||||
|
|
||||||
assertTrue(Arrays.equals(finalDelivery!!.data, bits))
|
assertTrue(Arrays.equals(finalDelivery!!.data, bits))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun broadcast() {
|
fun broadcast() {
|
||||||
val node1 = network.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
|
val node1 = mockNet.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
|
||||||
val node2 = network.createNode(networkMapAddress = node1.info.address)
|
val node2 = mockNet.createNode(networkMapAddress = node1.info.address)
|
||||||
val node3 = network.createNode(networkMapAddress = node1.info.address)
|
val node3 = mockNet.createNode(networkMapAddress = node1.info.address)
|
||||||
|
|
||||||
val bits = "test-content".toByteArray()
|
val bits = "test-content".toByteArray()
|
||||||
|
|
||||||
var counter = 0
|
var counter = 0
|
||||||
listOf(node1, node2, node3).forEach { it.net.addMessageHandler { _, _ -> counter++ } }
|
listOf(node1, node2, node3).forEach { it.network.addMessageHandler { _, _ -> counter++ } }
|
||||||
node1.net.send(node2.net.createMessage("test.topic", DEFAULT_SESSION_ID, bits), network.messagingNetwork.everyoneOnline)
|
node1.network.send(node2.network.createMessage("test.topic", DEFAULT_SESSION_ID, bits), mockNet.messagingNetwork.everyoneOnline)
|
||||||
network.runNetwork(rounds = 1)
|
mockNet.runNetwork(rounds = 1)
|
||||||
assertEquals(3, counter)
|
assertEquals(3, counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,31 +81,31 @@ class InMemoryMessagingTests {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
fun `skip unhandled messages`() {
|
fun `skip unhandled messages`() {
|
||||||
val node1 = network.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
|
val node1 = mockNet.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
|
||||||
val node2 = network.createNode(networkMapAddress = node1.info.address)
|
val node2 = mockNet.createNode(networkMapAddress = node1.info.address)
|
||||||
var received: Int = 0
|
var received: Int = 0
|
||||||
|
|
||||||
node1.net.addMessageHandler("valid_message") { _, _ ->
|
node1.network.addMessageHandler("valid_message") { _, _ ->
|
||||||
received++
|
received++
|
||||||
}
|
}
|
||||||
|
|
||||||
val invalidMessage = node2.net.createMessage("invalid_message", DEFAULT_SESSION_ID, ByteArray(0))
|
val invalidMessage = node2.network.createMessage("invalid_message", DEFAULT_SESSION_ID, ByteArray(0))
|
||||||
val validMessage = node2.net.createMessage("valid_message", DEFAULT_SESSION_ID, ByteArray(0))
|
val validMessage = node2.network.createMessage("valid_message", DEFAULT_SESSION_ID, ByteArray(0))
|
||||||
node2.net.send(invalidMessage, node1.net.myAddress)
|
node2.network.send(invalidMessage, node1.network.myAddress)
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertEquals(0, received)
|
assertEquals(0, received)
|
||||||
|
|
||||||
node2.net.send(validMessage, node1.net.myAddress)
|
node2.network.send(validMessage, node1.network.myAddress)
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertEquals(1, received)
|
assertEquals(1, received)
|
||||||
|
|
||||||
// Here's the core of the test; previously the unhandled message would cause runNetwork() to abort early, so
|
// Here's the core of the test; previously the unhandled message would cause runNetwork() to abort early, so
|
||||||
// this would fail. Make fresh messages to stop duplicate uniqueMessageId causing drops
|
// this would fail. Make fresh messages to stop duplicate uniqueMessageId causing drops
|
||||||
val invalidMessage2 = node2.net.createMessage("invalid_message", DEFAULT_SESSION_ID, ByteArray(0))
|
val invalidMessage2 = node2.network.createMessage("invalid_message", DEFAULT_SESSION_ID, ByteArray(0))
|
||||||
val validMessage2 = node2.net.createMessage("valid_message", DEFAULT_SESSION_ID, ByteArray(0))
|
val validMessage2 = node2.network.createMessage("valid_message", DEFAULT_SESSION_ID, ByteArray(0))
|
||||||
node2.net.send(invalidMessage2, node1.net.myAddress)
|
node2.network.send(invalidMessage2, node1.network.myAddress)
|
||||||
node2.net.send(validMessage2, node1.net.myAddress)
|
node2.network.send(validMessage2, node1.network.myAddress)
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertEquals(2, received)
|
assertEquals(2, received)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,11 +59,11 @@ import kotlin.test.assertTrue
|
|||||||
* We assume that Alice and Bob already found each other via some market, and have agreed the details already.
|
* We assume that Alice and Bob already found each other via some market, and have agreed the details already.
|
||||||
*/
|
*/
|
||||||
class TwoPartyTradeFlowTests {
|
class TwoPartyTradeFlowTests {
|
||||||
lateinit var net: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun before() {
|
fun before() {
|
||||||
net = MockNetwork(false)
|
mockNet = MockNetwork(false)
|
||||||
LogHelper.setLevel("platform.trade", "core.contract.TransactionGroup", "recordingmap")
|
LogHelper.setLevel("platform.trade", "core.contract.TransactionGroup", "recordingmap")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,10 +77,10 @@ class TwoPartyTradeFlowTests {
|
|||||||
// We run this in parallel threads to help catch any race conditions that may exist. The other tests
|
// We run this in parallel threads to help catch any race conditions that may exist. The other tests
|
||||||
// we run in the unit test thread exclusively to speed things up, ensure deterministic results and
|
// we run in the unit test thread exclusively to speed things up, ensure deterministic results and
|
||||||
// allow interruption half way through.
|
// allow interruption half way through.
|
||||||
net = MockNetwork(false, true)
|
mockNet = MockNetwork(false, true)
|
||||||
|
|
||||||
ledger {
|
ledger {
|
||||||
val basketOfNodes = net.createSomeNodes(2)
|
val basketOfNodes = mockNet.createSomeNodes(2)
|
||||||
val notaryNode = basketOfNodes.notaryNode
|
val notaryNode = basketOfNodes.notaryNode
|
||||||
val aliceNode = basketOfNodes.partyNodes[0]
|
val aliceNode = basketOfNodes.partyNodes[0]
|
||||||
val bobNode = basketOfNodes.partyNodes[1]
|
val bobNode = basketOfNodes.partyNodes[1]
|
||||||
@ -122,12 +122,12 @@ class TwoPartyTradeFlowTests {
|
|||||||
|
|
||||||
@Test(expected = InsufficientBalanceException::class)
|
@Test(expected = InsufficientBalanceException::class)
|
||||||
fun `trade cash for commercial paper fails using soft locking`() {
|
fun `trade cash for commercial paper fails using soft locking`() {
|
||||||
net = MockNetwork(false, true)
|
mockNet = MockNetwork(false, true)
|
||||||
|
|
||||||
ledger {
|
ledger {
|
||||||
val notaryNode = net.createNotaryNode(null, DUMMY_NOTARY.name)
|
val notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
|
||||||
val aliceNode = net.createPartyNode(notaryNode.info.address, ALICE.name)
|
val aliceNode = mockNet.createPartyNode(notaryNode.info.address, ALICE.name)
|
||||||
val bobNode = net.createPartyNode(notaryNode.info.address, BOB.name)
|
val bobNode = mockNet.createPartyNode(notaryNode.info.address, BOB.name)
|
||||||
|
|
||||||
aliceNode.disableDBCloseOnStop()
|
aliceNode.disableDBCloseOnStop()
|
||||||
bobNode.disableDBCloseOnStop()
|
bobNode.disableDBCloseOnStop()
|
||||||
@ -171,16 +171,16 @@ class TwoPartyTradeFlowTests {
|
|||||||
@Test
|
@Test
|
||||||
fun `shutdown and restore`() {
|
fun `shutdown and restore`() {
|
||||||
ledger {
|
ledger {
|
||||||
val notaryNode = net.createNotaryNode(null, DUMMY_NOTARY.name)
|
val notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
|
||||||
val aliceNode = net.createPartyNode(notaryNode.info.address, ALICE.name)
|
val aliceNode = mockNet.createPartyNode(notaryNode.info.address, ALICE.name)
|
||||||
var bobNode = net.createPartyNode(notaryNode.info.address, BOB.name)
|
var bobNode = mockNet.createPartyNode(notaryNode.info.address, BOB.name)
|
||||||
aliceNode.disableDBCloseOnStop()
|
aliceNode.disableDBCloseOnStop()
|
||||||
bobNode.disableDBCloseOnStop()
|
bobNode.disableDBCloseOnStop()
|
||||||
|
|
||||||
val bobAddr = bobNode.net.myAddress as InMemoryMessagingNetwork.PeerHandle
|
val bobAddr = bobNode.network.myAddress as InMemoryMessagingNetwork.PeerHandle
|
||||||
val networkMapAddr = notaryNode.info.address
|
val networkMapAddr = notaryNode.info.address
|
||||||
|
|
||||||
net.runNetwork() // Clear network map registration messages
|
mockNet.runNetwork() // Clear network map registration messages
|
||||||
|
|
||||||
bobNode.database.transaction {
|
bobNode.database.transaction {
|
||||||
bobNode.services.fillWithSomeTestCash(2000.DOLLARS, outputNotary = notaryNode.info.notaryIdentity)
|
bobNode.services.fillWithSomeTestCash(2000.DOLLARS, outputNotary = notaryNode.info.notaryIdentity)
|
||||||
@ -224,7 +224,7 @@ class TwoPartyTradeFlowTests {
|
|||||||
|
|
||||||
// ... bring the node back up ... the act of constructing the SMM will re-register the message handlers
|
// ... bring the node back up ... the act of constructing the SMM will re-register the message handlers
|
||||||
// that Bob was waiting on before the reboot occurred.
|
// that Bob was waiting on before the reboot occurred.
|
||||||
bobNode = net.createNode(networkMapAddr, bobAddr.id, object : MockNetwork.Factory {
|
bobNode = mockNet.createNode(networkMapAddr, bobAddr.id, object : MockNetwork.Factory {
|
||||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||||
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||||
entropyRoot: BigInteger): MockNetwork.MockNode {
|
entropyRoot: BigInteger): MockNetwork.MockNode {
|
||||||
@ -236,7 +236,7 @@ class TwoPartyTradeFlowTests {
|
|||||||
val bobFuture = bobNode.smm.findStateMachines(BuyerAcceptor::class.java).single().second
|
val bobFuture = bobNode.smm.findStateMachines(BuyerAcceptor::class.java).single().second
|
||||||
|
|
||||||
// And off we go again.
|
// And off we go again.
|
||||||
net.runNetwork()
|
mockNet.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.getOrThrow()).isEqualTo(aliceFuture.getOrThrow())
|
assertThat(bobFuture.getOrThrow()).isEqualTo(aliceFuture.getOrThrow())
|
||||||
@ -266,7 +266,7 @@ class TwoPartyTradeFlowTests {
|
|||||||
name: X500Name,
|
name: X500Name,
|
||||||
overrideServices: Map<ServiceInfo, KeyPair>? = null): MockNetwork.MockNode {
|
overrideServices: Map<ServiceInfo, KeyPair>? = null): MockNetwork.MockNode {
|
||||||
// Create a node in the mock network ...
|
// Create a node in the mock network ...
|
||||||
return net.createNode(networkMapAddr, -1, object : MockNetwork.Factory {
|
return mockNet.createNode(networkMapAddr, -1, object : MockNetwork.Factory {
|
||||||
override fun create(config: NodeConfiguration,
|
override fun create(config: NodeConfiguration,
|
||||||
network: MockNetwork,
|
network: MockNetwork,
|
||||||
networkMapAddr: SingleMessageRecipient?,
|
networkMapAddr: SingleMessageRecipient?,
|
||||||
@ -289,7 +289,7 @@ class TwoPartyTradeFlowTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check dependencies of sale asset are resolved`() {
|
fun `check dependencies of sale asset are resolved`() {
|
||||||
val notaryNode = net.createNotaryNode(null, DUMMY_NOTARY.name)
|
val notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
|
||||||
val aliceNode = makeNodeWithTracking(notaryNode.info.address, ALICE.name)
|
val aliceNode = makeNodeWithTracking(notaryNode.info.address, ALICE.name)
|
||||||
val bobNode = makeNodeWithTracking(notaryNode.info.address, BOB.name)
|
val bobNode = makeNodeWithTracking(notaryNode.info.address, BOB.name)
|
||||||
|
|
||||||
@ -317,11 +317,11 @@ class TwoPartyTradeFlowTests {
|
|||||||
}
|
}
|
||||||
val alicesSignedTxns = insertFakeTransactions(alicesFakePaper, aliceNode, notaryNode, MEGA_CORP_PUBKEY)
|
val alicesSignedTxns = insertFakeTransactions(alicesFakePaper, aliceNode, notaryNode, MEGA_CORP_PUBKEY)
|
||||||
|
|
||||||
net.runNetwork() // Clear network map registration messages
|
mockNet.runNetwork() // Clear network map registration messages
|
||||||
|
|
||||||
runBuyerAndSeller(notaryNode, aliceNode, bobNode, "alice's paper".outputStateAndRef())
|
runBuyerAndSeller(notaryNode, aliceNode, bobNode, "alice's paper".outputStateAndRef())
|
||||||
|
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
run {
|
run {
|
||||||
val records = (bobNode.storage.validatedTransactions as RecordingTransactionStorage).records
|
val records = (bobNode.storage.validatedTransactions as RecordingTransactionStorage).records
|
||||||
@ -388,7 +388,7 @@ class TwoPartyTradeFlowTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `track works`() {
|
fun `track works`() {
|
||||||
val notaryNode = net.createNotaryNode(null, DUMMY_NOTARY.name)
|
val notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
|
||||||
val aliceNode = makeNodeWithTracking(notaryNode.info.address, ALICE.name)
|
val aliceNode = makeNodeWithTracking(notaryNode.info.address, ALICE.name)
|
||||||
val bobNode = makeNodeWithTracking(notaryNode.info.address, BOB.name)
|
val bobNode = makeNodeWithTracking(notaryNode.info.address, BOB.name)
|
||||||
|
|
||||||
@ -418,14 +418,14 @@ class TwoPartyTradeFlowTests {
|
|||||||
|
|
||||||
insertFakeTransactions(alicesFakePaper, aliceNode, notaryNode, MEGA_CORP_PUBKEY)
|
insertFakeTransactions(alicesFakePaper, aliceNode, notaryNode, MEGA_CORP_PUBKEY)
|
||||||
|
|
||||||
net.runNetwork() // Clear network map registration messages
|
mockNet.runNetwork() // Clear network map registration messages
|
||||||
|
|
||||||
val aliceTxStream = aliceNode.storage.validatedTransactions.track().second
|
val aliceTxStream = aliceNode.storage.validatedTransactions.track().second
|
||||||
val aliceTxMappings = with(aliceNode) { database.transaction { storage.stateMachineRecordedTransactionMapping.track().second } }
|
val aliceTxMappings = with(aliceNode) { database.transaction { storage.stateMachineRecordedTransactionMapping.track().second } }
|
||||||
val aliceSmId = runBuyerAndSeller(notaryNode, aliceNode, bobNode,
|
val aliceSmId = runBuyerAndSeller(notaryNode, aliceNode, bobNode,
|
||||||
"alice's paper".outputStateAndRef()).sellerId
|
"alice's paper".outputStateAndRef()).sellerId
|
||||||
|
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
// We need to declare this here, if we do it inside [expectEvents] kotlin throws an internal compiler error(!).
|
// We need to declare this here, if we do it inside [expectEvents] kotlin throws an internal compiler error(!).
|
||||||
val aliceTxExpectations = sequence(
|
val aliceTxExpectations = sequence(
|
||||||
@ -526,9 +526,9 @@ class TwoPartyTradeFlowTests {
|
|||||||
aliceError: Boolean,
|
aliceError: Boolean,
|
||||||
expectedMessageSubstring: String
|
expectedMessageSubstring: String
|
||||||
) {
|
) {
|
||||||
val notaryNode = net.createNotaryNode(null, DUMMY_NOTARY.name)
|
val notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
|
||||||
val aliceNode = net.createPartyNode(notaryNode.info.address, ALICE.name)
|
val aliceNode = mockNet.createPartyNode(notaryNode.info.address, ALICE.name)
|
||||||
val bobNode = net.createPartyNode(notaryNode.info.address, BOB.name)
|
val bobNode = mockNet.createPartyNode(notaryNode.info.address, BOB.name)
|
||||||
val issuer = MEGA_CORP.ref(1, 2, 3)
|
val issuer = MEGA_CORP.ref(1, 2, 3)
|
||||||
|
|
||||||
val bobsBadCash = bobNode.database.transaction {
|
val bobsBadCash = bobNode.database.transaction {
|
||||||
@ -543,11 +543,11 @@ class TwoPartyTradeFlowTests {
|
|||||||
insertFakeTransactions(bobsBadCash, bobNode, notaryNode, DUMMY_CASH_ISSUER_KEY.public, MEGA_CORP_PUBKEY)
|
insertFakeTransactions(bobsBadCash, bobNode, notaryNode, DUMMY_CASH_ISSUER_KEY.public, MEGA_CORP_PUBKEY)
|
||||||
insertFakeTransactions(alicesFakePaper, aliceNode, notaryNode, MEGA_CORP_PUBKEY)
|
insertFakeTransactions(alicesFakePaper, aliceNode, notaryNode, MEGA_CORP_PUBKEY)
|
||||||
|
|
||||||
net.runNetwork() // Clear network map registration messages
|
mockNet.runNetwork() // Clear network map registration messages
|
||||||
|
|
||||||
val (bobStateMachine, aliceResult) = runBuyerAndSeller(notaryNode, aliceNode, bobNode, "alice's paper".outputStateAndRef())
|
val (bobStateMachine, aliceResult) = runBuyerAndSeller(notaryNode, aliceNode, bobNode, "alice's paper".outputStateAndRef())
|
||||||
|
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
val e = assertFailsWith<TransactionVerificationException> {
|
val e = assertFailsWith<TransactionVerificationException> {
|
||||||
if (bobError)
|
if (bobError)
|
||||||
|
@ -23,7 +23,7 @@ import java.time.Clock
|
|||||||
open class MockServiceHubInternal(
|
open class MockServiceHubInternal(
|
||||||
val customVault: VaultService? = null,
|
val customVault: VaultService? = null,
|
||||||
val keyManagement: KeyManagementService? = null,
|
val keyManagement: KeyManagementService? = null,
|
||||||
val net: MessagingService? = null,
|
val network: MessagingService? = null,
|
||||||
val identity: IdentityService? = MOCK_IDENTITY_SERVICE,
|
val identity: IdentityService? = MOCK_IDENTITY_SERVICE,
|
||||||
val storage: TxWritableStorageService? = MockStorageService(),
|
val storage: TxWritableStorageService? = MockStorageService(),
|
||||||
val mapCache: NetworkMapCacheInternal? = MockNetworkMapCache(),
|
val mapCache: NetworkMapCacheInternal? = MockNetworkMapCache(),
|
||||||
@ -41,7 +41,7 @@ open class MockServiceHubInternal(
|
|||||||
override val identityService: IdentityService
|
override val identityService: IdentityService
|
||||||
get() = identity ?: throw UnsupportedOperationException()
|
get() = identity ?: throw UnsupportedOperationException()
|
||||||
override val networkService: MessagingService
|
override val networkService: MessagingService
|
||||||
get() = net ?: throw UnsupportedOperationException()
|
get() = network ?: throw UnsupportedOperationException()
|
||||||
override val networkMapCache: NetworkMapCacheInternal
|
override val networkMapCache: NetworkMapCacheInternal
|
||||||
get() = mapCache ?: throw UnsupportedOperationException()
|
get() = mapCache ?: throw UnsupportedOperationException()
|
||||||
override val storageService: StorageService
|
override val storageService: StorageService
|
||||||
|
@ -25,7 +25,7 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class NotaryChangeTests {
|
class NotaryChangeTests {
|
||||||
lateinit var net: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
lateinit var oldNotaryNode: MockNetwork.MockNode
|
lateinit var oldNotaryNode: MockNetwork.MockNode
|
||||||
lateinit var newNotaryNode: MockNetwork.MockNode
|
lateinit var newNotaryNode: MockNetwork.MockNode
|
||||||
lateinit var clientNodeA: MockNetwork.MockNode
|
lateinit var clientNodeA: MockNetwork.MockNode
|
||||||
@ -33,15 +33,15 @@ class NotaryChangeTests {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
net = MockNetwork()
|
mockNet = MockNetwork()
|
||||||
oldNotaryNode = net.createNode(
|
oldNotaryNode = mockNet.createNode(
|
||||||
legalName = DUMMY_NOTARY.name,
|
legalName = DUMMY_NOTARY.name,
|
||||||
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(SimpleNotaryService.type)))
|
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(SimpleNotaryService.type)))
|
||||||
clientNodeA = net.createNode(networkMapAddress = oldNotaryNode.info.address)
|
clientNodeA = mockNet.createNode(networkMapAddress = oldNotaryNode.info.address)
|
||||||
clientNodeB = net.createNode(networkMapAddress = oldNotaryNode.info.address)
|
clientNodeB = mockNet.createNode(networkMapAddress = oldNotaryNode.info.address)
|
||||||
newNotaryNode = net.createNode(networkMapAddress = oldNotaryNode.info.address, advertisedServices = ServiceInfo(SimpleNotaryService.type))
|
newNotaryNode = mockNet.createNode(networkMapAddress = oldNotaryNode.info.address, advertisedServices = ServiceInfo(SimpleNotaryService.type))
|
||||||
|
|
||||||
net.runNetwork() // Clear network map registration messages
|
mockNet.runNetwork() // Clear network map registration messages
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -51,7 +51,7 @@ class NotaryChangeTests {
|
|||||||
val flow = NotaryChangeFlow(state, newNotary)
|
val flow = NotaryChangeFlow(state, newNotary)
|
||||||
val future = clientNodeA.services.startFlow(flow)
|
val future = clientNodeA.services.startFlow(flow)
|
||||||
|
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
val newState = future.resultFuture.getOrThrow()
|
val newState = future.resultFuture.getOrThrow()
|
||||||
assertEquals(newState.state.notary, newNotary)
|
assertEquals(newState.state.notary, newNotary)
|
||||||
@ -64,7 +64,7 @@ class NotaryChangeTests {
|
|||||||
val flow = NotaryChangeFlow(state, newNotary)
|
val flow = NotaryChangeFlow(state, newNotary)
|
||||||
val future = clientNodeA.services.startFlow(flow)
|
val future = clientNodeA.services.startFlow(flow)
|
||||||
|
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
val newState = future.resultFuture.getOrThrow()
|
val newState = future.resultFuture.getOrThrow()
|
||||||
assertEquals(newState.state.notary, newNotary)
|
assertEquals(newState.state.notary, newNotary)
|
||||||
@ -80,7 +80,7 @@ class NotaryChangeTests {
|
|||||||
val flow = NotaryChangeFlow(state, newEvilNotary.party)
|
val flow = NotaryChangeFlow(state, newEvilNotary.party)
|
||||||
val future = clientNodeA.services.startFlow(flow)
|
val future = clientNodeA.services.startFlow(flow)
|
||||||
|
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
assertThatExceptionOfType(StateReplacementException::class.java).isThrownBy {
|
assertThatExceptionOfType(StateReplacementException::class.java).isThrownBy {
|
||||||
future.resultFuture.getOrThrow()
|
future.resultFuture.getOrThrow()
|
||||||
@ -95,7 +95,7 @@ class NotaryChangeTests {
|
|||||||
val newNotary = newNotaryNode.info.notaryIdentity
|
val newNotary = newNotaryNode.info.notaryIdentity
|
||||||
val flow = NotaryChangeFlow(state, newNotary)
|
val flow = NotaryChangeFlow(state, newNotary)
|
||||||
val future = clientNodeA.services.startFlow(flow)
|
val future = clientNodeA.services.startFlow(flow)
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
val newState = future.resultFuture.getOrThrow()
|
val newState = future.resultFuture.getOrThrow()
|
||||||
assertEquals(newState.state.notary, newNotary)
|
assertEquals(newState.state.notary, newNotary)
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class NodeSchedulerServiceTest : SingletonSerializeAsToken() {
|
|||||||
InMemoryMessagingNetwork.PeerHandle(0, nullIdentity),
|
InMemoryMessagingNetwork.PeerHandle(0, nullIdentity),
|
||||||
AffinityExecutor.ServiceAffinityExecutor("test", 1),
|
AffinityExecutor.ServiceAffinityExecutor("test", 1),
|
||||||
database)
|
database)
|
||||||
services = object : MockServiceHubInternal(overrideClock = testClock, keyManagement = kms, net = mockMessagingService), TestReference {
|
services = object : MockServiceHubInternal(overrideClock = testClock, keyManagement = kms, network = mockMessagingService), TestReference {
|
||||||
override val vaultService: VaultService = NodeVaultService(this, dataSourceProps)
|
override val vaultService: VaultService = NodeVaultService(this, dataSourceProps)
|
||||||
override val testReference = this@NodeSchedulerServiceTest
|
override val testReference = this@NodeSchedulerServiceTest
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ import java.time.Instant
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class ScheduledFlowTests {
|
class ScheduledFlowTests {
|
||||||
lateinit var net: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
lateinit var notaryNode: MockNetwork.MockNode
|
lateinit var notaryNode: MockNetwork.MockNode
|
||||||
lateinit var nodeA: MockNetwork.MockNode
|
lateinit var nodeA: MockNetwork.MockNode
|
||||||
lateinit var nodeB: MockNetwork.MockNode
|
lateinit var nodeB: MockNetwork.MockNode
|
||||||
@ -90,18 +90,18 @@ class ScheduledFlowTests {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
net = MockNetwork(threadPerNode = true)
|
mockNet = MockNetwork(threadPerNode = true)
|
||||||
notaryNode = net.createNode(
|
notaryNode = mockNet.createNode(
|
||||||
legalName = DUMMY_NOTARY.name,
|
legalName = DUMMY_NOTARY.name,
|
||||||
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(ValidatingNotaryService.type)))
|
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(ValidatingNotaryService.type)))
|
||||||
nodeA = net.createNode(notaryNode.info.address, start = false)
|
nodeA = mockNet.createNode(notaryNode.info.address, start = false)
|
||||||
nodeB = net.createNode(notaryNode.info.address, start = false)
|
nodeB = mockNet.createNode(notaryNode.info.address, start = false)
|
||||||
net.startNodes()
|
mockNet.startNodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
fun cleanUp() {
|
fun cleanUp() {
|
||||||
net.stopNodes()
|
mockNet.stopNodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -116,7 +116,7 @@ class ScheduledFlowTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
nodeA.services.startFlow(InsertInitialStateFlow(nodeB.info.legalIdentity))
|
nodeA.services.startFlow(InsertInitialStateFlow(nodeB.info.legalIdentity))
|
||||||
net.waitQuiescent()
|
mockNet.waitQuiescent()
|
||||||
val stateFromA = nodeA.database.transaction {
|
val stateFromA = nodeA.database.transaction {
|
||||||
nodeA.services.vaultService.linearHeadsOfType<ScheduledState>().values.first()
|
nodeA.services.vaultService.linearHeadsOfType<ScheduledState>().values.first()
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ class ScheduledFlowTests {
|
|||||||
nodeA.services.startFlow(InsertInitialStateFlow(nodeB.info.legalIdentity))
|
nodeA.services.startFlow(InsertInitialStateFlow(nodeB.info.legalIdentity))
|
||||||
nodeB.services.startFlow(InsertInitialStateFlow(nodeA.info.legalIdentity))
|
nodeB.services.startFlow(InsertInitialStateFlow(nodeA.info.legalIdentity))
|
||||||
}
|
}
|
||||||
net.waitQuiescent()
|
mockNet.waitQuiescent()
|
||||||
val statesFromA = nodeA.database.transaction {
|
val statesFromA = nodeA.database.transaction {
|
||||||
nodeA.services.vaultService.linearHeadsOfType<ScheduledState>()
|
nodeA.services.vaultService.linearHeadsOfType<ScheduledState>()
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ import java.security.KeyPair
|
|||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService> {
|
abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService> {
|
||||||
lateinit var network: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
lateinit var mapServiceNode: MockNode
|
lateinit var mapServiceNode: MockNode
|
||||||
lateinit var alice: MockNode
|
lateinit var alice: MockNode
|
||||||
|
|
||||||
@ -49,18 +49,18 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
network = MockNetwork(defaultFactory = nodeFactory)
|
mockNet = MockNetwork(defaultFactory = nodeFactory)
|
||||||
network.createTwoNodes(firstNodeName = DUMMY_MAP.name, secondNodeName = ALICE.name).apply {
|
mockNet.createTwoNodes(firstNodeName = DUMMY_MAP.name, secondNodeName = ALICE.name).apply {
|
||||||
mapServiceNode = first
|
mapServiceNode = first
|
||||||
alice = second
|
alice = second
|
||||||
}
|
}
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
lastSerial = System.currentTimeMillis()
|
lastSerial = System.currentTimeMillis()
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
fun tearDown() {
|
fun tearDown() {
|
||||||
network.stopNodes()
|
mockNet.stopNodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract val nodeFactory: MockNetwork.Factory
|
protected abstract val nodeFactory: MockNetwork.Factory
|
||||||
@ -188,7 +188,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
|||||||
private fun MockNode.fetchMap(subscribe: Boolean = false, ifChangedSinceVersion: Int? = null): List<Changed> {
|
private fun MockNode.fetchMap(subscribe: Boolean = false, ifChangedSinceVersion: Int? = null): List<Changed> {
|
||||||
val request = FetchMapRequest(subscribe, ifChangedSinceVersion, info.address)
|
val request = FetchMapRequest(subscribe, ifChangedSinceVersion, info.address)
|
||||||
val response = services.networkService.sendRequest<FetchMapResponse>(FETCH_TOPIC, request, mapServiceNode.info.address)
|
val response = services.networkService.sendRequest<FetchMapResponse>(FETCH_TOPIC, request, mapServiceNode.info.address)
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
return response.getOrThrow().nodes?.map { it.toChanged() } ?: emptyList()
|
return response.getOrThrow().nodes?.map { it.toChanged() } ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
|||||||
private fun MockNode.identityQuery(): NodeInfo? {
|
private fun MockNode.identityQuery(): NodeInfo? {
|
||||||
val request = QueryIdentityRequest(info.legalIdentityAndCert, info.address)
|
val request = QueryIdentityRequest(info.legalIdentityAndCert, info.address)
|
||||||
val response = services.networkService.sendRequest<QueryIdentityResponse>(QUERY_TOPIC, request, mapServiceNode.info.address)
|
val response = services.networkService.sendRequest<QueryIdentityResponse>(QUERY_TOPIC, request, mapServiceNode.info.address)
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
return response.getOrThrow().node
|
return response.getOrThrow().node
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
|||||||
val nodeRegistration = NodeRegistration(info, distinctSerial, addOrRemove, expires)
|
val nodeRegistration = NodeRegistration(info, distinctSerial, addOrRemove, expires)
|
||||||
val request = RegistrationRequest(nodeRegistration.toWire(services.keyManagementService, services.legalIdentityKey), info.address)
|
val request = RegistrationRequest(nodeRegistration.toWire(services.keyManagementService, services.legalIdentityKey), info.address)
|
||||||
val response = services.networkService.sendRequest<RegistrationResponse>(REGISTER_TOPIC, request, mapServiceNode.info.address)
|
val response = services.networkService.sendRequest<RegistrationResponse>(REGISTER_TOPIC, request, mapServiceNode.info.address)
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,7 +229,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
|||||||
updates += message.data.deserialize<Update>()
|
updates += message.data.deserialize<Update>()
|
||||||
}
|
}
|
||||||
val response = services.networkService.sendRequest<SubscribeResponse>(SUBSCRIPTION_TOPIC, request, mapServiceNode.info.address)
|
val response = services.networkService.sendRequest<SubscribeResponse>(SUBSCRIPTION_TOPIC, request, mapServiceNode.info.address)
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThat(response.getOrThrow().confirmed).isTrue()
|
assertThat(response.getOrThrow().confirmed).isTrue()
|
||||||
return updates
|
return updates
|
||||||
}
|
}
|
||||||
@ -237,25 +237,25 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
|||||||
private fun MockNode.unsubscribe() {
|
private fun MockNode.unsubscribe() {
|
||||||
val request = SubscribeRequest(false, info.address)
|
val request = SubscribeRequest(false, info.address)
|
||||||
val response = services.networkService.sendRequest<SubscribeResponse>(SUBSCRIPTION_TOPIC, request, mapServiceNode.info.address)
|
val response = services.networkService.sendRequest<SubscribeResponse>(SUBSCRIPTION_TOPIC, request, mapServiceNode.info.address)
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThat(response.getOrThrow().confirmed).isTrue()
|
assertThat(response.getOrThrow().confirmed).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun MockNode.ackUpdate(mapVersion: Int) {
|
private fun MockNode.ackUpdate(mapVersion: Int) {
|
||||||
val request = UpdateAcknowledge(mapVersion, services.networkService.myAddress)
|
val request = UpdateAcknowledge(mapVersion, services.networkService.myAddress)
|
||||||
services.networkService.send(PUSH_ACK_TOPIC, DEFAULT_SESSION_ID, request, mapServiceNode.info.address)
|
services.networkService.send(PUSH_ACK_TOPIC, DEFAULT_SESSION_ID, request, mapServiceNode.info.address)
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addNewNodeToNetworkMap(legalName: X500Name): MockNode {
|
private fun addNewNodeToNetworkMap(legalName: X500Name): MockNode {
|
||||||
val node = network.createNode(networkMapAddress = mapServiceNode.info.address, legalName = legalName)
|
val node = mockNet.createNode(networkMapAddress = mapServiceNode.info.address, legalName = legalName)
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
lastSerial = System.currentTimeMillis()
|
lastSerial = System.currentTimeMillis()
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun newNodeSeparateFromNetworkMap(legalName: X500Name): MockNode {
|
private fun newNodeSeparateFromNetworkMap(legalName: X500Name): MockNode {
|
||||||
return network.createNode(legalName = legalName, nodeFactory = NoNMSNodeFactory)
|
return mockNet.createNode(legalName = legalName, nodeFactory = NoNMSNodeFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class Changed {
|
sealed class Changed {
|
||||||
|
@ -11,21 +11,21 @@ import java.math.BigInteger
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class InMemoryNetworkMapCacheTest {
|
class InMemoryNetworkMapCacheTest {
|
||||||
private val network = MockNetwork()
|
private val mockNet = MockNetwork()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun registerWithNetwork() {
|
fun registerWithNetwork() {
|
||||||
val (n0, n1) = network.createTwoNodes()
|
val (n0, n1) = mockNet.createTwoNodes()
|
||||||
val future = n1.services.networkMapCache.addMapService(n1.net, n0.info.address, false, null)
|
val future = n1.services.networkMapCache.addMapService(n1.network, n0.info.address, false, null)
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
future.getOrThrow()
|
future.getOrThrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `key collision`() {
|
fun `key collision`() {
|
||||||
val entropy = BigInteger.valueOf(24012017L)
|
val entropy = BigInteger.valueOf(24012017L)
|
||||||
val nodeA = network.createNode(null, -1, MockNetwork.DefaultFactory, true, ALICE.name, null, entropy, ServiceInfo(NetworkMapService.type))
|
val nodeA = mockNet.createNode(null, -1, MockNetwork.DefaultFactory, true, ALICE.name, null, entropy, ServiceInfo(NetworkMapService.type))
|
||||||
val nodeB = network.createNode(null, -1, MockNetwork.DefaultFactory, true, BOB.name, null, entropy, ServiceInfo(NetworkMapService.type))
|
val nodeB = mockNet.createNode(null, -1, MockNetwork.DefaultFactory, true, BOB.name, null, entropy, ServiceInfo(NetworkMapService.type))
|
||||||
assertEquals(nodeA.info.legalIdentity, nodeB.info.legalIdentity)
|
assertEquals(nodeA.info.legalIdentity, nodeB.info.legalIdentity)
|
||||||
|
|
||||||
// Node A currently knows only about itself, so this returns node A
|
// Node A currently knows only about itself, so this returns node A
|
||||||
|
@ -28,19 +28,19 @@ import kotlin.test.assertEquals
|
|||||||
* Tests for the data vending service.
|
* Tests for the data vending service.
|
||||||
*/
|
*/
|
||||||
class DataVendingServiceTests {
|
class DataVendingServiceTests {
|
||||||
lateinit var network: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
network = MockNetwork()
|
mockNet = MockNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `notify of transaction`() {
|
fun `notify of transaction`() {
|
||||||
val (vaultServiceNode, registerNode) = network.createTwoNodes()
|
val (vaultServiceNode, registerNode) = mockNet.createTwoNodes()
|
||||||
val beneficiary = vaultServiceNode.info.legalIdentity
|
val beneficiary = vaultServiceNode.info.legalIdentity
|
||||||
val deposit = registerNode.info.legalIdentity.ref(1)
|
val deposit = registerNode.info.legalIdentity.ref(1)
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
// Generate an issuance transaction
|
// Generate an issuance transaction
|
||||||
val ptx = TransactionType.General.Builder(null)
|
val ptx = TransactionType.General.Builder(null)
|
||||||
@ -65,10 +65,10 @@ class DataVendingServiceTests {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
fun `notify failure`() {
|
fun `notify failure`() {
|
||||||
val (vaultServiceNode, registerNode) = network.createTwoNodes()
|
val (vaultServiceNode, registerNode) = mockNet.createTwoNodes()
|
||||||
val beneficiary = vaultServiceNode.info.legalIdentity
|
val beneficiary = vaultServiceNode.info.legalIdentity
|
||||||
val deposit = MEGA_CORP.ref(1)
|
val deposit = MEGA_CORP.ref(1)
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
// Generate an issuance transaction
|
// Generate an issuance transaction
|
||||||
val ptx = TransactionType.General.Builder(DUMMY_NOTARY)
|
val ptx = TransactionType.General.Builder(DUMMY_NOTARY)
|
||||||
@ -89,7 +89,7 @@ class DataVendingServiceTests {
|
|||||||
private fun MockNode.sendNotifyTx(tx: SignedTransaction, walletServiceNode: MockNode) {
|
private fun MockNode.sendNotifyTx(tx: SignedTransaction, walletServiceNode: MockNode) {
|
||||||
walletServiceNode.registerInitiatedFlow(InitiateNotifyTxFlow::class.java)
|
walletServiceNode.registerInitiatedFlow(InitiateNotifyTxFlow::class.java)
|
||||||
services.startFlow(NotifyTxFlow(walletServiceNode.info.legalIdentity, tx))
|
services.startFlow(NotifyTxFlow(walletServiceNode.info.legalIdentity, tx))
|
||||||
network.runNetwork()
|
mockNet.runNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
@InitiatingFlow
|
@InitiatingFlow
|
||||||
|
@ -64,7 +64,7 @@ class FlowFrameworkTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val net = MockNetwork(servicePeerAllocationStrategy = RoundRobin())
|
private val mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin())
|
||||||
private val sessionTransfers = ArrayList<SessionTransfer>()
|
private val sessionTransfers = ArrayList<SessionTransfer>()
|
||||||
private lateinit var node1: MockNode
|
private lateinit var node1: MockNode
|
||||||
private lateinit var node2: MockNode
|
private lateinit var node2: MockNode
|
||||||
@ -73,7 +73,7 @@ class FlowFrameworkTests {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun start() {
|
fun start() {
|
||||||
val nodes = net.createTwoNodes()
|
val nodes = mockNet.createTwoNodes()
|
||||||
node1 = nodes.first
|
node1 = nodes.first
|
||||||
node2 = nodes.second
|
node2 = nodes.second
|
||||||
val notaryKeyPair = generateKeyPair()
|
val notaryKeyPair = generateKeyPair()
|
||||||
@ -81,16 +81,16 @@ class FlowFrameworkTests {
|
|||||||
val overrideServices = mapOf(Pair(notaryService, notaryKeyPair))
|
val overrideServices = mapOf(Pair(notaryService, notaryKeyPair))
|
||||||
// Note that these notaries don't operate correctly as they don't share their state. They are only used for testing
|
// Note that these notaries don't operate correctly as they don't share their state. They are only used for testing
|
||||||
// service addressing.
|
// service addressing.
|
||||||
notary1 = net.createNotaryNode(networkMapAddr = node1.services.myInfo.address, overrideServices = overrideServices, serviceName = notaryService.name)
|
notary1 = mockNet.createNotaryNode(networkMapAddr = node1.services.myInfo.address, overrideServices = overrideServices, serviceName = notaryService.name)
|
||||||
notary2 = net.createNotaryNode(networkMapAddr = node1.services.myInfo.address, overrideServices = overrideServices, serviceName = notaryService.name)
|
notary2 = mockNet.createNotaryNode(networkMapAddr = node1.services.myInfo.address, overrideServices = overrideServices, serviceName = notaryService.name)
|
||||||
|
|
||||||
net.messagingNetwork.receivedMessages.toSessionTransfers().forEach { sessionTransfers += it }
|
mockNet.messagingNetwork.receivedMessages.toSessionTransfers().forEach { sessionTransfers += it }
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
fun cleanUp() {
|
fun cleanUp() {
|
||||||
net.stopNodes()
|
mockNet.stopNodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -122,7 +122,7 @@ class FlowFrameworkTests {
|
|||||||
fiber.actionOnSuspend = {
|
fiber.actionOnSuspend = {
|
||||||
throw exceptionDuringSuspend
|
throw exceptionDuringSuspend
|
||||||
}
|
}
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThatThrownBy {
|
assertThatThrownBy {
|
||||||
fiber.resultFuture.getOrThrow()
|
fiber.resultFuture.getOrThrow()
|
||||||
}.isSameAs(exceptionDuringSuspend)
|
}.isSameAs(exceptionDuringSuspend)
|
||||||
@ -141,42 +141,42 @@ class FlowFrameworkTests {
|
|||||||
node2.disableDBCloseOnStop()
|
node2.disableDBCloseOnStop()
|
||||||
node2.acceptableLiveFiberCountOnStop = 1
|
node2.acceptableLiveFiberCountOnStop = 1
|
||||||
node2.stop()
|
node2.stop()
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
val restoredFlow = node2.restartAndGetRestoredFlow<ReceiveFlow>(node1)
|
val restoredFlow = node2.restartAndGetRestoredFlow<ReceiveFlow>(node1)
|
||||||
assertThat(restoredFlow.receivedPayloads[0]).isEqualTo("Hello")
|
assertThat(restoredFlow.receivedPayloads[0]).isEqualTo("Hello")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `flow added before network map does run after init`() {
|
fun `flow added before network map does run after init`() {
|
||||||
val node3 = net.createNode(node1.info.address) //create vanilla node
|
val node3 = mockNet.createNode(node1.info.address) //create vanilla node
|
||||||
val flow = NoOpFlow()
|
val flow = NoOpFlow()
|
||||||
node3.services.startFlow(flow)
|
node3.services.startFlow(flow)
|
||||||
assertEquals(false, flow.flowStarted) // Not started yet as no network activity has been allowed yet
|
assertEquals(false, flow.flowStarted) // Not started yet as no network activity has been allowed yet
|
||||||
net.runNetwork() // Allow network map messages to flow
|
mockNet.runNetwork() // Allow network map messages to flow
|
||||||
assertEquals(true, flow.flowStarted) // Now we should have run the flow
|
assertEquals(true, flow.flowStarted) // Now we should have run the flow
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `flow added before network map will be init checkpointed`() {
|
fun `flow added before network map will be init checkpointed`() {
|
||||||
var node3 = net.createNode(node1.info.address) //create vanilla node
|
var node3 = mockNet.createNode(node1.info.address) //create vanilla node
|
||||||
val flow = NoOpFlow()
|
val flow = NoOpFlow()
|
||||||
node3.services.startFlow(flow)
|
node3.services.startFlow(flow)
|
||||||
assertEquals(false, flow.flowStarted) // Not started yet as no network activity has been allowed yet
|
assertEquals(false, flow.flowStarted) // Not started yet as no network activity has been allowed yet
|
||||||
node3.disableDBCloseOnStop()
|
node3.disableDBCloseOnStop()
|
||||||
node3.stop()
|
node3.stop()
|
||||||
|
|
||||||
node3 = net.createNode(node1.info.address, forcedID = node3.id)
|
node3 = mockNet.createNode(node1.info.address, forcedID = node3.id)
|
||||||
val restoredFlow = node3.getSingleFlow<NoOpFlow>().first
|
val restoredFlow = node3.getSingleFlow<NoOpFlow>().first
|
||||||
assertEquals(false, restoredFlow.flowStarted) // Not started yet as no network activity has been allowed yet
|
assertEquals(false, restoredFlow.flowStarted) // Not started yet as no network activity has been allowed yet
|
||||||
net.runNetwork() // Allow network map messages to flow
|
mockNet.runNetwork() // Allow network map messages to flow
|
||||||
node3.smm.executor.flush()
|
node3.smm.executor.flush()
|
||||||
assertEquals(true, restoredFlow.flowStarted) // Now we should have run the flow and hopefully cleared the init checkpoint
|
assertEquals(true, restoredFlow.flowStarted) // Now we should have run the flow and hopefully cleared the init checkpoint
|
||||||
node3.disableDBCloseOnStop()
|
node3.disableDBCloseOnStop()
|
||||||
node3.stop()
|
node3.stop()
|
||||||
|
|
||||||
// Now it is completed the flow should leave no Checkpoint.
|
// Now it is completed the flow should leave no Checkpoint.
|
||||||
node3 = net.createNode(node1.info.address, forcedID = node3.id)
|
node3 = mockNet.createNode(node1.info.address, forcedID = node3.id)
|
||||||
net.runNetwork() // Allow network map messages to flow
|
mockNet.runNetwork() // Allow network map messages to flow
|
||||||
node3.smm.executor.flush()
|
node3.smm.executor.flush()
|
||||||
assertTrue(node3.smm.findStateMachines(NoOpFlow::class.java).isEmpty())
|
assertTrue(node3.smm.findStateMachines(NoOpFlow::class.java).isEmpty())
|
||||||
}
|
}
|
||||||
@ -199,11 +199,11 @@ class FlowFrameworkTests {
|
|||||||
val payload2 = random63BitValue()
|
val payload2 = random63BitValue()
|
||||||
|
|
||||||
var sentCount = 0
|
var sentCount = 0
|
||||||
net.messagingNetwork.sentMessages.toSessionTransfers().filter { it.isPayloadTransfer }.forEach { sentCount++ }
|
mockNet.messagingNetwork.sentMessages.toSessionTransfers().filter { it.isPayloadTransfer }.forEach { sentCount++ }
|
||||||
|
|
||||||
val node3 = net.createNode(node1.info.address)
|
val node3 = mockNet.createNode(node1.info.address)
|
||||||
val secondFlow = node3.registerFlowFactory(PingPongFlow::class) { PingPongFlow(it, payload2) }
|
val secondFlow = node3.registerFlowFactory(PingPongFlow::class) { PingPongFlow(it, payload2) }
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
// Kick off first send and receive
|
// Kick off first send and receive
|
||||||
node2.services.startFlow(PingPongFlow(node3.info.legalIdentity, payload))
|
node2.services.startFlow(PingPongFlow(node3.info.legalIdentity, payload))
|
||||||
@ -218,11 +218,11 @@ class FlowFrameworkTests {
|
|||||||
node2.database.transaction {
|
node2.database.transaction {
|
||||||
assertEquals(1, node2.checkpointStorage.checkpoints().size) // confirm checkpoint
|
assertEquals(1, node2.checkpointStorage.checkpoints().size) // confirm checkpoint
|
||||||
}
|
}
|
||||||
val node2b = net.createNode(node1.info.address, node2.id, advertisedServices = *node2.advertisedServices.toTypedArray())
|
val node2b = mockNet.createNode(node1.info.address, node2.id, advertisedServices = *node2.advertisedServices.toTypedArray())
|
||||||
node2.manuallyCloseDB()
|
node2.manuallyCloseDB()
|
||||||
val (firstAgain, fut1) = node2b.getSingleFlow<PingPongFlow>()
|
val (firstAgain, fut1) = node2b.getSingleFlow<PingPongFlow>()
|
||||||
// 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()
|
mockNet.runNetwork()
|
||||||
node2b.smm.executor.flush()
|
node2b.smm.executor.flush()
|
||||||
fut1.getOrThrow()
|
fut1.getOrThrow()
|
||||||
|
|
||||||
@ -245,13 +245,13 @@ class FlowFrameworkTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `sending to multiple parties`() {
|
fun `sending to multiple parties`() {
|
||||||
val node3 = net.createNode(node1.info.address)
|
val node3 = mockNet.createNode(node1.info.address)
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
node2.registerFlowFactory(SendFlow::class) { ReceiveFlow(it).nonTerminating() }
|
node2.registerFlowFactory(SendFlow::class) { ReceiveFlow(it).nonTerminating() }
|
||||||
node3.registerFlowFactory(SendFlow::class) { ReceiveFlow(it).nonTerminating() }
|
node3.registerFlowFactory(SendFlow::class) { ReceiveFlow(it).nonTerminating() }
|
||||||
val payload = "Hello World"
|
val payload = "Hello World"
|
||||||
node1.services.startFlow(SendFlow(payload, node2.info.legalIdentity, node3.info.legalIdentity))
|
node1.services.startFlow(SendFlow(payload, node2.info.legalIdentity, node3.info.legalIdentity))
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
val node2Flow = node2.getSingleFlow<ReceiveFlow>().first
|
val node2Flow = node2.getSingleFlow<ReceiveFlow>().first
|
||||||
val node3Flow = node3.getSingleFlow<ReceiveFlow>().first
|
val node3Flow = node3.getSingleFlow<ReceiveFlow>().first
|
||||||
assertThat(node2Flow.receivedPayloads[0]).isEqualTo(payload)
|
assertThat(node2Flow.receivedPayloads[0]).isEqualTo(payload)
|
||||||
@ -277,8 +277,8 @@ class FlowFrameworkTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `receiving from multiple parties`() {
|
fun `receiving from multiple parties`() {
|
||||||
val node3 = net.createNode(node1.info.address)
|
val node3 = mockNet.createNode(node1.info.address)
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
val node2Payload = "Test 1"
|
val node2Payload = "Test 1"
|
||||||
val node3Payload = "Test 2"
|
val node3Payload = "Test 2"
|
||||||
node2.registerFlowFactory(ReceiveFlow::class) { SendFlow(node2Payload, it) }
|
node2.registerFlowFactory(ReceiveFlow::class) { SendFlow(node2Payload, it) }
|
||||||
@ -286,7 +286,7 @@ class FlowFrameworkTests {
|
|||||||
val multiReceiveFlow = ReceiveFlow(node2.info.legalIdentity, node3.info.legalIdentity).nonTerminating()
|
val multiReceiveFlow = ReceiveFlow(node2.info.legalIdentity, node3.info.legalIdentity).nonTerminating()
|
||||||
node1.services.startFlow(multiReceiveFlow)
|
node1.services.startFlow(multiReceiveFlow)
|
||||||
node1.acceptableLiveFiberCountOnStop = 1
|
node1.acceptableLiveFiberCountOnStop = 1
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThat(multiReceiveFlow.receivedPayloads[0]).isEqualTo(node2Payload)
|
assertThat(multiReceiveFlow.receivedPayloads[0]).isEqualTo(node2Payload)
|
||||||
assertThat(multiReceiveFlow.receivedPayloads[1]).isEqualTo(node3Payload)
|
assertThat(multiReceiveFlow.receivedPayloads[1]).isEqualTo(node3Payload)
|
||||||
|
|
||||||
@ -309,7 +309,7 @@ class FlowFrameworkTests {
|
|||||||
fun `both sides do a send as their first IO request`() {
|
fun `both sides do a send as their first IO request`() {
|
||||||
node2.registerFlowFactory(PingPongFlow::class) { PingPongFlow(it, 20L) }
|
node2.registerFlowFactory(PingPongFlow::class) { PingPongFlow(it, 20L) }
|
||||||
node1.services.startFlow(PingPongFlow(node2.info.legalIdentity, 10L))
|
node1.services.startFlow(PingPongFlow(node2.info.legalIdentity, 10L))
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
assertSessionTransfers(
|
assertSessionTransfers(
|
||||||
node1 sent sessionInit(PingPongFlow::class, 1, 10L) to node2,
|
node1 sent sessionInit(PingPongFlow::class, 1, 10L) to node2,
|
||||||
@ -332,9 +332,9 @@ class FlowFrameworkTests {
|
|||||||
// We pay a couple of times, the notary picking should go round robin
|
// We pay a couple of times, the notary picking should go round robin
|
||||||
for (i in 1..3) {
|
for (i in 1..3) {
|
||||||
node1.services.startFlow(CashPaymentFlow(500.DOLLARS, node2.info.legalIdentity))
|
node1.services.startFlow(CashPaymentFlow(500.DOLLARS, node2.info.legalIdentity))
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
}
|
}
|
||||||
val endpoint = net.messagingNetwork.endpoint(notary1.net.myAddress as InMemoryMessagingNetwork.PeerHandle)!!
|
val endpoint = mockNet.messagingNetwork.endpoint(notary1.network.myAddress as InMemoryMessagingNetwork.PeerHandle)!!
|
||||||
val party1Info = notary1.services.networkMapCache.getPartyInfo(notary1.info.notaryIdentity)!!
|
val party1Info = notary1.services.networkMapCache.getPartyInfo(notary1.info.notaryIdentity)!!
|
||||||
assertTrue(party1Info is PartyInfo.Service)
|
assertTrue(party1Info is PartyInfo.Service)
|
||||||
val notary1Address: MessageRecipients = endpoint.getAddressOfParty(notary1.services.networkMapCache.getPartyInfo(notary1.info.notaryIdentity)!!)
|
val notary1Address: MessageRecipients = endpoint.getAddressOfParty(notary1.services.networkMapCache.getPartyInfo(notary1.info.notaryIdentity)!!)
|
||||||
@ -380,7 +380,7 @@ class FlowFrameworkTests {
|
|||||||
fun `other side ends before doing expected send`() {
|
fun `other side ends before doing expected send`() {
|
||||||
node2.registerFlowFactory(ReceiveFlow::class) { NoOpFlow() }
|
node2.registerFlowFactory(ReceiveFlow::class) { NoOpFlow() }
|
||||||
val resultFuture = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity)).resultFuture
|
val resultFuture = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
|
assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
|
||||||
resultFuture.getOrThrow()
|
resultFuture.getOrThrow()
|
||||||
}.withMessageContaining(String::class.java.name) // Make sure the exception message mentions the type the flow was expecting to receive
|
}.withMessageContaining(String::class.java.name) // Make sure the exception message mentions the type the flow was expecting to receive
|
||||||
@ -397,7 +397,7 @@ class FlowFrameworkTests {
|
|||||||
val receiveFlowSteps = receiveFlow.progressSteps
|
val receiveFlowSteps = receiveFlow.progressSteps
|
||||||
val receiveFlowResult = node1.services.startFlow(receiveFlow).resultFuture
|
val receiveFlowResult = node1.services.startFlow(receiveFlow).resultFuture
|
||||||
|
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
assertThat(erroringFlowSteps.get()).containsExactly(
|
assertThat(erroringFlowSteps.get()).containsExactly(
|
||||||
Notification.createOnNext(ExceptionFlow.START_STEP),
|
Notification.createOnNext(ExceptionFlow.START_STEP),
|
||||||
@ -429,7 +429,7 @@ class FlowFrameworkTests {
|
|||||||
|
|
||||||
val receivingFiber = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity)) as FlowStateMachineImpl
|
val receivingFiber = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity)) as FlowStateMachineImpl
|
||||||
|
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
assertThatExceptionOfType(MyFlowException::class.java)
|
assertThatExceptionOfType(MyFlowException::class.java)
|
||||||
.isThrownBy { receivingFiber.resultFuture.getOrThrow() }
|
.isThrownBy { receivingFiber.resultFuture.getOrThrow() }
|
||||||
@ -457,13 +457,13 @@ class FlowFrameworkTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `FlowException propagated in invocation chain`() {
|
fun `FlowException propagated in invocation chain`() {
|
||||||
val node3 = net.createNode(node1.info.address)
|
val node3 = mockNet.createNode(node1.info.address)
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
node3.registerFlowFactory(ReceiveFlow::class) { ExceptionFlow { MyFlowException("Chain") } }
|
node3.registerFlowFactory(ReceiveFlow::class) { ExceptionFlow { MyFlowException("Chain") } }
|
||||||
node2.registerFlowFactory(ReceiveFlow::class) { ReceiveFlow(node3.info.legalIdentity) }
|
node2.registerFlowFactory(ReceiveFlow::class) { ReceiveFlow(node3.info.legalIdentity) }
|
||||||
val receivingFiber = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity))
|
val receivingFiber = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity))
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThatExceptionOfType(MyFlowException::class.java)
|
assertThatExceptionOfType(MyFlowException::class.java)
|
||||||
.isThrownBy { receivingFiber.resultFuture.getOrThrow() }
|
.isThrownBy { receivingFiber.resultFuture.getOrThrow() }
|
||||||
.withMessage("Chain")
|
.withMessage("Chain")
|
||||||
@ -471,8 +471,8 @@ class FlowFrameworkTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `FlowException thrown and there is a 3rd unrelated party flow`() {
|
fun `FlowException thrown and there is a 3rd unrelated party flow`() {
|
||||||
val node3 = net.createNode(node1.info.address)
|
val node3 = mockNet.createNode(node1.info.address)
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
// Node 2 will send its payload and then block waiting for the receive from node 1. Meanwhile node 1 will move
|
// Node 2 will send its payload and then block waiting for the receive from node 1. Meanwhile node 1 will move
|
||||||
// onto node 3 which will throw the exception
|
// onto node 3 which will throw the exception
|
||||||
@ -482,7 +482,7 @@ class FlowFrameworkTests {
|
|||||||
node3.registerFlowFactory(ReceiveFlow::class) { ExceptionFlow { MyFlowException("Nothing useful") } }
|
node3.registerFlowFactory(ReceiveFlow::class) { ExceptionFlow { MyFlowException("Nothing useful") } }
|
||||||
|
|
||||||
val node1Fiber = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity, node3.info.legalIdentity)) as FlowStateMachineImpl
|
val node1Fiber = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity, node3.info.legalIdentity)) as FlowStateMachineImpl
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
// Node 1 will terminate with the error it received from node 3 but it won't propagate that to node 2 (as it's
|
// Node 1 will terminate with the error it received from node 3 but it won't propagate that to node 2 (as it's
|
||||||
// not relevant to it) but it will end its session with it
|
// not relevant to it) but it will end its session with it
|
||||||
@ -534,7 +534,7 @@ class FlowFrameworkTests {
|
|||||||
|
|
||||||
node2.registerFlowFactory(AskForExceptionFlow::class) { ConditionalExceptionFlow(it, "Hello") }
|
node2.registerFlowFactory(AskForExceptionFlow::class) { ConditionalExceptionFlow(it, "Hello") }
|
||||||
val resultFuture = node1.services.startFlow(RetryOnExceptionFlow(node2.info.legalIdentity)).resultFuture
|
val resultFuture = node1.services.startFlow(RetryOnExceptionFlow(node2.info.legalIdentity)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThat(resultFuture.getOrThrow()).isEqualTo("Hello")
|
assertThat(resultFuture.getOrThrow()).isEqualTo("Hello")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -542,7 +542,7 @@ class FlowFrameworkTests {
|
|||||||
fun `serialisation issue in counterparty`() {
|
fun `serialisation issue in counterparty`() {
|
||||||
node2.registerFlowFactory(ReceiveFlow::class) { SendFlow(NonSerialisableData(1), it) }
|
node2.registerFlowFactory(ReceiveFlow::class) { SendFlow(NonSerialisableData(1), it) }
|
||||||
val result = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity)).resultFuture
|
val result = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
|
assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
|
||||||
result.getOrThrow()
|
result.getOrThrow()
|
||||||
}
|
}
|
||||||
@ -554,7 +554,7 @@ class FlowFrameworkTests {
|
|||||||
ExceptionFlow { NonSerialisableFlowException(NonSerialisableData(1)) }
|
ExceptionFlow { NonSerialisableFlowException(NonSerialisableData(1)) }
|
||||||
}
|
}
|
||||||
val result = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity)).resultFuture
|
val result = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThatExceptionOfType(FlowException::class.java).isThrownBy {
|
assertThatExceptionOfType(FlowException::class.java).isThrownBy {
|
||||||
result.getOrThrow()
|
result.getOrThrow()
|
||||||
}
|
}
|
||||||
@ -570,7 +570,7 @@ class FlowFrameworkTests {
|
|||||||
WaitingFlows.Committer(it)
|
WaitingFlows.Committer(it)
|
||||||
}.map { it.stateMachine }
|
}.map { it.stateMachine }
|
||||||
val waiterStx = node2.services.startFlow(WaitingFlows.Waiter(stx, node1.info.legalIdentity)).resultFuture
|
val waiterStx = node2.services.startFlow(WaitingFlows.Waiter(stx, node1.info.legalIdentity)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThat(waiterStx.getOrThrow()).isEqualTo(committerFiber.getOrThrow().resultFuture.getOrThrow())
|
assertThat(waiterStx.getOrThrow()).isEqualTo(committerFiber.getOrThrow().resultFuture.getOrThrow())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,7 +584,7 @@ class FlowFrameworkTests {
|
|||||||
WaitingFlows.Committer(it) { throw Exception("Error") }
|
WaitingFlows.Committer(it) { throw Exception("Error") }
|
||||||
}
|
}
|
||||||
val waiter = node2.services.startFlow(WaitingFlows.Waiter(stx, node1.info.legalIdentity)).resultFuture
|
val waiter = node2.services.startFlow(WaitingFlows.Waiter(stx, node1.info.legalIdentity)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
|
assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
|
||||||
waiter.getOrThrow()
|
waiter.getOrThrow()
|
||||||
}
|
}
|
||||||
@ -593,7 +593,7 @@ class FlowFrameworkTests {
|
|||||||
@Test
|
@Test
|
||||||
fun `lazy db iterator left on stack during checkpointing`() {
|
fun `lazy db iterator left on stack during checkpointing`() {
|
||||||
val result = node2.services.startFlow(VaultAccessFlow()).resultFuture
|
val result = node2.services.startFlow(VaultAccessFlow()).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThatThrownBy { result.getOrThrow() }.hasMessageContaining("Vault").hasMessageContaining("private method")
|
assertThatThrownBy { result.getOrThrow() }.hasMessageContaining("Vault").hasMessageContaining("private method")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,14 +601,14 @@ class FlowFrameworkTests {
|
|||||||
fun `customised client flow`() {
|
fun `customised client flow`() {
|
||||||
val receiveFlowFuture = node2.registerFlowFactory(SendFlow::class) { ReceiveFlow(it) }
|
val receiveFlowFuture = node2.registerFlowFactory(SendFlow::class) { ReceiveFlow(it) }
|
||||||
node1.services.startFlow(CustomSendFlow("Hello", node2.info.legalIdentity)).resultFuture
|
node1.services.startFlow(CustomSendFlow("Hello", node2.info.legalIdentity)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThat(receiveFlowFuture.getOrThrow().receivedPayloads).containsOnly("Hello")
|
assertThat(receiveFlowFuture.getOrThrow().receivedPayloads).containsOnly("Hello")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `customised client flow which has annotated @InitiatingFlow again`() {
|
fun `customised client flow which has annotated @InitiatingFlow again`() {
|
||||||
val result = node1.services.startFlow(IncorrectCustomSendFlow("Hello", node2.info.legalIdentity)).resultFuture
|
val result = node1.services.startFlow(IncorrectCustomSendFlow("Hello", node2.info.legalIdentity)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThatExceptionOfType(IllegalArgumentException::class.java).isThrownBy {
|
assertThatExceptionOfType(IllegalArgumentException::class.java).isThrownBy {
|
||||||
result.getOrThrow()
|
result.getOrThrow()
|
||||||
}.withMessageContaining(InitiatingFlow::class.java.simpleName)
|
}.withMessageContaining(InitiatingFlow::class.java.simpleName)
|
||||||
@ -617,7 +617,7 @@ class FlowFrameworkTests {
|
|||||||
@Test
|
@Test
|
||||||
fun `upgraded flow`() {
|
fun `upgraded flow`() {
|
||||||
node1.services.startFlow(UpgradedFlow(node2.info.legalIdentity))
|
node1.services.startFlow(UpgradedFlow(node2.info.legalIdentity))
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThat(sessionTransfers).startsWith(
|
assertThat(sessionTransfers).startsWith(
|
||||||
node1 sent sessionInit(UpgradedFlow::class, 2) to node2
|
node1 sent sessionInit(UpgradedFlow::class, 2) to node2
|
||||||
)
|
)
|
||||||
@ -631,7 +631,7 @@ class FlowFrameworkTests {
|
|||||||
DoubleInlinedSubFlow::class.java,
|
DoubleInlinedSubFlow::class.java,
|
||||||
track = false)
|
track = false)
|
||||||
val result = node1.services.startFlow(UpgradedFlow(node2.info.legalIdentity)).resultFuture
|
val result = node1.services.startFlow(UpgradedFlow(node2.info.legalIdentity)).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
|
assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
|
||||||
result.getOrThrow()
|
result.getOrThrow()
|
||||||
}.withMessageContaining("Version")
|
}.withMessageContaining("Version")
|
||||||
@ -641,7 +641,7 @@ class FlowFrameworkTests {
|
|||||||
fun `single inlined sub-flow`() {
|
fun `single inlined sub-flow`() {
|
||||||
node2.registerFlowFactory(SendAndReceiveFlow::class, ::SingleInlinedSubFlow)
|
node2.registerFlowFactory(SendAndReceiveFlow::class, ::SingleInlinedSubFlow)
|
||||||
val result = node1.services.startFlow(SendAndReceiveFlow(node2.info.legalIdentity, "Hello")).resultFuture
|
val result = node1.services.startFlow(SendAndReceiveFlow(node2.info.legalIdentity, "Hello")).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThat(result.getOrThrow()).isEqualTo("HelloHello")
|
assertThat(result.getOrThrow()).isEqualTo("HelloHello")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -649,7 +649,7 @@ class FlowFrameworkTests {
|
|||||||
fun `double inlined sub-flow`() {
|
fun `double inlined sub-flow`() {
|
||||||
node2.registerFlowFactory(SendAndReceiveFlow::class, ::DoubleInlinedSubFlow)
|
node2.registerFlowFactory(SendAndReceiveFlow::class, ::DoubleInlinedSubFlow)
|
||||||
val result = node1.services.startFlow(SendAndReceiveFlow(node2.info.legalIdentity, "Hello")).resultFuture
|
val result = node1.services.startFlow(SendAndReceiveFlow(node2.info.legalIdentity, "Hello")).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
assertThat(result.getOrThrow()).isEqualTo("HelloHello")
|
assertThat(result.getOrThrow()).isEqualTo("HelloHello")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -696,7 +696,7 @@ class FlowFrameworkTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun assertSessionTransfers(node: MockNode, vararg expected: SessionTransfer): List<SessionTransfer> {
|
private fun assertSessionTransfers(node: MockNode, vararg expected: SessionTransfer): List<SessionTransfer> {
|
||||||
val actualForNode = sessionTransfers.filter { it.from == node.id || it.to == node.net.myAddress }
|
val actualForNode = sessionTransfers.filter { it.from == node.id || it.to == node.network.myAddress }
|
||||||
assertThat(actualForNode).containsExactly(*expected)
|
assertThat(actualForNode).containsExactly(*expected)
|
||||||
return actualForNode
|
return actualForNode
|
||||||
}
|
}
|
||||||
@ -724,7 +724,7 @@ class FlowFrameworkTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private infix fun MockNode.sent(message: SessionMessage): Pair<Int, SessionMessage> = Pair(id, message)
|
private infix fun MockNode.sent(message: SessionMessage): Pair<Int, SessionMessage> = Pair(id, message)
|
||||||
private infix fun Pair<Int, SessionMessage>.to(node: MockNode): SessionTransfer = SessionTransfer(first, second, node.net.myAddress)
|
private infix fun Pair<Int, SessionMessage>.to(node: MockNode): SessionTransfer = SessionTransfer(first, second, node.network.myAddress)
|
||||||
|
|
||||||
private val FlowLogic<*>.progressSteps: ListenableFuture<List<Notification<ProgressTracker.Step>>> get() {
|
private val FlowLogic<*>.progressSteps: ListenableFuture<List<Notification<ProgressTracker.Step>>> get() {
|
||||||
return progressTracker!!.changes
|
return progressTracker!!.changes
|
||||||
|
@ -26,17 +26,17 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
class NotaryServiceTests {
|
class NotaryServiceTests {
|
||||||
lateinit var net: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
lateinit var notaryNode: MockNetwork.MockNode
|
lateinit var notaryNode: MockNetwork.MockNode
|
||||||
lateinit var clientNode: MockNetwork.MockNode
|
lateinit var clientNode: MockNetwork.MockNode
|
||||||
|
|
||||||
@Before fun setup() {
|
@Before fun setup() {
|
||||||
net = MockNetwork()
|
mockNet = MockNetwork()
|
||||||
notaryNode = net.createNode(
|
notaryNode = mockNet.createNode(
|
||||||
legalName = DUMMY_NOTARY.name,
|
legalName = DUMMY_NOTARY.name,
|
||||||
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(SimpleNotaryService.type)))
|
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(SimpleNotaryService.type)))
|
||||||
clientNode = net.createNode(networkMapAddress = notaryNode.info.address)
|
clientNode = mockNet.createNode(networkMapAddress = notaryNode.info.address)
|
||||||
net.runNetwork() // Clear network map registration messages
|
mockNet.runNetwork() // Clear network map registration messages
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun `should sign a unique transaction with a valid time-window`() {
|
@Test fun `should sign a unique transaction with a valid time-window`() {
|
||||||
@ -90,7 +90,7 @@ class NotaryServiceTests {
|
|||||||
val f1 = clientNode.services.startFlow(firstAttempt)
|
val f1 = clientNode.services.startFlow(firstAttempt)
|
||||||
val f2 = clientNode.services.startFlow(secondAttempt)
|
val f2 = clientNode.services.startFlow(secondAttempt)
|
||||||
|
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
assertEquals(f1.resultFuture.getOrThrow(), f2.resultFuture.getOrThrow())
|
assertEquals(f1.resultFuture.getOrThrow(), f2.resultFuture.getOrThrow())
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ class NotaryServiceTests {
|
|||||||
clientNode.services.startFlow(firstSpend)
|
clientNode.services.startFlow(firstSpend)
|
||||||
val future = clientNode.services.startFlow(secondSpend)
|
val future = clientNode.services.startFlow(secondSpend)
|
||||||
|
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
|
|
||||||
val ex = assertFailsWith(NotaryException::class) { future.resultFuture.getOrThrow() }
|
val ex = assertFailsWith(NotaryException::class) { future.resultFuture.getOrThrow() }
|
||||||
val notaryError = ex.error as NotaryError.Conflict
|
val notaryError = ex.error as NotaryError.Conflict
|
||||||
@ -123,7 +123,7 @@ class NotaryServiceTests {
|
|||||||
private fun runNotaryClient(stx: SignedTransaction): ListenableFuture<List<DigitalSignature.WithKey>> {
|
private fun runNotaryClient(stx: SignedTransaction): ListenableFuture<List<DigitalSignature.WithKey>> {
|
||||||
val flow = NotaryFlow.Client(stx)
|
val flow = NotaryFlow.Client(stx)
|
||||||
val future = clientNode.services.startFlow(flow).resultFuture
|
val future = clientNode.services.startFlow(flow).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
return future
|
return future
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,18 +23,18 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
class ValidatingNotaryServiceTests {
|
class ValidatingNotaryServiceTests {
|
||||||
lateinit var net: MockNetwork
|
lateinit var mockNet: MockNetwork
|
||||||
lateinit var notaryNode: MockNetwork.MockNode
|
lateinit var notaryNode: MockNetwork.MockNode
|
||||||
lateinit var clientNode: MockNetwork.MockNode
|
lateinit var clientNode: MockNetwork.MockNode
|
||||||
|
|
||||||
@Before fun setup() {
|
@Before fun setup() {
|
||||||
net = MockNetwork()
|
mockNet = MockNetwork()
|
||||||
notaryNode = net.createNode(
|
notaryNode = mockNet.createNode(
|
||||||
legalName = DUMMY_NOTARY.name,
|
legalName = DUMMY_NOTARY.name,
|
||||||
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(ValidatingNotaryService.type))
|
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(ValidatingNotaryService.type))
|
||||||
)
|
)
|
||||||
clientNode = net.createNode(networkMapAddress = notaryNode.info.address)
|
clientNode = mockNet.createNode(networkMapAddress = notaryNode.info.address)
|
||||||
net.runNetwork() // Clear network map registration messages
|
mockNet.runNetwork() // Clear network map registration messages
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun `should report error for invalid transaction dependency`() {
|
@Test fun `should report error for invalid transaction dependency`() {
|
||||||
@ -74,7 +74,7 @@ class ValidatingNotaryServiceTests {
|
|||||||
private fun runClient(stx: SignedTransaction): ListenableFuture<List<DigitalSignature.WithKey>> {
|
private fun runClient(stx: SignedTransaction): ListenableFuture<List<DigitalSignature.WithKey>> {
|
||||||
val flow = NotaryFlow.Client(stx)
|
val flow = NotaryFlow.Client(stx)
|
||||||
val future = clientNode.services.startFlow(flow).resultFuture
|
val future = clientNode.services.startFlow(flow).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
return future
|
return future
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
|||||||
fun createAll(): List<SimulatedNode> {
|
fun createAll(): List<SimulatedNode> {
|
||||||
return bankLocations.mapIndexed { i, _ ->
|
return bankLocations.mapIndexed { i, _ ->
|
||||||
// Use deterministic seeds so the simulation is stable. Needed so that party owning keys are stable.
|
// Use deterministic seeds so the simulation is stable. Needed so that party owning keys are stable.
|
||||||
network.createNode(networkMap.info.address, start = false, nodeFactory = this, entropyRoot = BigInteger.valueOf(i.toLong())) as SimulatedNode
|
mockNet.createNode(networkMap.info.address, start = false, nodeFactory = this, entropyRoot = BigInteger.valueOf(i.toLong())) as SimulatedNode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,15 +158,15 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val network = MockNetwork(networkSendManuallyPumped, runAsync)
|
val mockNet = MockNetwork(networkSendManuallyPumped, runAsync)
|
||||||
// This one must come first.
|
// This one must come first.
|
||||||
val networkMap: SimulatedNode
|
val networkMap: SimulatedNode
|
||||||
= network.createNode(null, nodeFactory = NetworkMapNodeFactory, advertisedServices = ServiceInfo(NetworkMapService.type)) as SimulatedNode
|
= mockNet.createNode(null, nodeFactory = NetworkMapNodeFactory, advertisedServices = ServiceInfo(NetworkMapService.type)) as SimulatedNode
|
||||||
val notary: SimulatedNode
|
val notary: SimulatedNode
|
||||||
= network.createNode(networkMap.info.address, nodeFactory = NotaryNodeFactory, advertisedServices = ServiceInfo(SimpleNotaryService.type)) as SimulatedNode
|
= mockNet.createNode(networkMap.info.address, nodeFactory = NotaryNodeFactory, advertisedServices = ServiceInfo(SimpleNotaryService.type)) as SimulatedNode
|
||||||
val regulators: List<SimulatedNode> = listOf(network.createNode(networkMap.info.address, start = false, nodeFactory = RegulatorFactory) as SimulatedNode)
|
val regulators: List<SimulatedNode> = listOf(mockNet.createNode(networkMap.info.address, start = false, nodeFactory = RegulatorFactory) as SimulatedNode)
|
||||||
val ratesOracle: SimulatedNode
|
val ratesOracle: SimulatedNode
|
||||||
= network.createNode(networkMap.info.address, start = false, nodeFactory = RatesOracleFactory, advertisedServices = ServiceInfo(NodeInterestRates.Oracle.type)) as SimulatedNode
|
= mockNet.createNode(networkMap.info.address, start = false, nodeFactory = RatesOracleFactory, advertisedServices = ServiceInfo(NodeInterestRates.Oracle.type)) as SimulatedNode
|
||||||
|
|
||||||
// All nodes must be in one of these two lists for the purposes of the visualiser tool.
|
// All nodes must be in one of these two lists for the purposes of the visualiser tool.
|
||||||
val serviceProviders: List<SimulatedNode> = listOf(notary, ratesOracle, networkMap)
|
val serviceProviders: List<SimulatedNode> = listOf(notary, ratesOracle, networkMap)
|
||||||
@ -220,11 +220,11 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
|||||||
*/
|
*/
|
||||||
open fun iterate(): InMemoryMessagingNetwork.MessageTransfer? {
|
open fun iterate(): InMemoryMessagingNetwork.MessageTransfer? {
|
||||||
if (networkSendManuallyPumped) {
|
if (networkSendManuallyPumped) {
|
||||||
network.messagingNetwork.pumpSend(false)
|
mockNet.messagingNetwork.pumpSend(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep going until one of the nodes has something to do, or we have checked every node.
|
// Keep going until one of the nodes has something to do, or we have checked every node.
|
||||||
val endpoints = network.messagingNetwork.endpoints
|
val endpoints = mockNet.messagingNetwork.endpoints
|
||||||
var countDown = endpoints.size
|
var countDown = endpoints.size
|
||||||
while (countDown > 0) {
|
while (countDown > 0) {
|
||||||
val handledMessage = endpoints[pumpCursor].pumpReceive(false)
|
val handledMessage = endpoints[pumpCursor].pumpReceive(false)
|
||||||
@ -271,10 +271,10 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
|||||||
}
|
}
|
||||||
|
|
||||||
val networkInitialisationFinished: ListenableFuture<*> =
|
val networkInitialisationFinished: ListenableFuture<*> =
|
||||||
Futures.allAsList(network.nodes.map { it.networkMapRegistrationFuture })
|
Futures.allAsList(mockNet.nodes.map { it.networkMapRegistrationFuture })
|
||||||
|
|
||||||
fun start(): ListenableFuture<Unit> {
|
fun start(): ListenableFuture<Unit> {
|
||||||
network.startNodes()
|
mockNet.startNodes()
|
||||||
// Wait for all the nodes to have finished registering with the network map service.
|
// Wait for all the nodes to have finished registering with the network map service.
|
||||||
return networkInitialisationFinished.flatMap { startMainSimulation() }
|
return networkInitialisationFinished.flatMap { startMainSimulation() }
|
||||||
}
|
}
|
||||||
@ -288,6 +288,6 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
network.stopNodes()
|
mockNet.stopNodes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,9 +207,9 @@ class NodeInterestRatesTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `network tearoff`() {
|
fun `network tearoff`() {
|
||||||
val net = MockNetwork()
|
val mockNet = MockNetwork()
|
||||||
val n1 = net.createNotaryNode()
|
val n1 = mockNet.createNotaryNode()
|
||||||
val n2 = net.createNode(n1.info.address, advertisedServices = ServiceInfo(NodeInterestRates.Oracle.type))
|
val n2 = mockNet.createNode(n1.info.address, advertisedServices = ServiceInfo(NodeInterestRates.Oracle.type))
|
||||||
n2.registerInitiatedFlow(NodeInterestRates.FixQueryHandler::class.java)
|
n2.registerInitiatedFlow(NodeInterestRates.FixQueryHandler::class.java)
|
||||||
n2.registerInitiatedFlow(NodeInterestRates.FixSignHandler::class.java)
|
n2.registerInitiatedFlow(NodeInterestRates.FixSignHandler::class.java)
|
||||||
n2.database.transaction {
|
n2.database.transaction {
|
||||||
@ -220,9 +220,9 @@ class NodeInterestRatesTest {
|
|||||||
val oracle = n2.info.serviceIdentities(NodeInterestRates.Oracle.type).first()
|
val oracle = n2.info.serviceIdentities(NodeInterestRates.Oracle.type).first()
|
||||||
val flow = FilteredRatesFlow(tx, oracle, fixOf, "0.675".bd, "0.1".bd)
|
val flow = FilteredRatesFlow(tx, oracle, fixOf, "0.675".bd, "0.1".bd)
|
||||||
LogHelper.setLevel("rates")
|
LogHelper.setLevel("rates")
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
val future = n1.services.startFlow(flow).resultFuture
|
val future = n1.services.startFlow(flow).resultFuture
|
||||||
net.runNetwork()
|
mockNet.runNetwork()
|
||||||
future.getOrThrow()
|
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()
|
||||||
|
@ -110,9 +110,9 @@ class NetworkMapVisualiser : Application() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Fire the message bullets between nodes.
|
// Fire the message bullets between nodes.
|
||||||
simulation.network.messagingNetwork.sentMessages.observeOn(uiThread).subscribe { msg: InMemoryMessagingNetwork.MessageTransfer ->
|
simulation.mockNet.messagingNetwork.sentMessages.observeOn(uiThread).subscribe { msg: InMemoryMessagingNetwork.MessageTransfer ->
|
||||||
val senderNode: MockNetwork.MockNode = simulation.network.addressToNode(msg.sender)
|
val senderNode: MockNetwork.MockNode = simulation.mockNet.addressToNode(msg.sender)
|
||||||
val destNode: MockNetwork.MockNode = simulation.network.addressToNode(msg.recipients as SingleMessageRecipient)
|
val destNode: MockNetwork.MockNode = simulation.mockNet.addressToNode(msg.recipients as SingleMessageRecipient)
|
||||||
|
|
||||||
if (transferIsInteresting(msg)) {
|
if (transferIsInteresting(msg)) {
|
||||||
viewModel.nodesToWidgets[senderNode]!!.pulseAnim.play()
|
viewModel.nodesToWidgets[senderNode]!!.pulseAnim.play()
|
||||||
|
@ -233,7 +233,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
|||||||
@Suppress("unused") val place: PhysicalLocation get() = findMyLocation()!!
|
@Suppress("unused") val place: PhysicalLocation get() = findMyLocation()!!
|
||||||
|
|
||||||
fun pumpReceive(block: Boolean = false): InMemoryMessagingNetwork.MessageTransfer? {
|
fun pumpReceive(block: Boolean = false): InMemoryMessagingNetwork.MessageTransfer? {
|
||||||
return (net as InMemoryMessagingNetwork.InMemoryMessaging).pumpReceive(block)
|
return (network as InMemoryMessagingNetwork.InMemoryMessaging).pumpReceive(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun disableDBCloseOnStop() {
|
fun disableDBCloseOnStop() {
|
||||||
@ -382,7 +382,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("unused") // This is used from the network visualiser tool.
|
@Suppress("unused") // This is used from the network visualiser tool.
|
||||||
fun addressToNode(address: SingleMessageRecipient): MockNode = nodes.single { it.net.myAddress == address }
|
fun addressToNode(address: SingleMessageRecipient): MockNode = nodes.single { it.network.myAddress == address }
|
||||||
|
|
||||||
fun startNodes() {
|
fun startNodes() {
|
||||||
require(nodes.isNotEmpty())
|
require(nodes.isNotEmpty())
|
||||||
|
@ -45,7 +45,7 @@ class SimpleNode(val config: NodeConfiguration, val address: HostAndPort = freeL
|
|||||||
val executor = ServiceAffinityExecutor(config.myLegalName.commonName, 1)
|
val executor = ServiceAffinityExecutor(config.myLegalName.commonName, 1)
|
||||||
val broker = ArtemisMessagingServer(config, address.port, rpcAddress.port, InMemoryNetworkMapCache(), userService)
|
val broker = ArtemisMessagingServer(config, address.port, rpcAddress.port, InMemoryNetworkMapCache(), userService)
|
||||||
val networkMapRegistrationFuture: SettableFuture<Unit> = SettableFuture.create<Unit>()
|
val networkMapRegistrationFuture: SettableFuture<Unit> = SettableFuture.create<Unit>()
|
||||||
val net = database.transaction {
|
val network = database.transaction {
|
||||||
NodeMessagingClient(
|
NodeMessagingClient(
|
||||||
config,
|
config,
|
||||||
MOCK_VERSION_INFO,
|
MOCK_VERSION_INFO,
|
||||||
@ -59,18 +59,18 @@ class SimpleNode(val config: NodeConfiguration, val address: HostAndPort = freeL
|
|||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
broker.start()
|
broker.start()
|
||||||
net.start(
|
network.start(
|
||||||
object : RPCOps {
|
object : RPCOps {
|
||||||
override val protocolVersion = 0
|
override val protocolVersion = 0
|
||||||
},
|
},
|
||||||
userService)
|
userService)
|
||||||
thread(name = config.myLegalName.commonName) {
|
thread(name = config.myLegalName.commonName) {
|
||||||
net.run(broker.serverControl)
|
network.run(broker.serverControl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
net.stop()
|
network.stop()
|
||||||
broker.stop()
|
broker.stop()
|
||||||
databaseWithCloseable.first.close()
|
databaseWithCloseable.first.close()
|
||||||
executor.shutdownNow()
|
executor.shutdownNow()
|
||||||
|
Reference in New Issue
Block a user