com.github.phisgr.gatling.kt.grpc.check.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gatling-grpc-kt Show documentation
Show all versions of gatling-grpc-kt Show documentation
Kotlin/Java binding for Gatling-gRPC
The newest version!
@file:JvmMultifileClass
@file:JvmName("GrpcDsl")
package com.github.phisgr.gatling.kt.grpc
import com.github.phisgr.gatling.grpc.Predef
import com.github.phisgr.gatling.kt.grpc.internal.GrpcCheckType
import com.github.phisgr.gatling.kt.grpc.internal.dummyFrom
import com.github.phisgr.gatling.kt.internal.*
import io.gatling.javaapi.core.CheckBuilder
import io.grpc.Metadata
import io.grpc.Status
import net.jodah.typetools.TypeResolver
import java.util.function.Function
/**
* Allows defining extraction [CheckBuilder]s outside of
* the [From] context in [ActionCheckBuilder.check].
* See also [From.extract].
*/
inline fun extract(crossinline f: (Res) -> T?): CheckBuilder.Find =
(dummyFrom as From).extract { f(it) }
/**
* Java API to define extraction [CheckBuilder]s.
* This resolves the [Class] of the extracted type [X] from the [Function] object.
*
* See the other overload if it does not work as expected.
*/
fun extract(f: Function): CheckBuilder.Find {
val xClass = TypeResolver.resolveRawArguments(Function::class.java, f.javaClass)[1]
@Suppress("UNCHECKED_CAST")
return extract(f, xClass as Class)
}
/**
* Java API to define extraction [CheckBuilder]s.
*/
fun extract(f: Function, xClass: Class): CheckBuilder.Find {
return extract(
GrpcCheckType.Response,
"grpcResponse",
xClass,
toScalaOptionF { res: Res -> f.apply(res) }
)
}
/**
* Allows defining extraction [CheckBuilder]s outside of
* the [From] context in [ActionCheckBuilder.check].
* See also [From.extractMultiple].
*/
inline fun extractMultiple(crossinline f: (Res) -> List?): CheckBuilder.MultipleFind =
(dummyFrom as From).extractMultiple { f(it) }
/**
* Java API to define extraction [CheckBuilder]s.
*/
fun extractMultiple(f: Function?>, clazz: Class): CheckBuilder.MultipleFind =
extractMultiple(
GrpcCheckType.Response,
"grpcResponse",
clazz,
toScalaSeqOptionF { res: Res -> f.apply(res) }
)
@get:JvmName("statusCode")
val statusCode: CheckBuilder.Find = CheckBuilder.Find.Default(
Predef.statusCode(),
GrpcCheckType.Status,
Status.Code::class.java,
null,
)
@get:JvmName("statusDescription")
val statusDescription: CheckBuilder.Find = CheckBuilder.Find.Default(
Predef.statusDescription(),
GrpcCheckType.Status,
String::class.java,
null,
)
inline fun trailer(key: Metadata.Key): CheckBuilder.MultipleFind =
trailer(key, T::class.java)
/**
* Java API to check trailer values.
* [clazz] is for resolving equality and ordering in [io.gatling.javaapi.core.internal.Comparisons].
*/
fun trailer(key: Metadata.Key, clazz: Class): CheckBuilder.MultipleFind =
CheckBuilder.MultipleFind.Default(
Predef.trailer(key),
GrpcCheckType.Trailers,
clazz,
null,
)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy