Feature to exclude CorDapps from specific MockNodes in a MockNetwork. (#3028)

* Feature to exclude CorDapps from specific MockNode's in a MockNetwork.

* Fixed API stability issue.

* * Added docs.
* Changed approach for the new parameter to be additive as opposed to exclusive.

* * Updated incorrect comments.
This commit is contained in:
Roger Willis 2018-05-03 15:39:52 +01:00 committed by GitHub
parent 0494e45037
commit db22c5259d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 13 deletions

View File

@ -165,6 +165,40 @@ Nodes are created on the ``MockNetwork`` using:
}
}
Nodes added using ``createPartyNode`` are provided a default set of node parameters. However, it is also possible to
provide different parameters to each node using the following methods on ``MockNetwork``:
.. container:: codeset
.. sourcecode:: kotlin
/**
* Create a started node with the given parameters.
*
* @param legalName The node's legal name.
* @param forcedID A unique identifier for the node.
* @param entropyRoot The initial entropy value to use when generating keys. Defaults to an (insecure) random value,
* but can be overridden to cause nodes to have stable or colliding identity/service keys.
* @param configOverrides Add/override behaviour of the [NodeConfiguration] mock object.
* @param extraCordappPackages Extra CorDapp packages to add for this node.
*/
@JvmOverloads
fun createNode(legalName: CordaX500Name? = null,
forcedID: Int? = null,
entropyRoot: BigInteger = BigInteger.valueOf(random63BitValue()),
configOverrides: (NodeConfiguration) -> Any? = {},
extraCordappPackages: List<String> = emptyList()
): StartedMockNode
/** Create a started node with the given parameters. **/
fun createNode(parameters: MockNodeParameters = MockNodeParameters()): StartedMockNode
As you can see above, parameters can be added individually or encapsulated within a ``MockNodeParameters`` object. Of
particular interest are ``configOverrides`` which allow you to override any default config option specified within the
``NodeConfiguration`` object. Also, the ``extraCordappPackages`` parameter allows you to add extra CorDapps to a
specific node. This is useful when you wish for all nodes to load a common CorDapp but for a subset of nodes to load
CorDapps specific to their role in the network.
Running the network
^^^^^^^^^^^^^^^^^^^

View File

@ -33,17 +33,23 @@ import java.nio.file.Path
* @property entropyRoot the initial entropy value to use when generating keys. Defaults to an (insecure) random value,
* but can be overridden to cause nodes to have stable or colliding identity/service keys.
* @property configOverrides Add/override behaviour of the [NodeConfiguration] mock object.
* @property extraCordappPackages Extra CorDapp packages to include for this node.
*/
@Suppress("unused")
data class MockNodeParameters(
data class MockNodeParameters @JvmOverloads constructor(
val forcedID: Int? = null,
val legalName: CordaX500Name? = null,
val entropyRoot: BigInteger = BigInteger.valueOf(random63BitValue()),
val configOverrides: (NodeConfiguration) -> Any? = {}) {
val configOverrides: (NodeConfiguration) -> Any? = {},
val extraCordappPackages: List<String> = emptyList()) {
fun withForcedID(forcedID: Int?): MockNodeParameters = copy(forcedID = forcedID)
fun withLegalName(legalName: CordaX500Name?): MockNodeParameters = copy(legalName = legalName)
fun withEntropyRoot(entropyRoot: BigInteger): MockNodeParameters = copy(entropyRoot = entropyRoot)
fun withConfigOverrides(configOverrides: (NodeConfiguration) -> Any?): MockNodeParameters = copy(configOverrides = configOverrides)
fun withExtraCordappPackages(extraCordappPackages: List<String>): MockNodeParameters = copy(extraCordappPackages = extraCordappPackages)
fun copy(forcedID: Int?, legalName: CordaX500Name?, entropyRoot: BigInteger, configOverrides: (NodeConfiguration) -> Any?): MockNodeParameters {
return MockNodeParameters(forcedID, legalName, entropyRoot, configOverrides)
}
}
/**
@ -248,14 +254,15 @@ open class MockNetwork(
* @param entropyRoot The initial entropy value to use when generating keys. Defaults to an (insecure) random value,
* but can be overridden to cause nodes to have stable or colliding identity/service keys.
* @param configOverrides Add/override behaviour of the [NodeConfiguration] mock object.
* @param version The mock node's platform, release, revision and vendor versions.
* @param extraCordappPackages Extra CorDapp packages to add for this node.
*/
@JvmOverloads
fun createNode(legalName: CordaX500Name? = null,
forcedID: Int? = null,
entropyRoot: BigInteger = BigInteger.valueOf(random63BitValue()),
configOverrides: (NodeConfiguration) -> Any? = {}): StartedMockNode {
val parameters = MockNodeParameters(forcedID, legalName, entropyRoot, configOverrides)
configOverrides: (NodeConfiguration) -> Any? = {},
extraCordappPackages: List<String> = emptyList()): StartedMockNode {
val parameters = MockNodeParameters(forcedID, legalName, entropyRoot, configOverrides, extraCordappPackages)
return StartedMockNode.create(internalMockNetwork.createNode(InternalMockNodeParameters(parameters)))
}
@ -270,14 +277,15 @@ open class MockNetwork(
* @param entropyRoot The initial entropy value to use when generating keys. Defaults to an (insecure) random value,
* but can be overridden to cause nodes to have stable or colliding identity/service keys.
* @param configOverrides Add/override behaviour of the [NodeConfiguration] mock object.
* @param version The mock node's platform, release, revision and vendor versions.
* @param extraCordappPackages Extra CorDapp packages to add for this node.
*/
@JvmOverloads
fun createUnstartedNode(legalName: CordaX500Name? = null,
forcedID: Int? = null,
entropyRoot: BigInteger = BigInteger.valueOf(random63BitValue()),
configOverrides: (NodeConfiguration) -> Any? = {}): UnstartedMockNode {
val parameters = MockNodeParameters(forcedID, legalName, entropyRoot, configOverrides)
configOverrides: (NodeConfiguration) -> Any? = {},
extraCordappPackages: List<String> = emptyList()): UnstartedMockNode {
val parameters = MockNodeParameters(forcedID, legalName, entropyRoot, configOverrides, extraCordappPackages)
return UnstartedMockNode.create(internalMockNetwork.createUnstartedNode(InternalMockNodeParameters(parameters)))
}

View File

@ -74,7 +74,8 @@ data class MockNodeArgs(
val network: InternalMockNetwork,
val id: Int,
val entropyRoot: BigInteger,
val version: VersionInfo = MOCK_VERSION_INFO
val version: VersionInfo = MOCK_VERSION_INFO,
val extraCordappPackages: List<String> = emptyList()
)
data class InternalMockNodeParameters(
@ -82,12 +83,16 @@ data class InternalMockNodeParameters(
val legalName: CordaX500Name? = null,
val entropyRoot: BigInteger = BigInteger.valueOf(random63BitValue()),
val configOverrides: (NodeConfiguration) -> Any? = {},
val version: VersionInfo = MOCK_VERSION_INFO) {
val version: VersionInfo = MOCK_VERSION_INFO,
val extraCordappPackages: List<String> = emptyList()) {
constructor(mockNodeParameters: MockNodeParameters) : this(
mockNodeParameters.forcedID,
mockNodeParameters.legalName,
mockNodeParameters.entropyRoot,
mockNodeParameters.configOverrides)
mockNodeParameters.configOverrides,
MOCK_VERSION_INFO,
mockNodeParameters.extraCordappPackages
)
}
open class InternalMockNetwork(private val cordappPackages: List<String>,
@ -218,7 +223,8 @@ open class InternalMockNetwork(private val cordappPackages: List<String>,
args.config,
TestClock(Clock.systemUTC()),
args.version,
CordappLoader.createDefaultWithTestPackages(args.config, args.network.cordappPackages),
// Add the specified additional CorDapps.
CordappLoader.createDefaultWithTestPackages(args.config, args.network.cordappPackages + args.extraCordappPackages),
args.network.busyLatch
) {
companion object {
@ -369,7 +375,7 @@ open class InternalMockNetwork(private val cordappPackages: List<String>,
doReturn(emptyList<SecureHash>()).whenever(it).extraNetworkMapKeys
parameters.configOverrides(it)
}
val node = nodeFactory(MockNodeArgs(config, this, id, parameters.entropyRoot, parameters.version))
val node = nodeFactory(MockNodeArgs(config, this, id, parameters.entropyRoot, parameters.version, parameters.extraCordappPackages))
_nodes += node
if (start) {
node.start()