|
|
|
|
@ -16,6 +16,7 @@
@@ -16,6 +16,7 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.web.servlet.mvc.method.annotation; |
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
@ -372,6 +373,24 @@ class ReactiveTypeHandlerTests {
@@ -372,6 +373,24 @@ class ReactiveTypeHandlerTests {
|
|
|
|
|
assertThat(emitterHandler.getValuesAsText()).isEqualTo("The quick brown fox jumps over the lazy dog"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void failOnWriteShouldCompleteEmitter() throws Exception { |
|
|
|
|
|
|
|
|
|
Sinks.Many<String> sink = Sinks.many().unicast().onBackpressureBuffer(); |
|
|
|
|
ResponseBodyEmitter emitter = handleValue(sink.asFlux(), Flux.class, forClass(String.class)); |
|
|
|
|
|
|
|
|
|
ErroringEmitterHandler emitterHandler = new ErroringEmitterHandler(); |
|
|
|
|
emitter.initialize(emitterHandler); |
|
|
|
|
|
|
|
|
|
sink.tryEmitNext("The quick"); |
|
|
|
|
sink.tryEmitNext(" brown fox jumps over "); |
|
|
|
|
sink.tryEmitNext("the lazy dog"); |
|
|
|
|
sink.tryEmitComplete(); |
|
|
|
|
|
|
|
|
|
assertThat(emitterHandler.getHandlingStatus()).isEqualTo(HandlingStatus.ERROR); |
|
|
|
|
assertThat(emitterHandler.getFailure()).isInstanceOf(IOException.class); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void writeFluxOfString() throws Exception { |
|
|
|
|
|
|
|
|
|
@ -451,6 +470,10 @@ class ReactiveTypeHandlerTests {
@@ -451,6 +470,10 @@ class ReactiveTypeHandlerTests {
|
|
|
|
|
|
|
|
|
|
private final List<Object> values = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
private HandlingStatus handlingStatus; |
|
|
|
|
|
|
|
|
|
private Throwable failure; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<?> getValues() { |
|
|
|
|
return this.values; |
|
|
|
|
@ -460,22 +483,33 @@ class ReactiveTypeHandlerTests {
@@ -460,22 +483,33 @@ class ReactiveTypeHandlerTests {
|
|
|
|
|
return this.values.stream().map(Object::toString).collect(Collectors.joining()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public HandlingStatus getHandlingStatus() { |
|
|
|
|
return this.handlingStatus; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Throwable getFailure() { |
|
|
|
|
return this.failure; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void send(Object data, MediaType mediaType) { |
|
|
|
|
public void send(Object data, MediaType mediaType) throws IOException { |
|
|
|
|
this.values.add(data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void send(Set<ResponseBodyEmitter.DataWithMediaType> items) { |
|
|
|
|
public void send(Set<ResponseBodyEmitter.DataWithMediaType> items) throws IOException { |
|
|
|
|
items.forEach(item -> this.values.add(item.getData())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void complete() { |
|
|
|
|
this.handlingStatus = HandlingStatus.SUCCESS; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void completeWithError(Throwable failure) { |
|
|
|
|
this.handlingStatus = HandlingStatus.ERROR; |
|
|
|
|
this.failure = failure; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@ -491,6 +525,22 @@ class ReactiveTypeHandlerTests {
@@ -491,6 +525,22 @@ class ReactiveTypeHandlerTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private enum HandlingStatus { |
|
|
|
|
SUCCESS,ERROR |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static class ErroringEmitterHandler extends EmitterHandler { |
|
|
|
|
@Override |
|
|
|
|
public void send(Object data, MediaType mediaType) throws IOException { |
|
|
|
|
throw new IOException(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void send(Set<ResponseBodyEmitter.DataWithMediaType> items) throws IOException { |
|
|
|
|
throw new IOException(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static class Bar { |
|
|
|
|
|
|
|
|
|
private final String value; |
|
|
|
|
|