Remove mock identity service

Remove mock identity service and merge it with the in memory identity service. The two services
provide extremely similar functionality, and having two different version for production/test
risks subtle implementation differences. On that note, this patch includes changes to a number
of tests which worked only with mock identity service.
This commit is contained in:
Ross Nicoll
2017-05-19 11:22:47 +01:00
committed by GitHub
parent d288fcc979
commit 794ce03958
8 changed files with 39 additions and 56 deletions

View File

@ -20,9 +20,13 @@ import javax.annotation.concurrent.ThreadSafe
/**
* Simple identity service which caches parties and provides functionality for efficient lookup.
*
* @param identities initial set of identities for the service, typically only used for unit tests.
* @param certPaths initial set of certificate paths for the service, typically only used for unit tests.
*/
@ThreadSafe
class InMemoryIdentityService : SingletonSerializeAsToken(), IdentityService {
class InMemoryIdentityService(identities: Iterable<Party> = emptySet(),
certPaths: Map<AnonymousParty, CertPath> = emptyMap()) : SingletonSerializeAsToken(), IdentityService {
companion object {
private val log = loggerFor<InMemoryIdentityService>()
}
@ -31,6 +35,12 @@ class InMemoryIdentityService : SingletonSerializeAsToken(), IdentityService {
private val principalToParties = ConcurrentHashMap<X500Name, Party>()
private val partyToPath = ConcurrentHashMap<AnonymousParty, CertPath>()
init {
keyToParties.putAll(identities.associateBy { it.owningKey } )
principalToParties.putAll(identities.associateBy { it.name })
partyToPath.putAll(certPaths)
}
override fun registerIdentity(party: Party) {
log.trace { "Registering identity $party" }
keyToParties[party.owningKey] = party

View File

@ -70,7 +70,6 @@ class TwoPartyTradeFlowTests {
@Before
fun before() {
net = MockNetwork(false)
net.identities += MOCK_IDENTITY_SERVICE.identities
LogHelper.setLevel("platform.trade", "core.contract.TransactionGroup", "recordingmap")
}
@ -501,6 +500,8 @@ class TwoPartyTradeFlowTests {
serviceHub.legalIdentityKey))
}
sellerNode.services.identityService.registerIdentity(buyerNode.info.legalIdentity)
buyerNode.services.identityService.registerIdentity(sellerNode.info.legalIdentity)
val buyerFuture = buyerNode.initiateSingleShotFlow(SellerRunnerFlow::class) { otherParty ->
Buyer(otherParty, notaryNode.info.notaryIdentity, 1000.DOLLARS, CommercialPaper.State::class.java)
}.map { it.stateMachine }