mirror of
https://github.com/corda/corda.git
synced 2025-05-30 22:24:22 +00:00
node: Add driver dsl test, expose some needed functions
This commit is contained in:
parent
5f5a5e683d
commit
3bc62fdb95
@ -68,6 +68,7 @@ private fun getTimestampAsDirectoryName(): String {
|
|||||||
|
|
||||||
class DriverHandle(private val driverDsl: DriverDSL, private val shutdownHook: Thread) {
|
class DriverHandle(private val driverDsl: DriverDSL, private val shutdownHook: Thread) {
|
||||||
val messagingService = driverDsl.messagingService
|
val messagingService = driverDsl.messagingService
|
||||||
|
val networkMapCache = driverDsl.networkMapCache
|
||||||
|
|
||||||
fun waitForAllNodesToFinish() {
|
fun waitForAllNodesToFinish() {
|
||||||
driverDsl.waitForAllNodesToFinish()
|
driverDsl.waitForAllNodesToFinish()
|
||||||
@ -79,7 +80,7 @@ class DriverHandle(private val driverDsl: DriverDSL, private val shutdownHook: T
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <A> poll(f: () -> A?): A {
|
fun <A> poll(f: () -> A?): A {
|
||||||
var counter = 0
|
var counter = 0
|
||||||
var result = f()
|
var result = f()
|
||||||
while (result == null && counter < 30) {
|
while (result == null && counter < 30) {
|
||||||
|
48
node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt
Normal file
48
node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package com.r3corda.node.driver
|
||||||
|
|
||||||
|
import com.r3corda.node.services.messaging.ArtemisMessagingService
|
||||||
|
import com.r3corda.node.services.transactions.NotaryService
|
||||||
|
import org.junit.Test
|
||||||
|
import java.net.Socket
|
||||||
|
import java.net.SocketException
|
||||||
|
|
||||||
|
|
||||||
|
class DriverTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun simpleNodeStartupShutdownWorks() {
|
||||||
|
|
||||||
|
// Start a notary
|
||||||
|
val (handle, notaryNodeInfo) = driver(quasarPath = "../lib/quasar.jar") {
|
||||||
|
startNode(setOf(NotaryService.Type), "TestNotary")
|
||||||
|
}
|
||||||
|
// Check that the node is registered in the network map
|
||||||
|
poll {
|
||||||
|
handle.networkMapCache.get(NotaryService.Type).firstOrNull {
|
||||||
|
it.identity.name == "TestNotary"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check that the port is bound
|
||||||
|
val address = notaryNodeInfo.address as ArtemisMessagingService.Address
|
||||||
|
poll {
|
||||||
|
try {
|
||||||
|
Socket(address.hostAndPort.hostText, address.hostAndPort.port).close()
|
||||||
|
Unit
|
||||||
|
} catch (_exception: SocketException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shutdown
|
||||||
|
handle.shutdown()
|
||||||
|
// Check that the port is not bound
|
||||||
|
poll {
|
||||||
|
try {
|
||||||
|
Socket(address.hostAndPort.hostText, address.hostAndPort.port).close()
|
||||||
|
null
|
||||||
|
} catch (_exception: SocketException) {
|
||||||
|
Unit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user