From 9afa0793150cfcf988b34285cd555d5a5ace7682 Mon Sep 17 00:00:00 2001 From: volodymyr-babak Date: Thu, 15 Dec 2016 11:39:10 +0200 Subject: [PATCH 1/4] gatling-mqtt skeleton impl --- pom.xml | 26 +++++++++++++ tools/pom.xml | 25 ++++++++++++- .../client/tools/MqttStressTestClient.java | 5 ++- .../client/tools/MqttStressTestTool.java | 5 ++- .../thingsboard/client/tools/RestClient.java | 7 ++-- .../client/tools/ResultAccumulator.java | 5 ++- .../main/shell/install-local-gatling-mqtt.sh | 25 +++++++++++++ .../client/tools/MqttSimulation.scala | 37 +++++++++++++++++++ 8 files changed, 128 insertions(+), 7 deletions(-) create mode 100755 tools/src/main/shell/install-local-gatling-mqtt.sh create mode 100644 tools/src/test/scala/org/thingsboard/client/tools/MqttSimulation.scala diff --git a/pom.xml b/pom.xml index fc0bbd088c..06e9821187 100755 --- a/pom.xml +++ b/pom.xml @@ -69,6 +69,10 @@ 2.19.1 3.0.2 2.6.1 + 2.2.3 + 1.0.0 + 2.2.1 + 3.2.2 @@ -281,6 +285,16 @@ + + net.alchim31.maven + scala-maven-plugin + ${scala-maven-plugin.version} + + + io.gatling + gatling-maven-plugin + ${gatling-plugin.version} + @@ -689,6 +703,18 @@ springfox-swagger2 ${springfox-swagger.version} + + io.gatling.highcharts + gatling-charts-highcharts + ${gatling.version} + test + + + com.github.mnogu + gatling-mqtt + ${gatling-mqtt.version} + test + diff --git a/tools/pom.xml b/tools/pom.xml index d78c4cad85..904ca91c26 100644 --- a/tools/pom.xml +++ b/tools/pom.xml @@ -78,6 +78,29 @@ mockito-all test - + + io.gatling.highcharts + gatling-charts-highcharts + test + + + com.github.mnogu + gatling-mqtt + test + + + + + + net.alchim31.maven + scala-maven-plugin + + + io.gatling + gatling-maven-plugin + ${gatling-plugin.version} + + + diff --git a/tools/src/main/java/org/thingsboard/client/tools/MqttStressTestClient.java b/tools/src/main/java/org/thingsboard/client/tools/MqttStressTestClient.java index b0ddf73952..66970a9150 100644 --- a/tools/src/main/java/org/thingsboard/client/tools/MqttStressTestClient.java +++ b/tools/src/main/java/org/thingsboard/client/tools/MqttStressTestClient.java @@ -1,4 +1,4 @@ -package org.thingsboard.client.tools; /** +/** * Copyright © 2016 The Thingsboard Authors * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +13,9 @@ package org.thingsboard.client.tools; /** * See the License for the specific language governing permissions and * limitations under the License. */ + +package org.thingsboard.client.tools; + import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.eclipse.paho.client.mqttv3.*; diff --git a/tools/src/main/java/org/thingsboard/client/tools/MqttStressTestTool.java b/tools/src/main/java/org/thingsboard/client/tools/MqttStressTestTool.java index 900d81fa7d..7852c09197 100644 --- a/tools/src/main/java/org/thingsboard/client/tools/MqttStressTestTool.java +++ b/tools/src/main/java/org/thingsboard/client/tools/MqttStressTestTool.java @@ -1,4 +1,4 @@ -package org.thingsboard.client.tools; /** +/** * Copyright © 2016 The Thingsboard Authors * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +13,9 @@ package org.thingsboard.client.tools; /** * See the License for the specific language governing permissions and * limitations under the License. */ + +package org.thingsboard.client.tools; + import lombok.extern.slf4j.Slf4j; import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.security.DeviceCredentials; diff --git a/tools/src/main/java/org/thingsboard/client/tools/RestClient.java b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java index 8eda7b68d9..f30164f4b3 100644 --- a/tools/src/main/java/org/thingsboard/client/tools/RestClient.java +++ b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java @@ -1,4 +1,4 @@ -package org.thingsboard.client.tools; /** +/** * Copyright © 2016 The Thingsboard Authors * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,10 +13,11 @@ package org.thingsboard.client.tools; /** * See the License for the specific language governing permissions and * limitations under the License. */ + +package org.thingsboard.client.tools; + import com.fasterxml.jackson.databind.JsonNode; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; import org.springframework.http.ResponseEntity; import org.springframework.http.client.ClientHttpRequestExecution; diff --git a/tools/src/main/java/org/thingsboard/client/tools/ResultAccumulator.java b/tools/src/main/java/org/thingsboard/client/tools/ResultAccumulator.java index 5bba82a8e6..197a45b7de 100644 --- a/tools/src/main/java/org/thingsboard/client/tools/ResultAccumulator.java +++ b/tools/src/main/java/org/thingsboard/client/tools/ResultAccumulator.java @@ -1,4 +1,4 @@ -package org.thingsboard.client.tools; /** +/** * Copyright © 2016 The Thingsboard Authors * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +13,9 @@ package org.thingsboard.client.tools; /** * See the License for the specific language governing permissions and * limitations under the License. */ + +package org.thingsboard.client.tools; + import lombok.extern.slf4j.Slf4j; import java.util.concurrent.atomic.AtomicInteger; diff --git a/tools/src/main/shell/install-local-gatling-mqtt.sh b/tools/src/main/shell/install-local-gatling-mqtt.sh new file mode 100755 index 0000000000..fb500ff081 --- /dev/null +++ b/tools/src/main/shell/install-local-gatling-mqtt.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# +# Copyright © 2016 The Thingsboard Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +git clone https://github.com/mnogu/gatling-mqtt.git /tmp/gatling-mqtt +cd /tmp/gatling-mqtt + +sbt assembly + +cd /tmp/gatling-mqtt/target/scala-2.11 + +mvn install:install-file -Dfile=gatling-mqtt-assembly-0.1.0-SNAPSHOT.jar -DgroupId=com.github.mnogu -DartifactId=gatling-mqtt -Dversion=1.0.0 -Dpackaging=jar \ No newline at end of file diff --git a/tools/src/test/scala/org/thingsboard/client/tools/MqttSimulation.scala b/tools/src/test/scala/org/thingsboard/client/tools/MqttSimulation.scala new file mode 100644 index 0000000000..6ac17d74fa --- /dev/null +++ b/tools/src/test/scala/org/thingsboard/client/tools/MqttSimulation.scala @@ -0,0 +1,37 @@ +/** + * Copyright © 2016 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.thingsboard.client.tools + +import io.gatling.core.Predef._ +import org.fusesource.mqtt.client.QoS +import scala.concurrent.duration._ + +import com.github.mnogu.gatling.mqtt.Predef._ + +class MqttSimulation extends Simulation { + val mqttConf = mqtt + .host("tcp://localhost:1883") + .userName("A1_TEST_TOKEN") + + val scn = scenario("MQTT Test") + .exec(mqtt("request") + .publish("v1/devices/me/telemetry", "{\"key1\":\"value1\", \"key2\":\"value2\"}", QoS.AT_LEAST_ONCE, retain = false)) + + setUp( + scn + .inject(constantUsersPerSec(2) during(5 seconds))) + .protocols(mqttConf) +} \ No newline at end of file From ea9c8d2b61815fbef152d96cf619609b95916956 Mon Sep 17 00:00:00 2001 From: volodymyr-babak Date: Thu, 15 Dec 2016 16:15:27 +0200 Subject: [PATCH 2/4] small fix --- tools/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/pom.xml b/tools/pom.xml index 904ca91c26..552260be58 100644 --- a/tools/pom.xml +++ b/tools/pom.xml @@ -99,7 +99,6 @@ io.gatling gatling-maven-plugin - ${gatling-plugin.version} From 21d632744c04fdb6c82187ff22ecc2afe655f579 Mon Sep 17 00:00:00 2001 From: volodymyr-babak Date: Thu, 15 Dec 2016 16:20:56 +0200 Subject: [PATCH 3/4] Merge branch 'master' of https://github.com/thingsboard/thingsboard into gatling-mqtt # Conflicts: # tools/pom.xml # tools/src/main/java/org/thingsboard/client/tools/MqttStressTestTool.java --- tools/pom.xml | 224 +++++++++++++++++++++++++------------------------- 1 file changed, 112 insertions(+), 112 deletions(-) diff --git a/tools/pom.xml b/tools/pom.xml index 614ebd7d4d..c1b3cc0bac 100644 --- a/tools/pom.xml +++ b/tools/pom.xml @@ -17,121 +17,121 @@ --> - 4.0.0 - + 4.0.0 + + org.thingsboard + 1.0.1-SNAPSHOT + thingsboard + org.thingsboard - 1.0.1-SNAPSHOT - thingsboard - - org.thingsboard - tools - jar + tools + jar - Thingsboard Server Tools - http://thingsboard.org + Thingsboard Server Tools + http://thingsboard.org - - UTF-8 - ${basedir}/.. - + + UTF-8 + ${basedir}/.. + - - - org.thingsboard.common - data - - - org.springframework.boot - spring-boot-starter-web - - - org.eclipse.paho - org.eclipse.paho.client.mqttv3 - - - org.slf4j - slf4j-api - - - org.slf4j - log4j-over-slf4j - - - ch.qos.logback - logback-core - - - ch.qos.logback - logback-classic - - - org.springframework - spring-test - - - junit - junit - test - - - org.mockito - mockito-all - test - - - io.gatling.highcharts - gatling-charts-highcharts - test - - - com.github.mnogu - gatling-mqtt - test - - + + + org.thingsboard.common + data + + + org.springframework.boot + spring-boot-starter-web + + + org.eclipse.paho + org.eclipse.paho.client.mqttv3 + + + org.slf4j + slf4j-api + + + org.slf4j + log4j-over-slf4j + + + ch.qos.logback + logback-core + + + ch.qos.logback + logback-classic + + + org.springframework + spring-test + + + junit + junit + test + + + org.mockito + mockito-all + test + + + io.gatling.highcharts + gatling-charts-highcharts + test + + + com.github.mnogu + gatling-mqtt + test + + - - - - org.apache.maven.plugins - maven-shade-plugin - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - - org.thingsboard.client.tools.MqttStressTestTool - - - - - - - - - net.alchim31.maven - scala-maven-plugin - - - io.gatling - gatling-maven-plugin - - - + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + org.thingsboard.client.tools.MqttStressTestTool + + + + + + + + + net.alchim31.maven + scala-maven-plugin + + + io.gatling + gatling-maven-plugin + + + From 4e5bb26cafe069b50a81dee0547667e9ccf029aa Mon Sep 17 00:00:00 2001 From: volodymyr-babak Date: Thu, 15 Dec 2016 17:25:31 +0200 Subject: [PATCH 4/4] read from file --- .../client/tools/MqttStressTestTool.java | 25 ++++++++++++ .../client/tools/MqttSimulation.scala | 39 ++++++++++--------- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/tools/src/main/java/org/thingsboard/client/tools/MqttStressTestTool.java b/tools/src/main/java/org/thingsboard/client/tools/MqttStressTestTool.java index 08e5cfe6d3..05075ba9de 100644 --- a/tools/src/main/java/org/thingsboard/client/tools/MqttStressTestTool.java +++ b/tools/src/main/java/org/thingsboard/client/tools/MqttStressTestTool.java @@ -22,7 +22,12 @@ import org.eclipse.paho.client.mqttv3.IMqttToken; import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.security.DeviceCredentials; +import java.io.BufferedWriter; +import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -58,16 +63,20 @@ public class MqttStressTestTool { List clients = new ArrayList<>(); List connectTokens = new ArrayList<>(); + List deviceCredentialsIds = new ArrayList<>(); for (int i = 0; i < params.getDeviceCount(); i++) { Device device = restClient.createDevice("Device " + UUID.randomUUID()); DeviceCredentials credentials = restClient.getCredentials(device.getId()); String[] mqttUrls = params.getMqttUrls(); String mqttURL = mqttUrls[i % mqttUrls.length]; MqttStressTestClient client = new MqttStressTestClient(results, mqttURL, credentials.getCredentialsId()); + deviceCredentialsIds.add(credentials.getCredentialsId()); connectTokens.add(client.connect()); clients.add(client); } + dumpDeviceCredentialsIdsToTmpFile(deviceCredentialsIds); + for (IMqttToken tokens : connectTokens) { tokens.waitForCompletion(); } @@ -114,4 +123,20 @@ public class MqttStressTestTool { scheduler.shutdownNow(); } + private static void dumpDeviceCredentialsIdsToTmpFile(List deviceCredentialsIds) throws IOException { + Path path = Paths.get("/tmp/mqtt.csv"); + try (BufferedWriter writer = Files.newBufferedWriter(path)) { + writer.write("deviceCredentialsId"); + writer.write('\n'); + deviceCredentialsIds.forEach((deviceCredentialsId) -> { + try { + writer.write(deviceCredentialsId); + writer.write('\n'); + } catch (IOException e) { + e.printStackTrace(); + } + }); + } + } + } diff --git a/tools/src/test/scala/org/thingsboard/client/tools/MqttSimulation.scala b/tools/src/test/scala/org/thingsboard/client/tools/MqttSimulation.scala index 6ac17d74fa..d82ed5b7d4 100644 --- a/tools/src/test/scala/org/thingsboard/client/tools/MqttSimulation.scala +++ b/tools/src/test/scala/org/thingsboard/client/tools/MqttSimulation.scala @@ -1,18 +1,18 @@ /** - * Copyright © 2016 The Thingsboard Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + * Copyright © 2016 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.thingsboard.client.tools import io.gatling.core.Predef._ @@ -22,16 +22,19 @@ import scala.concurrent.duration._ import com.github.mnogu.gatling.mqtt.Predef._ class MqttSimulation extends Simulation { + val mqttConf = mqtt .host("tcp://localhost:1883") - .userName("A1_TEST_TOKEN") + .userName("${deviceCredentialsId}") val scn = scenario("MQTT Test") + .feed(csv("/tmp/mqtt.csv").circular) .exec(mqtt("request") .publish("v1/devices/me/telemetry", "{\"key1\":\"value1\", \"key2\":\"value2\"}", QoS.AT_LEAST_ONCE, retain = false)) setUp( - scn - .inject(constantUsersPerSec(2) during(5 seconds))) - .protocols(mqttConf) + scn + .inject(constantUsersPerSec(1000) during (5 seconds)) + ).protocols(mqttConf) + } \ No newline at end of file