mirror of
https://github.com/corda/corda.git
synced 2025-04-07 19:34:41 +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) {
|
||||
val messagingService = driverDsl.messagingService
|
||||
val networkMapCache = driverDsl.networkMapCache
|
||||
|
||||
fun 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 result = f()
|
||||
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