Skip to content

Commit

Permalink
OutboundSseEvent is not correctly serialized
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo gonzalez granados committed Jan 19, 2023
1 parent c0cecb4 commit 99b5eb1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package io.quarkus.ts.opentelemetry.reactive.sse;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.sse.OutboundSseEvent;
import javax.ws.rs.sse.Sse;

import org.eclipse.microprofile.rest.client.inject.RestClient;

Expand All @@ -24,4 +31,16 @@ public Multi<String> getPing() {
recordTraceId();
return pongClient.getPong().map(response -> "ping " + response);
}

@Path("/raw")
@GET
@Produces(MediaType.SERVER_SENT_EVENTS)
public Multi<OutboundSseEvent> sseRaw(@Context Sse sse, @QueryParam("amount") int amount) {
List<OutboundSseEvent> events = new ArrayList<>(amount);
for (int i = 0; i < amount; i++) {
events.add(sse.newEventBuilder().id("id_" + i).data("data_" + i).name("name_" + i).build());
}

return Multi.createFrom().items(events.toArray(OutboundSseEvent[]::new));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

import java.util.concurrent.TimeUnit;

import javax.ws.rs.core.MediaType;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import io.quarkus.test.bootstrap.JaegerService;
Expand Down Expand Up @@ -53,12 +56,24 @@ public void testServerClientTrace() throws InterruptedException {
.and().body(allOf(containsString(PING_ENDPOINT), containsString(PONG_ENDPOINT))));
}

@Tag("QUARKUS-2745")
@Test
public void verifySeeRawSerialization() {
final int amount = 3;
given()
.when().get(PING_ENDPOINT + "/raw?amount=" + amount)
.then().statusCode(HttpStatus.SC_OK)
.contentType(MediaType.SERVER_SENT_EVENTS)
.body(containsString("data:data_0"))
.body(containsString("id:id_1"))
.body(containsString("event:name_2"));
}

protected void assertTraceIdWithPongService(String expected) {
String pongTraceId = given()
.when().get(PONG_ENDPOINT + "/lastTraceId")
.then().statusCode(HttpStatus.SC_OK).and().extract().asString();

assertEquals(expected, pongTraceId);
}

}

0 comments on commit 99b5eb1

Please sign in to comment.