From f5b86d32f86f4334ee01bf3200e891040438baa0 Mon Sep 17 00:00:00 2001 From: Dominic Fox <40790090+distributedleetravis@users.noreply.github.com> Date: Wed, 25 Jul 2018 13:49:34 +0100 Subject: [PATCH] Eliminate StartedNode (#3690) * Shrink StartedNode * Eliminate StartedNode --- .../client/rpc/CordaRPCJavaClientTest.java | 7 +-- .../corda/client/rpc/CordaRPCClientTest.kt | 10 +-- .../client/rpc/FlowsExecutionModeRpcTest.kt | 6 +- .../net/corda/core/flows/AttachmentTests.kt | 10 +-- .../core/flows/CollectSignaturesFlowTests.kt | 4 +- .../core/flows/ContractUpgradeFlowRPCTest.kt | 9 ++- .../core/flows/ContractUpgradeFlowTest.kt | 18 +++--- .../net/corda/core/flows/FinalityFlowTests.kt | 4 +- .../corda/core/flows/mixins/WithContracts.kt | 16 ++--- .../corda/core/flows/mixins/WithFinality.kt | 8 +-- .../corda/core/flows/mixins/WithMockNet.kt | 14 ++--- .../AttachmentSerializationTest.kt | 5 +- .../kotlin/net/corda/node/AuthDBTests.kt | 7 +-- .../node/services/BFTNotaryServiceTests.kt | 12 ++-- .../net/corda/node/services/BFTSMaRtTests.kt | 4 +- .../network/PersistentNetworkMapCacheTest.kt | 4 +- .../statemachine/FlowVersioningTest.kt | 2 +- .../messaging/MQSecurityAsNodeTest.kt | 14 ++--- .../services/messaging/MQSecurityAsRPCTest.kt | 2 +- .../services/messaging/MQSecurityTest.kt | 9 ++- .../net/corda/node/internal/AbstractNode.kt | 8 +-- .../kotlin/net/corda/node/internal/Node.kt | 61 +++++-------------- .../net/corda/node/internal/NodeStartup.kt | 8 +-- .../net/corda/node/internal/StartedNode.kt | 34 ----------- .../net/corda/node/CordaRPCOpsImplTest.kt | 4 +- .../node/messaging/TwoPartyTradeFlowTests.kt | 13 ++-- .../ScheduledFlowsDrainingModeTest.kt | 10 +-- .../node/services/FinalityHandlerTest.kt | 6 +- .../net/corda/node/services/TimedFlowTests.kt | 12 ++-- .../services/events/ScheduledFlowTests.kt | 10 +-- .../statemachine/FlowFrameworkTests.kt | 7 +-- .../statemachine/IdempotentFlowTests.kt | 10 +-- .../statemachine/RetryFlowMockTest.kt | 3 +- .../transactions/NotaryServiceTests.kt | 12 ++-- .../testing/driver/internal/DriverInternal.kt | 6 +- .../testing/node/internal/DriverDSLImpl.kt | 13 ++-- .../node/internal/InternalMockNetwork.kt | 21 ++++++- .../testing/node/internal/NodeBasedTest.kt | 23 +++---- 38 files changed, 174 insertions(+), 252 deletions(-) delete mode 100644 node/src/main/kotlin/net/corda/node/internal/StartedNode.kt diff --git a/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java b/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java index 594458408a..44f65f0bc0 100644 --- a/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java +++ b/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java @@ -8,8 +8,7 @@ import net.corda.finance.flows.AbstractCashFlow; import net.corda.finance.flows.CashIssueFlow; import net.corda.finance.flows.CashPaymentFlow; import net.corda.finance.schemas.CashSchemaV1; -import net.corda.node.internal.StartedNode; -import net.corda.node.internal.StartedNodeWithInternals; +import net.corda.node.internal.NodeWithInfo; import net.corda.testing.internal.InternalTestUtilsKt; import net.corda.testing.node.User; import net.corda.testing.node.internal.NodeBasedTest; @@ -44,7 +43,7 @@ public class CordaRPCJavaClientTest extends NodeBasedTest { private Set permSet = new HashSet<>(perms); private User rpcUser = new User("user1", "test", permSet); - private StartedNodeWithInternals node; + private NodeWithInfo node; private CordaRPCClient client; private RPCConnection connection = null; private CordaRPCOps rpcProxy; @@ -57,7 +56,7 @@ public class CordaRPCJavaClientTest extends NodeBasedTest { @Before public void setUp() throws Exception { node = startNode(ALICE_NAME, 1, singletonList(rpcUser)); - client = new CordaRPCClient(requireNonNull(node.getInternals().getConfiguration().getRpcOptions().getAddress())); + client = new CordaRPCClient(requireNonNull(node.getNode().getConfiguration().getRpcOptions().getAddress())); } @After diff --git a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt index 1f26140c5f..9b788ed016 100644 --- a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt +++ b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt @@ -20,7 +20,7 @@ import net.corda.finance.contracts.getCashBalance import net.corda.finance.contracts.getCashBalances import net.corda.finance.flows.CashIssueFlow import net.corda.finance.flows.CashPaymentFlow -import net.corda.node.internal.StartedNodeWithInternals +import net.corda.node.internal.NodeWithInfo import net.corda.node.services.Permissions.Companion.all import net.corda.testing.common.internal.checkNotOnClasspath import net.corda.testing.core.* @@ -50,7 +50,7 @@ class CordaRPCClientTest : NodeBasedTest(listOf("net.corda.finance")) { val rpcUser = User("user1", "test", permissions = setOf(all())) } - private lateinit var node: StartedNodeWithInternals + private lateinit var node: NodeWithInfo private lateinit var identity: Party private lateinit var client: CordaRPCClient private var connection: CordaRPCConnection? = null @@ -62,7 +62,7 @@ class CordaRPCClientTest : NodeBasedTest(listOf("net.corda.finance")) { @Before fun setUp() { node = startNode(ALICE_NAME, rpcUsers = listOf(rpcUser)) - client = CordaRPCClient(node.internals.configuration.rpcOptions.address, CordaRPCClientConfiguration.DEFAULT.copy( + client = CordaRPCClient(node.node.configuration.rpcOptions.address, CordaRPCClientConfiguration.DEFAULT.copy( maxReconnectAttempts = 5 )) identity = node.info.identityFromX500Name(ALICE_NAME) @@ -127,7 +127,7 @@ class CordaRPCClientTest : NodeBasedTest(listOf("net.corda.finance")) { task.cancel(true) latch.countDown() }.doOnCompleted { - successful = (node.internals.started == null) + successful = (node.node.started == null) task.cancel(true) latch.countDown() }.subscribe() @@ -235,7 +235,7 @@ class CordaRPCClientTest : NodeBasedTest(listOf("net.corda.finance")) { node.services.startFlow(CashIssueFlow(100.POUNDS, OpaqueBytes.of(1), identity), InvocationContext.shell()).flatMap { it.resultFuture }.getOrThrow() val outOfProcessRpc = ProcessUtilities.startJavaProcess( classPath = classPathWithoutFinance, - arguments = listOf(node.internals.configuration.rpcOptions.address.toString(), financeLocation) + arguments = listOf(node.node.configuration.rpcOptions.address.toString(), financeLocation) ) assertThat(outOfProcessRpc.waitFor()).isZero() // i.e. no exceptions were thrown } diff --git a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/FlowsExecutionModeRpcTest.kt b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/FlowsExecutionModeRpcTest.kt index 4013aa823c..ee7be9eb2a 100644 --- a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/FlowsExecutionModeRpcTest.kt +++ b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/FlowsExecutionModeRpcTest.kt @@ -6,7 +6,7 @@ import net.corda.core.internal.packageName import net.corda.core.messaging.CordaRPCOps import net.corda.core.utilities.getOrThrow import net.corda.finance.schemas.CashSchemaV1 -import net.corda.node.internal.StartedNodeWithInternals +import net.corda.node.internal.NodeWithInfo import net.corda.node.services.Permissions import net.corda.node.services.Permissions.Companion.invokeRpc import net.corda.testing.core.ALICE_NAME @@ -48,13 +48,13 @@ class FlowsExecutionModeRpcTest { class FlowsExecutionModeTests : NodeBasedTest(listOf("net.corda.finance.contracts", CashSchemaV1::class.packageName)) { private val rpcUser = User("user1", "test", permissions = setOf(Permissions.all())) - private lateinit var node: StartedNodeWithInternals + private lateinit var node: NodeWithInfo private lateinit var client: CordaRPCClient @Before fun setup() { node = startNode(ALICE_NAME, rpcUsers = listOf(rpcUser)) - client = CordaRPCClient(node.internals.configuration.rpcOptions.address) + client = CordaRPCClient(node.node.configuration.rpcOptions.address) } @Test diff --git a/core/src/test/kotlin/net/corda/core/flows/AttachmentTests.kt b/core/src/test/kotlin/net/corda/core/flows/AttachmentTests.kt index ba145e0cf1..81299f7ada 100644 --- a/core/src/test/kotlin/net/corda/core/flows/AttachmentTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/AttachmentTests.kt @@ -13,13 +13,13 @@ import net.corda.core.identity.Party import net.corda.core.internal.FetchAttachmentsFlow import net.corda.core.internal.FetchDataFlow import net.corda.core.internal.hash -import net.corda.node.internal.StartedNode import net.corda.node.services.persistence.NodeAttachmentService import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.core.singleIdentity import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.InternalMockNodeParameters +import net.corda.testing.node.internal.TestStartedNode import org.junit.AfterClass import org.junit.Test import java.io.ByteArrayOutputStream @@ -148,18 +148,18 @@ class AttachmentTests : WithMockNet { //endregion //region Operations - private fun StartedNode.importAttachment(attachment: ByteArray) = + private fun TestStartedNode.importAttachment(attachment: ByteArray) = attachments.importAttachment(attachment.inputStream(), "test", null) .andRunNetwork() - private fun StartedNode.updateAttachment(attachment: NodeAttachmentService.DBAttachment) = database.transaction { + private fun TestStartedNode.updateAttachment(attachment: NodeAttachmentService.DBAttachment) = database.transaction { session.update(attachment) }.andRunNetwork() - private fun StartedNode.startAttachmentFlow(hash: SecureHash, otherSide: Party) = startFlowAndRunNetwork( + private fun TestStartedNode.startAttachmentFlow(hash: SecureHash, otherSide: Party) = startFlowAndRunNetwork( InitiatingFetchAttachmentsFlow(otherSide, setOf(hash))) - private fun StartedNode.getAttachmentWithId(id: SecureHash) = + private fun TestStartedNode.getAttachmentWithId(id: SecureHash) = attachments.openAttachment(id)!! //endregion diff --git a/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt b/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt index 94c386764c..68811a093b 100644 --- a/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt @@ -14,12 +14,12 @@ import net.corda.core.identity.excludeHostNode import net.corda.core.identity.groupAbstractPartyByWellKnownParty import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder -import net.corda.node.internal.StartedNode import net.corda.testing.contracts.DummyContract import net.corda.testing.core.* import net.corda.testing.internal.rigorousMock import net.corda.testing.node.MockServices import net.corda.testing.node.internal.InternalMockNetwork +import net.corda.testing.node.internal.TestStartedNode import net.corda.testing.node.internal.cordappsForPackages import org.junit.AfterClass import org.junit.Test @@ -93,7 +93,7 @@ class CollectSignaturesFlowTests : WithContracts { } //region Operators - private fun StartedNode.startTestFlow(vararg party: Party) = + private fun TestStartedNode.startTestFlow(vararg party: Party) = startFlowAndRunNetwork( TestFlow.Initiator(DummyContract.MultiOwnerState( MAGIC_NUMBER, diff --git a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowRPCTest.kt b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowRPCTest.kt index 7e006f1d5c..f185bf33ec 100644 --- a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowRPCTest.kt +++ b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowRPCTest.kt @@ -15,7 +15,6 @@ import net.corda.core.flows.mixins.WithFinality import net.corda.core.messaging.CordaRPCOps import net.corda.core.transactions.ContractUpgradeLedgerTransaction import net.corda.core.transactions.SignedTransaction -import net.corda.node.internal.StartedNode import net.corda.node.services.Permissions.Companion.startFlow import net.corda.testing.contracts.DummyContract import net.corda.testing.contracts.DummyContractV2 @@ -84,7 +83,7 @@ class ContractUpgradeFlowRPCTest : WithContracts, WithFinality { } //region RPC DSL - private fun RPCDriverDSL.startProxy(node: StartedNode, user: User): CordaRPCOps { + private fun RPCDriverDSL.startProxy(node: TestStartedNode, user: User): CordaRPCOps { return startRpcClient( rpcAddress = startRpcServer( rpcUser = user, @@ -112,16 +111,16 @@ class ContractUpgradeFlowRPCTest : WithContracts, WithFinality { //endregion //region Matchers - private fun StartedNode.hasDummyContractUpgradeTransaction() = + private fun TestStartedNode.hasDummyContractUpgradeTransaction() = hasContractUpgradeTransaction() - private inline fun StartedNode.hasContractUpgradeTransaction() = + private inline fun TestStartedNode.hasContractUpgradeTransaction() = has, ContractUpgradeLedgerTransaction>( "a contract upgrade transaction", { getContractUpgradeTransaction(it) }, isUpgrade()) - private fun StartedNode.getContractUpgradeTransaction(state: StateAndRef) = + private fun TestStartedNode.getContractUpgradeTransaction(state: StateAndRef) = services.validatedTransactions.getTransaction(state.ref.txhash)!! .resolveContractUpgradeTransaction(services) diff --git a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt index 793a30030e..57726d82c5 100644 --- a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt +++ b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt @@ -18,13 +18,13 @@ import net.corda.finance.USD import net.corda.finance.`issued by` import net.corda.finance.contracts.asset.Cash import net.corda.finance.flows.CashIssueFlow -import net.corda.node.internal.StartedNode import net.corda.testing.contracts.DummyContract import net.corda.testing.contracts.DummyContractV2 import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.core.singleIdentity import net.corda.testing.node.internal.InternalMockNetwork +import net.corda.testing.node.internal.TestStartedNode import net.corda.testing.node.internal.cordappsForPackages import net.corda.testing.node.internal.startFlow import org.junit.AfterClass @@ -85,14 +85,14 @@ class ContractUpgradeFlowTest : WithContracts, WithFinality { and bobNode.hasDummyContractUpgradeTransaction())) } - private fun StartedNode.issueCash(amount: Amount = Amount(1000, USD)) = + private fun TestStartedNode.issueCash(amount: Amount = Amount(1000, USD)) = services.startFlow(CashIssueFlow(amount, OpaqueBytes.of(1), notary)) .andRunNetwork() .resultFuture.getOrThrow() - private fun StartedNode.getBaseStateFromVault() = getStateFromVault(ContractState::class) + private fun TestStartedNode.getBaseStateFromVault() = getStateFromVault(ContractState::class) - private fun StartedNode.getCashStateFromVault() = getStateFromVault(CashV2.State::class) + private fun TestStartedNode.getCashStateFromVault() = getStateFromVault(CashV2.State::class) private fun hasIssuedAmount(expected: Amount>) = hasContractState(has(CashV2.State::amount, equalTo(expected))) @@ -162,24 +162,24 @@ class ContractUpgradeFlowTest : WithContracts, WithFinality { } //region Operations - private fun StartedNode.initiateDummyContractUpgrade(tx: SignedTransaction) = + private fun TestStartedNode.initiateDummyContractUpgrade(tx: SignedTransaction) = initiateContractUpgrade(tx, DummyContractV2::class) - private fun StartedNode.authoriseDummyContractUpgrade(tx: SignedTransaction) = + private fun TestStartedNode.authoriseDummyContractUpgrade(tx: SignedTransaction) = authoriseContractUpgrade(tx, DummyContractV2::class) //endregion //region Matchers - private fun StartedNode.hasDummyContractUpgradeTransaction() = + private fun TestStartedNode.hasDummyContractUpgradeTransaction() = hasContractUpgradeTransaction() - private inline fun StartedNode.hasContractUpgradeTransaction() = + private inline fun TestStartedNode.hasContractUpgradeTransaction() = has, ContractUpgradeLedgerTransaction>( "a contract upgrade transaction", { getContractUpgradeTransaction(it) }, isUpgrade()) - private fun StartedNode.getContractUpgradeTransaction(state: StateAndRef) = + private fun TestStartedNode.getContractUpgradeTransaction(state: StateAndRef) = services.validatedTransactions.getTransaction(state.ref.txhash)!! .resolveContractUpgradeTransaction(services) diff --git a/core/src/test/kotlin/net/corda/core/flows/FinalityFlowTests.kt b/core/src/test/kotlin/net/corda/core/flows/FinalityFlowTests.kt index ca0cfb496a..50718ccea0 100644 --- a/core/src/test/kotlin/net/corda/core/flows/FinalityFlowTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/FinalityFlowTests.kt @@ -11,9 +11,9 @@ import net.corda.core.transactions.TransactionBuilder import net.corda.finance.POUNDS import net.corda.finance.contracts.asset.Cash import net.corda.finance.issuedBy -import net.corda.node.internal.StartedNode import net.corda.testing.core.* import net.corda.testing.node.internal.InternalMockNetwork +import net.corda.testing.node.internal.TestStartedNode import net.corda.testing.node.internal.cordappsForPackages import org.junit.AfterClass import org.junit.Test @@ -58,7 +58,7 @@ class FinalityFlowTests : WithFinality { willThrow()) } - private fun StartedNode.signCashTransactionWith(other: Party): SignedTransaction { + private fun TestStartedNode.signCashTransactionWith(other: Party): SignedTransaction { val amount = 1000.POUNDS.issuedBy(alice.ref(0)) val builder = TransactionBuilder(notary) Cash().generateIssue(builder, amount, other, notary) diff --git a/core/src/test/kotlin/net/corda/core/flows/mixins/WithContracts.kt b/core/src/test/kotlin/net/corda/core/flows/mixins/WithContracts.kt index f77a11840a..c5794007fe 100644 --- a/core/src/test/kotlin/net/corda/core/flows/mixins/WithContracts.kt +++ b/core/src/test/kotlin/net/corda/core/flows/mixins/WithContracts.kt @@ -10,8 +10,8 @@ import net.corda.core.messaging.CordaRPCOps import net.corda.core.messaging.startFlow import net.corda.core.node.ServiceHub import net.corda.core.transactions.SignedTransaction -import net.corda.node.internal.StartedNode import net.corda.testing.contracts.DummyContract +import net.corda.testing.node.internal.TestStartedNode import kotlin.reflect.KClass /** @@ -29,33 +29,33 @@ interface WithContracts : WithMockNet { //region //region Operations - fun StartedNode.signDummyContract(owner: PartyAndReference, magicNumber: Int = 0, vararg others: PartyAndReference) = + fun TestStartedNode.signDummyContract(owner: PartyAndReference, magicNumber: Int = 0, vararg others: PartyAndReference) = services.signDummyContract(owner, magicNumber, *others).andRunNetwork() fun ServiceHub.signDummyContract(owner: PartyAndReference, magicNumber: Int = 0, vararg others: PartyAndReference) = signInitialTransaction(createDummyContract(owner, magicNumber, *others)) - fun StartedNode.collectSignatures(ptx: SignedTransaction) = + fun TestStartedNode.collectSignatures(ptx: SignedTransaction) = startFlowAndRunNetwork(CollectSignaturesFlow(ptx, emptySet())) - fun StartedNode.addSignatureTo(ptx: SignedTransaction) = + fun TestStartedNode.addSignatureTo(ptx: SignedTransaction) = services.addSignature(ptx).andRunNetwork() fun > - StartedNode.initiateContractUpgrade(tx: SignedTransaction, toClass: KClass) = + TestStartedNode.initiateContractUpgrade(tx: SignedTransaction, toClass: KClass) = initiateContractUpgrade(tx.tx.outRef(0), toClass) fun > - StartedNode.initiateContractUpgrade(stateAndRef: StateAndRef, toClass: KClass) = + TestStartedNode.initiateContractUpgrade(stateAndRef: StateAndRef, toClass: KClass) = startFlowAndRunNetwork(ContractUpgradeFlow.Initiate(stateAndRef, toClass.java)) - fun > StartedNode.authoriseContractUpgrade( + fun > TestStartedNode.authoriseContractUpgrade( tx: SignedTransaction, toClass: KClass) = startFlow( ContractUpgradeFlow.Authorise(tx.tx.outRef(0), toClass.java) ) - fun StartedNode.deauthoriseContractUpgrade(tx: SignedTransaction) = startFlow( + fun TestStartedNode.deauthoriseContractUpgrade(tx: SignedTransaction) = startFlow( ContractUpgradeFlow.Deauthorise(tx.tx.outRef(0).ref) ) diff --git a/core/src/test/kotlin/net/corda/core/flows/mixins/WithFinality.kt b/core/src/test/kotlin/net/corda/core/flows/mixins/WithFinality.kt index 7d6097e878..4e2ac3c5c5 100644 --- a/core/src/test/kotlin/net/corda/core/flows/mixins/WithFinality.kt +++ b/core/src/test/kotlin/net/corda/core/flows/mixins/WithFinality.kt @@ -10,16 +10,16 @@ import net.corda.core.identity.Party import net.corda.core.messaging.CordaRPCOps import net.corda.core.messaging.startFlow import net.corda.core.transactions.SignedTransaction -import net.corda.node.internal.StartedNode import net.corda.testing.core.singleIdentity +import net.corda.testing.node.internal.TestStartedNode interface WithFinality : WithMockNet { //region Operations - fun StartedNode.finalise(stx: SignedTransaction, vararg additionalParties: Party) = + fun TestStartedNode.finalise(stx: SignedTransaction, vararg additionalParties: Party) = startFlowAndRunNetwork(FinalityFlow(stx, additionalParties.toSet())) - fun StartedNode.getValidatedTransaction(stx: SignedTransaction) = + fun TestStartedNode.getValidatedTransaction(stx: SignedTransaction) = services.validatedTransactions.getTransaction(stx.id)!! fun CordaRPCOps.finalise(stx: SignedTransaction, vararg parties: Party) = @@ -28,7 +28,7 @@ interface WithFinality : WithMockNet { //endregion //region Matchers - fun visibleTo(other: StartedNode) = object : Matcher { + fun visibleTo(other: TestStartedNode) = object : Matcher { override val description = "has a transaction visible to ${other.info.singleIdentity()}" override fun invoke(actual: SignedTransaction) = equalTo(actual)(other.getValidatedTransaction(actual)) diff --git a/core/src/test/kotlin/net/corda/core/flows/mixins/WithMockNet.kt b/core/src/test/kotlin/net/corda/core/flows/mixins/WithMockNet.kt index ead51880d4..0901da704d 100644 --- a/core/src/test/kotlin/net/corda/core/flows/mixins/WithMockNet.kt +++ b/core/src/test/kotlin/net/corda/core/flows/mixins/WithMockNet.kt @@ -9,8 +9,8 @@ import net.corda.core.identity.PartyAndCertificate import net.corda.core.internal.FlowStateMachine import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder -import net.corda.node.internal.StartedNode import net.corda.testing.node.internal.InternalMockNetwork +import net.corda.testing.node.internal.TestStartedNode import net.corda.testing.node.internal.startFlow import java.util.* import kotlin.reflect.KClass @@ -41,32 +41,32 @@ interface WithMockNet { /** * Sign an initial transaction */ - fun StartedNode.signInitialTransaction(build: TransactionBuilder.() -> TransactionBuilder) = + fun TestStartedNode.signInitialTransaction(build: TransactionBuilder.() -> TransactionBuilder) = services.signInitialTransaction(TransactionBuilder(mockNet.defaultNotaryIdentity).build()) /** * Retrieve the sole instance of a state of a particular class from the node's vault */ - fun StartedNode.getStateFromVault(stateClass: KClass) = + fun TestStartedNode.getStateFromVault(stateClass: KClass) = services.vaultService.queryBy(stateClass.java).states.single() /** * Start a flow */ - fun StartedNode.startFlow(logic: FlowLogic): FlowStateMachine = services.startFlow(logic) + fun TestStartedNode.startFlow(logic: FlowLogic): FlowStateMachine = services.startFlow(logic) /** * Start a flow and run the network immediately afterwards */ - fun StartedNode.startFlowAndRunNetwork(logic: FlowLogic): FlowStateMachine = + fun TestStartedNode.startFlowAndRunNetwork(logic: FlowLogic): FlowStateMachine = startFlow(logic).andRunNetwork() - fun StartedNode.createConfidentialIdentity(party: Party) = + fun TestStartedNode.createConfidentialIdentity(party: Party) = services.keyManagementService.freshKeyAndCert( services.myInfo.legalIdentitiesAndCerts.single { it.name == party.name }, false) - fun StartedNode.verifyAndRegister(identity: PartyAndCertificate) = + fun TestStartedNode.verifyAndRegister(identity: PartyAndCertificate) = services.identityService.verifyAndRegisterIdentity(identity) //endregion diff --git a/core/src/test/kotlin/net/corda/core/serialization/AttachmentSerializationTest.kt b/core/src/test/kotlin/net/corda/core/serialization/AttachmentSerializationTest.kt index ceaffdeb28..af7a46d936 100644 --- a/core/src/test/kotlin/net/corda/core/serialization/AttachmentSerializationTest.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/AttachmentSerializationTest.kt @@ -13,7 +13,6 @@ import net.corda.core.internal.FetchDataFlow import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.unwrap import net.corda.node.internal.InitiatedFlowFactory -import net.corda.node.internal.StartedNode import net.corda.node.services.persistence.NodeAttachmentService import net.corda.nodeapi.internal.persistence.currentDBSession import net.corda.testing.core.ALICE_NAME @@ -45,11 +44,11 @@ private fun Attachment.extractContent() = ByteArrayOutputStream().apply { extractFile("content", this) }.toString(UTF_8.name()) @Suppress("deprecation") -private fun StartedNode.saveAttachment(content: String) = database.transaction { +private fun TestStartedNode.saveAttachment(content: String) = database.transaction { attachments.importAttachment(createAttachmentData(content).inputStream()) } -private fun StartedNode.hackAttachment(attachmentId: SecureHash, content: String) = database.transaction { +private fun TestStartedNode.hackAttachment(attachmentId: SecureHash, content: String) = database.transaction { updateAttachment(attachmentId, createAttachmentData(content)) } diff --git a/node/src/integration-test/kotlin/net/corda/node/AuthDBTests.kt b/node/src/integration-test/kotlin/net/corda/node/AuthDBTests.kt index 133ec65e66..9c45d852aa 100644 --- a/node/src/integration-test/kotlin/net/corda/node/AuthDBTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/AuthDBTests.kt @@ -10,8 +10,7 @@ import net.corda.core.messaging.CordaRPCOps import net.corda.core.messaging.startFlow import net.corda.finance.flows.CashIssueFlow import net.corda.node.internal.DataSourceFactory -import net.corda.node.internal.StartedNode -import net.corda.node.internal.StartedNodeWithInternals +import net.corda.node.internal.NodeWithInfo import net.corda.node.services.Permissions import net.corda.node.services.config.PasswordEncryption import net.corda.testing.node.internal.NodeBasedTest @@ -35,7 +34,7 @@ import kotlin.test.assertFailsWith @RunWith(Parameterized::class) class AuthDBTests : NodeBasedTest() { - private lateinit var node: StartedNodeWithInternals + private lateinit var node: NodeWithInfo private lateinit var client: CordaRPCClient private lateinit var db: UsersDB @@ -95,7 +94,7 @@ class AuthDBTests : NodeBasedTest() { ) node = startNode(ALICE_NAME, rpcUsers = emptyList(), configOverrides = securityConfig) - client = CordaRPCClient(node.internals.configuration.rpcOptions.address) + client = CordaRPCClient(node.node.configuration.rpcOptions.address) } @Test diff --git a/node/src/integration-test/kotlin/net/corda/node/services/BFTNotaryServiceTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/BFTNotaryServiceTests.kt index dfdd17aff8..c906474274 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/BFTNotaryServiceTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/BFTNotaryServiceTests.kt @@ -21,7 +21,6 @@ import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.Try import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.seconds -import net.corda.node.internal.StartedNode import net.corda.node.services.config.BFTSMaRtConfiguration import net.corda.node.services.config.NotaryConfig import net.corda.node.services.transactions.minClusterSize @@ -33,10 +32,7 @@ import net.corda.testing.contracts.DummyContract import net.corda.testing.core.dummyCommand import net.corda.testing.core.singleIdentity import net.corda.testing.node.TestClock -import net.corda.testing.node.internal.cordappsForPackages -import net.corda.testing.node.internal.InternalMockNetwork -import net.corda.testing.node.internal.InternalMockNodeParameters -import net.corda.testing.node.internal.startFlow +import net.corda.testing.node.internal.* import org.hamcrest.Matchers.instanceOf import org.junit.AfterClass import org.junit.Assert.assertThat @@ -56,7 +52,7 @@ class BFTNotaryServiceTests { companion object { private lateinit var mockNet: InternalMockNetwork private lateinit var notary: Party - private lateinit var node: StartedNode + private lateinit var node: TestStartedNode @BeforeClass @JvmStatic @@ -74,7 +70,7 @@ class BFTNotaryServiceTests { mockNet.stopNodes() } - fun startBftClusterAndNode(clusterSize: Int, mockNet: InternalMockNetwork, exposeRaces: Boolean = false): Pair { + fun startBftClusterAndNode(clusterSize: Int, mockNet: InternalMockNetwork, exposeRaces: Boolean = false): Pair { (Paths.get("config") / "currentView").deleteIfExists() // XXX: Make config object warn if this exists? val replicaIds = (0 until clusterSize) @@ -214,7 +210,7 @@ class BFTNotaryServiceTests { signatures.forEach { it.verify(txId) } } - private fun StartedNode.signInitialTransaction(notary: Party, block: TransactionBuilder.() -> Any?): SignedTransaction { + private fun TestStartedNode.signInitialTransaction(notary: Party, block: TransactionBuilder.() -> Any?): SignedTransaction { return services.signInitialTransaction( TransactionBuilder(notary).apply { addCommand(dummyCommand(services.myInfo.singleIdentity().owningKey)) diff --git a/node/src/integration-test/kotlin/net/corda/node/services/BFTSMaRtTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/BFTSMaRtTests.kt index 8d4635511a..c33ec2b2ac 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/BFTSMaRtTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/BFTSMaRtTests.kt @@ -6,7 +6,6 @@ import net.corda.core.identity.Party import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.getOrThrow -import net.corda.node.internal.StartedNode import net.corda.node.services.BFTNotaryServiceTests.Companion.startBftClusterAndNode import net.corda.node.services.transactions.minClusterSize import net.corda.testing.contracts.DummyContract @@ -14,6 +13,7 @@ import net.corda.testing.core.dummyCommand import net.corda.testing.core.singleIdentity import net.corda.testing.node.internal.cordappsForPackages import net.corda.testing.node.internal.InternalMockNetwork +import net.corda.testing.node.internal.TestStartedNode import net.corda.testing.node.internal.startFlow import org.junit.After import org.junit.Before @@ -48,7 +48,7 @@ class BFTSMaRtTests { f.getOrThrow() } - private fun StartedNode.signInitialTransaction(notary: Party, block: TransactionBuilder.() -> Any?): SignedTransaction { + private fun TestStartedNode.signInitialTransaction(notary: Party, block: TransactionBuilder.() -> Any?): SignedTransaction { return services.signInitialTransaction( TransactionBuilder(notary).apply { addCommand(dummyCommand(services.myInfo.singleIdentity().owningKey)) diff --git a/node/src/integration-test/kotlin/net/corda/node/services/network/PersistentNetworkMapCacheTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/network/PersistentNetworkMapCacheTest.kt index ef4656e881..3dcaf35130 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/network/PersistentNetworkMapCacheTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/network/PersistentNetworkMapCacheTest.kt @@ -5,7 +5,7 @@ import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party import net.corda.core.node.NodeInfo import net.corda.core.utilities.NetworkHostAndPort -import net.corda.node.internal.StartedNode +import net.corda.node.internal.NodeWithInfo import net.corda.testing.core.* import net.corda.testing.node.internal.NodeBasedTest import org.assertj.core.api.Assertions.assertThat @@ -108,7 +108,7 @@ class PersistentNetworkMapCacheTest : NodeBasedTest() { // HELPERS // Helper function to restart nodes with the same host and port. - private fun startNodesWithPort(nodesToStart: List, customRetryIntervalMs: Long? = null): List { + private fun startNodesWithPort(nodesToStart: List, customRetryIntervalMs: Long? = null): List { return nodesToStart.map { party -> val configOverrides = (addressesMap[party.name]?.let { mapOf("p2pAddress" to it.toString()) } ?: emptyMap()) + (customRetryIntervalMs?.let { mapOf("activeMQServer.bridge.retryIntervalMs" to it.toString()) } ?: emptyMap()) diff --git a/node/src/integration-test/kotlin/net/corda/node/services/statemachine/FlowVersioningTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/statemachine/FlowVersioningTest.kt index 86633a6a79..f4b3531b13 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/statemachine/FlowVersioningTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/statemachine/FlowVersioningTest.kt @@ -20,7 +20,7 @@ class FlowVersioningTest : NodeBasedTest() { fun `getFlowContext returns the platform version for core flows`() { val alice = startNode(ALICE_NAME, platformVersion = 2) val bob = startNode(BOB_NAME, platformVersion = 3) - bob.internals.installCoreFlow(PretendInitiatingCoreFlow::class, ::PretendInitiatedCoreFlow) + bob.node.installCoreFlow(PretendInitiatingCoreFlow::class, ::PretendInitiatedCoreFlow) val (alicePlatformVersionAccordingToBob, bobPlatformVersionAccordingToAlice) = alice.services.startFlow( PretendInitiatingCoreFlow(bob.info.singleIdentity())).resultFuture.getOrThrow() assertThat(alicePlatformVersionAccordingToBob).isEqualTo(2) diff --git a/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityAsNodeTest.kt b/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityAsNodeTest.kt index 7894ba0499..feda5b405f 100644 --- a/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityAsNodeTest.kt +++ b/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityAsNodeTest.kt @@ -30,7 +30,7 @@ import java.nio.file.Files */ class MQSecurityAsNodeTest : P2PMQSecurityTest() { override fun createAttacker(): SimpleMQClient { - return clientTo(alice.internals.configuration.p2pAddress) + return clientTo(alice.node.configuration.p2pAddress) } override fun startAttacker(attacker: SimpleMQClient) { @@ -44,7 +44,7 @@ class MQSecurityAsNodeTest : P2PMQSecurityTest() { @Test fun `only the node running the broker can login using the special P2P node user`() { - val attacker = clientTo(alice.internals.configuration.p2pAddress) + val attacker = clientTo(alice.node.configuration.p2pAddress) assertThatExceptionOfType(ActiveMQSecurityException::class.java).isThrownBy { attacker.start(NODE_P2P_USER, NODE_P2P_USER) } @@ -52,7 +52,7 @@ class MQSecurityAsNodeTest : P2PMQSecurityTest() { @Test fun `login as the default cluster user`() { - val attacker = clientTo(alice.internals.configuration.p2pAddress) + val attacker = clientTo(alice.node.configuration.p2pAddress) assertThatExceptionOfType(ActiveMQClusterSecurityException::class.java).isThrownBy { attacker.start(ActiveMQDefaultConfiguration.getDefaultClusterUser(), ActiveMQDefaultConfiguration.getDefaultClusterPassword()) } @@ -60,7 +60,7 @@ class MQSecurityAsNodeTest : P2PMQSecurityTest() { @Test fun `login without a username and password`() { - val attacker = clientTo(alice.internals.configuration.p2pAddress) + val attacker = clientTo(alice.node.configuration.p2pAddress) assertThatExceptionOfType(ActiveMQSecurityException::class.java).isThrownBy { attacker.start() } @@ -68,7 +68,7 @@ class MQSecurityAsNodeTest : P2PMQSecurityTest() { @Test fun `login to a non ssl port as a node user`() { - val attacker = clientTo(alice.internals.configuration.rpcOptions.address, sslConfiguration = null) + val attacker = clientTo(alice.node.configuration.rpcOptions.address, sslConfiguration = null) assertThatExceptionOfType(ActiveMQSecurityException::class.java).isThrownBy { attacker.start(NODE_P2P_USER, NODE_P2P_USER, enableSSL = false) } @@ -76,7 +76,7 @@ class MQSecurityAsNodeTest : P2PMQSecurityTest() { @Test fun `login to a non ssl port as a peer user`() { - val attacker = clientTo(alice.internals.configuration.rpcOptions.address, sslConfiguration = null) + val attacker = clientTo(alice.node.configuration.rpcOptions.address, sslConfiguration = null) assertThatExceptionOfType(ActiveMQSecurityException::class.java).isThrownBy { attacker.start(PEER_USER, PEER_USER, enableSSL = false) // Login as a peer } @@ -133,7 +133,7 @@ class MQSecurityAsNodeTest : P2PMQSecurityTest() { } } - val attacker = clientTo(alice.internals.configuration.p2pAddress, sslConfig) + val attacker = clientTo(alice.node.configuration.p2pAddress, sslConfig) assertThatExceptionOfType(ActiveMQNotConnectedException::class.java).isThrownBy { attacker.start(PEER_USER, PEER_USER) diff --git a/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityAsRPCTest.kt b/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityAsRPCTest.kt index 9eee5fd05d..2d534bddf9 100644 --- a/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityAsRPCTest.kt +++ b/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityAsRPCTest.kt @@ -8,7 +8,7 @@ import org.junit.Test */ class MQSecurityAsRPCTest : RPCMQSecurityTest() { override fun createAttacker(): SimpleMQClient { - return clientTo(alice.internals.configuration.rpcOptions.address) + return clientTo(alice.node.configuration.rpcOptions.address) } @Test diff --git a/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityTest.kt b/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityTest.kt index ec9602a023..d42949d020 100644 --- a/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityTest.kt +++ b/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityTest.kt @@ -14,7 +14,7 @@ import net.corda.core.messaging.CordaRPCOps import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.unwrap -import net.corda.node.internal.StartedNodeWithInternals +import net.corda.node.internal.NodeWithInfo import net.corda.nodeapi.RPCApi import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.INTERNAL_PREFIX import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.NOTIFICATIONS_ADDRESS @@ -25,7 +25,6 @@ import net.corda.testing.node.User import net.corda.testing.core.singleIdentity import net.corda.testing.internal.configureTestSSL import net.corda.testing.node.internal.NodeBasedTest -import net.corda.testing.node.internal.TestStartedNode import net.corda.testing.node.internal.startFlow import org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException import org.apache.activemq.artemis.api.core.ActiveMQSecurityException @@ -44,7 +43,7 @@ import kotlin.test.assertEquals */ abstract class MQSecurityTest : NodeBasedTest() { val rpcUser = User("user1", "pass", permissions = emptySet()) - lateinit var alice: StartedNodeWithInternals + lateinit var alice: NodeWithInfo lateinit var attacker: SimpleMQClient private val clients = ArrayList() @@ -112,9 +111,9 @@ abstract class MQSecurityTest : NodeBasedTest() { } fun loginToRPCAndGetClientQueue(): String { - loginToRPC(alice.internals.configuration.rpcOptions.address, rpcUser) + loginToRPC(alice.node.configuration.rpcOptions.address, rpcUser) val clientQueueQuery = SimpleString("${RPCApi.RPC_CLIENT_QUEUE_NAME_PREFIX}.${rpcUser.username}.*") - val client = clientTo(alice.internals.configuration.rpcOptions.address) + val client = clientTo(alice.node.configuration.rpcOptions.address) client.start(rpcUser.username, rpcUser.password, false) return client.session.addressQuery(clientQueueQuery).queueNames.single().toString() } diff --git a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt index 035839f838..7bba2ee345 100644 --- a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt @@ -110,7 +110,7 @@ import net.corda.core.crypto.generateKeyPair as cryptoGenerateKeyPair // In theory the NodeInfo for the node should be passed in, instead, however currently this is constructed by the // AbstractNode. It should be possible to generate the NodeInfo outside of AbstractNode, so it can be passed in. -abstract class AbstractNode(val configuration: NodeConfiguration, +abstract class AbstractNode(val configuration: NodeConfiguration, val platformClock: CordaClock, protected val versionInfo: VersionInfo, protected val cordappLoader: CordappLoader, @@ -183,7 +183,7 @@ abstract class AbstractNode(val configuration: NodeConfiguratio val services = ServiceHubInternalImpl().tokenize() @Suppress("LeakingThis") val smm = makeStateMachineManager() - protected val flowStarter = FlowStarterImpl(smm, flowLogicRefFactory) + val flowStarter = FlowStarterImpl(smm, flowLogicRefFactory) private val schedulerService = NodeSchedulerService( platformClock, database, @@ -221,7 +221,7 @@ abstract class AbstractNode(val configuration: NodeConfiguratio /** Set to non-null once [start] has been successfully called. */ open val started get() = _started @Volatile - private var _started: StartedNode? = null + private var _started: S? = null private fun T.tokenize(): T { tokenizableServices?.add(this) ?: throw IllegalStateException("The tokenisable services list has already been finialised") @@ -625,7 +625,7 @@ abstract class AbstractNode(val configuration: NodeConfiguratio } } - protected fun > registerInitiatedFlow(smm: StateMachineManager, initiatedFlowClass: Class): Observable { + fun > registerInitiatedFlow(smm: StateMachineManager, initiatedFlowClass: Class): Observable { return registerInitiatedFlowInternal(smm, initiatedFlowClass, track = true) } diff --git a/node/src/main/kotlin/net/corda/node/internal/Node.kt b/node/src/main/kotlin/net/corda/node/internal/Node.kt index 7fdc46065f..52dbfe8257 100644 --- a/node/src/main/kotlin/net/corda/node/internal/Node.kt +++ b/node/src/main/kotlin/net/corda/node/internal/Node.kt @@ -4,6 +4,7 @@ import com.codahale.metrics.JmxReporter import net.corda.client.rpc.internal.serialization.amqp.AMQPClientSerializationScheme import net.corda.core.concurrent.CordaFuture import net.corda.core.flows.FlowLogic +import net.corda.core.flows.InitiatedBy import net.corda.core.identity.CordaX500Name import net.corda.core.identity.PartyAndCertificate import net.corda.core.internal.Emoji @@ -13,8 +14,6 @@ import net.corda.core.internal.div import net.corda.core.internal.errors.AddressBindingException import net.corda.core.internal.notary.NotaryService import net.corda.node.services.api.StartedNodeServices -import net.corda.nodeapi.internal.persistence.CordaPersistence -import net.corda.node.services.statemachine.StateMachineManager import net.corda.core.messaging.CordaRPCOps import net.corda.core.messaging.RPCOps import net.corda.core.node.NetworkParameters @@ -67,15 +66,13 @@ import java.time.Clock import java.util.concurrent.atomic.AtomicInteger import javax.management.ObjectName import kotlin.system.exitProcess -import net.corda.node.services.persistence.NodeAttachmentService -/** - * A version of [StartedNode] which exposes its [Node] internals. - * - * Although this is the type of [StartedNode] created by [Node], it is not explicitly provided - * and should not ordinarily be used (the code that _does_ use it obtains it via a cast). - */ -interface StartedNodeWithInternals : StartedNode { - val internals: Node +import rx.Observable + +class NodeWithInfo(val node: Node, val info: NodeInfo) { + val services: StartedNodeServices = object : StartedNodeServices, ServiceHubInternal by node.services, FlowStarter by node.flowStarter {} + fun dispose() = node.stop() + fun > registerInitiatedFlow(initiatedFlowClass: Class): Observable = + node.registerInitiatedFlow(node.smm, initiatedFlowClass) } /** @@ -88,7 +85,7 @@ open class Node(configuration: NodeConfiguration, versionInfo: VersionInfo, private val initialiseSerialization: Boolean = true, cordappLoader: CordappLoader = makeCordappLoader(configuration) -) : AbstractNode( +) : AbstractNode( configuration, createClock(configuration), versionInfo, @@ -97,36 +94,8 @@ open class Node(configuration: NodeConfiguration, AffinityExecutor.ServiceAffinityExecutor("Node thread-${sameVmNodeCounter.incrementAndGet()}", 1) ) { - /** The actual [StartedNode] implementation created by this [AbstractNode]. */ - private class StartedNodeWithInternalsImpl( - override val internals: Node, - override val attachments: NodeAttachmentService, - override val network: MessagingService, - override val services: StartedNodeServices, - override val info: NodeInfo, - override val smm: StateMachineManager, - override val database: CordaPersistence, - override val rpcOps: CordaRPCOps, - override val notaryService: NotaryService?) : StartedNodeWithInternals { - - override fun dispose() = internals.stop() - - override fun > registerInitiatedFlow(initiatedFlowClass: Class) = - internals.registerInitiatedFlow(smm, initiatedFlowClass) - } - - override fun createStartedNode(nodeInfo: NodeInfo, rpcOps: CordaRPCOps, notaryService: NotaryService?): StartedNode = - StartedNodeWithInternalsImpl( - this, - attachments, - network, - object : StartedNodeServices, ServiceHubInternal by services, FlowStarter by flowStarter { }, - nodeInfo, - smm, - database, - rpcOps, - notaryService - ) + override fun createStartedNode(nodeInfo: NodeInfo, rpcOps: CordaRPCOps, notaryService: NotaryService?): NodeInfo = + nodeInfo companion object { private val staticLog = contextLogger() @@ -399,15 +368,15 @@ open class Node(configuration: NodeConfiguration, return super.generateAndSaveNodeInfo() } - override fun start(): StartedNode { + override fun start(): NodeInfo { initialiseSerialization() - val started: StartedNode = super.start() + val nodeInfo: NodeInfo = super.start() nodeReadyFuture.thenMatch({ serverThread.execute { // Begin exporting our own metrics via JMX. These can be monitored using any agent, e.g. Jolokia: // // https://jolokia.org/agent/jvm.html - JmxReporter.forRegistry(started.services.monitoringService.metrics).inDomain("net.corda").createsObjectNamesWith { _, domain, name -> + JmxReporter.forRegistry(services.monitoringService.metrics).inDomain("net.corda").createsObjectNamesWith { _, domain, name -> // Make the JMX hierarchy a bit better organised. val category = name.substringBefore('.') val subName = name.substringAfter('.', "") @@ -425,7 +394,7 @@ open class Node(configuration: NodeConfiguration, shutdownHook = addShutdownHook { stop() } - return started + return nodeInfo } override val rxIoScheduler: Scheduler get() = Schedulers.io() diff --git a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt index 9b0ecd89bd..40edcc8a13 100644 --- a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt +++ b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt @@ -324,18 +324,18 @@ open class NodeStartup(val args: Array) { } } - val startedNode = node.start() - Node.printBasicNodeInfo("Loaded CorDapps", startedNode.services.cordappProvider.cordapps.joinToString { it.name }) + val nodeInfo = node.start() + Node.printBasicNodeInfo("Loaded CorDapps", node.services.cordappProvider.cordapps.joinToString { it.name }) node.nodeReadyFuture.thenMatch({ val elapsed = (System.currentTimeMillis() - startTime) / 10 / 100.0 - val name = startedNode.info.legalIdentitiesAndCerts.first().name.organisation + val name = nodeInfo.legalIdentitiesAndCerts.first().name.organisation Node.printBasicNodeInfo("Node for \"$name\" started up and registered in $elapsed sec") // Don't start the shell if there's no console attached. if (conf.shouldStartLocalShell()) { node.startupComplete.then { try { - InteractiveShell.runLocalShell({ startedNode.dispose() }) + InteractiveShell.runLocalShell({ node.stop() }) } catch (e: Throwable) { logger.error("Shell failed to start", e) } diff --git a/node/src/main/kotlin/net/corda/node/internal/StartedNode.kt b/node/src/main/kotlin/net/corda/node/internal/StartedNode.kt deleted file mode 100644 index 62dfab916b..0000000000 --- a/node/src/main/kotlin/net/corda/node/internal/StartedNode.kt +++ /dev/null @@ -1,34 +0,0 @@ -package net.corda.node.internal - -import net.corda.core.flows.FlowLogic -import net.corda.core.flows.InitiatedBy -import net.corda.core.internal.VisibleForTesting -import net.corda.core.internal.notary.NotaryService -import net.corda.core.messaging.CordaRPCOps -import net.corda.core.node.NodeInfo -import net.corda.node.services.api.StartedNodeServices -import net.corda.node.services.messaging.MessagingService -import net.corda.node.services.persistence.NodeAttachmentService -import net.corda.node.services.statemachine.StateMachineManager -import net.corda.nodeapi.internal.persistence.CordaPersistence -import rx.Observable - -interface StartedNode { - val services: StartedNodeServices - val info: NodeInfo - val smm: StateMachineManager - val attachments: NodeAttachmentService - val network: MessagingService - val database: CordaPersistence - val rpcOps: CordaRPCOps - val notaryService: NotaryService? - - fun dispose() - - /** - * Use this method to register your initiated flows in your tests. This is automatically done by the node when it - * starts up for all [FlowLogic] classes it finds which are annotated with [InitiatedBy]. - * @return An [Observable] of the initiated flows started by counterparties. - */ - fun > registerInitiatedFlow(initiatedFlowClass: Class): Observable -} diff --git a/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt b/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt index 08e3adfec2..8996e1892c 100644 --- a/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt +++ b/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt @@ -27,7 +27,6 @@ import net.corda.finance.GBP import net.corda.finance.contracts.asset.Cash import net.corda.finance.flows.CashIssueFlow import net.corda.finance.flows.CashPaymentFlow -import net.corda.node.internal.StartedNode import net.corda.node.internal.security.RPCSecurityManagerImpl import net.corda.node.services.Permissions.Companion.invokeRpc import net.corda.node.services.Permissions.Companion.startFlow @@ -42,6 +41,7 @@ import net.corda.testing.core.sequence import net.corda.testing.node.internal.cordappsForPackages import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.InternalMockNodeParameters +import net.corda.testing.node.internal.TestStartedNode import net.corda.testing.node.testActor import org.apache.commons.io.IOUtils import org.assertj.core.api.Assertions.* @@ -71,7 +71,7 @@ class CordaRPCOpsImplTest { } private lateinit var mockNet: InternalMockNetwork - private lateinit var aliceNode: StartedNode + private lateinit var aliceNode: TestStartedNode private lateinit var alice: Party private lateinit var notary: Party private lateinit var rpc: CordaRPCOps diff --git a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt index e9c461ca3a..e8a5ae22b6 100644 --- a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt @@ -34,7 +34,6 @@ import net.corda.finance.contracts.asset.CASH import net.corda.finance.contracts.asset.Cash import net.corda.finance.flows.TwoPartyTradeFlow.Buyer import net.corda.finance.flows.TwoPartyTradeFlow.Seller -import net.corda.node.internal.StartedNode import net.corda.node.services.api.IdentityServiceInternal import net.corda.node.services.api.WritableTransactionStorage import net.corda.node.services.persistence.DBTransactionStorage @@ -313,7 +312,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { // Creates a mock node with an overridden storage service that uses a RecordingMap, that lets us test the order // of gets and puts. - private fun makeNodeWithTracking(name: CordaX500Name): StartedNode { + private fun makeNodeWithTracking(name: CordaX500Name): TestStartedNode { // Create a node in the mock network ... return mockNet.createNode(InternalMockNodeParameters(legalName = name), nodeFactory = { args, cordappLoader -> if (cordappLoader != null) { @@ -543,8 +542,8 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { private fun runBuyerAndSeller(notary: Party, buyer: Party, - sellerNode: StartedNode, - buyerNode: StartedNode, + sellerNode: TestStartedNode, + buyerNode: TestStartedNode, assetToSell: StateAndRef): RunResult { val buyerFlows: Observable> = buyerNode.registerInitiatedFlow(BuyerAcceptor::class.java) val firstBuyerFiber = buyerFlows.toFuture().map { it.stateMachine } @@ -638,10 +637,10 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { private fun insertFakeTransactions( wtxToSign: List, - node: StartedNode, + node: TestStartedNode, identity: Party, - notaryNode: StartedNode, - vararg extraSigningNodes: StartedNode): Map { + notaryNode: TestStartedNode, + vararg extraSigningNodes: TestStartedNode): Map { val notaryParty = mockNet.defaultNotaryIdentity val signed = wtxToSign.map { val id = it.id diff --git a/node/src/test/kotlin/net/corda/node/modes/draining/ScheduledFlowsDrainingModeTest.kt b/node/src/test/kotlin/net/corda/node/modes/draining/ScheduledFlowsDrainingModeTest.kt index a26582598f..9382566ab5 100644 --- a/node/src/test/kotlin/net/corda/node/modes/draining/ScheduledFlowsDrainingModeTest.kt +++ b/node/src/test/kotlin/net/corda/node/modes/draining/ScheduledFlowsDrainingModeTest.kt @@ -10,16 +10,12 @@ import net.corda.core.identity.Party import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.loggerFor -import net.corda.node.internal.StartedNode import net.corda.testing.contracts.DummyContract import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.core.dummyCommand import net.corda.testing.core.singleIdentity -import net.corda.testing.node.internal.cordappsForPackages -import net.corda.testing.node.internal.InternalMockNetwork -import net.corda.testing.node.internal.InternalMockNodeParameters -import net.corda.testing.node.internal.startFlow +import net.corda.testing.node.internal.* import org.junit.After import org.junit.Before import org.junit.Test @@ -34,8 +30,8 @@ import kotlin.test.fail class ScheduledFlowsDrainingModeTest { private lateinit var mockNet: InternalMockNetwork - private lateinit var aliceNode: StartedNode - private lateinit var bobNode: StartedNode + private lateinit var aliceNode: TestStartedNode + private lateinit var bobNode: TestStartedNode private lateinit var notary: Party private lateinit var alice: Party private lateinit var bob: Party diff --git a/node/src/test/kotlin/net/corda/node/services/FinalityHandlerTest.kt b/node/src/test/kotlin/net/corda/node/services/FinalityHandlerTest.kt index 9acde0e3ad..0f1e21be0e 100644 --- a/node/src/test/kotlin/net/corda/node/services/FinalityHandlerTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/FinalityHandlerTest.kt @@ -10,7 +10,6 @@ import net.corda.core.utilities.getOrThrow import net.corda.finance.POUNDS import net.corda.finance.contracts.asset.Cash import net.corda.finance.issuedBy -import net.corda.node.internal.StartedNode import net.corda.node.services.statemachine.StaffedFlowHospital import net.corda.node.services.statemachine.StaffedFlowHospital.MedicalRecord.KeptInForObservation import net.corda.testing.core.ALICE_NAME @@ -19,6 +18,7 @@ import net.corda.testing.core.singleIdentity import net.corda.testing.driver.TestCorDapp import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.InternalMockNodeParameters +import net.corda.testing.node.internal.TestStartedNode import net.corda.testing.node.internal.startFlow import org.assertj.core.api.Assertions.assertThat import org.junit.After @@ -75,7 +75,7 @@ class FinalityHandlerTest { assertThat(bob.getTransaction(finalisedTx.id)).isNull() } - private fun StartedNode.assertFlowSentForObservation(runId: StateMachineRunId) { + private fun TestStartedNode.assertFlowSentForObservation(runId: StateMachineRunId) { val keptInForObservation = smm.flowHospital .track() .let { it.updates.startWith(it.snapshot) } @@ -86,7 +86,7 @@ class FinalityHandlerTest { assertThat(keptInForObservation.by).contains(StaffedFlowHospital.FinalityDoctor) } - private fun StartedNode.getTransaction(id: SecureHash): SignedTransaction? { + private fun TestStartedNode.getTransaction(id: SecureHash): SignedTransaction? { return database.transaction { services.validatedTransactions.getTransaction(id) } diff --git a/node/src/test/kotlin/net/corda/node/services/TimedFlowTests.kt b/node/src/test/kotlin/net/corda/node/services/TimedFlowTests.kt index 3fd7fcee5f..1edf477911 100644 --- a/node/src/test/kotlin/net/corda/node/services/TimedFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/TimedFlowTests.kt @@ -22,7 +22,6 @@ import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.ProgressTracker import net.corda.core.utilities.seconds -import net.corda.node.internal.StartedNode import net.corda.node.services.config.FlowTimeoutConfiguration import net.corda.node.services.config.NodeConfiguration import net.corda.node.services.config.NotaryConfig @@ -35,10 +34,7 @@ import net.corda.testing.core.singleIdentity import net.corda.testing.internal.LogHelper import net.corda.testing.node.InMemoryMessagingNetwork import net.corda.testing.node.MockNetworkParameters -import net.corda.testing.node.internal.cordappsForPackages -import net.corda.testing.node.internal.InternalMockNetwork -import net.corda.testing.node.internal.InternalMockNodeParameters -import net.corda.testing.node.internal.startFlow +import net.corda.testing.node.internal.* import org.junit.AfterClass import org.junit.Before import org.junit.BeforeClass @@ -58,7 +54,7 @@ class TimedFlowTests { private lateinit var mockNet: InternalMockNetwork private lateinit var notary: Party - private lateinit var node: StartedNode + private lateinit var node: TestStartedNode init { LogHelper.setLevel("+net.corda.flow", "+net.corda.testing.node", "+net.corda.node.services.messaging") @@ -83,7 +79,7 @@ class TimedFlowTests { mockNet.stopNodes() } - private fun startClusterAndNode(mockNet: InternalMockNetwork): Pair { + private fun startClusterAndNode(mockNet: InternalMockNetwork): Pair { val replicaIds = (0 until CLUSTER_SIZE) val notaryIdentity = DevIdentityGenerator.generateDistributedNotaryCompositeIdentity( replicaIds.map { mockNet.baseDirectory(mockNet.nextNodeId + it) }, @@ -164,7 +160,7 @@ class TimedFlowTests { } } - private fun StartedNode.signInitialTransaction(notary: Party, block: TransactionBuilder.() -> Any?): SignedTransaction { + private fun TestStartedNode.signInitialTransaction(notary: Party, block: TransactionBuilder.() -> Any?): SignedTransaction { return services.signInitialTransaction( TransactionBuilder(notary).apply { addCommand(dummyCommand(services.myInfo.singleIdentity().owningKey)) diff --git a/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt b/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt index 764df9e18d..c9515977ba 100644 --- a/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt @@ -16,17 +16,13 @@ import net.corda.core.node.services.vault.Sort import net.corda.core.node.services.vault.SortAttribute import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.getOrThrow -import net.corda.node.internal.StartedNode import net.corda.node.services.statemachine.StateMachineManager import net.corda.testing.contracts.DummyContract import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.core.dummyCommand import net.corda.testing.core.singleIdentity -import net.corda.testing.node.internal.cordappsForPackages -import net.corda.testing.node.internal.InternalMockNetwork -import net.corda.testing.node.internal.InternalMockNodeParameters -import net.corda.testing.node.internal.startFlow +import net.corda.testing.node.internal.* import org.junit.After import org.junit.Assert.* import org.junit.Before @@ -42,8 +38,8 @@ class ScheduledFlowTests { } private lateinit var mockNet: InternalMockNetwork - private lateinit var aliceNode: StartedNode - private lateinit var bobNode: StartedNode + private lateinit var aliceNode: TestStartedNode + private lateinit var bobNode: TestStartedNode private lateinit var notary: Party private lateinit var alice: Party private lateinit var bob: Party diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt index 61925a41c2..59098cffed 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt @@ -27,7 +27,6 @@ import net.corda.core.utilities.ProgressTracker.Change import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.unwrap import net.corda.node.internal.InitiatedFlowFactory -import net.corda.node.internal.StartedNode import net.corda.node.services.persistence.checkpoints import net.corda.testing.contracts.DummyContract import net.corda.testing.contracts.DummyState @@ -445,7 +444,7 @@ class FlowFrameworkTests { private val normalEnd = ExistingSessionMessage(SessionId(0), EndSessionMessage) // NormalSessionEnd(0) - private fun StartedNode.sendSessionMessage(message: SessionMessage, destination: Party) { + private fun TestStartedNode.sendSessionMessage(message: SessionMessage, destination: Party) { services.networkService.apply { val address = getAddressOfParty(PartyInfo.SingleNode(destination, emptyList())) send(createMessage(FlowMessagingImpl.sessionTopic, message.serialize().bytes), address) @@ -774,7 +773,7 @@ class FlowFrameworkPersistenceTests { private fun sessionConfirm(flowVersion: Int = 1) = ExistingSessionMessage(SessionId(0), ConfirmSessionMessage(SessionId(0), FlowInfo(flowVersion, ""))) -private inline fun > StartedNode.getSingleFlow(): Pair> { +private inline fun > TestStartedNode.getSingleFlow(): Pair> { return smm.findStateMachines(P::class.java).single() } @@ -809,7 +808,7 @@ private fun Observable.toSessionTransfers(): Observable = Pair(internals.id, message) -private infix fun Pair.to(node: StartedNode): SessionTransfer = SessionTransfer(first, second, node.network.myAddress) +private infix fun Pair.to(node: TestStartedNode): SessionTransfer = SessionTransfer(first, second, node.network.myAddress) private data class SessionTransfer(val from: Int, val message: SessionMessage, val to: MessageRecipients) { val isPayloadTransfer: Boolean get() = diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/IdempotentFlowTests.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/IdempotentFlowTests.kt index 91ca18278e..04539c38ae 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/IdempotentFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/IdempotentFlowTests.kt @@ -11,13 +11,9 @@ import net.corda.core.internal.IdempotentFlow import net.corda.core.internal.TimedFlow import net.corda.core.internal.packageName import net.corda.core.utilities.seconds -import net.corda.node.internal.StartedNode import net.corda.node.services.config.FlowTimeoutConfiguration import net.corda.node.services.config.NodeConfiguration -import net.corda.testing.node.internal.cordappsForPackages -import net.corda.testing.node.internal.InternalMockNetwork -import net.corda.testing.node.internal.InternalMockNodeParameters -import net.corda.testing.node.internal.startFlow +import net.corda.testing.node.internal.* import org.junit.After import org.junit.Before import org.junit.Test @@ -27,8 +23,8 @@ import kotlin.test.assertEquals class IdempotentFlowTests { private lateinit var mockNet: InternalMockNetwork - private lateinit var nodeA: StartedNode - private lateinit var nodeB: StartedNode + private lateinit var nodeA: TestStartedNode + private lateinit var nodeB: TestStartedNode companion object { val executionCounter = AtomicInteger(0) diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt index 342d29fd3c..8053edd357 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt @@ -11,7 +11,6 @@ import net.corda.core.messaging.MessageRecipients import net.corda.core.utilities.UntrustworthyData import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.unwrap -import net.corda.node.internal.StartedNode import net.corda.node.services.FinalityHandler import net.corda.node.services.messaging.Message import net.corda.node.services.persistence.DBTransactionStorage @@ -53,7 +52,7 @@ class RetryFlowMockTest { KeepSendingFlow.count.set(0) } - private fun StartedNode.startFlow(logic: FlowLogic): CordaFuture { + private fun TestStartedNode.startFlow(logic: FlowLogic): CordaFuture { return this.services.startFlow(logic, this.services.newContext()).flatMap { it.resultFuture } } diff --git a/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt index c6f74a0361..40efe942d0 100644 --- a/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt @@ -10,15 +10,11 @@ import net.corda.core.internal.NotaryChangeTransactionBuilder import net.corda.core.node.ServiceHub import net.corda.core.transactions.SignedTransaction import net.corda.core.utilities.getOrThrow -import net.corda.node.internal.StartedNode import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.DUMMY_NOTARY_NAME import net.corda.testing.core.singleIdentity import net.corda.testing.node.MockNetworkNotarySpec -import net.corda.testing.node.internal.cordappsForPackages -import net.corda.testing.node.internal.InternalMockNetwork -import net.corda.testing.node.internal.InternalMockNodeParameters -import net.corda.testing.node.internal.startFlow +import net.corda.testing.node.internal.* import org.junit.After import org.junit.Before import org.junit.Test @@ -27,7 +23,7 @@ import kotlin.test.assertFailsWith class NotaryServiceTests { private lateinit var mockNet: InternalMockNetwork private lateinit var notaryServices: ServiceHub - private lateinit var aliceNode: StartedNode + private lateinit var aliceNode: TestStartedNode private lateinit var notary: Party private lateinit var alice: Party @@ -55,7 +51,7 @@ class NotaryServiceTests { internal companion object { /** This is used by both [NotaryServiceTests] and [ValidatingNotaryServiceTests]. */ - fun notariseWithTooManyInputs(node: StartedNode, party: Party, notary: Party, network: InternalMockNetwork) { + fun notariseWithTooManyInputs(node: TestStartedNode, party: Party, notary: Party, network: InternalMockNetwork) { val stx = generateTransaction(node, party, notary) val future = node.services.startFlow(DummyClientFlow(stx, notary)).resultFuture @@ -63,7 +59,7 @@ class NotaryServiceTests { assertFailsWith { future.getOrThrow() } } - private fun generateTransaction(node: StartedNode, party: Party, notary: Party): SignedTransaction { + private fun generateTransaction(node: TestStartedNode, party: Party, notary: Party): SignedTransaction { val txHash = SecureHash.randomSHA256() val inputs = (1..10_005).map { StateRef(txHash, it) } val tx = NotaryChangeTransactionBuilder(inputs, notary, party).build() diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/internal/DriverInternal.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/internal/DriverInternal.kt index 6ca49b5561..cf85d45e15 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/internal/DriverInternal.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/internal/DriverInternal.kt @@ -4,7 +4,7 @@ import net.corda.core.flows.FlowLogic import net.corda.core.messaging.CordaRPCOps import net.corda.core.node.NodeInfo import net.corda.core.utilities.NetworkHostAndPort -import net.corda.node.internal.StartedNodeWithInternals +import net.corda.node.internal.NodeWithInfo import net.corda.node.services.api.StartedNodeServices import net.corda.node.services.config.NodeConfiguration import net.corda.nodeapi.internal.persistence.CordaPersistence @@ -55,9 +55,9 @@ data class InProcessImpl( override val useHTTPS: Boolean, private val nodeThread: Thread, private val onStopCallback: () -> Unit, - private val node: StartedNodeWithInternals + private val node: NodeWithInfo ) : InProcess, NodeHandleInternal { - val database: CordaPersistence = node.database + val database: CordaPersistence = node.node.database override val services: StartedNodeServices get() = node.services override val rpcUsers: List = configuration.rpcUsers.map { User(it.username, it.password, it.permissions) } override fun stop() { diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt index d433f87a86..bfaed0df8f 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt @@ -25,7 +25,7 @@ import net.corda.core.utilities.millis import net.corda.node.NodeRegistrationOption import net.corda.node.VersionInfo import net.corda.node.internal.Node -import net.corda.node.internal.StartedNodeWithInternals +import net.corda.node.internal.NodeWithInfo import net.corda.node.services.Permissions import net.corda.node.services.config.* import net.corda.node.utilities.registration.HTTPNetworkRegistrationService @@ -783,7 +783,7 @@ class DriverDSLImpl( private fun startInProcessNode( executorService: ScheduledExecutorService, config: NodeConfig - ): CordaFuture> { + ): CordaFuture> { return executorService.fork { log.info("Starting in-process Node ${config.corda.myLegalName.organisation}") if (!(ManagementFactory.getRuntimeMXBean().inputArguments.any { it.contains("quasar") })) { @@ -792,12 +792,13 @@ class DriverDSLImpl( // Write node.conf writeConfig(config.corda.baseDirectory, "node.conf", config.typesafe.toNodeOnly()) // TODO pass the version in? - val internals = InProcessNode(config.corda, MOCK_VERSION_INFO) - val node = internals.start() as StartedNodeWithInternals + val node = InProcessNode(config.corda, MOCK_VERSION_INFO) + val nodeInfo = node.start() + val nodeWithInfo = NodeWithInfo(node, nodeInfo) val nodeThread = thread(name = config.corda.myLegalName.organisation) { - internals.run() + node.run() } - node to nodeThread + nodeWithInfo to nodeThread }.flatMap { nodeAndThread -> addressMustBeBoundFuture(executorService, config.corda.p2pAddress).map { nodeAndThread } } diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalMockNetwork.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalMockNetwork.kt index f027ab5a69..3fe3973ac2 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalMockNetwork.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalMockNetwork.kt @@ -9,6 +9,7 @@ import net.corda.core.crypto.Crypto import net.corda.core.crypto.SecureHash import net.corda.core.crypto.random63BitValue import net.corda.core.flows.FlowLogic +import net.corda.core.flows.InitiatedBy import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party import net.corda.core.identity.PartyAndCertificate @@ -28,7 +29,6 @@ import net.corda.node.VersionInfo import net.corda.node.cordapp.CordappLoader import net.corda.node.internal.AbstractNode import net.corda.node.internal.InitiatedFlowFactory -import net.corda.node.internal.StartedNode import net.corda.node.internal.cordapp.JarScanningCordappLoader import net.corda.node.services.api.FlowStarter import net.corda.node.services.api.ServiceHubInternal @@ -102,8 +102,25 @@ data class InternalMockNodeParameters( /** * A [StartedNode] which exposes its internal [InternalMockNetwork.MockNode] for testing. */ -interface TestStartedNode : StartedNode { +interface TestStartedNode { val internals: InternalMockNetwork.MockNode + val info: NodeInfo + val services: StartedNodeServices + val smm: StateMachineManager + val attachments: NodeAttachmentService + val rpcOps: CordaRPCOps + val network: MessagingService + val database: CordaPersistence + val notaryService: NotaryService? + + fun dispose() = internals.stop() + + /** + * Use this method to register your initiated flows in your tests. This is automatically done by the node when it + * starts up for all [FlowLogic] classes it finds which are annotated with [InitiatedBy]. + * @return An [Observable] of the initiated flows started by counterparties. + */ + fun > registerInitiatedFlow(initiatedFlowClass: Class): Observable fun > internalRegisterFlowFactory(initiatingFlowClass: Class>, flowFactory: InitiatedFlowFactory, diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/NodeBasedTest.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/NodeBasedTest.kt index e43471df80..bce128a107 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/NodeBasedTest.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/NodeBasedTest.kt @@ -10,9 +10,9 @@ import net.corda.core.node.NodeInfo import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.loggerFor import net.corda.node.VersionInfo +import net.corda.node.internal.NodeWithInfo import net.corda.node.internal.Node -import net.corda.node.internal.StartedNodeWithInternals import net.corda.node.services.config.* import net.corda.nodeapi.internal.config.toConfig import net.corda.nodeapi.internal.network.NetworkParametersCopier @@ -47,7 +47,7 @@ abstract class NodeBasedTest(private val cordappPackages: List = emptyLi val tempFolder = TemporaryFolder() private lateinit var defaultNetworkParameters: NetworkParametersCopier - private val nodes = mutableListOf() + private val nodes = mutableListOf() private val nodeInfos = mutableListOf() private val portAllocation = PortAllocation.Incremental(10000) @@ -72,8 +72,8 @@ abstract class NodeBasedTest(private val cordappPackages: List = emptyLi // Wait until ports are released val portNotBoundChecks = nodes.flatMap { listOf( - addressMustNotBeBoundFuture(shutdownExecutor, it.internals.configuration.p2pAddress), - addressMustNotBeBoundFuture(shutdownExecutor, it.internals.configuration.rpcOptions.address) + addressMustNotBeBoundFuture(shutdownExecutor, it.node.configuration.p2pAddress), + addressMustNotBeBoundFuture(shutdownExecutor, it.node.configuration.rpcOptions.address) ) } nodes.clear() @@ -87,7 +87,7 @@ abstract class NodeBasedTest(private val cordappPackages: List = emptyLi fun startNode(legalName: CordaX500Name, platformVersion: Int = 1, rpcUsers: List = emptyList(), - configOverrides: Map = emptyMap()): StartedNodeWithInternals { + configOverrides: Map = emptyMap()): NodeWithInfo { val baseDirectory = baseDirectory(legalName).createDirectories() val p2pAddress = configOverrides["p2pAddress"] ?: portAllocation.nextHostAndPort().toString() val config = ConfigHelper.loadConfig( @@ -119,15 +119,16 @@ abstract class NodeBasedTest(private val cordappPackages: List = emptyLi } defaultNetworkParameters.install(baseDirectory) - val internals = InProcessNode(parsedConfig, MOCK_VERSION_INFO.copy(platformVersion = platformVersion)) - val node = internals.start() as StartedNodeWithInternals - nodes += node + val node = InProcessNode(parsedConfig, MOCK_VERSION_INFO.copy(platformVersion = platformVersion)) + val nodeInfo = node.start() + val nodeWithInfo = NodeWithInfo(node, nodeInfo) + nodes += nodeWithInfo ensureAllNetworkMapCachesHaveAllNodeInfos() thread(name = legalName.organisation) { - internals.run() + node.run() } - return node + return nodeWithInfo } protected fun baseDirectory(legalName: CordaX500Name): Path { @@ -135,7 +136,7 @@ abstract class NodeBasedTest(private val cordappPackages: List = emptyLi } private fun ensureAllNetworkMapCachesHaveAllNodeInfos() { - val runningNodes = nodes.filter { it.internals.started != null } + val runningNodes = nodes.filter { it.node.started != null } val runningNodesInfo = runningNodes.map { it.info } for (node in runningNodes) for (nodeInfo in runningNodesInfo) {