Skip to content

Commit

Permalink
adding a project for profiling experiments #1685
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrthomas committed Jul 20, 2021
1 parent 77408d8 commit 280a432
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 1 deletion.
70 changes: 70 additions & 0 deletions examples/profiling-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.intuit.karate.examples</groupId>
<artifactId>profiling-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.version>3.6.0</maven.compiler.version>
<karate.version>2.0.0</karate.version>
<gatling.plugin.version>3.1.2</gatling.plugin.version>
</properties>

<dependencies>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-gatling</artifactId>
<version>${karate.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<encoding>UTF-8</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgument>-Werror</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling.plugin.version}</version>
<configuration>
<simulationsFolder>src/test/java</simulationsFolder>
<includes>
<include>perf.TestSimulation</include>
</includes>
</configuration>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<name>profiling-test</name>
</project>
3 changes: 3 additions & 0 deletions examples/profiling-test/src/test/java/karate-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function(){
return {};
}
26 changes: 26 additions & 0 deletions examples/profiling-test/src/test/java/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<immediateFlush>false</immediateFlush>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<immediateFlush>false</immediateFlush>
<file>target/karate.log</file>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<logger name="com.intuit.karate" level="WARN"/>

<root level="WARN">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>

</configuration>
56 changes: 56 additions & 0 deletions examples/profiling-test/src/test/java/perf/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package perf;

import com.intuit.karate.PerfHook;
import com.intuit.karate.Runner;
import com.intuit.karate.core.FeatureResult;
import com.intuit.karate.core.PerfEvent;
import com.intuit.karate.core.ScenarioRuntime;
import com.intuit.karate.http.HttpRequest;

/**
*
* @author pthomas3
*/
public class Main {

public static void main(String[] args) {
TestUtils.startServer();
int count = 0;
PerfHook hook = new PerfHook() {
@Override
public String getPerfEventName(HttpRequest request, ScenarioRuntime sr) {
return request.getMethod() + " " + request.getUrl();
}

@Override
public void reportPerfEvent(PerfEvent event) {

}

@Override
public void submit(Runnable runnable) {
runnable.run();
}

@Override
public void afterFeature(FeatureResult fr) {

}

@Override
public void pause(Number millis) {

}

};
while (true) {
count++;
Runner.callAsync(Runner.builder(), "classpath:perf/test.feature", null, hook);
System.out.print(count + " ");
if (count % 100 == 0) {
System.out.println("");
}
}
}

}
19 changes: 19 additions & 0 deletions examples/profiling-test/src/test/java/perf/TestSimulation.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package perf

import com.intuit.karate.gatling.PreDef._
import io.gatling.core.Predef._

import scala.concurrent.duration._

class TestSimulation extends Simulation {

val protocol = karateProtocol()
TestUtils.startServer()

val test = scenario("test").exec(karateFeature("classpath:perf/test.feature"))

setUp(
test.inject(rampUsers(10) during (5 seconds)).protocols(protocol)
)

}
16 changes: 16 additions & 0 deletions examples/profiling-test/src/test/java/perf/TestUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package perf;

import com.intuit.karate.core.MockServer;

/**
*
* @author pthomas3
*/
public class TestUtils {

public static void startServer() {
MockServer server = MockServer.feature("classpath:perf/mock.feature").build();
System.setProperty("mock.server.url", "http://localhost:" + server.getPort());
}

}
5 changes: 5 additions & 0 deletions examples/profiling-test/src/test/java/perf/called.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature:

Scenario:
* def var1 = { foo: 'bar' }
* def var2 = { baz: 'ban' }
4 changes: 4 additions & 0 deletions examples/profiling-test/src/test/java/perf/mock.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Feature:

Scenario: pathMatches('/test')
* def response = { success: true }
13 changes: 13 additions & 0 deletions examples/profiling-test/src/test/java/perf/test.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Feature:

Background:
* def backgroundData = callonce read('called.feature')
* url karate.properties['mock.server.url']

Scenario:
* path 'test'
* method get
* match response == { success: true }
* match backgroundData contains { var1: { foo: 'bar' } }
* def scenarioData = karate.call('called.feature')
* match scenarioData contains { var2: { baz: 'ban' } }
1 change: 0 additions & 1 deletion karate-core/src/main/java/com/intuit/karate/PerfHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.intuit.karate.core.PerfEvent;
import com.intuit.karate.core.ScenarioRuntime;
import com.intuit.karate.http.HttpRequest;
import java.util.Map;

/**
*
Expand Down

0 comments on commit 280a432

Please sign in to comment.