use of jakarta.servlet.AsyncEvent in project spring-framework by spring-projects.
the class WebAsyncManagerErrorTests method startCallableProcessingErrorAndResumeThroughCallback.
@Test
public void startCallableProcessingErrorAndResumeThroughCallback() throws Exception {
StubCallable callable = new StubCallable();
WebAsyncTask<Object> webAsyncTask = new WebAsyncTask<>(callable);
webAsyncTask.onError(() -> 7);
this.asyncManager.startCallableProcessing(webAsyncTask);
Exception e = new Exception();
AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
this.asyncWebRequest.onError(event);
assertThat(this.asyncManager.hasConcurrentResult()).isTrue();
assertThat(this.asyncManager.getConcurrentResult()).isEqualTo(7);
assertThat(((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath()).isEqualTo("/test");
}
use of jakarta.servlet.AsyncEvent in project spring-framework by spring-projects.
the class WebAsyncManagerErrorTests method startDeferredResultProcessingAfterException.
@Test
public void startDeferredResultProcessingAfterException() throws Exception {
DeferredResult<Integer> deferredResult = new DeferredResult<>();
final Exception exception = new Exception();
DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptor() {
@Override
public <T> boolean handleError(NativeWebRequest request, DeferredResult<T> result, Throwable t) throws Exception {
throw exception;
}
};
this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
this.asyncManager.startDeferredResultProcessing(deferredResult);
Exception e = new Exception();
AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
this.asyncWebRequest.onError(event);
assertThat(this.asyncManager.hasConcurrentResult()).isTrue();
assertThat(this.asyncManager.getConcurrentResult()).isEqualTo(e);
assertThat(((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath()).isEqualTo("/test");
}
use of jakarta.servlet.AsyncEvent in project spring-framework by spring-projects.
the class StandardServletAsyncWebRequestTests method onCompletionHandlerAfterOnCompleteEvent.
@Test
public void onCompletionHandlerAfterOnCompleteEvent() throws Exception {
Runnable handler = mock(Runnable.class);
this.asyncRequest.addCompletionHandler(handler);
this.asyncRequest.startAsync();
this.asyncRequest.onComplete(new AsyncEvent(this.request.getAsyncContext()));
verify(handler).run();
assertThat(this.asyncRequest.isAsyncComplete()).isTrue();
}
use of jakarta.servlet.AsyncEvent in project spring-framework by spring-projects.
the class WebAsyncManagerErrorTests method startCallableProcessingAfterException.
@Test
public void startCallableProcessingAfterException() throws Exception {
StubCallable callable = new StubCallable();
Exception exception = new Exception();
CallableProcessingInterceptor interceptor = mock(CallableProcessingInterceptor.class);
Exception e = new Exception();
given(interceptor.handleError(this.asyncWebRequest, callable, e)).willThrow(exception);
this.asyncManager.registerCallableInterceptor("errorInterceptor", interceptor);
this.asyncManager.startCallableProcessing(callable);
AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
this.asyncWebRequest.onError(event);
assertThat(this.asyncManager.hasConcurrentResult()).isTrue();
assertThat(this.asyncManager.getConcurrentResult()).isEqualTo(exception);
assertThat(((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath()).isEqualTo("/test");
verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable);
}
use of jakarta.servlet.AsyncEvent in project spring-framework by spring-projects.
the class WebAsyncManagerErrorTests method startDeferredResultProcessingErrorAndComplete.
@Test
public void startDeferredResultProcessingErrorAndComplete() throws Exception {
DeferredResult<Integer> deferredResult = new DeferredResult<>();
DeferredResultProcessingInterceptor interceptor = mock(DeferredResultProcessingInterceptor.class);
Exception e = new Exception();
given(interceptor.handleError(this.asyncWebRequest, deferredResult, e)).willReturn(true);
this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
this.asyncManager.startDeferredResultProcessing(deferredResult);
AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
this.asyncWebRequest.onError(event);
this.asyncWebRequest.onComplete(event);
assertThat(this.asyncManager.hasConcurrentResult()).isTrue();
assertThat(this.asyncManager.getConcurrentResult()).isEqualTo(e);
verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, deferredResult);
verify(interceptor).preProcess(this.asyncWebRequest, deferredResult);
verify(interceptor).afterCompletion(this.asyncWebRequest, deferredResult);
}
Aggregations