makeNotaryService now enforces post condition with type system.

This commit is contained in:
Clinton Alexander 2016-08-15 16:33:21 +01:00
parent a74c491745
commit 85dce390f4
2 changed files with 5 additions and 6 deletions

View File

@ -257,7 +257,7 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
val notaryServiceType = serviceTypes.singleOrNull { it.isSubTypeOf(NotaryService.Type) }
if (notaryServiceType != null) {
makeNotaryService(notaryServiceType)
inNodeNotaryService = makeNotaryService(notaryServiceType)
}
}
@ -313,19 +313,17 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
inNodeNetworkMapService = InMemoryNetworkMapService(net, reg, services.networkMapCache)
}
open protected fun makeNotaryService(type: ServiceType) {
open protected fun makeNotaryService(type: ServiceType): NotaryService {
val uniquenessProvider = InMemoryUniquenessProvider()
val timestampChecker = TimestampChecker(platformClock, 30.seconds)
inNodeNotaryService = when (type) {
return when (type) {
SimpleNotaryService.Type -> SimpleNotaryService(smm, net, timestampChecker, uniquenessProvider, services.networkMapCache)
ValidatingNotaryService.Type -> ValidatingNotaryService(smm, net, timestampChecker, uniquenessProvider, services.networkMapCache)
else -> {
throw IllegalArgumentException("Notary type ${type.id} is not handled by makeNotaryService.")
}
}
require(inNodeNotaryService != null)
}
protected open fun makeIdentityService(): IdentityService {

View File

@ -5,6 +5,7 @@ import com.r3corda.core.node.services.NetworkMapCache
import com.r3corda.node.services.api.RegulatorService
import com.r3corda.node.services.messaging.ArtemisMessagingComponent
import com.r3corda.node.services.transactions.NotaryService
import com.r3corda.node.services.transactions.SimpleNotaryService
import org.junit.Test
@ -32,7 +33,7 @@ class DriverTests {
@Test
fun simpleNodeStartupShutdownWorks() {
val (notary, regulator) = driver {
val notary = startNode("TestNotary", setOf(NotaryService.Type))
val notary = startNode("TestNotary", setOf(SimpleNotaryService.Type))
val regulator = startNode("Regulator", setOf(RegulatorService.Type))
nodeMustBeUp(networkMapCache, notary, "TestNotary")