Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import net.corda.client.rpc.CordaRPCClient
import net.corda.client.rpc.CordaRPCConnection
import net.corda.core.utilities.loggerFor
import java.io.File
import java.net.URI
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
Expand All @@ -22,7 +21,7 @@ class NodeProcess(
private companion object {
val log = loggerFor<NodeProcess>()
val javaPath: Path = Paths.get(System.getProperty("java.home"), "bin", "java")
val corda: URI = this::class.java.getResource("/corda.jar").toURI()
val corda = File(this::class.java.getResource("/corda.jar").toURI())
val buildDir: Path = Paths.get(System.getProperty("build.dir"))
val capsuleDir: Path = buildDir.resolve("capsule")
}
Expand All @@ -33,17 +32,20 @@ class NodeProcess(
}

override fun close() {
log.info("Stopping node '${config.commonName}'")
node.destroy()
val isDead = node.waitFor(60, SECONDS)
assertTrue(isDead, "Node '${config.commonName}' has not shutdown correctly")
if (!node.waitFor(60, SECONDS)) {
log.warn("Node '${config.commonName}' has not shutdown correctly")
node.destroyForcibly()
}

log.info("Deleting Artemis directories, because they're large!")
nodeDir.resolve("artemis").toFile().deleteRecursively()
}

class Factory(val nodesDir: Path) {
init {
assertTrue(nodesDir.toFile().forceDirectory(), "Nodes directory does not exist")
assertTrue(nodesDir.toFile().forceDirectory(), "Directory '$nodesDir' does not exist")
}

fun create(config: NodeConfig): NodeProcess {
Expand All @@ -61,6 +63,10 @@ class NodeProcess(
try {
setupExecutor.scheduleWithFixedDelay({
try {
if (!process.isAlive) {
log.error("Node '${config.commonName}' has died.")
return@scheduleWithFixedDelay
}
val conn = client.start(user.username, user.password)
conn.close()

Expand All @@ -72,9 +78,9 @@ class NodeProcess(
}, 5, 1, SECONDS)

val setupOK = setupExecutor.awaitTermination(120, SECONDS)
assertTrue(setupOK, "Failed to create RPC connection")
assertTrue(setupOK && process.isAlive, "Failed to create RPC connection")
} catch (e: Exception) {
process.destroy()
process.destroyForcibly()
throw e
} finally {
setupExecutor.shutdownNow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.nio.file.Path
import java.nio.file.Paths
import java.time.Duration.ofSeconds
import java.util.Currency
import java.util.concurrent.atomic.AtomicInteger
import kotlin.test.*
import net.corda.client.rpc.CordaRPCConnection
import net.corda.client.rpc.notUsed
Expand Down Expand Up @@ -33,6 +34,7 @@ class StandaloneCordaRPClientTest {
val nodesDir: Path = buildDir.resolve("nodes")
val user = User("user1", "test", permissions = setOf("ALL"))
val factory = NodeProcess.Factory(nodesDir)
val port = AtomicInteger(15000)
const val attachmentSize = 2116
const val timeout = 60L
}
Expand All @@ -44,9 +46,9 @@ class StandaloneCordaRPClientTest {

private val notaryConfig = NodeConfig(
party = DUMMY_NOTARY,
p2pPort = 10002,
rpcPort = 10003,
webPort = 10004,
p2pPort = port.andIncrement,
rpcPort = port.andIncrement,
webPort = port.andIncrement,
extraServices = listOf("corda.notary.validating"),
users = listOf(user)
)
Expand All @@ -61,14 +63,16 @@ class StandaloneCordaRPClientTest {

@After
fun done() {
connection.close()
notary.close()
try {
connection.close()
} finally {
notary.close()
}
}

@Test
fun `test attachment upload`() {
val attachment = sizedInputStreamAndHash(attachmentSize)

assertFalse(rpcProxy.attachmentExists(attachment.sha256))
val id = WrapperStream(attachment.inputStream).use { rpcProxy.uploadAttachment(it) }
assertEquals(id, attachment.sha256, "Attachment has incorrect SHA256 hash")
Expand Down Expand Up @@ -138,7 +142,7 @@ class StandaloneCordaRPClientTest {
val cashBalance = rpcProxy.getCashBalances()
log.info("Cash Balances: $cashBalance")
assertEquals(1, cashBalance.size)
assertEquals(629.POUNDS, cashBalance.get(Currency.getInstance("GBP")))
assertEquals(629.POUNDS, cashBalance[Currency.getInstance("GBP")])
}


Expand Down