Package io.karatelabs.core
Interface PerfContext
- All Known Implementing Classes:
KarateJs
public interface PerfContext
Interface for capturing custom performance events from Java code.
This allows users to report timing for non-HTTP operations (database calls, gRPC, custom protocols) to Gatling's statistics engine.
The karate object passed to Java code implements this interface,
so custom Java helpers can capture performance events:
// In feature file:
* def result = Java.type('mock.MockUtils').myRpc({ sleep: 100 }, karate)
// In MockUtils.java:
public static Map myRpc(Map args, PerfContext context) {
long start = System.currentTimeMillis();
// ... custom logic ...
long end = System.currentTimeMillis();
context.capturePerfEvent("myRpc", start, end);
return Map.of("success", true);
}
-
Method Summary
Modifier and TypeMethodDescriptionvoidcapturePerfEvent(String name, long startTime, long endTime) Capture a custom performance event.
-
Method Details
-
capturePerfEvent
Capture a custom performance event.When running under Gatling, this event will be reported to the Gatling statistics engine with OK status (code 200). When not in performance mode, this is a no-op.
- Parameters:
name- the event name for Gatling reportsstartTime- the start time in epoch millisecondsendTime- the end time in epoch milliseconds
-