Allow setting timeout in ResponseBodyEmitter

Issue: SPR-13104
This commit is contained in:
Rossen Stoyanchev
2015-06-10 14:47:24 -04:00
parent 4611d058c8
commit 9712a32c46
4 changed files with 57 additions and 9 deletions

View File

@@ -15,6 +15,10 @@
*/
package org.springframework.web.servlet.mvc.method.annotation;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.springframework.web.servlet.mvc.method.annotation.SseEmitter.*;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
@@ -38,13 +42,6 @@ import org.springframework.web.context.request.async.StandardServletAsyncWebRequ
import org.springframework.web.context.request.async.WebAsyncUtils;
import org.springframework.web.method.support.ModelAndViewContainer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.springframework.web.servlet.mvc.method.annotation.SseEmitter.event;
/**
* Unit tests for ResponseBodyEmitterReturnValueHandler.
@@ -126,6 +123,25 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
assertNotNull(asyncContext.getDispatchedPath());
}
@Test
public void timeoutValueAndCallback() throws Exception {
AsyncWebRequest asyncWebRequest = mock(AsyncWebRequest.class);
WebAsyncUtils.getAsyncManager(this.request).setAsyncWebRequest(asyncWebRequest);
ResponseBodyEmitter emitter = new ResponseBodyEmitter(19000L);
emitter.onTimeout(mock(Runnable.class));
emitter.onCompletion(mock(Runnable.class));
MethodParameter returnType = returnType(TestController.class, "handle");
this.handler.handleReturnValue(emitter, returnType, this.mavContainer, this.webRequest);
verify(asyncWebRequest).setTimeout(19000L);
verify(asyncWebRequest).addTimeoutHandler(any(Runnable.class));
verify(asyncWebRequest, times(2)).addCompletionHandler(any(Runnable.class));
verify(asyncWebRequest).startAsync();
}
@Test
public void sseEmitter() throws Exception {
MethodParameter returnType = returnType(TestController.class, "handleSse");