Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OutboundSseEvent is not correctly serialized #1006

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}