Alright I have somewhat of answer and implementation.
Turns out I had to rewrite the entire AsyncCheckDSL for need:
`
import akka.japi.Predicate
import project.Envelope
import io.gatling.commons.validation._
import io.gatling.core.session._
import io.gatling.http.check.async._
import io.gatling.core.check._
import io.gatling.core.check.extractor.{Extractor, SingleArity}
import org.asynchttpclient.util.Base64
import scala.concurrent.duration.FiniteDuration
object CustomAsyncCheckDSL {
// val myWsListen = new MyTimeoutStep(false)
val myWsAwait = new MyTimeoutStep(true)
class MyTimeoutStep(await: Boolean) {
def within(timeout: FiniteDuration) = new MyExpectationStep(await, timeout)
}
class MyExpectationStep(await: Boolean, timeout: FiniteDuration) {
def until(count: Int) = new MyCheckTypeStep(await, timeout, UntilCount(count))
def expect(count: Int) = new MyCheckTypeStep(await, timeout, ExpectedCount(count))
def expect(range: Range) = new MyCheckTypeStep(await, timeout, ExpectedRange(range))
}
class MyCheckTypeStep(await: Boolean, timeout: FiniteDuration, expectation: Expectation) {
def compareEnvelope(pred: Predicate[Envelope]) = {
new ValidatorCheckBuilder[AsyncCheck, String, Envelope, Boolean](
AsyncCheckBuilders.extender(await, timeout, expectation),
EnvelopePreparer.safeParse,
new CustomExtractor(pred).expressionSuccess
)
}
}
// inspired from HttpStatusCheckBuilder
class CustomExtractor(pred: Predicate[Envelope]) extends Extractor[Envelope, Boolean] with SingleArity {
override def name: String = “useless”
override def apply(prepared: Envelope) = {
println(“PREPARED:\n” + prepared)
pred.test(prepared) match {
case true => Some(true).success
case false => “Not matched”.failure
}
}
}
object EnvelopePreparer {
private val ErrorMapper: String => String = "Protobuf failed to parse Envelope: " + _
def safeParse(msg: String): Validation[Envelope] =
safely(ErrorMapper)(Envelope.parseFrom(Base64.decode(msg)).success)
}
}
`
Suggestions to improve this implementations are more than welcome.