node: Add driver dsl test, expose some needed functions

This commit is contained in:
Andras Slemmer 2016-08-01 14:07:59 +01:00
parent 5f5a5e683d
commit 3bc62fdb95
2 changed files with 50 additions and 1 deletions

View File

@ -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) {

View 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
}
}
}
}