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:
Andrzej Cichocki
2017-06-05 14:00:14 +01:00
committed by GitHub
parent e5fba5d0af
commit 101e96d8d7
38 changed files with 353 additions and 354 deletions

View File

@ -53,7 +53,7 @@ class P2PMessagingTest : NodeBasedTest() {
networkMapNode.respondWith("Hello")
val alice = startNode(ALICE.name).getOrThrow()
val serviceAddress = alice.services.networkMapCache.run {
alice.net.getAddressOfParty(getPartyInfo(getAnyNotary()!!)!!)
alice.network.getAddressOfParty(getPartyInfo(getAnyNotary()!!)!!)
}
val received = alice.receiveFrom(serviceAddress).getOrThrow(10.seconds)
assertThat(received).isEqualTo("Hello")
@ -98,7 +98,7 @@ class P2PMessagingTest : NodeBasedTest() {
val distributedServiceNodes = startNotaryCluster(DISTRIBUTED_SERVICE_NAME, 2).getOrThrow()
val alice = startNode(ALICE.name, configOverrides = mapOf("messageRedeliveryDelaySeconds" to 1)).getOrThrow()
val serviceAddress = alice.services.networkMapCache.run {
alice.net.getAddressOfParty(getPartyInfo(getAnyNotary()!!)!!)
alice.network.getAddressOfParty(getPartyInfo(getAnyNotary()!!)!!)
}
val dummyTopic = "dummy.topic"
@ -107,7 +107,7 @@ class P2PMessagingTest : NodeBasedTest() {
simulateCrashingNode(distributedServiceNodes, dummyTopic, responseMessage)
// Send a single request with retry
val response = with(alice.net) {
val response = with(alice.network) {
val request = TestRequest(replyTo = myAddress)
val responseFuture = onNext<Any>(dummyTopic, request.sessionID)
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 alice = startNode(ALICE.name, configOverrides = mapOf("messageRedeliveryDelaySeconds" to 1)).getOrThrow()
val serviceAddress = alice.services.networkMapCache.run {
alice.net.getAddressOfParty(getPartyInfo(getAnyNotary()!!)!!)
alice.network.getAddressOfParty(getPartyInfo(getAnyNotary()!!)!!)
}
val dummyTopic = "dummy.topic"
@ -134,7 +134,7 @@ class P2PMessagingTest : NodeBasedTest() {
val sessionId = random63BitValue()
// Send a single request with retry
with(alice.net) {
with(alice.network) {
val request = TestRequest(sessionId, myAddress)
val msg = createMessage(TopicSession(dummyTopic), data = request.serialize().bytes)
send(msg, serviceAddress, retryId = request.sessionID)
@ -148,7 +148,7 @@ class P2PMessagingTest : NodeBasedTest() {
// Restart the node and expect a response
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(response).isEqualTo(responseMessage)
@ -166,7 +166,7 @@ class P2PMessagingTest : NodeBasedTest() {
distributedServiceNodes.forEach {
val nodeName = it.info.legalIdentity.name
var ignoreRequests = false
it.net.addMessageHandler(dummyTopic, DEFAULT_SESSION_ID) { netMessage, _ ->
it.network.addMessageHandler(dummyTopic, DEFAULT_SESSION_ID) { netMessage, _ ->
requestsReceived.incrementAndGet()
firstRequestReceived.countDown()
// The node which receives the first request will ignore all requests
@ -179,8 +179,8 @@ class P2PMessagingTest : NodeBasedTest() {
} else {
println("sending response")
val request = netMessage.data.deserialize<TestRequest>()
val response = it.net.createMessage(dummyTopic, request.sessionID, responseMessage.serialize().bytes)
it.net.send(response, request.replyTo)
val response = it.network.createMessage(dummyTopic, request.sessionID, responseMessage.serialize().bytes)
it.network.send(response, request.replyTo)
}
}
}
@ -193,7 +193,7 @@ class P2PMessagingTest : NodeBasedTest() {
node.respondWith(node.info)
}
val serviceAddress = originatingNode.services.networkMapCache.run {
originatingNode.net.getAddressOfParty(getPartyInfo(getNotary(serviceName)!!)!!)
originatingNode.network.getAddressOfParty(getPartyInfo(getNotary(serviceName)!!)!!)
}
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
@ -209,16 +209,16 @@ class P2PMessagingTest : NodeBasedTest() {
}
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 response = net.createMessage(javaClass.name, request.sessionID, message.serialize().bytes)
net.send(response, request.replyTo)
val response = network.createMessage(javaClass.name, request.sessionID, message.serialize().bytes)
network.send(response, request.replyTo)
}
}
private fun Node.receiveFrom(target: MessageRecipients): ListenableFuture<Any> {
val request = TestRequest(replyTo = net.myAddress)
return net.sendRequest<Any>(javaClass.name, request, target)
val request = TestRequest(replyTo = network.myAddress)
return network.sendRequest<Any>(javaClass.name, request, target)
}
@CordaSerializable

View File

@ -69,9 +69,9 @@ class P2PSecurityTest : NodeBasedTest() {
private fun SimpleNode.registerWithNetworkMap(registrationName: X500Name): ListenableFuture<NetworkMapService.RegistrationResponse> {
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 request = RegistrationRequest(registration.toWire(keyService, identity.public), net.myAddress)
return net.sendRequest<NetworkMapService.RegistrationResponse>(NetworkMapService.REGISTER_TOPIC, request, networkMapNode.net.myAddress)
val request = RegistrationRequest(registration.toWire(keyService, identity.public), network.myAddress)
return network.sendRequest<NetworkMapService.RegistrationResponse>(NetworkMapService.REGISTER_TOPIC, request, networkMapNode.network.myAddress)
}
}

View File

@ -116,7 +116,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
protected val partyKeys = mutableSetOf<KeyPair>()
val services = object : ServiceHubInternal() {
override val networkService: MessagingService get() = net
override val networkService: MessagingService get() = network
override val networkMapCache: NetworkMapCacheInternal get() = netMapCache
override val storageService: TxWritableStorageService get() = storage
override val vaultService: VaultService get() = vault
@ -167,7 +167,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
var inNodeNetworkMapService: NetworkMapService? = null
lateinit var txVerifierService: TransactionVerifierService
lateinit var identity: IdentityService
lateinit var net: MessagingService
lateinit var network: MessagingService
lateinit var netMapCache: NetworkMapCacheInternal
lateinit var scheduler: NodeSchedulerService
lateinit var schemas: SchemaService
@ -255,7 +255,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
initUploaders()
runOnStop += Runnable { net.stop() }
runOnStop += Runnable { network.stop() }
_networkMapRegistrationFuture.setFuture(registerWithNetworkMapIfConfigured())
smm.start(tokenizableServices)
// Shut down the SMM so no Fibers are scheduled.
@ -437,7 +437,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
storage = storageServices.first
checkpointStorage = storageServices.second
netMapCache = InMemoryNetworkMapCache()
net = makeMessagingService()
network = makeMessagingService()
schemas = makeSchemaService()
vault = makeVaultService(configuration.dataSourceProperties)
txVerifierService = makeTransactionVerifierService()
@ -451,7 +451,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
keyManagement = makeKeyManagementService(identity)
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)
return tokenizableServices
@ -523,7 +523,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
private fun makeInfo(): NodeInfo {
val advertisedServiceEntries = makeServiceEntries()
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) ->
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
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 reg = NodeRegistration(info, instant.toEpochMilli(), ADD, expires)
val legalIdentityKey = obtainLegalIdentityKey()
val request = NetworkMapService.RegistrationRequest(reg.toWire(keyManagement, legalIdentityKey.public), net.myAddress)
return net.sendRequest(NetworkMapService.REGISTER_TOPIC, request, networkMapAddress)
val request = NetworkMapService.RegistrationRequest(reg.toWire(keyManagement, legalIdentityKey.public), network.myAddress)
return network.sendRequest(NetworkMapService.REGISTER_TOPIC, request, networkMapAddress)
}
/** This is overriden by the mock node implementation to enable operation without any network map service */

View File

@ -71,7 +71,7 @@ class Node(override val configuration: FullNodeConfiguration,
override val log: Logger get() = logger
override val platformVersion: Int get() = versionInfo.platformVersion
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
//
@ -232,8 +232,7 @@ class Node(override val configuration: FullNodeConfiguration,
}
// Start up the MQ client.
val net = net as NodeMessagingClient
net.start(rpcOps, userService)
(network as NodeMessagingClient).start(rpcOps, userService)
}
/**
@ -321,7 +320,7 @@ class Node(override val configuration: FullNodeConfiguration,
/** Starts a blocking event loop for message dispatch. */
fun run() {
(net as NodeMessagingClient).run(messageBroker!!.serverControl)
(network as NodeMessagingClient).run(messageBroker!!.serverControl)
}
// TODO: Do we really need setup?

View File

@ -13,7 +13,7 @@ import javax.annotation.concurrent.ThreadSafe
@ThreadSafe
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
@ -28,14 +28,14 @@ abstract class AbstractNodeService(val services: ServiceHubInternal) : Singleton
addMessageHandler(topic: String,
crossinline handler: (Q) -> R,
crossinline exceptionConsumer: (Message, Exception) -> Unit): MessageHandlerRegistration {
return net.addMessageHandler(topic, DEFAULT_SESSION_ID) { message, _ ->
return network.addMessageHandler(topic, DEFAULT_SESSION_ID) { message, _ ->
try {
val request = message.data.deserialize<Q>()
val response = handler(request)
// If the return type R is Unit, then do not send a response
if (response.javaClass != Unit.javaClass) {
val msg = net.createMessage(topic, request.sessionID, response.serialize().bytes)
net.send(msg, request.replyTo)
val msg = network.createMessage(topic, request.sessionID, response.serialize().bytes)
network.send(msg, request.replyTo)
}
} catch(e: Exception) {
exceptionConsumer(message, e)

View File

@ -21,21 +21,21 @@ import net.corda.node.services.statemachine.FlowStateMachineImpl
interface NetworkMapCacheInternal : NetworkMapCache {
/**
* 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.
*/
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
* 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 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
* 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>
/** Adds a node to the local cache (generally only used for adding ourselves). */

View File

@ -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> {
if (subscribe && !registeredForPush) {
// 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 {
val req = message.data.deserialize<NetworkMapService.Update>()
val ackMessage = net.createMessage(NetworkMapService.PUSH_ACK_TOPIC, DEFAULT_SESSION_ID,
NetworkMapService.UpdateAcknowledge(req.mapVersion, net.myAddress).serialize().bytes)
net.send(ackMessage, req.replyTo)
val ackMessage = network.createMessage(NetworkMapService.PUSH_ACK_TOPIC, DEFAULT_SESSION_ID,
NetworkMapService.UpdateAcknowledge(req.mapVersion, network.myAddress).serialize().bytes)
network.send(ackMessage, req.replyTo)
processUpdatePush(req)
} catch(e: NodeMapError) {
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
val req = NetworkMapService.FetchMapRequest(subscribe, ifChangedSinceVer, net.myAddress)
val future = net.sendRequest<FetchMapResponse>(NetworkMapService.FETCH_TOPIC, req, networkMapAddress).map { (nodes) ->
val req = NetworkMapService.FetchMapRequest(subscribe, ifChangedSinceVer, network.myAddress)
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
nodes?.forEach { processRegistration(it) }
Unit
@ -131,10 +131,10 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach
* Unsubscribes from updates from the given map service.
* @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
val req = NetworkMapService.SubscribeRequest(false, net.myAddress)
val future = net.sendRequest<SubscribeResponse>(NetworkMapService.SUBSCRIPTION_TOPIC, req, service.address).map {
val req = NetworkMapService.SubscribeRequest(false, network.myAddress)
val future = network.sendRequest<SubscribeResponse>(NetworkMapService.SUBSCRIPTION_TOPIC, req, service.address).map {
if (it.confirmed) Unit else throw NetworkCacheError.DeregistrationFailed()
}
_registrationFuture.setFuture(future)

View File

@ -172,7 +172,7 @@ abstract class AbstractNetworkMapService(services: ServiceHubInternal,
handlers += addMessageHandler(QUERY_TOPIC) { req: QueryIdentityRequest -> processQueryRequest(req) }
handlers += addMessageHandler(REGISTER_TOPIC) { req: RegistrationRequest -> processRegistrationRequest(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>()
processAcknowledge(req)
}
@ -181,7 +181,7 @@ abstract class AbstractNetworkMapService(services: ServiceHubInternal,
@VisibleForTesting
fun unregisterNetworkHandlers() {
for (handler in handlers) {
net.removeMessageHandler(handler)
network.removeMessageHandler(handler)
}
handlers.clear()
}
@ -289,14 +289,14 @@ abstract class AbstractNetworkMapService(services: ServiceHubInternal,
// 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
// service itself managing the group
val update = NetworkMapService.Update(wireReg, newMapVersion, net.myAddress).serialize().bytes
val message = net.createMessage(PUSH_TOPIC, DEFAULT_SESSION_ID, update)
val update = NetworkMapService.Update(wireReg, newMapVersion, network.myAddress).serialize().bytes
val message = network.createMessage(PUSH_TOPIC, DEFAULT_SESSION_ID, update)
subscribers.locked {
// Remove any stale subscribers
values.removeIf { (mapVersion) -> newMapVersion - mapVersion > maxUnacknowledgedUpdates }
// 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) }
}
}

View File

@ -47,7 +47,7 @@ class CordaRPCOpsImplTest {
val testJar = "net/corda/node/testing/test.jar"
}
lateinit var network: MockNetwork
lateinit var mockNet: MockNetwork
lateinit var aliceNode: MockNode
lateinit var notaryNode: MockNode
lateinit var rpc: CordaRPCOpsImpl
@ -57,10 +57,10 @@ class CordaRPCOpsImplTest {
@Before
fun setup() {
network = MockNetwork()
val networkMap = network.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
aliceNode = network.createNode(networkMapAddress = networkMap.info.address)
notaryNode = network.createNode(advertisedServices = ServiceInfo(SimpleNotaryService.type), networkMapAddress = networkMap.info.address)
mockNet = MockNetwork()
val networkMap = mockNet.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
aliceNode = mockNet.createNode(networkMapAddress = networkMap.info.address)
notaryNode = mockNet.createNode(advertisedServices = ServiceInfo(SimpleNotaryService.type), networkMapAddress = networkMap.info.address)
rpc = CordaRPCOpsImpl(aliceNode.services, aliceNode.smm, aliceNode.database)
CURRENT_RPC_CONTEXT.set(RpcContext(User("user", "pwd", permissions = setOf(
startFlowPermission<CashIssueFlow>(),
@ -87,7 +87,7 @@ class CordaRPCOpsImplTest {
// Tell the monitoring service node to issue some cash
val recipient = aliceNode.info.legalIdentity
rpc.startFlow(::CashIssueFlow, Amount(quantity, GBP), ref, recipient, notaryNode.info.notaryIdentity)
network.runNetwork()
mockNet.runNetwork()
val expectedState = Cash.State(Amount(quantity,
Issued(aliceNode.info.legalIdentity.ref(ref), GBP)),
@ -129,11 +129,11 @@ class CordaRPCOpsImplTest {
notaryNode.info.notaryIdentity
)
network.runNetwork()
mockNet.runNetwork()
rpc.startFlow(::CashPaymentFlow, Amount(100, USD), aliceNode.info.legalIdentity)
network.runNetwork()
mockNet.runNetwork()
var issueSmId: StateMachineRunId? = null
var moveSmId: StateMachineRunId? = null

View File

@ -31,14 +31,14 @@ import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
class AttachmentTests {
lateinit var network: MockNetwork
lateinit var mockNet: MockNetwork
lateinit var dataSource: Closeable
lateinit var database: Database
lateinit var configuration: RequeryConfiguration
@Before
fun setUp() {
network = MockNetwork()
mockNet = MockNetwork()
val dataSourceProperties = makeTestDataSourceProperties()
@ -57,7 +57,7 @@ class AttachmentTests {
@Test
fun `download and store`() {
val (n0, n1) = network.createTwoNodes()
val (n0, n1) = mockNet.createTwoNodes()
// Insert an attachment into node zero's store directly.
val id = n0.database.transaction {
@ -65,9 +65,9 @@ class AttachmentTests {
}
// 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))
network.runNetwork()
mockNet.runNetwork()
assertEquals(0, f1.resultFuture.getOrThrow().fromDisk.size)
// Verify it was inserted into node one's store.
@ -86,13 +86,13 @@ class AttachmentTests {
@Test
fun `missing`() {
val (n0, n1) = network.createTwoNodes()
val (n0, n1) = mockNet.createTwoNodes()
// Get node one to fetch a non-existent attachment.
val hash = SecureHash.randomSHA256()
network.runNetwork()
mockNet.runNetwork()
val f1 = n1.services.startFlow(FetchAttachmentsFlow(setOf(hash), n0.info.legalIdentity))
network.runNetwork()
mockNet.runNetwork()
val e = assertFailsWith<FetchDataFlow.HashNotFound> { f1.resultFuture.getOrThrow() }
assertEquals(hash, e.requested)
}
@ -100,7 +100,7 @@ class AttachmentTests {
@Test
fun `malicious response`() {
// 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?,
advertisedServices: Set<ServiceInfo>, id: Int,
overrideServices: Map<ServiceInfo, KeyPair>?,
@ -114,7 +114,7 @@ class AttachmentTests {
}
}
}, 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()
// 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.
network.runNetwork()
mockNet.runNetwork()
val f1 = n1.services.startFlow(FetchAttachmentsFlow(setOf(id), n0.info.legalIdentity))
network.runNetwork()
mockNet.runNetwork()
assertFailsWith<FetchDataFlow.DownloadedVsRequestedDataMismatch> { f1.resultFuture.getOrThrow() }
}
}

View File

@ -14,7 +14,7 @@ import kotlin.test.assertFails
import kotlin.test.assertTrue
class InMemoryMessagingTests {
val network = MockNetwork()
val mockNet = MockNetwork()
@Test
fun topicStringValidation() {
@ -33,45 +33,45 @@ class InMemoryMessagingTests {
@Test
fun basics() {
val node1 = network.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
val node2 = network.createNode(networkMapAddress = node1.info.address)
val node3 = network.createNode(networkMapAddress = node1.info.address)
val node1 = mockNet.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
val node2 = mockNet.createNode(networkMapAddress = node1.info.address)
val node3 = mockNet.createNode(networkMapAddress = node1.info.address)
val bits = "test-content".toByteArray()
var finalDelivery: Message? = null
with(node2) {
node2.net.addMessageHandler { msg, _ ->
node2.net.send(msg, node3.info.address)
node2.network.addMessageHandler { msg, _ ->
node2.network.send(msg, node3.info.address)
}
}
with(node3) {
node2.net.addMessageHandler { msg, _ ->
node2.network.addMessageHandler { msg, _ ->
finalDelivery = msg
}
}
// 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))
}
@Test
fun broadcast() {
val node1 = network.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
val node2 = network.createNode(networkMapAddress = node1.info.address)
val node3 = network.createNode(networkMapAddress = node1.info.address)
val node1 = mockNet.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
val node2 = mockNet.createNode(networkMapAddress = node1.info.address)
val node3 = mockNet.createNode(networkMapAddress = node1.info.address)
val bits = "test-content".toByteArray()
var counter = 0
listOf(node1, node2, node3).forEach { it.net.addMessageHandler { _, _ -> counter++ } }
node1.net.send(node2.net.createMessage("test.topic", DEFAULT_SESSION_ID, bits), network.messagingNetwork.everyoneOnline)
network.runNetwork(rounds = 1)
listOf(node1, node2, node3).forEach { it.network.addMessageHandler { _, _ -> counter++ } }
node1.network.send(node2.network.createMessage("test.topic", DEFAULT_SESSION_ID, bits), mockNet.messagingNetwork.everyoneOnline)
mockNet.runNetwork(rounds = 1)
assertEquals(3, counter)
}
@ -81,31 +81,31 @@ class InMemoryMessagingTests {
*/
@Test
fun `skip unhandled messages`() {
val node1 = network.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
val node2 = network.createNode(networkMapAddress = node1.info.address)
val node1 = mockNet.createNode(advertisedServices = ServiceInfo(NetworkMapService.type))
val node2 = mockNet.createNode(networkMapAddress = node1.info.address)
var received: Int = 0
node1.net.addMessageHandler("valid_message") { _, _ ->
node1.network.addMessageHandler("valid_message") { _, _ ->
received++
}
val invalidMessage = node2.net.createMessage("invalid_message", DEFAULT_SESSION_ID, ByteArray(0))
val validMessage = node2.net.createMessage("valid_message", DEFAULT_SESSION_ID, ByteArray(0))
node2.net.send(invalidMessage, node1.net.myAddress)
network.runNetwork()
val invalidMessage = node2.network.createMessage("invalid_message", DEFAULT_SESSION_ID, ByteArray(0))
val validMessage = node2.network.createMessage("valid_message", DEFAULT_SESSION_ID, ByteArray(0))
node2.network.send(invalidMessage, node1.network.myAddress)
mockNet.runNetwork()
assertEquals(0, received)
node2.net.send(validMessage, node1.net.myAddress)
network.runNetwork()
node2.network.send(validMessage, node1.network.myAddress)
mockNet.runNetwork()
assertEquals(1, received)
// 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
val invalidMessage2 = node2.net.createMessage("invalid_message", DEFAULT_SESSION_ID, ByteArray(0))
val validMessage2 = node2.net.createMessage("valid_message", DEFAULT_SESSION_ID, ByteArray(0))
node2.net.send(invalidMessage2, node1.net.myAddress)
node2.net.send(validMessage2, node1.net.myAddress)
network.runNetwork()
val invalidMessage2 = node2.network.createMessage("invalid_message", DEFAULT_SESSION_ID, ByteArray(0))
val validMessage2 = node2.network.createMessage("valid_message", DEFAULT_SESSION_ID, ByteArray(0))
node2.network.send(invalidMessage2, node1.network.myAddress)
node2.network.send(validMessage2, node1.network.myAddress)
mockNet.runNetwork()
assertEquals(2, received)
}
}

View File

@ -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.
*/
class TwoPartyTradeFlowTests {
lateinit var net: MockNetwork
lateinit var mockNet: MockNetwork
@Before
fun before() {
net = MockNetwork(false)
mockNet = MockNetwork(false)
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 in the unit test thread exclusively to speed things up, ensure deterministic results and
// allow interruption half way through.
net = MockNetwork(false, true)
mockNet = MockNetwork(false, true)
ledger {
val basketOfNodes = net.createSomeNodes(2)
val basketOfNodes = mockNet.createSomeNodes(2)
val notaryNode = basketOfNodes.notaryNode
val aliceNode = basketOfNodes.partyNodes[0]
val bobNode = basketOfNodes.partyNodes[1]
@ -122,12 +122,12 @@ class TwoPartyTradeFlowTests {
@Test(expected = InsufficientBalanceException::class)
fun `trade cash for commercial paper fails using soft locking`() {
net = MockNetwork(false, true)
mockNet = MockNetwork(false, true)
ledger {
val notaryNode = net.createNotaryNode(null, DUMMY_NOTARY.name)
val aliceNode = net.createPartyNode(notaryNode.info.address, ALICE.name)
val bobNode = net.createPartyNode(notaryNode.info.address, BOB.name)
val notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
val aliceNode = mockNet.createPartyNode(notaryNode.info.address, ALICE.name)
val bobNode = mockNet.createPartyNode(notaryNode.info.address, BOB.name)
aliceNode.disableDBCloseOnStop()
bobNode.disableDBCloseOnStop()
@ -171,16 +171,16 @@ class TwoPartyTradeFlowTests {
@Test
fun `shutdown and restore`() {
ledger {
val notaryNode = net.createNotaryNode(null, DUMMY_NOTARY.name)
val aliceNode = net.createPartyNode(notaryNode.info.address, ALICE.name)
var bobNode = net.createPartyNode(notaryNode.info.address, BOB.name)
val notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
val aliceNode = mockNet.createPartyNode(notaryNode.info.address, ALICE.name)
var bobNode = mockNet.createPartyNode(notaryNode.info.address, BOB.name)
aliceNode.disableDBCloseOnStop()
bobNode.disableDBCloseOnStop()
val bobAddr = bobNode.net.myAddress as InMemoryMessagingNetwork.PeerHandle
val bobAddr = bobNode.network.myAddress as InMemoryMessagingNetwork.PeerHandle
val networkMapAddr = notaryNode.info.address
net.runNetwork() // Clear network map registration messages
mockNet.runNetwork() // Clear network map registration messages
bobNode.database.transaction {
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
// 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?,
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
entropyRoot: BigInteger): MockNetwork.MockNode {
@ -236,7 +236,7 @@ class TwoPartyTradeFlowTests {
val bobFuture = bobNode.smm.findStateMachines(BuyerAcceptor::class.java).single().second
// And off we go again.
net.runNetwork()
mockNet.runNetwork()
// Bob is now finished and has the same transaction as Alice.
assertThat(bobFuture.getOrThrow()).isEqualTo(aliceFuture.getOrThrow())
@ -266,7 +266,7 @@ class TwoPartyTradeFlowTests {
name: X500Name,
overrideServices: Map<ServiceInfo, KeyPair>? = null): MockNetwork.MockNode {
// 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,
network: MockNetwork,
networkMapAddr: SingleMessageRecipient?,
@ -289,7 +289,7 @@ class TwoPartyTradeFlowTests {
@Test
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 bobNode = makeNodeWithTracking(notaryNode.info.address, BOB.name)
@ -317,11 +317,11 @@ class TwoPartyTradeFlowTests {
}
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())
net.runNetwork()
mockNet.runNetwork()
run {
val records = (bobNode.storage.validatedTransactions as RecordingTransactionStorage).records
@ -388,7 +388,7 @@ class TwoPartyTradeFlowTests {
@Test
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 bobNode = makeNodeWithTracking(notaryNode.info.address, BOB.name)
@ -418,14 +418,14 @@ class TwoPartyTradeFlowTests {
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 aliceTxMappings = with(aliceNode) { database.transaction { storage.stateMachineRecordedTransactionMapping.track().second } }
val aliceSmId = runBuyerAndSeller(notaryNode, aliceNode, bobNode,
"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(!).
val aliceTxExpectations = sequence(
@ -526,9 +526,9 @@ class TwoPartyTradeFlowTests {
aliceError: Boolean,
expectedMessageSubstring: String
) {
val notaryNode = net.createNotaryNode(null, DUMMY_NOTARY.name)
val aliceNode = net.createPartyNode(notaryNode.info.address, ALICE.name)
val bobNode = net.createPartyNode(notaryNode.info.address, BOB.name)
val notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
val aliceNode = mockNet.createPartyNode(notaryNode.info.address, ALICE.name)
val bobNode = mockNet.createPartyNode(notaryNode.info.address, BOB.name)
val issuer = MEGA_CORP.ref(1, 2, 3)
val bobsBadCash = bobNode.database.transaction {
@ -543,11 +543,11 @@ class TwoPartyTradeFlowTests {
insertFakeTransactions(bobsBadCash, bobNode, notaryNode, DUMMY_CASH_ISSUER_KEY.public, 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())
net.runNetwork()
mockNet.runNetwork()
val e = assertFailsWith<TransactionVerificationException> {
if (bobError)

View File

@ -23,7 +23,7 @@ import java.time.Clock
open class MockServiceHubInternal(
val customVault: VaultService? = null,
val keyManagement: KeyManagementService? = null,
val net: MessagingService? = null,
val network: MessagingService? = null,
val identity: IdentityService? = MOCK_IDENTITY_SERVICE,
val storage: TxWritableStorageService? = MockStorageService(),
val mapCache: NetworkMapCacheInternal? = MockNetworkMapCache(),
@ -41,7 +41,7 @@ open class MockServiceHubInternal(
override val identityService: IdentityService
get() = identity ?: throw UnsupportedOperationException()
override val networkService: MessagingService
get() = net ?: throw UnsupportedOperationException()
get() = network ?: throw UnsupportedOperationException()
override val networkMapCache: NetworkMapCacheInternal
get() = mapCache ?: throw UnsupportedOperationException()
override val storageService: StorageService

View File

@ -25,7 +25,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertTrue
class NotaryChangeTests {
lateinit var net: MockNetwork
lateinit var mockNet: MockNetwork
lateinit var oldNotaryNode: MockNetwork.MockNode
lateinit var newNotaryNode: MockNetwork.MockNode
lateinit var clientNodeA: MockNetwork.MockNode
@ -33,15 +33,15 @@ class NotaryChangeTests {
@Before
fun setup() {
net = MockNetwork()
oldNotaryNode = net.createNode(
mockNet = MockNetwork()
oldNotaryNode = mockNet.createNode(
legalName = DUMMY_NOTARY.name,
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(SimpleNotaryService.type)))
clientNodeA = net.createNode(networkMapAddress = oldNotaryNode.info.address)
clientNodeB = net.createNode(networkMapAddress = oldNotaryNode.info.address)
newNotaryNode = net.createNode(networkMapAddress = oldNotaryNode.info.address, advertisedServices = ServiceInfo(SimpleNotaryService.type))
clientNodeA = mockNet.createNode(networkMapAddress = oldNotaryNode.info.address)
clientNodeB = mockNet.createNode(networkMapAddress = oldNotaryNode.info.address)
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
@ -51,7 +51,7 @@ class NotaryChangeTests {
val flow = NotaryChangeFlow(state, newNotary)
val future = clientNodeA.services.startFlow(flow)
net.runNetwork()
mockNet.runNetwork()
val newState = future.resultFuture.getOrThrow()
assertEquals(newState.state.notary, newNotary)
@ -64,7 +64,7 @@ class NotaryChangeTests {
val flow = NotaryChangeFlow(state, newNotary)
val future = clientNodeA.services.startFlow(flow)
net.runNetwork()
mockNet.runNetwork()
val newState = future.resultFuture.getOrThrow()
assertEquals(newState.state.notary, newNotary)
@ -80,7 +80,7 @@ class NotaryChangeTests {
val flow = NotaryChangeFlow(state, newEvilNotary.party)
val future = clientNodeA.services.startFlow(flow)
net.runNetwork()
mockNet.runNetwork()
assertThatExceptionOfType(StateReplacementException::class.java).isThrownBy {
future.resultFuture.getOrThrow()
@ -95,7 +95,7 @@ class NotaryChangeTests {
val newNotary = newNotaryNode.info.notaryIdentity
val flow = NotaryChangeFlow(state, newNotary)
val future = clientNodeA.services.startFlow(flow)
net.runNetwork()
mockNet.runNetwork()
val newState = future.resultFuture.getOrThrow()
assertEquals(newState.state.notary, newNotary)

View File

@ -87,7 +87,7 @@ class NodeSchedulerServiceTest : SingletonSerializeAsToken() {
InMemoryMessagingNetwork.PeerHandle(0, nullIdentity),
AffinityExecutor.ServiceAffinityExecutor("test", 1),
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 testReference = this@NodeSchedulerServiceTest
}

View File

@ -27,7 +27,7 @@ import java.time.Instant
import kotlin.test.assertEquals
class ScheduledFlowTests {
lateinit var net: MockNetwork
lateinit var mockNet: MockNetwork
lateinit var notaryNode: MockNetwork.MockNode
lateinit var nodeA: MockNetwork.MockNode
lateinit var nodeB: MockNetwork.MockNode
@ -90,18 +90,18 @@ class ScheduledFlowTests {
@Before
fun setup() {
net = MockNetwork(threadPerNode = true)
notaryNode = net.createNode(
mockNet = MockNetwork(threadPerNode = true)
notaryNode = mockNet.createNode(
legalName = DUMMY_NOTARY.name,
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(ValidatingNotaryService.type)))
nodeA = net.createNode(notaryNode.info.address, start = false)
nodeB = net.createNode(notaryNode.info.address, start = false)
net.startNodes()
nodeA = mockNet.createNode(notaryNode.info.address, start = false)
nodeB = mockNet.createNode(notaryNode.info.address, start = false)
mockNet.startNodes()
}
@After
fun cleanUp() {
net.stopNodes()
mockNet.stopNodes()
}
@Test
@ -116,7 +116,7 @@ class ScheduledFlowTests {
}
}
nodeA.services.startFlow(InsertInitialStateFlow(nodeB.info.legalIdentity))
net.waitQuiescent()
mockNet.waitQuiescent()
val stateFromA = nodeA.database.transaction {
nodeA.services.vaultService.linearHeadsOfType<ScheduledState>().values.first()
}
@ -135,7 +135,7 @@ class ScheduledFlowTests {
nodeA.services.startFlow(InsertInitialStateFlow(nodeB.info.legalIdentity))
nodeB.services.startFlow(InsertInitialStateFlow(nodeA.info.legalIdentity))
}
net.waitQuiescent()
mockNet.waitQuiescent()
val statesFromA = nodeA.database.transaction {
nodeA.services.vaultService.linearHeadsOfType<ScheduledState>()
}

View File

@ -39,7 +39,7 @@ import java.security.KeyPair
import java.time.Instant
abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService> {
lateinit var network: MockNetwork
lateinit var mockNet: MockNetwork
lateinit var mapServiceNode: MockNode
lateinit var alice: MockNode
@ -49,18 +49,18 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
@Before
fun setup() {
network = MockNetwork(defaultFactory = nodeFactory)
network.createTwoNodes(firstNodeName = DUMMY_MAP.name, secondNodeName = ALICE.name).apply {
mockNet = MockNetwork(defaultFactory = nodeFactory)
mockNet.createTwoNodes(firstNodeName = DUMMY_MAP.name, secondNodeName = ALICE.name).apply {
mapServiceNode = first
alice = second
}
network.runNetwork()
mockNet.runNetwork()
lastSerial = System.currentTimeMillis()
}
@After
fun tearDown() {
network.stopNodes()
mockNet.stopNodes()
}
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> {
val request = FetchMapRequest(subscribe, ifChangedSinceVersion, 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()
}
@ -200,7 +200,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
private fun MockNode.identityQuery(): NodeInfo? {
val request = QueryIdentityRequest(info.legalIdentityAndCert, info.address)
val response = services.networkService.sendRequest<QueryIdentityResponse>(QUERY_TOPIC, request, mapServiceNode.info.address)
network.runNetwork()
mockNet.runNetwork()
return response.getOrThrow().node
}
@ -218,7 +218,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
val nodeRegistration = NodeRegistration(info, distinctSerial, addOrRemove, expires)
val request = RegistrationRequest(nodeRegistration.toWire(services.keyManagementService, services.legalIdentityKey), info.address)
val response = services.networkService.sendRequest<RegistrationResponse>(REGISTER_TOPIC, request, mapServiceNode.info.address)
network.runNetwork()
mockNet.runNetwork()
return response
}
@ -229,7 +229,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
updates += message.data.deserialize<Update>()
}
val response = services.networkService.sendRequest<SubscribeResponse>(SUBSCRIPTION_TOPIC, request, mapServiceNode.info.address)
network.runNetwork()
mockNet.runNetwork()
assertThat(response.getOrThrow().confirmed).isTrue()
return updates
}
@ -237,25 +237,25 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
private fun MockNode.unsubscribe() {
val request = SubscribeRequest(false, info.address)
val response = services.networkService.sendRequest<SubscribeResponse>(SUBSCRIPTION_TOPIC, request, mapServiceNode.info.address)
network.runNetwork()
mockNet.runNetwork()
assertThat(response.getOrThrow().confirmed).isTrue()
}
private fun MockNode.ackUpdate(mapVersion: Int) {
val request = UpdateAcknowledge(mapVersion, services.networkService.myAddress)
services.networkService.send(PUSH_ACK_TOPIC, DEFAULT_SESSION_ID, request, mapServiceNode.info.address)
network.runNetwork()
mockNet.runNetwork()
}
private fun addNewNodeToNetworkMap(legalName: X500Name): MockNode {
val node = network.createNode(networkMapAddress = mapServiceNode.info.address, legalName = legalName)
network.runNetwork()
val node = mockNet.createNode(networkMapAddress = mapServiceNode.info.address, legalName = legalName)
mockNet.runNetwork()
lastSerial = System.currentTimeMillis()
return node
}
private fun newNodeSeparateFromNetworkMap(legalName: X500Name): MockNode {
return network.createNode(legalName = legalName, nodeFactory = NoNMSNodeFactory)
return mockNet.createNode(legalName = legalName, nodeFactory = NoNMSNodeFactory)
}
sealed class Changed {

View File

@ -11,21 +11,21 @@ import java.math.BigInteger
import kotlin.test.assertEquals
class InMemoryNetworkMapCacheTest {
private val network = MockNetwork()
private val mockNet = MockNetwork()
@Test
fun registerWithNetwork() {
val (n0, n1) = network.createTwoNodes()
val future = n1.services.networkMapCache.addMapService(n1.net, n0.info.address, false, null)
network.runNetwork()
val (n0, n1) = mockNet.createTwoNodes()
val future = n1.services.networkMapCache.addMapService(n1.network, n0.info.address, false, null)
mockNet.runNetwork()
future.getOrThrow()
}
@Test
fun `key collision`() {
val entropy = BigInteger.valueOf(24012017L)
val nodeA = network.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 nodeA = mockNet.createNode(null, -1, MockNetwork.DefaultFactory, true, ALICE.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)
// Node A currently knows only about itself, so this returns node A

View File

@ -28,19 +28,19 @@ import kotlin.test.assertEquals
* Tests for the data vending service.
*/
class DataVendingServiceTests {
lateinit var network: MockNetwork
lateinit var mockNet: MockNetwork
@Before
fun setup() {
network = MockNetwork()
mockNet = MockNetwork()
}
@Test
fun `notify of transaction`() {
val (vaultServiceNode, registerNode) = network.createTwoNodes()
val (vaultServiceNode, registerNode) = mockNet.createTwoNodes()
val beneficiary = vaultServiceNode.info.legalIdentity
val deposit = registerNode.info.legalIdentity.ref(1)
network.runNetwork()
mockNet.runNetwork()
// Generate an issuance transaction
val ptx = TransactionType.General.Builder(null)
@ -65,10 +65,10 @@ class DataVendingServiceTests {
*/
@Test
fun `notify failure`() {
val (vaultServiceNode, registerNode) = network.createTwoNodes()
val (vaultServiceNode, registerNode) = mockNet.createTwoNodes()
val beneficiary = vaultServiceNode.info.legalIdentity
val deposit = MEGA_CORP.ref(1)
network.runNetwork()
mockNet.runNetwork()
// Generate an issuance transaction
val ptx = TransactionType.General.Builder(DUMMY_NOTARY)
@ -89,7 +89,7 @@ class DataVendingServiceTests {
private fun MockNode.sendNotifyTx(tx: SignedTransaction, walletServiceNode: MockNode) {
walletServiceNode.registerInitiatedFlow(InitiateNotifyTxFlow::class.java)
services.startFlow(NotifyTxFlow(walletServiceNode.info.legalIdentity, tx))
network.runNetwork()
mockNet.runNetwork()
}
@InitiatingFlow

View File

@ -64,7 +64,7 @@ class FlowFrameworkTests {
}
}
private val net = MockNetwork(servicePeerAllocationStrategy = RoundRobin())
private val mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin())
private val sessionTransfers = ArrayList<SessionTransfer>()
private lateinit var node1: MockNode
private lateinit var node2: MockNode
@ -73,7 +73,7 @@ class FlowFrameworkTests {
@Before
fun start() {
val nodes = net.createTwoNodes()
val nodes = mockNet.createTwoNodes()
node1 = nodes.first
node2 = nodes.second
val notaryKeyPair = generateKeyPair()
@ -81,16 +81,16 @@ class FlowFrameworkTests {
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
// service addressing.
notary1 = net.createNotaryNode(networkMapAddr = node1.services.myInfo.address, overrideServices = overrideServices, serviceName = notaryService.name)
notary2 = 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 = mockNet.createNotaryNode(networkMapAddr = node1.services.myInfo.address, overrideServices = overrideServices, serviceName = notaryService.name)
net.messagingNetwork.receivedMessages.toSessionTransfers().forEach { sessionTransfers += it }
net.runNetwork()
mockNet.messagingNetwork.receivedMessages.toSessionTransfers().forEach { sessionTransfers += it }
mockNet.runNetwork()
}
@After
fun cleanUp() {
net.stopNodes()
mockNet.stopNodes()
}
@Test
@ -122,7 +122,7 @@ class FlowFrameworkTests {
fiber.actionOnSuspend = {
throw exceptionDuringSuspend
}
net.runNetwork()
mockNet.runNetwork()
assertThatThrownBy {
fiber.resultFuture.getOrThrow()
}.isSameAs(exceptionDuringSuspend)
@ -141,42 +141,42 @@ class FlowFrameworkTests {
node2.disableDBCloseOnStop()
node2.acceptableLiveFiberCountOnStop = 1
node2.stop()
net.runNetwork()
mockNet.runNetwork()
val restoredFlow = node2.restartAndGetRestoredFlow<ReceiveFlow>(node1)
assertThat(restoredFlow.receivedPayloads[0]).isEqualTo("Hello")
}
@Test
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()
node3.services.startFlow(flow)
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
}
@Test
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()
node3.services.startFlow(flow)
assertEquals(false, flow.flowStarted) // Not started yet as no network activity has been allowed yet
node3.disableDBCloseOnStop()
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
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()
assertEquals(true, restoredFlow.flowStarted) // Now we should have run the flow and hopefully cleared the init checkpoint
node3.disableDBCloseOnStop()
node3.stop()
// Now it is completed the flow should leave no Checkpoint.
node3 = net.createNode(node1.info.address, forcedID = node3.id)
net.runNetwork() // Allow network map messages to flow
node3 = mockNet.createNode(node1.info.address, forcedID = node3.id)
mockNet.runNetwork() // Allow network map messages to flow
node3.smm.executor.flush()
assertTrue(node3.smm.findStateMachines(NoOpFlow::class.java).isEmpty())
}
@ -199,11 +199,11 @@ class FlowFrameworkTests {
val payload2 = random63BitValue()
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) }
net.runNetwork()
mockNet.runNetwork()
// Kick off first send and receive
node2.services.startFlow(PingPongFlow(node3.info.legalIdentity, payload))
@ -218,11 +218,11 @@ class FlowFrameworkTests {
node2.database.transaction {
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()
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.
net.runNetwork()
mockNet.runNetwork()
node2b.smm.executor.flush()
fut1.getOrThrow()
@ -245,13 +245,13 @@ class FlowFrameworkTests {
@Test
fun `sending to multiple parties`() {
val node3 = net.createNode(node1.info.address)
net.runNetwork()
val node3 = mockNet.createNode(node1.info.address)
mockNet.runNetwork()
node2.registerFlowFactory(SendFlow::class) { ReceiveFlow(it).nonTerminating() }
node3.registerFlowFactory(SendFlow::class) { ReceiveFlow(it).nonTerminating() }
val payload = "Hello World"
node1.services.startFlow(SendFlow(payload, node2.info.legalIdentity, node3.info.legalIdentity))
net.runNetwork()
mockNet.runNetwork()
val node2Flow = node2.getSingleFlow<ReceiveFlow>().first
val node3Flow = node3.getSingleFlow<ReceiveFlow>().first
assertThat(node2Flow.receivedPayloads[0]).isEqualTo(payload)
@ -277,8 +277,8 @@ class FlowFrameworkTests {
@Test
fun `receiving from multiple parties`() {
val node3 = net.createNode(node1.info.address)
net.runNetwork()
val node3 = mockNet.createNode(node1.info.address)
mockNet.runNetwork()
val node2Payload = "Test 1"
val node3Payload = "Test 2"
node2.registerFlowFactory(ReceiveFlow::class) { SendFlow(node2Payload, it) }
@ -286,7 +286,7 @@ class FlowFrameworkTests {
val multiReceiveFlow = ReceiveFlow(node2.info.legalIdentity, node3.info.legalIdentity).nonTerminating()
node1.services.startFlow(multiReceiveFlow)
node1.acceptableLiveFiberCountOnStop = 1
net.runNetwork()
mockNet.runNetwork()
assertThat(multiReceiveFlow.receivedPayloads[0]).isEqualTo(node2Payload)
assertThat(multiReceiveFlow.receivedPayloads[1]).isEqualTo(node3Payload)
@ -309,7 +309,7 @@ class FlowFrameworkTests {
fun `both sides do a send as their first IO request`() {
node2.registerFlowFactory(PingPongFlow::class) { PingPongFlow(it, 20L) }
node1.services.startFlow(PingPongFlow(node2.info.legalIdentity, 10L))
net.runNetwork()
mockNet.runNetwork()
assertSessionTransfers(
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
for (i in 1..3) {
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)!!
assertTrue(party1Info is PartyInfo.Service)
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`() {
node2.registerFlowFactory(ReceiveFlow::class) { NoOpFlow() }
val resultFuture = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity)).resultFuture
net.runNetwork()
mockNet.runNetwork()
assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
resultFuture.getOrThrow()
}.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 receiveFlowResult = node1.services.startFlow(receiveFlow).resultFuture
net.runNetwork()
mockNet.runNetwork()
assertThat(erroringFlowSteps.get()).containsExactly(
Notification.createOnNext(ExceptionFlow.START_STEP),
@ -429,7 +429,7 @@ class FlowFrameworkTests {
val receivingFiber = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity)) as FlowStateMachineImpl
net.runNetwork()
mockNet.runNetwork()
assertThatExceptionOfType(MyFlowException::class.java)
.isThrownBy { receivingFiber.resultFuture.getOrThrow() }
@ -457,13 +457,13 @@ class FlowFrameworkTests {
@Test
fun `FlowException propagated in invocation chain`() {
val node3 = net.createNode(node1.info.address)
net.runNetwork()
val node3 = mockNet.createNode(node1.info.address)
mockNet.runNetwork()
node3.registerFlowFactory(ReceiveFlow::class) { ExceptionFlow { MyFlowException("Chain") } }
node2.registerFlowFactory(ReceiveFlow::class) { ReceiveFlow(node3.info.legalIdentity) }
val receivingFiber = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity))
net.runNetwork()
mockNet.runNetwork()
assertThatExceptionOfType(MyFlowException::class.java)
.isThrownBy { receivingFiber.resultFuture.getOrThrow() }
.withMessage("Chain")
@ -471,8 +471,8 @@ class FlowFrameworkTests {
@Test
fun `FlowException thrown and there is a 3rd unrelated party flow`() {
val node3 = net.createNode(node1.info.address)
net.runNetwork()
val node3 = mockNet.createNode(node1.info.address)
mockNet.runNetwork()
// 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
@ -482,7 +482,7 @@ class FlowFrameworkTests {
node3.registerFlowFactory(ReceiveFlow::class) { ExceptionFlow { MyFlowException("Nothing useful") } }
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
// 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") }
val resultFuture = node1.services.startFlow(RetryOnExceptionFlow(node2.info.legalIdentity)).resultFuture
net.runNetwork()
mockNet.runNetwork()
assertThat(resultFuture.getOrThrow()).isEqualTo("Hello")
}
@ -542,7 +542,7 @@ class FlowFrameworkTests {
fun `serialisation issue in counterparty`() {
node2.registerFlowFactory(ReceiveFlow::class) { SendFlow(NonSerialisableData(1), it) }
val result = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity)).resultFuture
net.runNetwork()
mockNet.runNetwork()
assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
result.getOrThrow()
}
@ -554,7 +554,7 @@ class FlowFrameworkTests {
ExceptionFlow { NonSerialisableFlowException(NonSerialisableData(1)) }
}
val result = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity)).resultFuture
net.runNetwork()
mockNet.runNetwork()
assertThatExceptionOfType(FlowException::class.java).isThrownBy {
result.getOrThrow()
}
@ -570,7 +570,7 @@ class FlowFrameworkTests {
WaitingFlows.Committer(it)
}.map { it.stateMachine }
val waiterStx = node2.services.startFlow(WaitingFlows.Waiter(stx, node1.info.legalIdentity)).resultFuture
net.runNetwork()
mockNet.runNetwork()
assertThat(waiterStx.getOrThrow()).isEqualTo(committerFiber.getOrThrow().resultFuture.getOrThrow())
}
@ -584,7 +584,7 @@ class FlowFrameworkTests {
WaitingFlows.Committer(it) { throw Exception("Error") }
}
val waiter = node2.services.startFlow(WaitingFlows.Waiter(stx, node1.info.legalIdentity)).resultFuture
net.runNetwork()
mockNet.runNetwork()
assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
waiter.getOrThrow()
}
@ -593,7 +593,7 @@ class FlowFrameworkTests {
@Test
fun `lazy db iterator left on stack during checkpointing`() {
val result = node2.services.startFlow(VaultAccessFlow()).resultFuture
net.runNetwork()
mockNet.runNetwork()
assertThatThrownBy { result.getOrThrow() }.hasMessageContaining("Vault").hasMessageContaining("private method")
}
@ -601,14 +601,14 @@ class FlowFrameworkTests {
fun `customised client flow`() {
val receiveFlowFuture = node2.registerFlowFactory(SendFlow::class) { ReceiveFlow(it) }
node1.services.startFlow(CustomSendFlow("Hello", node2.info.legalIdentity)).resultFuture
net.runNetwork()
mockNet.runNetwork()
assertThat(receiveFlowFuture.getOrThrow().receivedPayloads).containsOnly("Hello")
}
@Test
fun `customised client flow which has annotated @InitiatingFlow again`() {
val result = node1.services.startFlow(IncorrectCustomSendFlow("Hello", node2.info.legalIdentity)).resultFuture
net.runNetwork()
mockNet.runNetwork()
assertThatExceptionOfType(IllegalArgumentException::class.java).isThrownBy {
result.getOrThrow()
}.withMessageContaining(InitiatingFlow::class.java.simpleName)
@ -617,7 +617,7 @@ class FlowFrameworkTests {
@Test
fun `upgraded flow`() {
node1.services.startFlow(UpgradedFlow(node2.info.legalIdentity))
net.runNetwork()
mockNet.runNetwork()
assertThat(sessionTransfers).startsWith(
node1 sent sessionInit(UpgradedFlow::class, 2) to node2
)
@ -631,7 +631,7 @@ class FlowFrameworkTests {
DoubleInlinedSubFlow::class.java,
track = false)
val result = node1.services.startFlow(UpgradedFlow(node2.info.legalIdentity)).resultFuture
net.runNetwork()
mockNet.runNetwork()
assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
result.getOrThrow()
}.withMessageContaining("Version")
@ -641,7 +641,7 @@ class FlowFrameworkTests {
fun `single inlined sub-flow`() {
node2.registerFlowFactory(SendAndReceiveFlow::class, ::SingleInlinedSubFlow)
val result = node1.services.startFlow(SendAndReceiveFlow(node2.info.legalIdentity, "Hello")).resultFuture
net.runNetwork()
mockNet.runNetwork()
assertThat(result.getOrThrow()).isEqualTo("HelloHello")
}
@ -649,7 +649,7 @@ class FlowFrameworkTests {
fun `double inlined sub-flow`() {
node2.registerFlowFactory(SendAndReceiveFlow::class, ::DoubleInlinedSubFlow)
val result = node1.services.startFlow(SendAndReceiveFlow(node2.info.legalIdentity, "Hello")).resultFuture
net.runNetwork()
mockNet.runNetwork()
assertThat(result.getOrThrow()).isEqualTo("HelloHello")
}
@ -696,7 +696,7 @@ class FlowFrameworkTests {
}
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)
return actualForNode
}
@ -724,7 +724,7 @@ class FlowFrameworkTests {
}
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() {
return progressTracker!!.changes

View File

@ -26,17 +26,17 @@ import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
class NotaryServiceTests {
lateinit var net: MockNetwork
lateinit var mockNet: MockNetwork
lateinit var notaryNode: MockNetwork.MockNode
lateinit var clientNode: MockNetwork.MockNode
@Before fun setup() {
net = MockNetwork()
notaryNode = net.createNode(
mockNet = MockNetwork()
notaryNode = mockNet.createNode(
legalName = DUMMY_NOTARY.name,
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(SimpleNotaryService.type)))
clientNode = net.createNode(networkMapAddress = notaryNode.info.address)
net.runNetwork() // Clear network map registration messages
clientNode = mockNet.createNode(networkMapAddress = notaryNode.info.address)
mockNet.runNetwork() // Clear network map registration messages
}
@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 f2 = clientNode.services.startFlow(secondAttempt)
net.runNetwork()
mockNet.runNetwork()
assertEquals(f1.resultFuture.getOrThrow(), f2.resultFuture.getOrThrow())
}
@ -112,7 +112,7 @@ class NotaryServiceTests {
clientNode.services.startFlow(firstSpend)
val future = clientNode.services.startFlow(secondSpend)
net.runNetwork()
mockNet.runNetwork()
val ex = assertFailsWith(NotaryException::class) { future.resultFuture.getOrThrow() }
val notaryError = ex.error as NotaryError.Conflict
@ -123,7 +123,7 @@ class NotaryServiceTests {
private fun runNotaryClient(stx: SignedTransaction): ListenableFuture<List<DigitalSignature.WithKey>> {
val flow = NotaryFlow.Client(stx)
val future = clientNode.services.startFlow(flow).resultFuture
net.runNetwork()
mockNet.runNetwork()
return future
}

View File

@ -23,18 +23,18 @@ import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
class ValidatingNotaryServiceTests {
lateinit var net: MockNetwork
lateinit var mockNet: MockNetwork
lateinit var notaryNode: MockNetwork.MockNode
lateinit var clientNode: MockNetwork.MockNode
@Before fun setup() {
net = MockNetwork()
notaryNode = net.createNode(
mockNet = MockNetwork()
notaryNode = mockNet.createNode(
legalName = DUMMY_NOTARY.name,
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(ValidatingNotaryService.type))
)
clientNode = net.createNode(networkMapAddress = notaryNode.info.address)
net.runNetwork() // Clear network map registration messages
clientNode = mockNet.createNode(networkMapAddress = notaryNode.info.address)
mockNet.runNetwork() // Clear network map registration messages
}
@Test fun `should report error for invalid transaction dependency`() {
@ -74,7 +74,7 @@ class ValidatingNotaryServiceTests {
private fun runClient(stx: SignedTransaction): ListenableFuture<List<DigitalSignature.WithKey>> {
val flow = NotaryFlow.Client(stx)
val future = clientNode.services.startFlow(flow).resultFuture
net.runNetwork()
mockNet.runNetwork()
return future
}