Skip to content

Commit 33b9a3c

Browse files
committed
Migrated to JUnit 5 and added partition keys to Kafka records
1 parent 4353555 commit 33b9a3c

File tree

10 files changed

+177
-313
lines changed

10 files changed

+177
-313
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ It is inspired from JMeter [ElasticSearch](https://github.com/delirius325/jmeter
123123

124124
![Screenshot of configuration](docs/configuration.JPG "Screenshot of configuration")
125125

126+
### Running your JMeter test plan
127+
128+
You can run the test plan in GUI mode or in CLI mode using command like below:
129+
130+
```bash
131+
bin/jmeter -H [HTTP proxy server] -P [HTTP proxy port] -N "localhost|127.0.0.1|*.singhaiuklimited.com" -n -t test_kafkaserver.jmx -l test_kafkaserver_result.jtl
132+
```
133+
126134
## Screenshots
127135

128136
### Sample Grafana dashboard

config/log4j2.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

docs/configuration.JPG

95.1 KB
Loading

docs/logstash.conf

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,6 @@ filter {
1212
json {
1313
source => "message"
1414
}
15-
16-
# Logstash has strange implementation for json filter above.
17-
# If it sees a field named @timestamp, then it expects it to be a seconds based value (UNIX rather than UNIX_MS) and tries to parse on its own to reuse as event's @timestamp.
18-
# In our case, @timestamp is milli-seconds based long, hence it fails to parse and causes a warning with _timestampparsefailure tag.
19-
20-
if "_timestampparsefailure" in [tags] {
21-
date {
22-
match => [ "_@timestamp", "UNIX_MS" ]
23-
remove_tag => "_timestampparsefailure"
24-
remove_field => "_@timestamp"
25-
}
26-
}
27-
28-
ruby {
29-
code => "if event.get('tags').length == 0 then event.remove('tags') end"
30-
}
3115
}
3216

3317
output {
@@ -37,6 +21,6 @@ output {
3721
index => "jmeter_metrics-%{+xxxx-ww}" # Weekly index
3822
hosts => ["localhost:9201"]
3923
user => "elastic"
40-
password => "elastic"
24+
password => "changeme"
4125
}
4226
}

pom.xml

Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,34 @@
4949

5050
<properties>
5151
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
52+
<maven.cobertura.plugin.version>2.7</maven.cobertura.plugin.version>
5253
<maven.compiler.source>1.8</maven.compiler.source>
5354
<maven.compiler.target>1.8</maven.compiler.target>
55+
<maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
5456
<maven.deploy.plugin.version>3.0.0-M1</maven.deploy.plugin.version>
55-
<maven-git-code-format.version>1.24</maven-git-code-format.version>
56-
<maven.cobertura.plugin.version>2.7</maven.cobertura.plugin.version>
57+
<maven.dependency.plugin.version>3.1.1</maven.dependency.plugin.version>
58+
<maven.enforcer.plugin.version>3.0.0-M2</maven.enforcer.plugin.version>
59+
<maven.gpg.plugin.version>1.6</maven.gpg.plugin.version>
60+
<maven.git.code.format.plugin.version>1.24</maven.git.code.format.plugin.version>
61+
<maven.javadoc.plugin.version>3.1.0</maven.javadoc.plugin.version>
62+
<maven.nexus.staging.plugin.version>1.6.8</maven.nexus.staging.plugin.version>
63+
<maven.shade.plugin.version>3.2.1</maven.shade.plugin.version>
64+
<maven.source.plugin.version>3.1.0</maven.source.plugin.version>
65+
<maven.surefire.plugin.version>3.0.0-M3</maven.surefire.plugin.version>
66+
<guava.version>28.0-jre</guava.version>
5767
<java.version>1.8</java.version>
58-
<junit.version>4.12</junit.version>
59-
<junit.jupiter.version>5.4.2</junit.jupiter.version>
60-
<junit.vintage.version>${junit.version}.0</junit.vintage.version>
61-
<junit.jupiter.version>5.0.0</junit.jupiter.version>
62-
<junit.platform.version>1.4.2</junit.platform.version>
68+
<junit.version>5.4.2</junit.version>
69+
<junit.platform.surefire.provider.version>1.3.2</junit.platform.surefire.provider.version>
70+
<org.apache.commons>3.8.1</org.apache.commons>
6371
<org.apache.jmeter.version>5.1.1</org.apache.jmeter.version>
64-
<org.apache.commons>3.9</org.apache.commons>
65-
<org.apache.kafka>2.2.1</org.apache.kafka>
72+
<org.apache.kafka>2.3.0</org.apache.kafka>
6673
</properties>
6774

6875
<dependencies>
6976
<dependency>
70-
<groupId>org.json</groupId>
71-
<artifactId>json</artifactId>
72-
<version>20180813</version>
73-
</dependency>
74-
<dependency>
75-
<groupId>com.google.code.gson</groupId>
76-
<artifactId>gson</artifactId>
77-
<version>2.8.5</version>
77+
<groupId>com.google.guava</groupId>
78+
<artifactId>guava</artifactId>
79+
<version>${guava.version}</version>
7880
</dependency>
7981
<dependency>
8082
<groupId>org.apache.jmeter</groupId>
@@ -114,25 +116,13 @@
114116
<dependency>
115117
<groupId>org.junit.jupiter</groupId>
116118
<artifactId>junit-jupiter-engine</artifactId>
117-
<version>${junit.jupiter.version}</version>
118-
<scope>test</scope>
119-
</dependency>
120-
<dependency>
121-
<groupId>junit</groupId>
122-
<artifactId>junit</artifactId>
123119
<version>${junit.version}</version>
124120
<scope>test</scope>
125121
</dependency>
126122
<dependency>
127-
<groupId>org.junit.platform</groupId>
128-
<artifactId>junit-platform-runner</artifactId>
129-
<version>${junit.platform.version}</version>
130-
<scope>test</scope>
131-
</dependency>
132-
<dependency>
133-
<groupId>org.junit.vintage</groupId>
134-
<artifactId>junit-vintage-engine</artifactId>
135-
<version>${junit.vintage.version}</version>
123+
<groupId>org.junit.jupiter</groupId>
124+
<artifactId>junit-jupiter</artifactId>
125+
<version>${junit.version}</version>
136126
<scope>test</scope>
137127
</dependency>
138128
<dependency>
@@ -169,7 +159,7 @@
169159
<plugin>
170160
<groupId>org.apache.maven.plugins</groupId>
171161
<artifactId>maven-gpg-plugin</artifactId>
172-
<version>1.6</version>
162+
<version>${maven.gpg.plugin.version}</version>
173163
<executions>
174164
<execution>
175165
<id>sign-artifacts</id>
@@ -190,7 +180,7 @@
190180
<plugin>
191181
<groupId>org.sonatype.plugins</groupId>
192182
<artifactId>nexus-staging-maven-plugin</artifactId>
193-
<version>1.6.8</version>
183+
<version>${maven.nexus.staging.plugin.version}</version>
194184
<extensions>true</extensions>
195185
<configuration>
196186
<serverId>ossrh</serverId>
@@ -202,7 +192,7 @@
202192
<plugin>
203193
<groupId>org.apache.maven.plugins</groupId>
204194
<artifactId>maven-source-plugin</artifactId>
205-
<version>3.1.0</version>
195+
<version>${maven.source.plugin.version}</version>
206196
<executions>
207197
<execution>
208198
<id>attach-sources</id>
@@ -216,7 +206,7 @@
216206
<plugin>
217207
<groupId>org.apache.maven.plugins</groupId>
218208
<artifactId>maven-javadoc-plugin</artifactId>
219-
<version>3.1.0</version>
209+
<version>${maven.javadoc.plugin.version}</version>
220210
<executions>
221211
<execution>
222212
<id>attach-javadocs</id>
@@ -233,7 +223,7 @@
233223
<plugin>
234224
<groupId>com.cosium.code</groupId>
235225
<artifactId>maven-git-code-format</artifactId>
236-
<version>${maven-git-code-format.version}</version>
226+
<version>${maven.git.code.format.plugin.version}</version>
237227
<executions>
238228
<!-- On commit, format the modified java files -->
239229
<execution>
@@ -254,7 +244,7 @@
254244

255245
<plugin>
256246
<artifactId>maven-enforcer-plugin</artifactId>
257-
<version>3.0.0-M2</version>
247+
<version>${maven.enforcer.plugin.version}</version>
258248
<executions>
259249
<execution>
260250
<goals>
@@ -272,26 +262,19 @@
272262
</plugin>
273263

274264
<plugin>
265+
<groupId>org.apache.maven.plugins</groupId>
275266
<artifactId>maven-surefire-plugin</artifactId>
276-
<version>2.22.2</version>
277-
<dependencies>
278-
<dependency>
279-
<groupId>org.junit.platform</groupId>
280-
<artifactId>junit-platform-surefire-provider</artifactId>
281-
<version>1.3.2</version>
282-
</dependency>
283-
<dependency>
284-
<groupId>org.junit.jupiter</groupId>
285-
<artifactId>junit-jupiter-engine</artifactId>
286-
<version>${junit.jupiter.version}</version>
287-
</dependency>
288-
</dependencies>
267+
<version>${maven.surefire.plugin.version}</version>
268+
<configuration>
269+
<parallel>methods</parallel>
270+
<threadCount>10</threadCount>
271+
</configuration>
289272
</plugin>
290273

291274
<plugin>
292275
<groupId>org.apache.maven.plugins</groupId>
293276
<artifactId>maven-compiler-plugin</artifactId>
294-
<version>3.8.1</version>
277+
<version>${maven.compiler.plugin.version}</version>
295278
<configuration>
296279
<source>1.8</source>
297280
<target>1.8</target>
@@ -301,7 +284,7 @@
301284
<plugin>
302285
<groupId>org.apache.maven.plugins</groupId>
303286
<artifactId>maven-dependency-plugin</artifactId>
304-
<version>3.1.1</version>
287+
<version>${maven.dependency.plugin.version}</version>
305288
<executions>
306289
<execution>
307290
<id>copy-dependencies</id>
@@ -339,7 +322,7 @@
339322
<plugin>
340323
<groupId>org.apache.maven.plugins</groupId>
341324
<artifactId>maven-shade-plugin</artifactId>
342-
<version>3.2.1</version>
325+
<version>${maven.shade.plugin.version}</version>
343326
<executions>
344327
<!-- Run shade goal on package phase -->
345328
<execution>

src/main/java/io/github/rahulsinghai/jmeter/backendlistener/kafka/JSONMetric.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.github.rahulsinghai.jmeter.backendlistener.kafka;
1818

1919
import java.net.InetAddress;
20+
import java.net.UnknownHostException;
2021
import java.text.ParseException;
2122
import java.text.SimpleDateFormat;
2223
import java.time.LocalDateTime;
@@ -70,8 +71,9 @@ public JSONMetric(
7071
*
7172
* @param context BackendListenerContext
7273
* @return a JSON Object as Map(String, Object)
74+
* @throws UnknownHostException If unable to determine injector host name.
7375
*/
74-
public Map<String, Object> getMetric(BackendListenerContext context) throws Exception {
76+
public Map<String, Object> getMetric(BackendListenerContext context) throws UnknownHostException {
7577
SimpleDateFormat sdf = new SimpleDateFormat(this.kafkaTimestamp);
7678

7779
// add all the default SampleResult parameters
@@ -101,8 +103,6 @@ public Map<String, Object> getMetric(BackendListenerContext context) throws Exce
101103
// Add the details according to the mode that is set
102104
switch (this.kafkaTestMode) {
103105
case "debug":
104-
addDetails();
105-
break;
106106
case "error":
107107
addDetails();
108108
break;
@@ -127,7 +127,8 @@ public Map<String, Object> getMetric(BackendListenerContext context) throws Exce
127127
private void addAssertions() {
128128
AssertionResult[] assertionResults = this.sampleResult.getAssertionResults();
129129
if (assertionResults != null) {
130-
Map<String, Object>[] assertionArray = new HashMap[assertionResults.length];
130+
@SuppressWarnings("unchecked")
131+
HashMap<String, Object>[] assertionArray = new HashMap[assertionResults.length];
131132
int i = 0;
132133
String failureMessage = "";
133134
boolean isFailure = false;
@@ -183,7 +184,7 @@ private void addCustomFields(BackendListenerContext context) {
183184
while (pluginParameters.hasNext()) {
184185
String parameterName = pluginParameters.next();
185186

186-
if (!parameterName.startsWith("es.")
187+
if (!parameterName.startsWith(KafkaBackendClient.SERVICE_NAME_PREFIX)
187188
&& !context.getParameter(parameterName).trim().equals("")) {
188189
String parameter = context.getParameter(parameterName).trim();
189190

@@ -232,8 +233,8 @@ private void parseHeadersAsJsonProps(boolean allReqHeaders, boolean allResHeader
232233
}
233234

234235
for (String[] lines : headersArrayList) {
235-
for (int i = 0; i < lines.length; i++) {
236-
String[] header = lines[i].split(":", 2);
236+
for (String line : lines) {
237+
String[] header = line.split(":", 2);
237238

238239
// if not all req headers and header contains special X-tag
239240
if (header.length > 1) {

0 commit comments

Comments
 (0)