|
1 | 1 | package io.quarkus.resteasy.reactive.server.test.compress;
|
2 | 2 |
|
3 | 3 | import static io.restassured.RestAssured.get;
|
| 4 | +import static org.hamcrest.core.IsNull.nullValue; |
4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
5 | 6 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
6 | 7 |
|
7 | 8 | import jakarta.ws.rs.GET;
|
8 | 9 | import jakarta.ws.rs.Path;
|
9 | 10 | import jakarta.ws.rs.Produces;
|
| 11 | +import jakarta.ws.rs.core.MediaType; |
| 12 | +import jakarta.ws.rs.sse.Sse; |
| 13 | +import jakarta.ws.rs.sse.SseEventSink; |
10 | 14 |
|
11 | 15 | import org.hamcrest.CoreMatchers;
|
12 | 16 | import org.jboss.resteasy.reactive.RestResponse;
|
@@ -52,6 +56,19 @@ public void noContent() {
|
52 | 56 | assertNoContent("/endpoint/void-no-content");
|
53 | 57 | }
|
54 | 58 |
|
| 59 | + @Test |
| 60 | + public void testStream() { |
| 61 | + get("/endpoint/stream-uncompressed") |
| 62 | + .then() |
| 63 | + .statusCode(200) |
| 64 | + .header("Content-Encoding", nullValue()); |
| 65 | + |
| 66 | + get("/endpoint/stream-compressed") |
| 67 | + .then() |
| 68 | + .statusCode(200) |
| 69 | + .header("Content-Encoding", "gzip"); |
| 70 | + } |
| 71 | + |
55 | 72 | private void assertCompressed(String path) {
|
56 | 73 | String bodyStr = get(path).then().statusCode(200).header("Content-Encoding", "gzip").extract().asString();
|
57 | 74 | assertEquals(MyEndpoint.MESSAGE, bodyStr);
|
@@ -147,6 +164,29 @@ public RestResponse<Void> noContent() {
|
147 | 164 | public void voidNoContent() {
|
148 | 165 |
|
149 | 166 | }
|
| 167 | + |
| 168 | + @GET |
| 169 | + @Produces(MediaType.SERVER_SENT_EVENTS) |
| 170 | + @Path("stream-uncompressed") |
| 171 | + public void uncompressedSseSink(Sse sse, SseEventSink sink) { |
| 172 | + doSend(sse, sink); |
| 173 | + } |
| 174 | + |
| 175 | + @GET |
| 176 | + @Produces(MediaType.SERVER_SENT_EVENTS) |
| 177 | + @Compressed |
| 178 | + @Path("stream-compressed") |
| 179 | + public void compressedSseSink(Sse sse, SseEventSink sink) { |
| 180 | + doSend(sse, sink); |
| 181 | + } |
| 182 | + |
| 183 | + private void doSend(Sse sse, SseEventSink sink) { |
| 184 | + for (var i = 0; i < 1000; i++) { |
| 185 | + var event = sse.newEventBuilder().data(String.class, MESSAGE).build(); |
| 186 | + sink.send(event); |
| 187 | + } |
| 188 | + sink.close(); |
| 189 | + } |
150 | 190 | }
|
151 | 191 |
|
152 | 192 | }
|
0 commit comments