com.r3corda.node.internal.testing / MockNetwork

# MockNetwork

`class MockNetwork`

A mock node brings up a suite of in-memory services in a fast manner suitable for unit testing. Components that do IO are either swapped out for mocks, or pointed to a Jimfs in memory filesystem.

Mock network nodes require manual pumping by default: they will not run asynchronous. This means that for message exchanges to take place (and associated handlers to run), you must call the runNetwork method.

You can get a printout of every message sent by using code like:

BriefLogFormatter.initVerbose("+messaging")

### Types

DefaultFactory | `object DefaultFactory : Factory`
Factory | `interface Factory` Allows customisation of how nodes are created.
MockNode | `class MockNode : AbstractNode`

### Constructors

<init> | `MockNetwork(threadPerNode: Boolean = false, defaultFactory: Factory = MockNetwork.DefaultFactory)` A mock node brings up a suite of in-memory services in a fast manner suitable for unit testing. Components that do IO are either swapped out for mocks, or pointed to a Jimfs in memory filesystem.

### Properties

filesystem | `val filesystem: <ERROR CLASS>`
identities | `val identities: ArrayList<Party>`
messagingNetwork | `val messagingNetwork: InMemoryMessagingNetwork`
nodes | `val nodes: List<MockNode>` A read only view of the current set of executing nodes.

### Functions

addressToNode | `fun addressToNode(address: SingleMessageRecipient): MockNode`
createNode | `fun createNode(networkMapAddress: NodeInfo? = null, forcedID: Int = -1, nodeFactory: Factory = defaultFactory, start: Boolean = true, legalName: String? = null, keyPair: KeyPair? = null, vararg advertisedServices: ServiceType): MockNode` Returns a node, optionally created by the passed factory method.
createNotaryNode | `fun createNotaryNode(legalName: String? = null, keyPair: KeyPair? = null): MockNode`
createPartyNode | `fun createPartyNode(networkMapAddr: NodeInfo, legalName: String? = null, keyPair: KeyPair? = null): MockNode`
createTwoNodes | `fun createTwoNodes(nodeFactory: Factory = defaultFactory, notaryKeyPair: KeyPair? = null): <ERROR CLASS><MockNode, MockNode>` Sets up a two node network, in which the first node runs network map and notary services and the other doesnt.
runNetwork | `fun runNetwork(rounds: Int = -1): Unit` Asks every node in order to process any queued up inbound messages. This may in turn result in nodes sending more messages to each other, thus, a typical usage is to call runNetwork with the rounds parameter set to -1 (the default) which simply runs as many rounds as necessary to result in network stability (no nodes sent any messages in the last round).
startNodes | `fun startNodes(): Unit`
stopNodes | `fun stopNodes(): Unit`