Cancel WebAsyncManager thread on request timeout
Issue: SPR-15852
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.web.context.request.async;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import javax.servlet.AsyncEvent;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -30,9 +31,12 @@ import org.springframework.web.context.request.NativeWebRequest;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.mock;
|
||||
import static org.mockito.BDDMockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.web.context.request.async.CallableProcessingInterceptor.RESULT_NONE;
|
||||
|
||||
/**
|
||||
@@ -151,6 +155,27 @@ public class WebAsyncManagerTimeoutTests {
|
||||
verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void startCallableProcessingTimeoutAndCheckThreadInterrupted() throws Exception {
|
||||
|
||||
StubCallable callable = new StubCallable();
|
||||
Future future = mock(Future.class);
|
||||
|
||||
AsyncTaskExecutor executor = mock(AsyncTaskExecutor.class);
|
||||
when(executor.submit(any(Runnable.class))).thenReturn(future);
|
||||
|
||||
this.asyncManager.setTaskExecutor(executor);
|
||||
this.asyncManager.startCallableProcessing(callable);
|
||||
|
||||
this.asyncWebRequest.onTimeout(ASYNC_EVENT);
|
||||
|
||||
assertTrue(this.asyncManager.hasConcurrentResult());
|
||||
|
||||
verify(future).cancel(true);
|
||||
verifyNoMoreInteractions(future);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startDeferredResultProcessingTimeoutAndComplete() throws Exception {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user