thingsboard-aplcache

Details

pom.xml 26(+26 -0)

diff --git a/pom.xml b/pom.xml
index b68bee7..22fb73f 100755
--- a/pom.xml
+++ b/pom.xml
@@ -69,6 +69,10 @@
         <surfire.version>2.19.1</surfire.version>
         <jar-plugin.version>3.0.2</jar-plugin.version>
         <springfox-swagger.version>2.6.1</springfox-swagger.version>
+        <gatling.version>2.2.3</gatling.version>
+        <gatling-mqtt.version>1.0.0</gatling-mqtt.version>
+        <gatling-plugin.version>2.2.1</gatling-plugin.version>
+        <scala-maven-plugin.version>3.2.2</scala-maven-plugin.version>
     </properties>
 
     <modules>
@@ -281,6 +285,16 @@
                         </execution>
                     </executions>
                 </plugin>
+                <plugin>
+                    <groupId>net.alchim31.maven</groupId>
+                    <artifactId>scala-maven-plugin</artifactId>
+                    <version>${scala-maven-plugin.version}</version>
+                </plugin>
+                <plugin>
+                    <groupId>io.gatling</groupId>
+                    <artifactId>gatling-maven-plugin</artifactId>
+                    <version>${gatling-plugin.version}</version>
+                </plugin>
             </plugins>
         </pluginManagement>
         <plugins>
@@ -689,6 +703,18 @@
                 <artifactId>springfox-swagger2</artifactId>
                 <version>${springfox-swagger.version}</version>
             </dependency>
+            <dependency>
+                <groupId>io.gatling.highcharts</groupId>
+                <artifactId>gatling-charts-highcharts</artifactId>
+                <version>${gatling.version}</version>
+                <scope>test</scope>
+            </dependency>
+            <dependency>
+                <groupId>com.github.mnogu</groupId>
+                <artifactId>gatling-mqtt</artifactId>
+                <version>${gatling-mqtt.version}</version>
+                <scope>test</scope>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 

tools/pom.xml 21(+19 -2)

diff --git a/tools/pom.xml b/tools/pom.xml
index a3cfe6a..ad5921f 100644
--- a/tools/pom.xml
+++ b/tools/pom.xml
@@ -78,9 +78,18 @@
             <artifactId>mockito-all</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>io.gatling.highcharts</groupId>
+            <artifactId>gatling-charts-highcharts</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.github.mnogu</groupId>
+            <artifactId>gatling-mqtt</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
-
     <build>
         <plugins>
             <plugin>
@@ -105,7 +114,7 @@
                             </filters>
                             <transformers>
                                 <transformer
-                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                     <manifestEntries>
                                         <Main-Class>org.thingsboard.client.tools.MqttStressTestTool</Main-Class>
                                     </manifestEntries>
@@ -115,6 +124,14 @@
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>net.alchim31.maven</groupId>
+                <artifactId>scala-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>io.gatling</groupId>
+                <artifactId>gatling-maven-plugin</artifactId>
+            </plugin>
         </plugins>
     </build>
 </project>
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 5805cad..5d1af34 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 ed6f42b..05075ba 100644
--- a/tools/src/main/java/org/thingsboard/client/tools/MqttStressTestTool.java
+++ b/tools/src/main/java/org/thingsboard/client/tools/MqttStressTestTool.java
@@ -13,28 +13,21 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.thingsboard.client.tools; /**
- * Copyright © 2016 The Thingsboard Authors
- * <p>
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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 lombok.extern.slf4j.Slf4j;
 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;
@@ -70,16 +63,20 @@ public class MqttStressTestTool {
 
         List<MqttStressTestClient> clients = new ArrayList<>();
         List<IMqttToken> connectTokens = new ArrayList<>();
+        List<String> 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();
         }
@@ -126,4 +123,20 @@ public class MqttStressTestTool {
         scheduler.shutdownNow();
     }
 
+    private static void dumpDeviceCredentialsIdsToTmpFile(List<String> 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/main/java/org/thingsboard/client/tools/RestClient.java b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java
index 8eda7b6..f30164f 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 1364fc1..ac1fa19 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 0000000..fb500ff
--- /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 0000000..d82ed5b
--- /dev/null
+++ b/tools/src/test/scala/org/thingsboard/client/tools/MqttSimulation.scala
@@ -0,0 +1,40 @@
+/**
+  * 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("${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(1000) during (5 seconds))
+  ).protocols(mqttConf)
+
+}
\ No newline at end of file