mirror of
https://github.com/corda/corda.git
synced 2024-12-24 15:16:45 +00:00
Merge pull request #1642 from corda/shams-fix-attachment-demo-test
Fixed AttachmentDemoTest
This commit is contained in:
commit
4030903fee
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)}"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user