IRSDemoTest: wait until transactions have finished before completing the test.

The date to set the demo date to is now + 6 months.
This commit is contained in:
Andrius Dagys 2017-01-05 11:26:53 +00:00
parent 6b7edf5af6
commit 078a9e2b70
2 changed files with 51 additions and 20 deletions

View File

@ -5,46 +5,77 @@ import com.google.common.util.concurrent.Futures
import net.corda.core.getOrThrow
import net.corda.core.node.services.ServiceInfo
import net.corda.irs.api.NodeInterestRates
import net.corda.irs.contract.InterestRateSwap
import net.corda.irs.utilities.postJson
import net.corda.irs.utilities.putJson
import net.corda.irs.utilities.uploadFile
import net.corda.node.driver.driver
import net.corda.node.services.User
import net.corda.node.services.config.FullNodeConfiguration
import net.corda.node.services.messaging.CordaRPCClient
import net.corda.node.services.transactions.SimpleNotaryService
import net.corda.testing.IntegrationTestCategory
import org.apache.commons.io.IOUtils
import org.junit.Test
import rx.observables.BlockingObservable
import java.net.URL
import java.time.LocalDate
class IRSDemoTest : IntegrationTestCategory {
val rpcUser = User("user", "password", emptySet())
val currentDate = LocalDate.now()
val futureDate = currentDate.plusMonths(6)
@Test
fun `runs IRS demo`() {
driver(dsl = {
driver(useTestClock = true, isDebug = true) {
val (controller, nodeA, nodeB) = Futures.allAsList(
startNode("Notary", setOf(ServiceInfo(SimpleNotaryService.type), ServiceInfo(NodeInterestRates.type))),
startNode("Bank A"),
startNode("Bank A", rpcUsers = listOf(rpcUser)),
startNode("Bank B")
).getOrThrow()
val nextFixingDates = getFixingDateObservable(nodeA.configuration)
runUploadRates(controller.configuration.webAddress)
runTrade(nodeA.configuration.webAddress)
// Wait until the initial trade and all scheduled fixings up to the current date have finished
nextFixingDates.first { it == null || it > currentDate }
runDateChange(nodeB.configuration.webAddress)
}, useTestClock = true, isDebug = true)
nextFixingDates.first { it == null || it > futureDate }
}
}
}
private fun runDateChange(nodeAddr: HostAndPort) {
val url = URL("http://$nodeAddr/api/irs/demodate")
assert(putJson(url, "\"2017-06-05\""))
}
fun getFixingDateObservable(config: FullNodeConfiguration): BlockingObservable<LocalDate?> {
val client = CordaRPCClient(config.artemisAddress, config)
client.start("user", "password")
val proxy = client.proxy()
val vaultUpdates = proxy.vaultAndUpdates().second
private fun runTrade(nodeAddr: HostAndPort) {
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example-irs-trade.json"))
val tradeFile = fileContents.replace("tradeXXX", "trade1")
val url = URL("http://$nodeAddr/api/irs/deals")
assert(postJson(url, tradeFile))
}
val fixingDates = vaultUpdates.map { update ->
val irsStates = update.produced.map { it.state.data }.filterIsInstance<InterestRateSwap.State>()
irsStates.mapNotNull { it.calculation.nextFixingDate() }.max()
}.cache().toBlocking()
private fun runUploadRates(host: HostAndPort) {
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example.rates.txt"))
val url = URL("http://$host/upload/interest-rates")
assert(uploadFile(url, fileContents))
}
return fixingDates
}
private fun runDateChange(nodeAddr: HostAndPort) {
val url = URL("http://$nodeAddr/api/irs/demodate")
assert(putJson(url, "\"$futureDate\""))
}
private fun runTrade(nodeAddr: HostAndPort) {
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example-irs-trade.json"))
val tradeFile = fileContents.replace("tradeXXX", "trade1")
val url = URL("http://$nodeAddr/api/irs/deals")
assert(postJson(url, tradeFile))
}
private fun runUploadRates(host: HostAndPort) {
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example.rates.txt"))
val url = URL("http://$host/upload/interest-rates")
assert(uploadFile(url, fileContents))
}
}

View File

@ -51,7 +51,7 @@ object UpdateBusinessDayFlow {
@Suspendable
override fun call(): Unit {
progressTracker.currentStep = NOTIFYING
for (recipient in serviceHub.networkMapCache.partyNodes) {
for (recipient in serviceHub.networkMapCache.partyNodes.sortedBy { it.legalIdentity.name }) {
doNextRecipient(recipient)
}
}