Skip to content

Commit 3b546b2

Browse files
committed
test: Assert hook runs on handler's thread
1 parent 3ed4faa commit 3b546b2

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/test/java/com/retailsvc/http/AfterResponseHookIT.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,25 @@ void preRequestFailureSkipsHooks() throws Exception {
212212
}
213213

214214
@Test
215-
void hookSeesScopedRequest() throws Exception {
215+
void hookSeesScopedRequestAndSameThreadAsHandler() throws Exception {
216216
AtomicReference<Request> hookScopedRequest = new AtomicReference<>();
217+
AtomicReference<Thread> handlerThread = new AtomicReference<>();
218+
AtomicReference<Thread> hookThread = new AtomicReference<>();
217219
CountDownLatch latch = new CountDownLatch(1);
218220

219221
try (OpenApiServer server =
220222
baseBuilder()
221-
.handlers(Map.of(OK_OPERATION_ID, req -> Response.status(HTTP_NO_CONTENT)))
223+
.handlers(
224+
Map.of(
225+
OK_OPERATION_ID,
226+
req -> {
227+
handlerThread.set(Thread.currentThread());
228+
return Response.status(HTTP_NO_CONTENT);
229+
}))
222230
.afterResponseHook(
223231
(req, resp) -> {
224232
hookScopedRequest.set(DispatchHandler.CURRENT.get());
233+
hookThread.set(Thread.currentThread());
225234
latch.countDown();
226235
})
227236
.build()) {
@@ -234,6 +243,7 @@ void hookSeesScopedRequest() throws Exception {
234243
assertThat(latch.await(5, TimeUnit.SECONDS)).isTrue();
235244
assertThat(hookScopedRequest.get()).isNotNull();
236245
assertThat(hookScopedRequest.get().operationId()).isEqualTo(OK_OPERATION_ID);
246+
assertThat(hookThread.get()).isSameAs(handlerThread.get());
237247
}
238248
}
239249
}

0 commit comments

Comments
 (0)