Add onError callback to DeferredResult
Issue: SPR-15614
This commit is contained in:
committed by
Rossen Stoyanchev
parent
140542e8b1
commit
e0678ba583
@@ -22,6 +22,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -380,6 +381,10 @@ public class ReactiveTypeHandlerTests {
|
||||
public void onTimeout(Runnable callback) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Consumer<Throwable> callback) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompletion(Runnable callback) {
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -175,6 +176,25 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
|
||||
verify(asyncWebRequest).startAsync();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void responseBodyEmitterWithErrorValue() throws Exception {
|
||||
|
||||
AsyncWebRequest asyncWebRequest = mock(AsyncWebRequest.class);
|
||||
WebAsyncUtils.getAsyncManager(this.request).setAsyncWebRequest(asyncWebRequest);
|
||||
|
||||
ResponseBodyEmitter emitter = new ResponseBodyEmitter(19000L);
|
||||
emitter.onError(mock(Consumer.class));
|
||||
emitter.onCompletion(mock(Runnable.class));
|
||||
|
||||
MethodParameter type = on(TestController.class).resolveReturnType(ResponseBodyEmitter.class);
|
||||
this.handler.handleReturnValue(emitter, type, this.mavContainer, this.webRequest);
|
||||
|
||||
verify(asyncWebRequest).addErrorHandler(any(Consumer.class));
|
||||
verify(asyncWebRequest, times(2)).addCompletionHandler(any(Runnable.class));
|
||||
verify(asyncWebRequest).startAsync();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sseEmitter() throws Exception {
|
||||
MethodParameter type = on(TestController.class).resolveReturnType(SseEmitter.class);
|
||||
|
||||
@@ -102,6 +102,7 @@ public class ResponseBodyEmitterTests {
|
||||
public void sendAfterHandlerInitialized() throws Exception {
|
||||
this.emitter.initialize(this.handler);
|
||||
verify(this.handler).onTimeout(any());
|
||||
verify(this.handler).onError(any());
|
||||
verify(this.handler).onCompletion(any());
|
||||
verifyNoMoreInteractions(this.handler);
|
||||
|
||||
@@ -119,6 +120,7 @@ public class ResponseBodyEmitterTests {
|
||||
public void sendAfterHandlerInitializedWithError() throws Exception {
|
||||
this.emitter.initialize(this.handler);
|
||||
verify(this.handler).onTimeout(any());
|
||||
verify(this.handler).onError(any());
|
||||
verify(this.handler).onCompletion(any());
|
||||
verifyNoMoreInteractions(this.handler);
|
||||
|
||||
@@ -137,6 +139,7 @@ public class ResponseBodyEmitterTests {
|
||||
public void sendWithError() throws Exception {
|
||||
this.emitter.initialize(this.handler);
|
||||
verify(this.handler).onTimeout(any());
|
||||
verify(this.handler).onError(any());
|
||||
verify(this.handler).onCompletion(any());
|
||||
verifyNoMoreInteractions(this.handler);
|
||||
|
||||
@@ -150,7 +153,6 @@ public class ResponseBodyEmitterTests {
|
||||
// expected
|
||||
}
|
||||
verify(this.handler).send("foo", MediaType.TEXT_PLAIN);
|
||||
verify(this.handler).completeWithError(failure);
|
||||
verifyNoMoreInteractions(this.handler);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.web.servlet.mvc.method.annotation;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -152,6 +153,10 @@ public class SseEmitterTests {
|
||||
public void onTimeout(Runnable callback) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Consumer<Throwable> callback) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompletion(Runnable callback) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user