use of javax.ws.rs.sse.SseEventSource in project cxf by apache.
the class AbstractSseTest method testNoDataIsReturnedFromInboundSseEvents.
@Test
public void testNoDataIsReturnedFromInboundSseEvents() throws InterruptedException {
final WebTarget target = createWebTarget("/rest/api/bookstore/nodata");
final Collection<Book> books = new ArrayList<>();
try (SseEventSource eventSource = SseEventSource.target(target).build()) {
eventSource.register(collect(books), System.out::println);
eventSource.open();
// Give the SSE stream some time to collect all events
Thread.sleep(1000);
}
// Easing the test verification here, it does not work well for Atm + Jetty
assertTrue(books.isEmpty());
}
use of javax.ws.rs.sse.SseEventSource in project cxf by apache.
the class AbstractSseTest method testBookTitlesStreamIsReturnedFromInboundSseEvents.
@Test
public void testBookTitlesStreamIsReturnedFromInboundSseEvents() throws InterruptedException {
final WebTarget target = createWebTarget("/rest/api/bookstore/titles/sse");
final Collection<String> titles = new ArrayList<>();
try (SseEventSource eventSource = SseEventSource.target(target).build()) {
eventSource.register(collectRaw(titles), System.out::println);
eventSource.open();
// Give the SSE stream some time to collect all events
awaitEvents(5000, titles, 4);
}
// Easing the test verification here, it does not work well for Atm + Jetty
assertThat(titles, hasItems("New Book #1", "New Book #2", "New Book #3", "New Book #4"));
}
use of javax.ws.rs.sse.SseEventSource in project cxf by apache.
the class AbstractSseTest method testBooksStreamIsReturnedFromInboundSseEvents.
@Test
public void testBooksStreamIsReturnedFromInboundSseEvents() throws InterruptedException {
final WebTarget target = createWebTarget("/rest/api/bookstore/sse/0");
final Collection<Book> books = new ArrayList<>();
try (SseEventSource eventSource = SseEventSource.target(target).build()) {
eventSource.register(collect(books), System.out::println);
eventSource.open();
// Give the SSE stream some time to collect all events
awaitEvents(5000, books, 4);
}
// Easing the test verification here, it does not work well for Atm + Jetty
assertThat(books, hasItems(new Book("New Book #1", 1), new Book("New Book #2", 2), new Book("New Book #3", 3), new Book("New Book #4", 4)));
}
use of javax.ws.rs.sse.SseEventSource in project cxf by apache.
the class SseEventSourceImplTest method testNoReconnectAndNotAuthorized.
@Test
public void testNoReconnectAndNotAuthorized() throws InterruptedException, IOException {
try (SseEventSource eventSource = withNoReconnect(Type.EVENT_NOT_AUTHORIZED)) {
eventSource.open();
assertThat(eventSource.isOpen(), equalTo(false));
assertThat(errors.size(), equalTo(1));
// Allow the event processor to pull for events (150ms)
Thread.sleep(150L);
}
await().atMost(Duration.ofMillis(500L)).untilAsserted(() -> assertThat(errors.size(), equalTo(1)));
assertThat(events.size(), equalTo(0));
}
use of javax.ws.rs.sse.SseEventSource in project cxf by apache.
the class SseEventSourceImplTest method withNoReconnect.
private SseEventSource withNoReconnect(Type type, String lastEventId, Map<String, Object> properties) {
SseEventSource eventSource = SseEventSource.target(target(type, lastEventId, properties)).build();
eventSource.register(events::add, errors::add);
return eventSource;
}
Aggregations