Package brave.test.http
Class ITHttpServer
- java.lang.Object
-
- brave.test.ITRemote
-
- brave.test.http.ITHttpServer
-
- Direct Known Subclasses:
ITServletContainer
public abstract class ITHttpServer extends ITRemote
-
-
Field Summary
Fields Modifier and Type Field Description protected okhttp3.OkHttpClient
client
protected HttpTracing
httpTracing
static IllegalStateException
NOT_READY_ISE
-
Fields inherited from class brave.test.ITRemote
BAGGAGE_FIELD, BAGGAGE_FIELD_KEY, currentTraceContext, propagationFactory, testName, testSpanHandler, tracing
-
-
Constructor Summary
Constructors Constructor Description ITHttpServer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addsStatusCode_badRequest()
protected void
async()
Tests that the span propagates between under asynchronous callbacks (even if explicitly)protected void
childCompletesBeforeServer()
The child completes before the response code is established, so it should be contained completely by the server's interval.protected void
createsChildSpan()
This ensures thread-state is propagated from trace interceptors to user code.protected void
createsChildWhenJoinDisabled()
protected void
customSampler()
protected void
defaultSpanNameIsMethodNameOrRoute()
protected okhttp3.Response
get(String path)
protected okhttp3.Response
get(okhttp3.Request request)
protected void
httpPathTagExcludesQueryParams()
protected void
httpRoute()
The "/items/{itemId}" endpoint should return the itemId in the response body, which proves templating worked (including that it ignores query parameters).protected void
httpRoute_async()
Sometimes state used to carry http route data is different for async requests.protected void
httpRoute_nested()
The "/nested/items/{itemId}" endpoint should be implemented by two route expressions: A path prefix: "/nested" and then a relative expression "/items/{itemId}"protected void
httpStatusCodeSettable_onUncaughtException()
This tests that the actual code is503
, not500
on exception.protected void
httpStatusCodeSettable_onUncaughtException_async()
protected void
httpStatusCodeTagMatchesResponse_onUncaughtException()
ThrowNOT_READY_ISE
inside your controller after setting the status code {code 503}.protected okhttp3.Response
httpStatusCodeTagMatchesResponse_onUncaughtException(String path)
protected okhttp3.Response
httpStatusCodeTagMatchesResponse_onUncaughtException(String path, String errorMessage)
protected void
httpStatusCodeTagMatchesResponse_onUncaughtException_async()
protected abstract void
init()
recreate the server if neededprotected void
notFound()
If http route is supported, then the span name should include itprotected void
options()
This tests both that a root path ends up as "/" (slash) not "" (empty), as well that less typical OPTIONS methods can be traced.protected void
readsBaggage_existingTrace()
protected void
readsBaggage_newTrace()
protected void
readsBaggage_unsampled()
protected void
readsRequestAtResponseTime()
protected void
reportsClientAddress()
protected void
reportsClientAddress_XForwardedFor()
protected void
reportsServerKindToZipkin()
protected void
reusesPropagatedSpanId()
protected void
samplingDisabled()
protected void
setsErrorAndHttpStatusOnUncaughtException()
protected void
setsErrorAndHttpStatusOnUncaughtException_async()
protected void
setup()
protected void
spanHandlerSeesError()
protected void
spanHandlerSeesError_async()
protected void
supportsPortableCustomization()
protected abstract String
url(String path)
-
Methods inherited from class brave.test.ITRemote
assertChildOf, assertChildOf, assertChildOf, assertNoError, assertNoErrorTag, assertSameIds, assertSequential, assertSpanInInterval, checkForLeakedScopes, close, currentTraceContextBuilder, newTraceContext, tracingBuilder
-
-
-
-
Field Detail
-
NOT_READY_ISE
public static final IllegalStateException NOT_READY_ISE
-
client
protected okhttp3.OkHttpClient client
-
httpTracing
protected HttpTracing httpTracing
-
-
Method Detail
-
setup
@BeforeEach protected void setup() throws IOException
- Throws:
IOException
-
init
protected abstract void init() throws IOException
recreate the server if needed- Throws:
IOException
-
reusesPropagatedSpanId
@Test protected void reusesPropagatedSpanId() throws IOException
- Throws:
IOException
-
createsChildWhenJoinDisabled
@Test protected void createsChildWhenJoinDisabled() throws IOException
- Throws:
IOException
-
readsBaggage_newTrace
@Test protected void readsBaggage_newTrace() throws IOException
- Throws:
IOException
-
readsBaggage_unsampled
@Test protected void readsBaggage_unsampled() throws IOException
- Throws:
IOException
-
readsBaggage_existingTrace
@Test protected void readsBaggage_existingTrace() throws IOException
- Throws:
IOException
-
samplingDisabled
@Test protected void samplingDisabled() throws IOException
- Throws:
IOException
-
customSampler
@Test protected void customSampler() throws IOException
- Throws:
IOException
-
async
@Test protected void async() throws IOException
Tests that the span propagates between under asynchronous callbacks (even if explicitly)- Throws:
IOException
-
createsChildSpan
@Test protected void createsChildSpan() throws IOException
This ensures thread-state is propagated from trace interceptors to user code. The endpoint "/child" is expected to create an in-process span. When this works, it should be a child of the "current span", in this case the span representing an incoming server request. When thread state isn't managed properly, the child span will appear as a new trace.- Throws:
IOException
-
childCompletesBeforeServer
@Test protected void childCompletesBeforeServer() throws IOException
The child completes before the response code is established, so it should be contained completely by the server's interval.- Throws:
IOException
-
reportsClientAddress
@Test protected void reportsClientAddress() throws IOException
- Throws:
IOException
-
reportsClientAddress_XForwardedFor
@Test protected void reportsClientAddress_XForwardedFor() throws IOException
- Throws:
IOException
-
reportsServerKindToZipkin
@Test protected void reportsServerKindToZipkin() throws IOException
- Throws:
IOException
-
defaultSpanNameIsMethodNameOrRoute
@Test protected void defaultSpanNameIsMethodNameOrRoute() throws IOException
- Throws:
IOException
-
readsRequestAtResponseTime
@Test protected void readsRequestAtResponseTime() throws IOException
- Throws:
IOException
-
supportsPortableCustomization
@Test protected void supportsPortableCustomization() throws IOException
- Throws:
IOException
-
httpRoute
@Test protected void httpRoute() throws IOException
The "/items/{itemId}" endpoint should return the itemId in the response body, which proves templating worked (including that it ignores query parameters). Note the route format is framework specific, ex "/items/:itemId" in vert.x- Throws:
IOException
-
httpRoute_nested
@Test protected void httpRoute_nested() throws IOException
The "/nested/items/{itemId}" endpoint should be implemented by two route expressions: A path prefix: "/nested" and then a relative expression "/items/{itemId}"- Throws:
IOException
-
httpRoute_async
@Test protected void httpRoute_async() throws IOException
Sometimes state used to carry http route data is different for async requests. This helps ensure we don't miss issues like this.- Throws:
IOException
-
notFound
@Test protected void notFound() throws IOException
If http route is supported, then the span name should include it- Throws:
IOException
-
options
@Test protected void options() throws IOException
This tests both that a root path ends up as "/" (slash) not "" (empty), as well that less typical OPTIONS methods can be traced.- Throws:
IOException
-
addsStatusCode_badRequest
@Test protected void addsStatusCode_badRequest() throws IOException
- Throws:
IOException
-
httpPathTagExcludesQueryParams
@Test protected void httpPathTagExcludesQueryParams() throws IOException
- Throws:
IOException
-
httpStatusCodeTagMatchesResponse_onUncaughtException
@Test protected void httpStatusCodeTagMatchesResponse_onUncaughtException() throws IOException
ThrowNOT_READY_ISE
inside your controller after setting the status code {code 503}.Note: Don't throw
UnavailableException
as Jetty ignores the exception message!- Throws:
IOException
-
httpStatusCodeTagMatchesResponse_onUncaughtException_async
@Test protected void httpStatusCodeTagMatchesResponse_onUncaughtException_async() throws IOException
- Throws:
IOException
-
httpStatusCodeSettable_onUncaughtException
@Test protected void httpStatusCodeSettable_onUncaughtException() throws IOException
This tests that the actual code is503
, not500
on exception.Usually, frameworks have an exception wrapper which allow you to control the status code. Other times, you have to set the status before raising the exception.
Note: Some frameworks cannot control the status code upon unhandled error in a controller at all. If this is the case, just override and ignore this test.
- Throws:
IOException
-
httpStatusCodeSettable_onUncaughtException_async
@Test protected void httpStatusCodeSettable_onUncaughtException_async() throws IOException
- Throws:
IOException
-
httpStatusCodeTagMatchesResponse_onUncaughtException
protected okhttp3.Response httpStatusCodeTagMatchesResponse_onUncaughtException(String path, String errorMessage) throws IOException
- Throws:
IOException
-
httpStatusCodeTagMatchesResponse_onUncaughtException
protected okhttp3.Response httpStatusCodeTagMatchesResponse_onUncaughtException(String path) throws IOException
- Throws:
IOException
-
setsErrorAndHttpStatusOnUncaughtException
@Test protected void setsErrorAndHttpStatusOnUncaughtException() throws IOException
- Throws:
IOException
-
setsErrorAndHttpStatusOnUncaughtException_async
@Test protected void setsErrorAndHttpStatusOnUncaughtException_async() throws IOException
- Throws:
IOException
-
spanHandlerSeesError
@Test protected void spanHandlerSeesError() throws IOException
- Throws:
IOException
-
spanHandlerSeesError_async
@Test protected void spanHandlerSeesError_async() throws IOException
- Throws:
IOException
-
get
protected okhttp3.Response get(String path) throws IOException
- Throws:
IOException
-
get
protected okhttp3.Response get(okhttp3.Request request) throws IOException
- Throws:
IOException
-
-