Skip to content
Draft
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,5 +1,5 @@
/*
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,7 @@

class SseBaseTest {

private static final System.Logger LOGGER = System.getLogger(SseBaseTest.class.getName());
private final WebServer webServer;

SseBaseTest() {
Expand Down Expand Up @@ -62,11 +63,14 @@ static void sseString2(ServerRequest req, ServerResponse res) throws Interrupted
}

static void sseJson1(ServerRequest req, ServerResponse res) {
LOGGER.log(System.Logger.Level.ERROR, "sseJson1 called");
JsonObject json = Json.createObjectBuilder()
.add("hello", "world")
.build();
try (SseSink sseSink = res.sink(SseSink.TYPE)) {
LOGGER.log(System.Logger.Level.ERROR, "sseJson1 sseSink called");
sseSink.emit(SseEvent.create(json));
LOGGER.log(System.Logger.Level.ERROR, "sseJson1 emit called");
}
}

Expand All @@ -84,10 +88,13 @@ public void setHello(String hello) {
}

static void sseJson2(ServerRequest req, ServerResponse res) {
LOGGER.log(System.Logger.Level.ERROR, "sseJson2 called");
SseServerTest.HelloWorld json = new SseServerTest.HelloWorld();
json.setHello("world");
try (SseSink sseSink = res.sink(SseSink.TYPE)) {
LOGGER.log(System.Logger.Level.ERROR, "sseJson2 sseSink called");
sseSink.emit(SseEvent.create(json));
LOGGER.log(System.Logger.Level.ERROR, "sseJson2 emit called");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
@Disabled
class SseClientTest extends SseBaseTest {

private static final System.Logger LOGGER = System.getLogger(SseClientTest.class.getName());
private final Http1Client client;

SseClientTest(WebServer webServer, Http1Client client) {
Expand Down Expand Up @@ -145,9 +146,12 @@ public void onClose() {

@Test
void testSseJson1() throws InterruptedException {
LOGGER.log(System.Logger.Level.ERROR, "testSseJson1 called");
try (Http1ClientResponse r = client.get("/sseJson1").header(ACCEPT_EVENT_STREAM).request()) {
LOGGER.log(System.Logger.Level.ERROR, "testSseJson1 client called");
CountDownLatch latch = new CountDownLatch(1);
r.source(SseSource.TYPE, event -> {
LOGGER.log(System.Logger.Level.ERROR, "testSseJson1 source called");
JsonObject json = event.data(JsonObject.class);
assertThat(json, is(notNullValue()));
assertThat(json.getString("hello"), is("world"));
Expand All @@ -159,9 +163,12 @@ void testSseJson1() throws InterruptedException {

@Test
void testSseJson2() throws InterruptedException {
LOGGER.log(System.Logger.Level.ERROR, "testSseJson2 called");
try (Http1ClientResponse r = client.get("/sseJson2").header(ACCEPT_EVENT_STREAM).request()) {
LOGGER.log(System.Logger.Level.ERROR, "testSseJson2 client called");
CountDownLatch latch = new CountDownLatch(1);
r.source(SseSource.TYPE, event -> {
LOGGER.log(System.Logger.Level.ERROR, "testSseJson2 source called");
HelloWorld json = event.data(HelloWorld.class, MediaTypes.APPLICATION_JSON);
assertThat(json, is(notNullValue()));
assertThat(json.getHello(), is("world"));
Expand Down
Loading