Skip to content

Commit

Permalink
Add test file
Browse files Browse the repository at this point in the history
Signed-off-by: Adrián Moreno <adrian@morenomartinez.com>
  • Loading branch information
adrianmo committed Feb 10, 2020
1 parent 53363c2 commit 7d514b3
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ hs_err_pid*

# IDE
.idea/
*.iml
*.iml

target/
175 changes: 171 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<org.apache.commons>3.9</org.apache.commons>
<org.apache.jmeter.version>5.2.1</org.apache.jmeter.version>
<com.microsoft.azure.version>2.5.1</com.microsoft.azure.version>
<junit.version>4.12</junit.version>
<junit.jupiter.version>5.0.0</junit.jupiter.version>
<junit.vintage.version>${junit.version}.0</junit.vintage.version>
<junit.jupiter.version>5.0.0</junit.jupiter.version>
<junit.platform.version>1.0.0</junit.platform.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -55,19 +60,181 @@
<!-- or applicationinsights-core for bare API -->
<version>${com.microsoft.azure.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<profiles>
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<version>3.7.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>compile</includeScope>
<excludeScope>provided</excludeScope>
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>org.apache.jmeter:*</exclude>
<exclude>commons-codec:*</exclude>
<exclude>commons-logging:*</exclude>
<exclude>org.apache.httpcomponents:*</exclude>
<exclude>net.java.dev.jna:*</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.microsoft.applicationinsights.TelemetryClient;
import com.microsoft.applicationinsights.TelemetryConfiguration;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient;
Expand All @@ -14,11 +15,23 @@
public class AzureBackendClient extends AbstractBackendListenerClient {

private TelemetryClient client;
private static final String INSTRUMENTATION_KEY = "instrumentationKey";

public AzureBackendClient() {
super();
}

@Override
public Arguments getDefaultParameters() {
Arguments arguments = new Arguments();
arguments.addArgument(INSTRUMENTATION_KEY, "");
return arguments;
}

@Override
public void setupTest(BackendListenerContext context) throws Exception {
TelemetryClient client = new TelemetryClient(TelemetryConfiguration.createDefault());
client.getContext().setInstrumentationKey("");
client = new TelemetryClient(TelemetryConfiguration.createDefault());
client.getContext().setInstrumentationKey(context.getParameter(INSTRUMENTATION_KEY));
super.setupTest(context);
}

Expand All @@ -38,8 +51,9 @@ private void trackMetric(String name, Double value, SampleResult sr) {
client.trackMetric(name, value, sr.getSampleCount(), value, value, value, properties);
}


@Override
public void handleSampleResults(List<SampleResult> results, BackendListenerContext backendListenerContext) {
public void handleSampleResults(List<SampleResult> results, BackendListenerContext context) {
for (SampleResult sr : results) {
trackMetric("Bytes", (double)sr.getBytesAsLong(), sr);
trackMetric("SentBytes", (double)sr.getSentBytes(), sr);
Expand All @@ -51,4 +65,10 @@ public void handleSampleResults(List<SampleResult> results, BackendListenerConte
}
}

@Override
public void teardownTest(BackendListenerContext context) throws Exception {
client.flush();
super.teardownTest(context);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.adrianmo.jmeter.backendlistener.azure;

import org.apache.jmeter.config.Arguments;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeAll;

import static org.junit.jupiter.api.Assertions.assertNotNull;

public class TestAzureBackendClient {

private static AzureBackendClient client;

@BeforeAll
public static void setUp() {
client = new AzureBackendClient();
}

@Test
public void testGetDefaultParameters() {
Arguments args = client.getDefaultParameters();
assertNotNull(args);
}

}

0 comments on commit 7d514b3

Please sign in to comment.