Clean up mentions of nodeReady future and friends from MockNetwork/Driver (#1979)

* Clean up mentions of nodeReady future and friends from MockNetwork/Driver
This commit is contained in:
Alberto Arri
2017-11-02 10:31:31 +00:00
committed by GitHub
parent 20a6fda357
commit a21d361df8
4 changed files with 11 additions and 37 deletions

View File

@ -7,7 +7,6 @@ import net.corda.core.flows.FlowLogic
import net.corda.core.flows.StartableByRPC import net.corda.core.flows.StartableByRPC
import net.corda.core.identity.AbstractParty import net.corda.core.identity.AbstractParty
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.internal.concurrent.transpose
import net.corda.core.messaging.startFlow import net.corda.core.messaging.startFlow
import net.corda.core.schemas.MappedSchema import net.corda.core.schemas.MappedSchema
import net.corda.core.schemas.PersistentState import net.corda.core.schemas.PersistentState
@ -22,8 +21,6 @@ import net.corda.node.services.FlowPermissions
import net.corda.nodeapi.User import net.corda.nodeapi.User
import net.corda.testing.DUMMY_NOTARY import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.chooseIdentity import net.corda.testing.chooseIdentity
import net.corda.testing.driver.DriverDSLExposedInterface
import net.corda.testing.driver.NodeHandle
import net.corda.testing.driver.driver import net.corda.testing.driver.driver
import org.junit.Assume import org.junit.Assume
import org.junit.Test import org.junit.Test
@ -48,17 +45,15 @@ class NodeStatePersistenceTests {
val (nodeName, notaryNodeHandle) = { val (nodeName, notaryNodeHandle) = {
val notaryNodeHandle = startNotaryNode(DUMMY_NOTARY.name, validating = false).getOrThrow() val notaryNodeHandle = startNotaryNode(DUMMY_NOTARY.name, validating = false).getOrThrow()
val nodeHandle = startNode(rpcUsers = listOf(user)).getOrThrow() val nodeHandle = startNode(rpcUsers = listOf(user)).getOrThrow()
ensureAcquainted(notaryNodeHandle, nodeHandle)
val nodeName = nodeHandle.nodeInfo.chooseIdentity().name val nodeName = nodeHandle.nodeInfo.chooseIdentity().name
nodeHandle.rpcClientToNode().start(user.username, user.password).use { nodeHandle.rpcClientToNode().start(user.username, user.password).use {
it.proxy.startFlow(::SendMessageFlow, message).returnValue.getOrThrow() it.proxy.startFlow(::SendMessageFlow, message).returnValue.getOrThrow()
} }
nodeHandle.stop().getOrThrow() nodeHandle.stop()
nodeName to notaryNodeHandle nodeName to notaryNodeHandle
}() }()
val nodeHandle = startNode(providedName = nodeName, rpcUsers = listOf(user)).getOrThrow() val nodeHandle = startNode(providedName = nodeName, rpcUsers = listOf(user)).getOrThrow()
ensureAcquainted(notaryNodeHandle, nodeHandle)
nodeHandle.rpcClientToNode().start(user.username, user.password).use { nodeHandle.rpcClientToNode().start(user.username, user.password).use {
val page = it.proxy.vaultQuery(MessageState::class.java) val page = it.proxy.vaultQuery(MessageState::class.java)
val stateAndRef = page.states.singleOrNull() val stateAndRef = page.states.singleOrNull()
@ -68,10 +63,6 @@ class NodeStatePersistenceTests {
} }
} }
} }
private fun DriverDSLExposedInterface.ensureAcquainted(one: NodeHandle, another: NodeHandle) {
listOf(one.pollUntilKnowsAbout(another), another.pollUntilKnowsAbout(one)).transpose().getOrThrow()
}
} }
fun isQuasarAgentSpecified(): Boolean { fun isQuasarAgentSpecified(): Boolean {

View File

@ -175,15 +175,6 @@ interface DriverDSLExposedInterface : CordformContext {
return pollUntilNonNull(pollName, pollInterval, warnCount) { if (check()) Unit else null } return pollUntilNonNull(pollName, pollInterval, warnCount) { if (check()) Unit else null }
} }
/**
* Polls until a given node knows about presence of another node via its own NetworkMap
*/
fun NodeHandle.pollUntilKnowsAbout(another: NodeHandle, pollInterval: Duration = DEFAULT_POLL_INTERVAL, warnCount: Int = DEFAULT_WARN_COUNT): CordaFuture<Unit> {
return pollUntilTrue("${nodeInfo.legalIdentities} knows about ${another.nodeInfo.legalIdentities}", pollInterval, warnCount) {
another.nodeInfo in rpc.networkMapSnapshot()
}
}
val shutdownManager: ShutdownManager val shutdownManager: ShutdownManager
} }
@ -202,6 +193,11 @@ sealed class NodeHandle {
abstract val configuration: NodeConfiguration abstract val configuration: NodeConfiguration
abstract val webAddress: NetworkHostAndPort abstract val webAddress: NetworkHostAndPort
/**
* Stops the referenced node.
*/
abstract fun stop()
data class OutOfProcess( data class OutOfProcess(
override val nodeInfo: NodeInfo, override val nodeInfo: NodeInfo,
override val rpc: CordaRPCOps, override val rpc: CordaRPCOps,
@ -211,13 +207,12 @@ sealed class NodeHandle {
val process: Process, val process: Process,
private val onStopCallback: () -> Unit private val onStopCallback: () -> Unit
) : NodeHandle() { ) : NodeHandle() {
override fun stop(): CordaFuture<Unit> { override fun stop() {
with(process) { with(process) {
destroy() destroy()
waitFor() waitFor()
} }
onStopCallback() onStopCallback()
return doneFuture(Unit)
} }
} }
@ -230,23 +225,17 @@ sealed class NodeHandle {
val nodeThread: Thread, val nodeThread: Thread,
private val onStopCallback: () -> Unit private val onStopCallback: () -> Unit
) : NodeHandle() { ) : NodeHandle() {
override fun stop(): CordaFuture<Unit> { override fun stop() {
node.dispose() node.dispose()
with(nodeThread) { with(nodeThread) {
interrupt() interrupt()
join() join()
} }
onStopCallback() onStopCallback()
return doneFuture(Unit)
} }
} }
fun rpcClientToNode(): CordaRPCClient = CordaRPCClient(configuration.rpcAddress!!) fun rpcClientToNode(): CordaRPCClient = CordaRPCClient(configuration.rpcAddress!!)
/**
* Stops the referenced node.
*/
abstract fun stop(): CordaFuture<Unit>
} }
data class WebserverHandle( data class WebserverHandle(
@ -742,8 +731,7 @@ class DriverDSL(
"webAddress" to webAddress.toString(), "webAddress" to webAddress.toString(),
"useTestClock" to useTestClock, "useTestClock" to useTestClock,
"rpcUsers" to if (rpcUsers.isEmpty()) defaultRpcUserList else rpcUsers.map { it.toConfig().root().unwrapped() }, "rpcUsers" to if (rpcUsers.isEmpty()) defaultRpcUserList else rpcUsers.map { it.toConfig().root().unwrapped() },
"verifierType" to verifierType.name, "verifierType" to verifierType.name
"noNetworkMapServiceMode" to true
) + customOverrides ) + customOverrides
) )
return startNodeInternal(config, webAddress, startInSameProcess, maximumHeapSize) return startNodeInternal(config, webAddress, startInSameProcess, maximumHeapSize)
@ -769,8 +757,7 @@ class DriverDSL(
baseDirectory = baseDirectory(name), baseDirectory = baseDirectory(name),
allowMissingConfig = true, allowMissingConfig = true,
configOverrides = node.config + notary + mapOf( configOverrides = node.config + notary + mapOf(
"rpcUsers" to if (rpcUsers.isEmpty()) defaultRpcUserList else rpcUsers, "rpcUsers" to if (rpcUsers.isEmpty()) defaultRpcUserList else rpcUsers
"noNetworkMapServiceMode" to true
) )
) )
startNodeInternal(config, webAddress, startInSameProcess, maximumHeapSize) startNodeInternal(config, webAddress, startInSameProcess, maximumHeapSize)

View File

@ -300,7 +300,6 @@ class MockNetwork(defaultParameters: MockNetworkParameters = MockNetworkParamete
return nodeFactory(MockNodeArgs(config, this, id, parameters.notaryIdentity, parameters.entropyRoot)).apply { return nodeFactory(MockNodeArgs(config, this, id, parameters.notaryIdentity, parameters.entropyRoot)).apply {
if (start) { if (start) {
start() start()
if (threadPerNode) nodeReadyFuture.getOrThrow() // XXX: What about manually-started nodes?
ensureAllNetworkMapCachesHaveAllNodeInfos() ensureAllNetworkMapCachesHaveAllNodeInfos()
} }
_nodes.add(this) _nodes.add(this)

View File

@ -7,7 +7,6 @@ import net.corda.core.messaging.startFlow
import net.corda.core.transactions.LedgerTransaction import net.corda.core.transactions.LedgerTransaction
import net.corda.core.transactions.WireTransaction import net.corda.core.transactions.WireTransaction
import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.getOrThrow
import net.corda.finance.DOLLARS import net.corda.finance.DOLLARS
import net.corda.finance.flows.CashIssueFlow import net.corda.finance.flows.CashIssueFlow
import net.corda.finance.flows.CashPaymentFlow import net.corda.finance.flows.CashPaymentFlow
@ -19,8 +18,8 @@ import net.corda.testing.DUMMY_NOTARY_SERVICE_NAME
import org.junit.Test import org.junit.Test
import java.util.* import java.util.*
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
import kotlin.test.assertTrue
import kotlin.test.assertNotNull import kotlin.test.assertNotNull
import kotlin.test.assertTrue
class VerifierTests { class VerifierTests {
private fun generateTransactions(number: Int): List<LedgerTransaction> { private fun generateTransactions(number: Int): List<LedgerTransaction> {
@ -137,8 +136,6 @@ class VerifierTests {
val alice = aliceNode.rpc.wellKnownPartyFromX500Name(ALICE_NAME)!! val alice = aliceNode.rpc.wellKnownPartyFromX500Name(ALICE_NAME)!!
val notary = notaryNode.rpc.notaryPartyFromX500Name(DUMMY_NOTARY_SERVICE_NAME)!! val notary = notaryNode.rpc.notaryPartyFromX500Name(DUMMY_NOTARY_SERVICE_NAME)!!
startVerifier(notaryNode) startVerifier(notaryNode)
notaryNode.pollUntilKnowsAbout(aliceNode).getOrThrow()
aliceNode.pollUntilKnowsAbout(notaryNode).getOrThrow()
aliceNode.rpc.startFlow(::CashIssueFlow, 10.DOLLARS, OpaqueBytes.of(0), notary).returnValue.get() aliceNode.rpc.startFlow(::CashIssueFlow, 10.DOLLARS, OpaqueBytes.of(0), notary).returnValue.get()
notaryNode.waitUntilNumberOfVerifiers(1) notaryNode.waitUntilNumberOfVerifiers(1)
for (i in 1..10) { for (i in 1..10) {