mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +00:00
Merge pull request #1207 from corda/aslemmer-move-testclock-branching-to-Node
Move useTestClock conditional to Node constructor
This commit is contained in:
commit
f6e7814638
@ -24,6 +24,7 @@ import net.corda.node.services.messaging.MessagingService
|
||||
import net.corda.node.services.messaging.NodeMessagingClient
|
||||
import net.corda.node.utilities.AddressUtils
|
||||
import net.corda.node.utilities.AffinityExecutor
|
||||
import net.corda.node.utilities.TestClock
|
||||
import net.corda.nodeapi.ArtemisMessagingComponent
|
||||
import net.corda.nodeapi.ArtemisMessagingComponent.Companion.IP_REQUEST_PREFIX
|
||||
import net.corda.nodeapi.ArtemisMessagingComponent.Companion.PEER_USER
|
||||
@ -58,8 +59,8 @@ import kotlin.system.exitProcess
|
||||
open class Node(override val configuration: FullNodeConfiguration,
|
||||
advertisedServices: Set<ServiceInfo>,
|
||||
val versionInfo: VersionInfo,
|
||||
clock: Clock = NodeClock(),
|
||||
val initialiseSerialization: Boolean = true) : AbstractNode(configuration, advertisedServices, clock) {
|
||||
val initialiseSerialization: Boolean = true
|
||||
) : AbstractNode(configuration, advertisedServices, createClock(configuration)) {
|
||||
companion object {
|
||||
private val logger = loggerFor<Node>()
|
||||
var renderBasicInfoToConsole = true
|
||||
@ -76,6 +77,10 @@ open class Node(override val configuration: FullNodeConfiguration,
|
||||
println("Corda will now exit...")
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
private fun createClock(configuration: FullNodeConfiguration): Clock {
|
||||
return if (configuration.useTestClock) TestClock() else NodeClock()
|
||||
}
|
||||
}
|
||||
|
||||
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 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) {
|
||||
|
@ -7,6 +7,7 @@ import net.corda.core.toFuture
|
||||
import net.corda.core.internal.concurrent.transpose
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import net.corda.core.utilities.seconds
|
||||
import net.corda.irs.api.NodeInterestRates
|
||||
import net.corda.irs.contract.InterestRateSwap
|
||||
@ -29,6 +30,11 @@ import java.time.Duration
|
||||
import java.time.LocalDate
|
||||
|
||||
class IRSDemoTest : IntegrationTestCategory {
|
||||
|
||||
companion object {
|
||||
val log = loggerFor<IRSDemoTest>()
|
||||
}
|
||||
|
||||
val rpcUser = User("user", "password", emptySet())
|
||||
val currentDate: LocalDate = LocalDate.now()
|
||||
val futureDate: LocalDate = currentDate.plusMonths(6)
|
||||
@ -43,7 +49,7 @@ class IRSDemoTest : IntegrationTestCategory {
|
||||
startNode(DUMMY_BANK_B.name)
|
||||
).transpose().getOrThrow()
|
||||
|
||||
println("All nodes started")
|
||||
log.info("All nodes started")
|
||||
|
||||
val (controllerAddr, nodeAAddr, nodeBAddr) = listOf(
|
||||
startWebserver(controller),
|
||||
@ -51,7 +57,7 @@ class IRSDemoTest : IntegrationTestCategory {
|
||||
startWebserver(nodeB)
|
||||
).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 mapper = net.corda.jackson.JacksonSupport.createDefaultMapper(it.first.rpc)
|
||||
@ -85,25 +91,25 @@ class IRSDemoTest : IntegrationTestCategory {
|
||||
val vaultUpdates = proxy.vaultTrackBy<InterestRateSwap.State>().updates
|
||||
|
||||
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()
|
||||
}.cache()
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
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 tradeFile = fileContents.replace("tradeXXX", "trade1")
|
||||
assertThat(nodeApi.postJson("deals", tradeFile)).isTrue()
|
||||
}
|
||||
|
||||
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 url = URL("http://$host/api/irs/fixes")
|
||||
assertThat(uploadFile(url, fileContents)).isTrue()
|
||||
@ -114,13 +120,13 @@ class IRSDemoTest : IntegrationTestCategory {
|
||||
}
|
||||
|
||||
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")
|
||||
return deals.size
|
||||
}
|
||||
|
||||
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")
|
||||
return deals
|
||||
}
|
||||
|
@ -772,9 +772,8 @@ class DriverDSL(
|
||||
log.info("Starting in-process Node ${nodeConf.myLegalName.commonName}")
|
||||
// Write node.conf
|
||||
writeConfig(nodeConf.baseDirectory, "node.conf", config)
|
||||
val clock: Clock = if (nodeConf.useTestClock) TestClock() else NodeClock()
|
||||
// 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()
|
||||
val nodeThread = thread(name = nodeConf.myLegalName.commonName) {
|
||||
node.run()
|
||||
|
@ -164,7 +164,7 @@ abstract class NodeBasedTest : TestDependencyInjectionBase() {
|
||||
|
||||
val parsedConfig = config.parseAs<FullNodeConfiguration>()
|
||||
val node = Node(parsedConfig, parsedConfig.calculateServices(), MOCK_VERSION_INFO.copy(platformVersion = platformVersion),
|
||||
if (parsedConfig.useTestClock) TestClock() else NodeClock(), initialiseSerialization = false)
|
||||
initialiseSerialization = false)
|
||||
node.start()
|
||||
nodes += node
|
||||
thread(name = legalName.commonName) {
|
||||
|
Loading…
Reference in New Issue
Block a user