All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.phisgr.gatling.kt.grpc.internal.checks.kt Maven / Gradle / Ivy

The newest version!
@file:Suppress("UNCHECKED_CAST")

package com.github.phisgr.gatling.kt.grpc.internal

import com.github.phisgr.gatling.generic.check.ResponseExtract
import com.github.phisgr.gatling.grpc.Predef
import com.github.phisgr.gatling.grpc.check.*
import io.gatling.javaapi.core.CheckBuilder
import io.grpc.Metadata
import io.grpc.Status
import io.gatling.core.check.CheckBuilder as CheckBuilderS

enum class GrpcCheckType : CheckBuilder.CheckType {
    Response,
    Status,
    Trailers
}

/**
 * Kotlin does not know this class is contravariant
 */
private fun  GrpcCheck.upcast(): GrpcCheck = this as GrpcCheck

private fun  CheckBuilder.asScalaTyped(): CheckBuilderS =
    asScala() as CheckBuilderS

fun  CheckBuilder.build(): GrpcCheck = when (val t = type()) {
    GrpcCheckType.Response -> asScalaTyped().build(Predef.resMat())
    GrpcCheckType.Status -> asScalaTyped().build(Predef.statusMat()).upcast()
    GrpcCheckType.Trailers -> asScalaTyped().build(Predef.trailersMat()).upcast()
    else -> throw IllegalArgumentException("gRPC DSL doesn't support $t")
}

typealias GrpcStreamEnd = GrpcResponse

fun CheckBuilder.buildStreamEnd(): StreamCheck = when (val t = type()) {
    GrpcCheckType.Status -> asScalaTyped().build(Predef.streamStatusMat())
    GrpcCheckType.Trailers -> asScalaTyped().build(Predef.streamTrailersMat())
    else -> throw IllegalArgumentException("gRPC DSL doesn't support $t")
} as StreamCheck

fun  CheckBuilder.buildStream(): StreamCheck = when (val t = type()) {
    GrpcCheckType.Response -> asScalaTyped().build(Predef.streamResMat())
    else -> throw IllegalArgumentException("gRPC DSL doesn't support $t")
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy