-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug: Reactive Stream error handling is incorrect (#482)
* Add test for error handling [skip ci] * Potential fix
- Loading branch information
Showing
2 changed files
with
134 additions
and
36 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
http-server-jetty/src/test/groovy/io/micronaut/servlet/jetty/StreamErrorSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.micronaut.servlet.jetty | ||
|
||
import io.micronaut.context.annotation.Property | ||
import io.micronaut.context.annotation.Requires | ||
import io.micronaut.http.HttpHeaders | ||
import io.micronaut.http.HttpRequest | ||
import io.micronaut.http.HttpStatus | ||
import io.micronaut.http.MediaType | ||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import io.micronaut.http.client.HttpClient | ||
import io.micronaut.http.client.annotation.Client | ||
import io.micronaut.http.client.exceptions.HttpClientResponseException | ||
import io.micronaut.http.exceptions.HttpStatusException | ||
import io.micronaut.test.extensions.spock.annotation.MicronautTest | ||
import jakarta.inject.Inject | ||
import org.reactivestreams.Publisher | ||
import reactor.core.publisher.Flux | ||
import spock.lang.Specification | ||
|
||
@MicronautTest | ||
@Property(name = "spec.name", value = SPEC_NAME) | ||
class StreamErrorSpec extends Specification { | ||
|
||
static final String SPEC_NAME = "StreamErrorSpec" | ||
|
||
@Inject | ||
@Client("/") | ||
HttpClient client; | ||
|
||
void "status error as first item"() { | ||
when: | ||
def response = client.toBlocking().exchange(HttpRequest.GET("/stream-error/status-error-as-first-item"), String) | ||
|
||
then: | ||
def e = thrown(HttpClientResponseException) | ||
e.response.status == HttpStatus.NOT_FOUND | ||
e.response.body() == "foo" | ||
} | ||
|
||
void "immediate status error"() { | ||
when: | ||
def response = client.toBlocking().exchange(HttpRequest.GET("/stream-error/status-error-immediate"), String) | ||
|
||
then: | ||
def e = thrown(HttpClientResponseException) | ||
e.response.status == HttpStatus.NOT_FOUND | ||
e.response.body() == "foo" | ||
} | ||
|
||
@Controller("/stream-error") | ||
@Requires(property = "spec.name", value = SPEC_NAME) | ||
static class StreamController { | ||
|
||
@Get(uri = "/status-error-as-first-item") | ||
Publisher<String> statusErrorAsFirstItem() { | ||
return Flux.error(new HttpStatusException(HttpStatus.NOT_FOUND, (Object) "foo")); | ||
} | ||
|
||
@Get(uri = "/status-error-immediate") | ||
Publisher<String> statusErrorImmediate() { | ||
throw new HttpStatusException(HttpStatus.NOT_FOUND, (Object) "foo"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters