Cancel WebAsyncManager thread on request timeout

Issue: SPR-15852
This commit is contained in:
Rossen Stoyanchev
2017-08-16 09:26:21 +02:00
parent 9c3bd8ce85
commit 8b7a670821
3 changed files with 51 additions and 1 deletions

View File

@@ -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 {