mirror of
https://github.com/corda/corda.git
synced 2025-02-01 08:48:09 +00:00
Move useTestClock conditional to Node constructor
This commit is contained in:
parent
907ec9ff46
commit
ea0d10787a
@ -24,6 +24,7 @@ import net.corda.node.services.messaging.MessagingService
|
|||||||
import net.corda.node.services.messaging.NodeMessagingClient
|
import net.corda.node.services.messaging.NodeMessagingClient
|
||||||
import net.corda.node.utilities.AddressUtils
|
import net.corda.node.utilities.AddressUtils
|
||||||
import net.corda.node.utilities.AffinityExecutor
|
import net.corda.node.utilities.AffinityExecutor
|
||||||
|
import net.corda.node.utilities.TestClock
|
||||||
import net.corda.nodeapi.ArtemisMessagingComponent
|
import net.corda.nodeapi.ArtemisMessagingComponent
|
||||||
import net.corda.nodeapi.ArtemisMessagingComponent.Companion.IP_REQUEST_PREFIX
|
import net.corda.nodeapi.ArtemisMessagingComponent.Companion.IP_REQUEST_PREFIX
|
||||||
import net.corda.nodeapi.ArtemisMessagingComponent.Companion.PEER_USER
|
import net.corda.nodeapi.ArtemisMessagingComponent.Companion.PEER_USER
|
||||||
@ -58,8 +59,8 @@ import kotlin.system.exitProcess
|
|||||||
open class Node(override val configuration: FullNodeConfiguration,
|
open class Node(override val configuration: FullNodeConfiguration,
|
||||||
advertisedServices: Set<ServiceInfo>,
|
advertisedServices: Set<ServiceInfo>,
|
||||||
val versionInfo: VersionInfo,
|
val versionInfo: VersionInfo,
|
||||||
clock: Clock = NodeClock(),
|
val initialiseSerialization: Boolean = true
|
||||||
val initialiseSerialization: Boolean = true) : AbstractNode(configuration, advertisedServices, clock) {
|
) : AbstractNode(configuration, advertisedServices, createClock(configuration)) {
|
||||||
companion object {
|
companion object {
|
||||||
private val logger = loggerFor<Node>()
|
private val logger = loggerFor<Node>()
|
||||||
var renderBasicInfoToConsole = true
|
var renderBasicInfoToConsole = true
|
||||||
@ -76,6 +77,10 @@ open class Node(override val configuration: FullNodeConfiguration,
|
|||||||
println("Corda will now exit...")
|
println("Corda will now exit...")
|
||||||
exitProcess(1)
|
exitProcess(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createClock(configuration: FullNodeConfiguration): Clock {
|
||||||
|
return if (configuration.useTestClock) TestClock() else NodeClock()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val log: Logger get() = logger
|
override val log: Logger get() = logger
|
||||||
|
@ -93,7 +93,7 @@ open class NodeStartup(val args: Array<String>) {
|
|||||||
open protected fun preNetworkRegistration(conf: FullNodeConfiguration) = Unit
|
open protected fun preNetworkRegistration(conf: FullNodeConfiguration) = Unit
|
||||||
|
|
||||||
open protected fun createNode(conf: FullNodeConfiguration, versionInfo: VersionInfo, services: Set<ServiceInfo>): Node {
|
open protected fun createNode(conf: FullNodeConfiguration, versionInfo: VersionInfo, services: Set<ServiceInfo>): Node {
|
||||||
return Node(conf, services, versionInfo, if (conf.useTestClock) TestClock() else NodeClock())
|
return Node(conf, services, versionInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
open protected fun startNode(conf: FullNodeConfiguration, versionInfo: VersionInfo, startTime: Long, cmdlineOptions: CmdLineOptions) {
|
open protected fun startNode(conf: FullNodeConfiguration, versionInfo: VersionInfo, startTime: Long, cmdlineOptions: CmdLineOptions) {
|
||||||
|
@ -7,6 +7,7 @@ import net.corda.core.toFuture
|
|||||||
import net.corda.core.internal.concurrent.transpose
|
import net.corda.core.internal.concurrent.transpose
|
||||||
import net.corda.core.utilities.NetworkHostAndPort
|
import net.corda.core.utilities.NetworkHostAndPort
|
||||||
import net.corda.core.utilities.getOrThrow
|
import net.corda.core.utilities.getOrThrow
|
||||||
|
import net.corda.core.utilities.loggerFor
|
||||||
import net.corda.core.utilities.seconds
|
import net.corda.core.utilities.seconds
|
||||||
import net.corda.irs.api.NodeInterestRates
|
import net.corda.irs.api.NodeInterestRates
|
||||||
import net.corda.irs.contract.InterestRateSwap
|
import net.corda.irs.contract.InterestRateSwap
|
||||||
@ -29,6 +30,11 @@ import java.time.Duration
|
|||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
|
|
||||||
class IRSDemoTest : IntegrationTestCategory {
|
class IRSDemoTest : IntegrationTestCategory {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val log = loggerFor<IRSDemoTest>()
|
||||||
|
}
|
||||||
|
|
||||||
val rpcUser = User("user", "password", emptySet())
|
val rpcUser = User("user", "password", emptySet())
|
||||||
val currentDate: LocalDate = LocalDate.now()
|
val currentDate: LocalDate = LocalDate.now()
|
||||||
val futureDate: LocalDate = currentDate.plusMonths(6)
|
val futureDate: LocalDate = currentDate.plusMonths(6)
|
||||||
@ -43,7 +49,7 @@ class IRSDemoTest : IntegrationTestCategory {
|
|||||||
startNode(DUMMY_BANK_B.name)
|
startNode(DUMMY_BANK_B.name)
|
||||||
).transpose().getOrThrow()
|
).transpose().getOrThrow()
|
||||||
|
|
||||||
println("All nodes started")
|
log.info("All nodes started")
|
||||||
|
|
||||||
val (controllerAddr, nodeAAddr, nodeBAddr) = listOf(
|
val (controllerAddr, nodeAAddr, nodeBAddr) = listOf(
|
||||||
startWebserver(controller),
|
startWebserver(controller),
|
||||||
@ -51,7 +57,7 @@ class IRSDemoTest : IntegrationTestCategory {
|
|||||||
startWebserver(nodeB)
|
startWebserver(nodeB)
|
||||||
).transpose().getOrThrow().map { it.listenAddress }
|
).transpose().getOrThrow().map { it.listenAddress }
|
||||||
|
|
||||||
println("All webservers started")
|
log.info("All webservers started")
|
||||||
|
|
||||||
val (_, nodeAApi, nodeBApi) = listOf(controller, nodeA, nodeB).zip(listOf(controllerAddr, nodeAAddr, nodeBAddr)).map {
|
val (_, nodeAApi, nodeBApi) = listOf(controller, nodeA, nodeB).zip(listOf(controllerAddr, nodeAAddr, nodeBAddr)).map {
|
||||||
val mapper = net.corda.jackson.JacksonSupport.createDefaultMapper(it.first.rpc)
|
val mapper = net.corda.jackson.JacksonSupport.createDefaultMapper(it.first.rpc)
|
||||||
@ -85,25 +91,25 @@ class IRSDemoTest : IntegrationTestCategory {
|
|||||||
val vaultUpdates = proxy.vaultTrackBy<InterestRateSwap.State>().updates
|
val vaultUpdates = proxy.vaultTrackBy<InterestRateSwap.State>().updates
|
||||||
|
|
||||||
return vaultUpdates.map { update ->
|
return vaultUpdates.map { update ->
|
||||||
val irsStates = update.produced.map { it.state.data }.filterIsInstance<InterestRateSwap.State>()
|
val irsStates = update.produced.map { it.state.data }
|
||||||
irsStates.mapNotNull { it.calculation.nextFixingDate() }.max()
|
irsStates.mapNotNull { it.calculation.nextFixingDate() }.max()
|
||||||
}.cache()
|
}.cache()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runDateChange(nodeApi: HttpApi) {
|
private fun runDateChange(nodeApi: HttpApi) {
|
||||||
println("Running date change against ${nodeApi.root}")
|
log.info("Running date change against ${nodeApi.root}")
|
||||||
assertThat(nodeApi.putJson("demodate", "\"$futureDate\"")).isTrue()
|
assertThat(nodeApi.putJson("demodate", "\"$futureDate\"")).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runTrade(nodeApi: HttpApi) {
|
private fun runTrade(nodeApi: HttpApi) {
|
||||||
println("Running trade against ${nodeApi.root}")
|
log.info("Running trade against ${nodeApi.root}")
|
||||||
val fileContents = loadResourceFile("net/corda/irs/simulation/example-irs-trade.json")
|
val fileContents = loadResourceFile("net/corda/irs/simulation/example-irs-trade.json")
|
||||||
val tradeFile = fileContents.replace("tradeXXX", "trade1")
|
val tradeFile = fileContents.replace("tradeXXX", "trade1")
|
||||||
assertThat(nodeApi.postJson("deals", tradeFile)).isTrue()
|
assertThat(nodeApi.postJson("deals", tradeFile)).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runUploadRates(host: NetworkHostAndPort) {
|
private fun runUploadRates(host: NetworkHostAndPort) {
|
||||||
println("Running upload rates against $host")
|
log.info("Running upload rates against $host")
|
||||||
val fileContents = loadResourceFile("net/corda/irs/simulation/example.rates.txt")
|
val fileContents = loadResourceFile("net/corda/irs/simulation/example.rates.txt")
|
||||||
val url = URL("http://$host/api/irs/fixes")
|
val url = URL("http://$host/api/irs/fixes")
|
||||||
assertThat(uploadFile(url, fileContents)).isTrue()
|
assertThat(uploadFile(url, fileContents)).isTrue()
|
||||||
@ -114,13 +120,13 @@ class IRSDemoTest : IntegrationTestCategory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getTradeCount(nodeApi: HttpApi): Int {
|
private fun getTradeCount(nodeApi: HttpApi): Int {
|
||||||
println("Getting trade count from ${nodeApi.root}")
|
log.info("Getting trade count from ${nodeApi.root}")
|
||||||
val deals = nodeApi.getJson<Array<*>>("deals")
|
val deals = nodeApi.getJson<Array<*>>("deals")
|
||||||
return deals.size
|
return deals.size
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTrades(nodeApi: HttpApi): Array<InterestRateSwap.State> {
|
private fun getTrades(nodeApi: HttpApi): Array<InterestRateSwap.State> {
|
||||||
println("Getting trades from ${nodeApi.root}")
|
log.info("Getting trades from ${nodeApi.root}")
|
||||||
val deals = nodeApi.getJson<Array<InterestRateSwap.State>>("deals")
|
val deals = nodeApi.getJson<Array<InterestRateSwap.State>>("deals")
|
||||||
return deals
|
return deals
|
||||||
}
|
}
|
||||||
|
@ -772,9 +772,8 @@ class DriverDSL(
|
|||||||
log.info("Starting in-process Node ${nodeConf.myLegalName.commonName}")
|
log.info("Starting in-process Node ${nodeConf.myLegalName.commonName}")
|
||||||
// Write node.conf
|
// Write node.conf
|
||||||
writeConfig(nodeConf.baseDirectory, "node.conf", config)
|
writeConfig(nodeConf.baseDirectory, "node.conf", config)
|
||||||
val clock: Clock = if (nodeConf.useTestClock) TestClock() else NodeClock()
|
|
||||||
// TODO pass the version in?
|
// TODO pass the version in?
|
||||||
val node = Node(nodeConf, nodeConf.calculateServices(), MOCK_VERSION_INFO, clock, initialiseSerialization = false)
|
val node = Node(nodeConf, nodeConf.calculateServices(), MOCK_VERSION_INFO, initialiseSerialization = false)
|
||||||
node.start()
|
node.start()
|
||||||
val nodeThread = thread(name = nodeConf.myLegalName.commonName) {
|
val nodeThread = thread(name = nodeConf.myLegalName.commonName) {
|
||||||
node.run()
|
node.run()
|
||||||
|
@ -164,7 +164,7 @@ abstract class NodeBasedTest : TestDependencyInjectionBase() {
|
|||||||
|
|
||||||
val parsedConfig = config.parseAs<FullNodeConfiguration>()
|
val parsedConfig = config.parseAs<FullNodeConfiguration>()
|
||||||
val node = Node(parsedConfig, parsedConfig.calculateServices(), MOCK_VERSION_INFO.copy(platformVersion = platformVersion),
|
val node = Node(parsedConfig, parsedConfig.calculateServices(), MOCK_VERSION_INFO.copy(platformVersion = platformVersion),
|
||||||
if (parsedConfig.useTestClock) TestClock() else NodeClock(), initialiseSerialization = false)
|
initialiseSerialization = false)
|
||||||
node.start()
|
node.start()
|
||||||
nodes += node
|
nodes += node
|
||||||
thread(name = legalName.commonName) {
|
thread(name = legalName.commonName) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user