Search in sources :

Example 1 with Builder

use of javax.ws.rs.sse.SseEventSource.Builder in project cxf by apache.

the class AbstractSseTest method testBooksStreamIsReconnectedFromInboundSseEvents.

@Test
public void testBooksStreamIsReconnectedFromInboundSseEvents() throws InterruptedException {
    final WebTarget target = createWebTarget("/rest/api/bookstore/sse/0");
    final Collection<Book> books = new ArrayList<>();
    final Builder builder = SseEventSource.target(target).reconnectingEvery(1, TimeUnit.SECONDS);
    try (SseEventSource eventSource = builder.build()) {
        eventSource.register(collect(books), System.out::println);
        eventSource.open();
        // Give the SSE stream some time to collect all events
        awaitEvents(5000, books, 12);
    }
    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), new Book("New Book #5", 5), new Book("New Book #6", 6), new Book("New Book #7", 7), new Book("New Book #8", 8), new Book("New Book #9", 9), new Book("New Book #10", 10), new Book("New Book #11", 11), new Book("New Book #12", 12)));
}
Also used : SseEventSource(javax.ws.rs.sse.SseEventSource) Builder(javax.ws.rs.sse.SseEventSource.Builder) ArrayList(java.util.ArrayList) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 WebTarget (javax.ws.rs.client.WebTarget)1 SseEventSource (javax.ws.rs.sse.SseEventSource)1 Builder (javax.ws.rs.sse.SseEventSource.Builder)1 Test (org.junit.Test)1