ResponseBodyEmitter allows complete after non-IOException

Closes gh-30687
This commit is contained in:
rstoyanchev
2023-10-02 01:16:26 +01:00
parent 37d03e536f
commit a3636affa2
2 changed files with 46 additions and 16 deletions

View File

@@ -92,10 +92,9 @@ public class ResponseBodyEmitterTests {
}
@Test
void sendFailsAfterComplete() throws Exception {
void sendFailsAfterComplete() {
this.emitter.complete();
assertThatIllegalStateException().isThrownBy(() ->
this.emitter.send("foo"));
assertThatIllegalStateException().isThrownBy(() -> this.emitter.send("foo"));
}
@Test
@@ -143,14 +142,47 @@ public class ResponseBodyEmitterTests {
verify(this.handler).onCompletion(any());
verifyNoMoreInteractions(this.handler);
IOException failure = new IOException();
willThrow(failure).given(this.handler).send("foo", MediaType.TEXT_PLAIN);
assertThatIOException().isThrownBy(() ->
this.emitter.send("foo", MediaType.TEXT_PLAIN));
willThrow(new IOException()).given(this.handler).send("foo", MediaType.TEXT_PLAIN);
assertThatIOException().isThrownBy(() -> this.emitter.send("foo", MediaType.TEXT_PLAIN));
verify(this.handler).send("foo", MediaType.TEXT_PLAIN);
verifyNoMoreInteractions(this.handler);
}
@Test // gh-30687
void completeIgnoredAfterIOException() 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);
willThrow(new IOException()).given(this.handler).send("foo", MediaType.TEXT_PLAIN);
assertThatIOException().isThrownBy(() -> this.emitter.send("foo", MediaType.TEXT_PLAIN));
verify(this.handler).send("foo", MediaType.TEXT_PLAIN);
verifyNoMoreInteractions(this.handler);
this.emitter.complete();
verifyNoMoreInteractions(this.handler);
}
@Test // gh-30687
void completeAfterNonIOException() 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);
willThrow(new IllegalStateException()).given(this.handler).send("foo", MediaType.TEXT_PLAIN);
assertThatIllegalStateException().isThrownBy(() -> this.emitter.send("foo", MediaType.TEXT_PLAIN));
verify(this.handler).send("foo", MediaType.TEXT_PLAIN);
verifyNoMoreInteractions(this.handler);
this.emitter.complete();
verify(this.handler).complete();
verifyNoMoreInteractions(this.handler);
}
@Test
void onTimeoutBeforeHandlerInitialized() throws Exception {
Runnable runnable = mock();