Fixed AttachmentDemoTest

This commit is contained in:
Shams Asari 2017-09-25 20:32:00 +01:00
parent 8bab2ae9a1
commit faadfd6954
2 changed files with 15 additions and 15 deletions

View File

@ -2,9 +2,9 @@ package net.corda.attachmentdemo
import net.corda.core.utilities.getOrThrow
import net.corda.node.services.FlowPermissions.Companion.startFlowPermission
import net.corda.nodeapi.internal.ServiceInfo
import net.corda.node.services.transactions.SimpleNotaryService
import net.corda.nodeapi.User
import net.corda.nodeapi.internal.ServiceInfo
import net.corda.testing.DUMMY_BANK_A
import net.corda.testing.DUMMY_BANK_B
import net.corda.testing.DUMMY_NOTARY
@ -18,26 +18,27 @@ class AttachmentDemoTest {
val numOfExpectedBytes = 10_000_000
driver(dsl = {
val demoUser = listOf(User("demo", "demo", setOf(startFlowPermission<AttachmentDemoFlow>())))
val notaryFuture = startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type)))
val nodeAFuture = startNode(providedName = DUMMY_BANK_A.name, rpcUsers = demoUser)
val nodeBFuture = startNode(providedName = DUMMY_BANK_B.name, rpcUsers = demoUser)
val (nodeA, nodeB) = listOf(nodeAFuture, nodeBFuture, notaryFuture).map { it.getOrThrow() }
val (nodeA, nodeB) = listOf(
startNode(providedName = DUMMY_BANK_A.name, rpcUsers = demoUser),
startNode(providedName = DUMMY_BANK_B.name, rpcUsers = demoUser),
startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type))))
.map { it.getOrThrow() }
startWebserver(nodeB).getOrThrow()
val senderThread = supplyAsync {
nodeA.rpcClientToNode().start(demoUser[0].username, demoUser[0].password).use {
sender(it.proxy, numOfExpectedBytes)
}
}.exceptionally { it.printStackTrace() }
}
val recipientThread = supplyAsync {
nodeB.rpcClientToNode().start(demoUser[0].username, demoUser[0].password).use {
recipient(it.proxy)
recipient(it.proxy, nodeB.webAddress.port)
}
}.exceptionally { it.printStackTrace() }
}
// Just check they finish and don't throw any exceptions.
senderThread.get()
recipientThread.get()
senderThread.getOrThrow()
recipientThread.getOrThrow()
}, isDebug = true)
}
}

View File

@ -67,7 +67,7 @@ fun main(args: Array<String>) {
val host = NetworkHostAndPort("localhost", 10009)
println("Connecting to the recipient node ($host)")
CordaRPCClient(host).start("demo", "demo").use {
recipient(it.proxy)
recipient(it.proxy, 10010)
}
}
}
@ -131,7 +131,7 @@ class AttachmentDemoFlow(private val otherSide: Party,
}
}
fun recipient(rpc: CordaRPCOps) {
fun recipient(rpc: CordaRPCOps, webPort: Int) {
println("Waiting to receive transaction ...")
val stx = rpc.internalVerifiedTransactionsFeed().updates.toBlocking().first()
val wtx = stx.tx
@ -141,11 +141,10 @@ fun recipient(rpc: CordaRPCOps) {
require(rpc.attachmentExists(state.hash))
// Download the attachment via the Web endpoint.
val connection = URL("http://localhost:10010/attachments/${state.hash}").openConnection() as HttpURLConnection
val connection = URL("http://localhost:$webPort/attachments/${state.hash}").openConnection() as HttpURLConnection
try {
require(connection.responseCode == SC_OK) { "HTTP status code was ${connection.responseCode}" }
require(connection.contentType == APPLICATION_OCTET_STREAM) { "Content-Type header was ${connection.contentType}" }
require(connection.contentLength > 1024) { "Attachment contains only ${connection.contentLength} bytes" }
require(connection.getHeaderField(CONTENT_DISPOSITION) == "attachment; filename=\"${state.hash}.zip\"") {
"Content-Disposition header was ${connection.getHeaderField(CONTENT_DISPOSITION)}"
}