mirror of
https://github.com/corda/corda.git
synced 2024-12-21 22:07:55 +00:00
Fixed AttachmentDemoTest
This commit is contained in:
parent
8bab2ae9a1
commit
faadfd6954
@ -2,9 +2,9 @@ package net.corda.attachmentdemo
|
|||||||
|
|
||||||
import net.corda.core.utilities.getOrThrow
|
import net.corda.core.utilities.getOrThrow
|
||||||
import net.corda.node.services.FlowPermissions.Companion.startFlowPermission
|
import net.corda.node.services.FlowPermissions.Companion.startFlowPermission
|
||||||
import net.corda.nodeapi.internal.ServiceInfo
|
|
||||||
import net.corda.node.services.transactions.SimpleNotaryService
|
import net.corda.node.services.transactions.SimpleNotaryService
|
||||||
import net.corda.nodeapi.User
|
import net.corda.nodeapi.User
|
||||||
|
import net.corda.nodeapi.internal.ServiceInfo
|
||||||
import net.corda.testing.DUMMY_BANK_A
|
import net.corda.testing.DUMMY_BANK_A
|
||||||
import net.corda.testing.DUMMY_BANK_B
|
import net.corda.testing.DUMMY_BANK_B
|
||||||
import net.corda.testing.DUMMY_NOTARY
|
import net.corda.testing.DUMMY_NOTARY
|
||||||
@ -18,26 +18,27 @@ class AttachmentDemoTest {
|
|||||||
val numOfExpectedBytes = 10_000_000
|
val numOfExpectedBytes = 10_000_000
|
||||||
driver(dsl = {
|
driver(dsl = {
|
||||||
val demoUser = listOf(User("demo", "demo", setOf(startFlowPermission<AttachmentDemoFlow>())))
|
val demoUser = listOf(User("demo", "demo", setOf(startFlowPermission<AttachmentDemoFlow>())))
|
||||||
val notaryFuture = startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type)))
|
val (nodeA, nodeB) = listOf(
|
||||||
val nodeAFuture = startNode(providedName = DUMMY_BANK_A.name, rpcUsers = demoUser)
|
startNode(providedName = DUMMY_BANK_A.name, rpcUsers = demoUser),
|
||||||
val nodeBFuture = startNode(providedName = DUMMY_BANK_B.name, rpcUsers = demoUser)
|
startNode(providedName = DUMMY_BANK_B.name, rpcUsers = demoUser),
|
||||||
val (nodeA, nodeB) = listOf(nodeAFuture, nodeBFuture, notaryFuture).map { it.getOrThrow() }
|
startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type))))
|
||||||
|
.map { it.getOrThrow() }
|
||||||
|
startWebserver(nodeB).getOrThrow()
|
||||||
|
|
||||||
val senderThread = supplyAsync {
|
val senderThread = supplyAsync {
|
||||||
nodeA.rpcClientToNode().start(demoUser[0].username, demoUser[0].password).use {
|
nodeA.rpcClientToNode().start(demoUser[0].username, demoUser[0].password).use {
|
||||||
sender(it.proxy, numOfExpectedBytes)
|
sender(it.proxy, numOfExpectedBytes)
|
||||||
}
|
}
|
||||||
}.exceptionally { it.printStackTrace() }
|
}
|
||||||
|
|
||||||
val recipientThread = supplyAsync {
|
val recipientThread = supplyAsync {
|
||||||
nodeB.rpcClientToNode().start(demoUser[0].username, demoUser[0].password).use {
|
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.getOrThrow()
|
||||||
senderThread.get()
|
recipientThread.getOrThrow()
|
||||||
recipientThread.get()
|
|
||||||
}, isDebug = true)
|
}, isDebug = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ fun main(args: Array<String>) {
|
|||||||
val host = NetworkHostAndPort("localhost", 10009)
|
val host = NetworkHostAndPort("localhost", 10009)
|
||||||
println("Connecting to the recipient node ($host)")
|
println("Connecting to the recipient node ($host)")
|
||||||
CordaRPCClient(host).start("demo", "demo").use {
|
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 ...")
|
println("Waiting to receive transaction ...")
|
||||||
val stx = rpc.internalVerifiedTransactionsFeed().updates.toBlocking().first()
|
val stx = rpc.internalVerifiedTransactionsFeed().updates.toBlocking().first()
|
||||||
val wtx = stx.tx
|
val wtx = stx.tx
|
||||||
@ -141,11 +141,10 @@ fun recipient(rpc: CordaRPCOps) {
|
|||||||
require(rpc.attachmentExists(state.hash))
|
require(rpc.attachmentExists(state.hash))
|
||||||
|
|
||||||
// Download the attachment via the Web endpoint.
|
// 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 {
|
try {
|
||||||
require(connection.responseCode == SC_OK) { "HTTP status code was ${connection.responseCode}" }
|
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.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\"") {
|
require(connection.getHeaderField(CONTENT_DISPOSITION) == "attachment; filename=\"${state.hash}.zip\"") {
|
||||||
"Content-Disposition header was ${connection.getHeaderField(CONTENT_DISPOSITION)}"
|
"Content-Disposition header was ${connection.getHeaderField(CONTENT_DISPOSITION)}"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user