I have a subclass of SimpleDecoratingHttpService that contains something like this:
override fun serve(ctx: ServiceRequestContext, req: HttpRequest): HttpResponse {
ctx.log().whenComplete().thenAccept {
if (it.responseCause() == ...) {
// do stuff
}
}
return unwrap().serve(ctx, req)
}
I want to test the logic inside the whenComplete() callback. However, when writing tests like this:
myDecorator.serve(context, request).aggregate().join()
the log() future never completes. What do I need to do to ensure that the log() future eventually completes?
Emulating
RequestLogcompletionA
RequestLogis completed by Armeria's networking layer, so just consuming anHttpRequestorHttpResponsewill not complete aRequestLog. To complete it, you need to call the methods inRequestLogBuilder:Armeria team uses the same technique for testing
BraveService, so you might want to check it out as well at BraveServiceTest.java:161.Testing with a real server
If your setup is too complex to use a mock, as an alternative approach, you can launch a real Armeria server so that Armeria fills the log for you. You can easily launch a server using
ServerRule(JUnit 4) orServerExtension(JUnit 5):