100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Load Testing: Re-connect when MQTT connection lost in connect-and-publish load2 scenario (#2693)
Eric Bariauxbb841d18e430
diff --git a/test/load2-eks/README.md b/test/load2-eks/README.mdindex 0f043163c..079a40edc 100644--- a/test/load2-eks/README.md+++ b/test/load2-eks/README.md@@ -62,6 +62,7 @@ Two scenarios are provided:Runs for a given duration, publishing attribute value changes over MQTT once connected.For each connection, it publishes ASSETS_COUNT values at the same time (50ms interval), then pauses for MILLIS_BETWEEN_PUBLISHES.+If a publish fails because the connection is lost and `RECONNECT_ATTEMPTS` is greater than 0, the thread returns to the connect step and retries only while its original per-thread runtime has not yet elapsed. If `RECONNECT_ATTEMPTS` is 0, the thread does not retry and its load is lost.At the end of publish loop, it waits for DISCONNECT_DELAY before disconnecting from MQTT.The parameters are:@@ -71,6 +72,7 @@ ASSETS_COUNT: Number of Light assets for which to publish an attribute during eaRAMP_RATE: Number of thread to add per second during ramp-up. Default is 20.DURATION: Total duration to run the test for, in seconds. Default is 300.MILLIS_BETWEEN_PUBLISHES: Delay between each publishing iteration. Default is 1000.+RECONNECT_ATTEMPTS: Reconnect control. Default is 0. With the current HiveMQ-based xmeter client, 0 disables automatic reconnect and any positive value enables it using the client's default reconnect configuration. The scenario also uses this setting to control JMeter-level retry behavior: 0 means no reconnect retry loop, any positive value means failed publish loops return to the connect step and retry only until the original per-thread runtime expires, even if connect attempts keep timing out.DISCONNECT_DELAY: Delay before closing the MQTT connection after publishing loop, in seconds. Default is 0.#### connect-settle-testdiff --git a/test/load2-eks/scenarios/connect-and-publish.jmx b/test/load2-eks/scenarios/connect-and-publish.jmxindex 4c26ab1a5..52a2fe5a1 100644--- a/test/load2-eks/scenarios/connect-and-publish.jmx+++ b/test/load2-eks/scenarios/connect-and-publish.jmx@@ -27,7 +27,7 @@</elementProp></SetupThreadGroup><hashTree>- <JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="Setup">+ <JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="Setup" enabled="true"><stringProp name="scriptLanguage">groovy</stringProp><stringProp name="parameters"></stringProp><stringProp name="filename"></stringProp>@@ -57,7 +57,7 @@ props.put("successes", new java.util.concurrent.atomic.AtomicInteger(0<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp><stringProp name="ThreadGroup.on_sample_error">startnextloop</stringProp><elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController">- <stringProp name="LoopController.loops">1</stringProp>+ <stringProp name="LoopController.loops">${__groovy(((props.get("RECONNECT_ATTEMPTS") ?: "0").toString().toInteger() > 0) ? "-1" : "1",)}</stringProp><boolProp name="LoopController.continue_forever">false</boolProp></elementProp></ThreadGroup>@@ -72,7 +72,7 @@ import com.fasterxml.uuid.Generators;import com.fasterxml.uuid.impl.NameBasedGenerator;// Generate asset ids to be used in ForEach controller later-def assetsCount = vars.get("ASSETS_COUNT") ?: "5"+def assetsCount = props.get("ASSETS_COUNT") ?: "5"def count = assetsCount.toInteger()for (int i = 1; i <= count; i++) {def assetId = Url62.encode(Generators.nameBasedGenerator().generate("masterlight-${__threadNum}-${i}"))@@ -87,11 +87,19 @@ vars.put("assetId_matchNr", count.toString())<stringProp name="parameters"></stringProp><stringProp name="filename"></stringProp><stringProp name="cacheKey">true</stringProp>- <stringProp name="script">// Record when this thread started-vars.putObject("threadStartTime", System.currentTimeMillis())-def duration = (props.get("DURATION") ?: "300").toString().toInteger()-vars.put("testDuration", duration.toString())-log.info(">>> Thread ${ctx.getThreadNum()} started, will run for ${duration} seconds")+ <stringProp name="script">// Keep a fixed per-thread end time so reconnect attempts do not extend runtime.+if (vars.getObject("threadEndTime") == null) {+ def startTime = System.currentTimeMillis()+ def duration = (props.get("DURATION") ?: "300").toString().toInteger()+ def endTime = startTime + (duration * 1000L)+ vars.putObject("threadStartTime", startTime)+ vars.putObject("threadEndTime", endTime)+ vars.put("testDuration", duration.toString())+ log.info(">>> Thread ${ctx.getThreadNum()} started, will run for ${duration} seconds")+} else if (System.currentTimeMillis() >= vars.getObject("threadEndTime")) {+ log.info(">>> Thread ${ctx.getThreadNum()} runtime elapsed before reconnect attempt, stopping thread")+ ctx.getThread().stop()+}</stringProp></JSR223Sampler><hashTree/>@@ -108,17 +116,15 @@ log.info(">>> Thread ${ctx.getThreadNum()} started, will run for $<stringProp name="mqtt.client_id_prefix">device${__threadNum}</stringProp><boolProp name="mqtt.client_id_suffix">false</boolProp><stringProp name="mqtt.conn_keep_alive">30</stringProp>- <stringProp name="mqtt.conn_attampt_max">0</stringProp>- <stringProp name="mqtt.reconn_attampt_max">0</stringProp><stringProp name="mqtt.conn_clean_session">true</stringProp><stringProp name="mqtt.user_name">master:serviceuser${__threadNum}</stringProp><stringProp name="mqtt.password">serviceuser${__threadNum}</stringProp><stringProp name="mqtt.connect_name">mqttconn</stringProp><stringProp name="mqtt.conn_attempt_max">0</stringProp>- <stringProp name="mqtt.reconn_attempt_max">0</stringProp>+ <stringProp name="mqtt.reconn_attempt_max">${__P(RECONNECT_ATTEMPTS,0)}</stringProp></net.xmeter.samplers.ConnectSampler><hashTree>- <JSR223Timer guiclass="TestBeanGUI" testclass="JSR223Timer" testname="Connect Delay Timer" enabled="false">+ <JSR223Timer guiclass="TestBeanGUI" testclass="JSR223Timer" testname="Connect Delay Timer" enabled="true"><stringProp name="cacheKey">true</stringProp><stringProp name="filename"></stringProp><stringProp name="parameters"></stringProp>@@ -161,20 +167,14 @@ return delay</stringProp></ConstantTimer><hashTree/></hashTree>- <WhileController guiclass="WhileControllerGui" testclass="WhileController" testname="While Controller">+ <WhileController guiclass="WhileControllerGui" testclass="WhileController" testname="While Controller" enabled="true"><stringProp name="WhileController.condition">${__groovy(- def startTime = vars.getObject("threadStartTime");- if (startTime == null) {- false- } else {- def elapsed = (System.currentTimeMillis() - vars.getObject("threadStartTime")) / 1000;- def duration = (vars.get("testDuration") ?: "300").toInteger()- elapsed < duration;- }+ def endTime = vars.getObject("threadEndTime");+ endTime != null && System.currentTimeMillis() < endTime)}</stringProp></WhileController><hashTree>- <JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="JSR223 Sampler">+ <JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="JSR223 Sampler" enabled="true"><stringProp name="scriptLanguage">groovy</stringProp><stringProp name="parameters"></stringProp><stringProp name="filename"></stringProp>@@ -187,7 +187,7 @@ return delay</stringProp></ConstantTimer><hashTree/></hashTree>- <ForeachController guiclass="ForeachControlPanel" testclass="ForeachController" testname="ForEach Controller">+ <ForeachController guiclass="ForeachControlPanel" testclass="ForeachController" testname="ForEach Controller" enabled="true"><stringProp name="ForeachController.inputVal">assetId</stringProp><stringProp name="ForeachController.returnVal">currentAssetId</stringProp><boolProp name="ForeachController.useSeparator">true</boolProp>@@ -228,7 +228,7 @@ log.info(">>>Direct vars.get currentAssetId = " + vars.get(&q<hashTree/></hashTree></hashTree>- <TestAction guiclass="TestActionGui" testclass="TestAction" testname="Flow Control Action">+ <TestAction guiclass="TestActionGui" testclass="TestAction" testname="Flow Control Action" enabled="true"><intProp name="ActionProcessor.action">1</intProp><intProp name="ActionProcessor.target">0</intProp><stringProp name="ActionProcessor.duration">${__groovy((props.get("DISCONNECT_DELAY") ?: "0").toInteger() * 1000)}</stringProp>@@ -238,6 +238,12 @@ log.info(">>>Direct vars.get currentAssetId = " + vars.get(&q<stringProp name="mqtt.connect_name">mqttconn</stringProp></net.xmeter.samplers.DisConnectSampler><hashTree/>+ <TestAction guiclass="TestActionGui" testclass="TestAction" testname="Stop Thread" enabled="true">+ <intProp name="ActionProcessor.action">0</intProp>+ <intProp name="ActionProcessor.target">0</intProp>+ <stringProp name="ActionProcessor.duration"></stringProp>+ </TestAction>+ <hashTree/><ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true"><boolProp name="ResultCollector.error_logging">false</boolProp><objProp>diff --git a/test/load2-eks/scenarios/connect-and-publish.yml b/test/load2-eks/scenarios/connect-and-publish.ymlindex 004b23617..0a7403a0c 100644--- a/test/load2-eks/scenarios/connect-and-publish.yml+++ b/test/load2-eks/scenarios/connect-and-publish.yml@@ -8,6 +8,7 @@ settings:RAMP_RATE: 20DURATION: 300MILLIS_BETWEEN_PUBLISHES: 1000+ RECONNECT_ATTEMPTS: 0DISCONNECT_DELAY: 0reporting:@@ -29,9 +30,11 @@ modules:properties:MANAGER_HOSTNAME: ${MANAGER_HOSTNAME}THREAD_COUNT: ${THREAD_COUNT}+ ASSETS_COUNT: ${ASSETS_COUNT}RAMP_RATE: ${RAMP_RATE}DURATION: ${DURATION}MILLIS_BETWEEN_PUBLISHES: ${MILLIS_BETWEEN_PUBLISHES}+ RECONNECT_ATTEMPTS: ${RECONNECT_ATTEMPTS}DISCONNECT_DELAY: ${DISCONNECT_DELAY}execution:@@ -40,4 +43,3 @@ execution:scenarios:simple:script: connect-and-publish.jmx-