use of org.apache.cxf.systest.microprofile.rest.client.mock.AsyncInvocationInterceptorFactoryTestImpl2 in project cxf by apache.
the class AsyncMethodTest method testInvokesPostOperationWithRegisteredProvidersAsyncCompletionStageWithExecutor.
@Test
public void testInvokesPostOperationWithRegisteredProvidersAsyncCompletionStageWithExecutor() throws Exception {
final String inputBody = "input body will be ignored";
wireMockRule.stubFor(put(urlEqualTo("/echo/test")).willReturn(aResponse().withBody(inputBody)));
AsyncInvocationInterceptorFactoryTestImpl.INBOUND.remove();
AsyncInvocationInterceptorFactoryTestImpl.OUTBOUND.remove();
try {
final String asyncThreadName = "CXF-MPRestClientThread-2";
AsyncClientWithCompletionStage api = RestClientBuilder.newBuilder().register(AsyncInvocationInterceptorFactoryTestImpl.class).register(AsyncInvocationInterceptorFactoryTestImpl2.class).register(ThreadLocalClientFilter.class).baseUri(getBaseUri()).executorService(Executors.newSingleThreadExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(r, asyncThreadName);
}
})).build(AsyncClientWithCompletionStage.class);
CompletionStage<Response> cs = api.put(inputBody);
List<String> outboundList = AsyncInvocationInterceptorFactoryTestImpl.OUTBOUND.get();
assertEquals(4, outboundList.size());
// ensure filters and asyncInvocationInterceptors are executed in the correct order and the correct thread
// outbound:
assertEquals(ThreadLocalClientFilter.class.getSimpleName(), outboundList.get(0));
assertEquals(AsyncInvocationInterceptorFactoryTestImpl.class.getSimpleName(), outboundList.get(1));
assertEquals(AsyncInvocationInterceptorFactoryTestImpl2.class.getSimpleName(), outboundList.get(2));
assertEquals(Thread.currentThread().getName(), outboundList.get(3));
// inbound:
// should need <1 second, but 20s timeout in case something goes wrong
Response response = cs.toCompletableFuture().get(20, TimeUnit.SECONDS);
List<String> responseList = response.getStringHeaders().get("CXFTestResponse");
assertEquals(4, responseList.size());
assertEquals(asyncThreadName, responseList.get(0));
assertEquals(AsyncInvocationInterceptorFactoryTestImpl2.class.getSimpleName(), responseList.get(1));
assertEquals(AsyncInvocationInterceptorFactoryTestImpl.class.getSimpleName(), responseList.get(2));
assertEquals(ThreadLocalClientFilter.class.getSimpleName(), responseList.get(3));
} finally {
AsyncInvocationInterceptorFactoryTestImpl.INBOUND.remove();
AsyncInvocationInterceptorFactoryTestImpl.OUTBOUND.remove();
}
}
Aggregations