Merged in clint-no-notary-error (pull request #283)

Fixed bug when incorrect notary service type is specified.
This commit is contained in:
Clinton Alexander
2016-08-22 16:41:38 +01:00
4 changed files with 14 additions and 8 deletions

View File

@ -27,7 +27,6 @@ class NodeRunner {
companion object { companion object {
@JvmStatic fun main(arguments: Array<String>) { @JvmStatic fun main(arguments: Array<String>) {
val cliParams = CliParams.parse(CliParams.parser.parse(*arguments)) val cliParams = CliParams.parse(CliParams.parser.parse(*arguments))
val nodeDirectory = Paths.get(cliParams.baseDirectory) val nodeDirectory = Paths.get(cliParams.baseDirectory)
createNodeRunDirectory(nodeDirectory) createNodeRunDirectory(nodeDirectory)

View File

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

View File

@ -24,6 +24,8 @@ abstract class NotaryService(val smm: StateMachineManager,
val timestampChecker: TimestampChecker, val timestampChecker: TimestampChecker,
val uniquenessProvider: UniquenessProvider, val uniquenessProvider: UniquenessProvider,
networkMapCache: NetworkMapCache) : AbstractNodeService(net, networkMapCache) { networkMapCache: NetworkMapCache) : AbstractNodeService(net, networkMapCache) {
// Do not specify this as an advertised service. Use a concrete implementation.
// TODO: We do not want a service type that cannot be used. Fix the type system abuse here.
object Type : ServiceType("corda.notary") object Type : ServiceType("corda.notary")
abstract val logger: org.slf4j.Logger abstract val logger: org.slf4j.Logger

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.api.RegulatorService
import com.r3corda.node.services.messaging.ArtemisMessagingComponent import com.r3corda.node.services.messaging.ArtemisMessagingComponent
import com.r3corda.node.services.transactions.NotaryService import com.r3corda.node.services.transactions.NotaryService
import com.r3corda.node.services.transactions.SimpleNotaryService
import org.junit.Test import org.junit.Test
@ -32,7 +33,7 @@ class DriverTests {
@Test @Test
fun simpleNodeStartupShutdownWorks() { fun simpleNodeStartupShutdownWorks() {
val (notary, regulator) = driver { 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)) val regulator = startNode("Regulator", setOf(RegulatorService.Type))
nodeMustBeUp(networkMapCache, notary.get(), "TestNotary") nodeMustBeUp(networkMapCache, notary.get(), "TestNotary")