core.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.

### 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, vararg advertisedServices: ServiceType): MockNode` Returns a started node, optionally created by the passed factory method
createTwoNodes | `fun createTwoNodes(nodeFactory: Factory = defaultFactory): <ERROR CLASS><MockNode, MockNode>` Sets up a two node network, in which the first node runs network map and timestamping 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).