mirror of
https://github.com/corda/corda.git
synced 2025-03-11 15:04:14 +00:00
Merge pull request #1053 from corda/kit-getServiceOf
Extending NetwokMapCache with a convenience method for by type servic…
This commit is contained in:
commit
197e627970
@ -119,6 +119,20 @@ interface NetworkMapCache {
|
|||||||
return nodes.randomOrNull()?.notaryIdentity
|
return nodes.randomOrNull()?.notaryIdentity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a service identity advertised by one of the nodes on the network
|
||||||
|
* @param type Specifies the type of the service
|
||||||
|
*/
|
||||||
|
fun getAnyServiceOfType(type: ServiceType): Party? {
|
||||||
|
for (node in partyNodes) {
|
||||||
|
val serviceIdentities = node.serviceIdentities(type)
|
||||||
|
if (serviceIdentities.isNotEmpty()) {
|
||||||
|
return serviceIdentities.randomOrNull()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/** Checks whether a given party is an advertised notary identity */
|
/** Checks whether a given party is an advertised notary identity */
|
||||||
fun isNotary(party: Party): Boolean = notaryNodes.any { it.notaryIdentity == party }
|
fun isNotary(party: Party): Boolean = notaryNodes.any { it.notaryIdentity == party }
|
||||||
|
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package net.corda.node.services
|
||||||
|
|
||||||
|
import co.paralleluniverse.fibers.Suspendable
|
||||||
|
import net.corda.core.flows.FlowLogic
|
||||||
|
import net.corda.core.flows.StartableByRPC
|
||||||
|
import net.corda.core.messaging.startFlow
|
||||||
|
import net.corda.core.node.services.ServiceInfo
|
||||||
|
import net.corda.core.node.services.ServiceType
|
||||||
|
import net.corda.nodeapi.User
|
||||||
|
import net.corda.testing.driver.driver
|
||||||
|
import org.bouncycastle.asn1.x500.X500Name
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
class AdvertisedServiceTests {
|
||||||
|
private val serviceName = X500Name("CN=Custom Service,O=R3,OU=corda,L=London,C=GB")
|
||||||
|
private val serviceType = ServiceType.corda.getSubType("custom")
|
||||||
|
private val user = "bankA"
|
||||||
|
private val pass = "passA"
|
||||||
|
|
||||||
|
|
||||||
|
@StartableByRPC
|
||||||
|
class ServiceTypeCheckingFlow : FlowLogic<Boolean>() {
|
||||||
|
|
||||||
|
@Suspendable
|
||||||
|
override fun call(): Boolean {
|
||||||
|
return serviceHub.networkMapCache.getAnyServiceOfType(ServiceType.corda.getSubType("custom")) != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `service is accessible through getAnyServiceOfType`() {
|
||||||
|
driver(startNodesInProcess = true) {
|
||||||
|
val bankA = startNode(rpcUsers = listOf(User(user, pass, setOf(startFlowPermission<ServiceTypeCheckingFlow>())))).get()
|
||||||
|
val bankB = startNode(advertisedServices = setOf(ServiceInfo(serviceType, serviceName))).get()
|
||||||
|
bankA.rpcClientToNode().use(user, pass) { connection ->
|
||||||
|
val result = connection.proxy.startFlow(::ServiceTypeCheckingFlow).returnValue.get()
|
||||||
|
assertTrue(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user