mirror of
https://github.com/corda/corda.git
synced 2024-12-28 00:38:55 +00:00
First working version of RPC & JMeter
This commit is contained in:
parent
a84e9fdb2b
commit
39ab188e1b
@ -0,0 +1,83 @@
|
|||||||
|
package net.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
|
||||||
|
|
||||||
|
|
||||||
|
class CordaRPCSampler() : 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 className = Argument("pluginClassName", "", "<meta>", "The class name of the implementation of ${CordaRPCSampler.Plugin::class.java}.")
|
||||||
|
|
||||||
|
val allArgs = setOf(host, port, username, password, className)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rpcClient: CordaRPCClient? = null
|
||||||
|
var rpcConnection: CordaRPCConnection? = null
|
||||||
|
var rpcProxy: CordaRPCOps? = null
|
||||||
|
var plugin: Plugin? = 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) } }
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
plugin = Class.forName(context.getParameter(className.name)).newInstance() as Plugin
|
||||||
|
plugin!!.setupTest(rpcProxy!!, context)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun runTest(context: JavaSamplerContext): SampleResult {
|
||||||
|
val flowInvoke = plugin!!.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) {
|
||||||
|
plugin!!.teardownTest(rpcProxy!!, context)
|
||||||
|
plugin = null
|
||||||
|
rpcProxy = null
|
||||||
|
rpcConnection!!.close()
|
||||||
|
rpcConnection = null
|
||||||
|
rpcClient = null
|
||||||
|
super.teardownTest(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Plugin {
|
||||||
|
fun setupTest(rpcProxy: CordaRPCOps, testContext: JavaSamplerContext)
|
||||||
|
fun createFlowInvoke(rpcProxy: CordaRPCOps, testContext: JavaSamplerContext): FlowInvoke<*>
|
||||||
|
fun teardownTest(rpcProxy: CordaRPCOps, testContext: JavaSamplerContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
class FlowInvoke<T : FlowLogic<*>>(val flowLogicClass: Class<out T>, val args: Array<Any?>)
|
||||||
|
}
|
13
tools/jmeter/src/main/kotlin/net/corda/jmeter/Launcher.kt
Normal file
13
tools/jmeter/src/main/kotlin/net/corda/jmeter/Launcher.kt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package net.corda.jmeter
|
||||||
|
|
||||||
|
import org.apache.jmeter.JMeter
|
||||||
|
|
||||||
|
class Launcher {
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
val jmeter = JMeter()
|
||||||
|
jmeter.start(args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package net.corda.jmeter
|
||||||
|
|
||||||
|
import net.corda.core.identity.Party
|
||||||
|
import net.corda.core.messaging.CordaRPCOps
|
||||||
|
import net.corda.core.messaging.startFlow
|
||||||
|
import net.corda.core.utilities.OpaqueBytes
|
||||||
|
import net.corda.core.utilities.getOrThrow
|
||||||
|
import net.corda.finance.DOLLARS
|
||||||
|
import net.corda.finance.flows.CashIssueFlow
|
||||||
|
import net.corda.jmeter.CordaRPCSampler.FlowInvoke
|
||||||
|
import net.corda.testing.DUMMY_BANK_A
|
||||||
|
import net.corda.testing.DUMMY_BANK_B
|
||||||
|
import net.corda.testing.contracts.calculateRandomlySizedAmounts
|
||||||
|
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
|
abstract class AsbtractTraderDemoPlugin : CordaRPCSampler.Plugin {
|
||||||
|
|
||||||
|
lateinit var buyer: Party
|
||||||
|
lateinit var seller: Party
|
||||||
|
lateinit var notary: Party
|
||||||
|
|
||||||
|
protected fun getIdentities(rpc: CordaRPCOps) {
|
||||||
|
buyer = rpc.wellKnownPartyFromX500Name(DUMMY_BANK_A.name) ?: throw IllegalStateException("Don't know ${DUMMY_BANK_A.name}")
|
||||||
|
seller = rpc.wellKnownPartyFromX500Name(DUMMY_BANK_B.name) ?: throw IllegalStateException("Don't know ${DUMMY_BANK_B.name}")
|
||||||
|
notary = rpc.notaryIdentities().first()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class CashIssuerPlugin : AsbtractTraderDemoPlugin() {
|
||||||
|
override fun setupTest(rpcProxy: CordaRPCOps, testContext: JavaSamplerContext) {
|
||||||
|
getIdentities(rpcProxy)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun teardownTest(rpcProxy: CordaRPCOps, testContext: JavaSamplerContext) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createFlowInvoke(rpcProxy: CordaRPCOps, testContext: JavaSamplerContext): FlowInvoke<CashIssueFlow> {
|
||||||
|
val amount = 1_100_000_000_000.DOLLARS
|
||||||
|
//val amounts = calculateRandomlySizedAmounts(amount, 3, 10, Random())
|
||||||
|
//rpc.startFlow(net.corda.finance.flows::CashIssueFlow, amount, OpaqueBytes.of(1), notary).returnValue.getOrThrow()
|
||||||
|
return FlowInvoke<CashIssueFlow>(CashIssueFlow::class.java, arrayOf(amount, OpaqueBytes.of(1), notary))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
177
tools/jmeter/src/main/resources/Java Request.jmx
Normal file
177
tools/jmeter/src/main/resources/Java Request.jmx
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<jmeterTestPlan version="1.2" properties="3.2" jmeter="3.3 r1808647">
|
||||||
|
<hashTree>
|
||||||
|
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
|
||||||
|
<stringProp name="TestPlan.comments"></stringProp>
|
||||||
|
<boolProp name="TestPlan.functional_mode">false</boolProp>
|
||||||
|
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
|
||||||
|
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
|
||||||
|
<collectionProp name="Arguments.arguments"/>
|
||||||
|
</elementProp>
|
||||||
|
<stringProp name="TestPlan.user_define_classpath"></stringProp>
|
||||||
|
</TestPlan>
|
||||||
|
<hashTree>
|
||||||
|
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
|
||||||
|
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
|
||||||
|
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
|
||||||
|
<boolProp name="LoopController.continue_forever">false</boolProp>
|
||||||
|
<stringProp name="LoopController.loops">1000</stringProp>
|
||||||
|
</elementProp>
|
||||||
|
<stringProp name="ThreadGroup.num_threads">2</stringProp>
|
||||||
|
<stringProp name="ThreadGroup.ramp_time"></stringProp>
|
||||||
|
<longProp name="ThreadGroup.start_time">1509455820000</longProp>
|
||||||
|
<longProp name="ThreadGroup.end_time">1509455820000</longProp>
|
||||||
|
<boolProp name="ThreadGroup.scheduler">false</boolProp>
|
||||||
|
<stringProp name="ThreadGroup.duration"></stringProp>
|
||||||
|
<stringProp name="ThreadGroup.delay"></stringProp>
|
||||||
|
</ThreadGroup>
|
||||||
|
<hashTree>
|
||||||
|
<JavaSampler guiclass="JavaTestSamplerGui" testclass="JavaSampler" testname="Java Request" enabled="true">
|
||||||
|
<elementProp name="arguments" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" enabled="true">
|
||||||
|
<collectionProp name="Arguments.arguments">
|
||||||
|
<elementProp name="host" elementType="Argument">
|
||||||
|
<stringProp name="Argument.name">host</stringProp>
|
||||||
|
<stringProp name="Argument.value">localhost</stringProp>
|
||||||
|
<stringProp name="Argument.metadata">=</stringProp>
|
||||||
|
</elementProp>
|
||||||
|
<elementProp name="port" elementType="Argument">
|
||||||
|
<stringProp name="Argument.name">port</stringProp>
|
||||||
|
<stringProp name="Argument.value">10012</stringProp>
|
||||||
|
<stringProp name="Argument.metadata">=</stringProp>
|
||||||
|
</elementProp>
|
||||||
|
<elementProp name="username" elementType="Argument">
|
||||||
|
<stringProp name="Argument.name">username</stringProp>
|
||||||
|
<stringProp name="Argument.value">demo</stringProp>
|
||||||
|
<stringProp name="Argument.metadata">=</stringProp>
|
||||||
|
</elementProp>
|
||||||
|
<elementProp name="password" elementType="Argument">
|
||||||
|
<stringProp name="Argument.name">password</stringProp>
|
||||||
|
<stringProp name="Argument.value">demo</stringProp>
|
||||||
|
<stringProp name="Argument.metadata">=</stringProp>
|
||||||
|
</elementProp>
|
||||||
|
<elementProp name="pluginClassName" elementType="Argument">
|
||||||
|
<stringProp name="Argument.name">pluginClassName</stringProp>
|
||||||
|
<stringProp name="Argument.value">net.corda.jmeter.CashIssuerPlugin</stringProp>
|
||||||
|
<stringProp name="Argument.metadata">=</stringProp>
|
||||||
|
</elementProp>
|
||||||
|
</collectionProp>
|
||||||
|
</elementProp>
|
||||||
|
<stringProp name="classname">net.corda.jmeter.CordaRPCSampler</stringProp>
|
||||||
|
</JavaSampler>
|
||||||
|
<hashTree/>
|
||||||
|
</hashTree>
|
||||||
|
<ResultCollector guiclass="TableVisualizer" testclass="ResultCollector" testname="View Results in Table" enabled="true">
|
||||||
|
<boolProp name="ResultCollector.error_logging">false</boolProp>
|
||||||
|
<objProp>
|
||||||
|
<name>saveConfig</name>
|
||||||
|
<value class="SampleSaveConfiguration">
|
||||||
|
<time>true</time>
|
||||||
|
<latency>true</latency>
|
||||||
|
<timestamp>true</timestamp>
|
||||||
|
<success>true</success>
|
||||||
|
<label>true</label>
|
||||||
|
<code>true</code>
|
||||||
|
<message>true</message>
|
||||||
|
<threadName>true</threadName>
|
||||||
|
<dataType>true</dataType>
|
||||||
|
<encoding>false</encoding>
|
||||||
|
<assertions>true</assertions>
|
||||||
|
<subresults>true</subresults>
|
||||||
|
<responseData>false</responseData>
|
||||||
|
<samplerData>false</samplerData>
|
||||||
|
<xml>false</xml>
|
||||||
|
<fieldNames>true</fieldNames>
|
||||||
|
<responseHeaders>false</responseHeaders>
|
||||||
|
<requestHeaders>false</requestHeaders>
|
||||||
|
<responseDataOnError>false</responseDataOnError>
|
||||||
|
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
|
||||||
|
<assertionsResultsToSave>0</assertionsResultsToSave>
|
||||||
|
<bytes>true</bytes>
|
||||||
|
<sentBytes>true</sentBytes>
|
||||||
|
<threadCounts>true</threadCounts>
|
||||||
|
<idleTime>true</idleTime>
|
||||||
|
<connectTime>true</connectTime>
|
||||||
|
</value>
|
||||||
|
</objProp>
|
||||||
|
<stringProp name="filename"></stringProp>
|
||||||
|
</ResultCollector>
|
||||||
|
<hashTree/>
|
||||||
|
<ResultCollector guiclass="StatGraphVisualizer" testclass="ResultCollector" testname="Aggregate Graph" enabled="true">
|
||||||
|
<boolProp name="ResultCollector.error_logging">false</boolProp>
|
||||||
|
<objProp>
|
||||||
|
<name>saveConfig</name>
|
||||||
|
<value class="SampleSaveConfiguration">
|
||||||
|
<time>true</time>
|
||||||
|
<latency>true</latency>
|
||||||
|
<timestamp>true</timestamp>
|
||||||
|
<success>true</success>
|
||||||
|
<label>true</label>
|
||||||
|
<code>true</code>
|
||||||
|
<message>true</message>
|
||||||
|
<threadName>true</threadName>
|
||||||
|
<dataType>true</dataType>
|
||||||
|
<encoding>false</encoding>
|
||||||
|
<assertions>true</assertions>
|
||||||
|
<subresults>true</subresults>
|
||||||
|
<responseData>false</responseData>
|
||||||
|
<samplerData>false</samplerData>
|
||||||
|
<xml>false</xml>
|
||||||
|
<fieldNames>true</fieldNames>
|
||||||
|
<responseHeaders>false</responseHeaders>
|
||||||
|
<requestHeaders>false</requestHeaders>
|
||||||
|
<responseDataOnError>false</responseDataOnError>
|
||||||
|
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
|
||||||
|
<assertionsResultsToSave>0</assertionsResultsToSave>
|
||||||
|
<bytes>true</bytes>
|
||||||
|
<sentBytes>true</sentBytes>
|
||||||
|
<threadCounts>true</threadCounts>
|
||||||
|
<idleTime>true</idleTime>
|
||||||
|
<connectTime>true</connectTime>
|
||||||
|
</value>
|
||||||
|
</objProp>
|
||||||
|
<stringProp name="filename"></stringProp>
|
||||||
|
</ResultCollector>
|
||||||
|
<hashTree/>
|
||||||
|
<ResultCollector guiclass="GraphVisualizer" testclass="ResultCollector" testname="Graph Results" enabled="true">
|
||||||
|
<boolProp name="ResultCollector.error_logging">false</boolProp>
|
||||||
|
<objProp>
|
||||||
|
<name>saveConfig</name>
|
||||||
|
<value class="SampleSaveConfiguration">
|
||||||
|
<time>true</time>
|
||||||
|
<latency>true</latency>
|
||||||
|
<timestamp>true</timestamp>
|
||||||
|
<success>true</success>
|
||||||
|
<label>true</label>
|
||||||
|
<code>true</code>
|
||||||
|
<message>true</message>
|
||||||
|
<threadName>true</threadName>
|
||||||
|
<dataType>true</dataType>
|
||||||
|
<encoding>false</encoding>
|
||||||
|
<assertions>true</assertions>
|
||||||
|
<subresults>true</subresults>
|
||||||
|
<responseData>false</responseData>
|
||||||
|
<samplerData>false</samplerData>
|
||||||
|
<xml>false</xml>
|
||||||
|
<fieldNames>true</fieldNames>
|
||||||
|
<responseHeaders>false</responseHeaders>
|
||||||
|
<requestHeaders>false</requestHeaders>
|
||||||
|
<responseDataOnError>false</responseDataOnError>
|
||||||
|
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
|
||||||
|
<assertionsResultsToSave>0</assertionsResultsToSave>
|
||||||
|
<bytes>true</bytes>
|
||||||
|
<sentBytes>true</sentBytes>
|
||||||
|
<threadCounts>true</threadCounts>
|
||||||
|
<idleTime>true</idleTime>
|
||||||
|
<connectTime>true</connectTime>
|
||||||
|
</value>
|
||||||
|
</objProp>
|
||||||
|
<stringProp name="filename"></stringProp>
|
||||||
|
</ResultCollector>
|
||||||
|
<hashTree/>
|
||||||
|
</hashTree>
|
||||||
|
<WorkBench guiclass="WorkBenchGui" testclass="WorkBench" testname="WorkBench" enabled="true">
|
||||||
|
<boolProp name="WorkBench.save">true</boolProp>
|
||||||
|
</WorkBench>
|
||||||
|
<hashTree/>
|
||||||
|
</hashTree>
|
||||||
|
</jmeterTestPlan>
|
Loading…
Reference in New Issue
Block a user