Add some comments and clean up.

This commit is contained in:
rick.parker 2017-11-15 13:30:56 +00:00
parent 08577510af
commit 1d5d54e063
2 changed files with 4 additions and 88 deletions

View File

@ -1,85 +0,0 @@
package com.r3.corda.jmeter
import net.corda.client.rpc.CordaRPCClient
import net.corda.client.rpc.CordaRPCConnection
import net.corda.core.flows.FlowLogic
import net.corda.core.messaging.CordaRPCOps
import net.corda.core.utilities.NetworkHostAndPort
import org.apache.jmeter.config.Argument
import org.apache.jmeter.config.Arguments
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext
import org.apache.jmeter.samplers.SampleResult
abstract class FlowSampler() : AbstractJavaSamplerClient() {
companion object {
val host = Argument("host", "localhost", "<meta>", "The remote network address (hostname or IP address) to connect to for RPC.")
val port = Argument("port", "10000", "<meta>", "The remote port to connect to for RPC.")
val username = Argument("username", "corda", "<meta>", "The RPC user to connect to connect as.")
val password = Argument("password", "corda_is_awesome", "<meta>", "The password for the RPC user.")
val allArgs = setOf(host, port, username, password)
}
var rpcClient: CordaRPCClient? = null
var rpcConnection: CordaRPCConnection? = null
var rpcProxy: CordaRPCOps? = null
override fun getDefaultParameters(): Arguments {
// Add copies of all args, since they seem to be mutable.
return Arguments().apply {
for (arg in allArgs) {
addArgument(arg.clone() as Argument)
}
for (arg in additionalArgs) {
addArgument(arg.clone() as Argument)
}
}
}
override fun setupTest(context: JavaSamplerContext) {
super.setupTest(context)
rpcClient = CordaRPCClient(NetworkHostAndPort(context.getParameter(host.name), context.getIntParameter(port.name)))
rpcConnection = rpcClient!!.start(context.getParameter(username.name), context.getParameter(password.name))
rpcProxy = rpcConnection!!.proxy
setupTest(rpcProxy!!, context)
}
override fun runTest(context: JavaSamplerContext): SampleResult {
val flowInvoke = createFlowInvoke(rpcProxy!!, context)
val result = SampleResult()
result.sampleStart()
val handle = rpcProxy!!.startFlowDynamic(flowInvoke!!.flowLogicClass, *(flowInvoke!!.args))
result.sampleLabel = handle.id.toString()
result.latencyEnd()
try {
val flowResult = handle.returnValue.get()
result.sampleEnd()
return result.apply {
isSuccessful = true
}
} catch (e: Exception) {
result.sampleEnd()
return result.apply {
isSuccessful = false
}
}
}
override fun teardownTest(context: JavaSamplerContext) {
teardownTest(rpcProxy!!, context)
rpcProxy = null
rpcConnection!!.close()
rpcConnection = null
rpcClient = null
super.teardownTest(context)
}
abstract val additionalArgs: Set<Argument>
abstract fun setupTest(rpcProxy: CordaRPCOps, testContext: JavaSamplerContext)
abstract fun createFlowInvoke(rpcProxy: CordaRPCOps, testContext: JavaSamplerContext): FlowInvoke<*>
abstract fun teardownTest(rpcProxy: CordaRPCOps, testContext: JavaSamplerContext)
class FlowInvoke<T : FlowLogic<*>>(val flowLogicClass: Class<out T>, val args: Array<Any?>)
}

View File

@ -10,7 +10,9 @@ import java.io.BufferedReader
import java.io.InputStreamReader import java.io.InputStreamReader
import java.util.* import java.util.*
/**
* Creates SSH tunnels for remote controlling SSH servers/agents from the local host (via UI or headless).
*/
class Ssh { class Ssh {
companion object { companion object {
val log = LoggerFactory.getLogger(this::class.java) val log = LoggerFactory.getLogger(this::class.java)
@ -28,7 +30,7 @@ class Ssh {
val jmeterProps = loadProps("/jmeter.properties") val jmeterProps = loadProps("/jmeter.properties")
// The port the JMeter remote agents call back to on this client host. // The port the JMeter remote agents call back to on this client host.
val clientRmiLocalPort = jmeterProps.getProperty("client.rmi.localport").toInt() val clientRmiLocalPort = jmeterProps.getProperty("client.rmi.localport").toInt()
// TODO: Where is this value used? Just on the remote agent to set up the RMI registry? // Remote RMI registry port.
val serverRmiPort = jmeterProps.getProperty("server.rmi.port", "1099").toInt() val serverRmiPort = jmeterProps.getProperty("server.rmi.port", "1099").toInt()
// Where JMeter driver will try to connect for remote agents (should all be localhost so can ssh tunnel). // Where JMeter driver will try to connect for remote agents (should all be localhost so can ssh tunnel).
@ -47,7 +49,6 @@ class Ssh {
val session = connectToHost(jsch, remoteHost, userName) val session = connectToHost(jsch, remoteHost, userName)
sessions += session sessions += session
// TODO: maybe check the local host is actually "localhost"?
// For tunnelling the RMI registry on the remote agent // For tunnelling the RMI registry on the remote agent
// ssh ${remoteHostAndPort.host} -L 0.0.0.0:${localHostAndPort.port}:localhost:$serverRmiPort -N // ssh ${remoteHostAndPort.host} -L 0.0.0.0:${localHostAndPort.port}:localhost:$serverRmiPort -N
createOutboundTunnel(session, NetworkHostAndPort("0.0.0.0", localHostAndPort.port), NetworkHostAndPort("localhost", serverRmiPort)) createOutboundTunnel(session, NetworkHostAndPort("0.0.0.0", localHostAndPort.port), NetworkHostAndPort("localhost", serverRmiPort))