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:
LogHelper.setLevel("+messages")
BasketOfNodes |
data class BasketOfNodes A bundle that separates the generic user nodes and service-providing nodes. A real network might not be so clearly separated, but this is convenient for testing. |
DefaultFactory |
object DefaultFactory : Factory |
Factory |
interface Factory Allows customisation of how nodes are created. |
MockNode |
class MockNode : AbstractNode |
<init> |
MockNetwork(networkSendManuallyPumped: Boolean = false, 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. |
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. |
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, databasePersistence: Boolean = false, 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 |
createSomeNodes |
fun createSomeNodes(numPartyNodes: Int = 2, nodeFactory: Factory = defaultFactory, notaryKeyPair: KeyPair? = DUMMY_NOTARY_KEY): BasketOfNodes Sets up a network with the requested number of nodes (defaulting to two), with one or more service nodes that run a notary, network map, any oracles etc. Cant be combined with createTwoNodes. |
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 |