Search in sources :

Example 26 with SseEventSource

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

the class SseEventSourceImplTest method testNoReconnectWhenRetryAfterIsReturned.

@Test
public void testNoReconnectWhenRetryAfterIsReturned() {
    try (SseEventSource eventSource = withNoReconnect(Type.RETRY_AFTER)) {
        eventSource.open();
        assertThat(eventSource.isOpen(), equalTo(false));
        await().atMost(Duration.ofMillis(3000L)).untilAsserted(() -> assertThat(eventSource.isOpen(), equalTo(true)));
        assertThat(events.size(), equalTo(1));
    }
}
Also used : SseEventSource(javax.ws.rs.sse.SseEventSource) Test(org.junit.Test)

Example 27 with SseEventSource

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

the class SseEventSourceImplTest method testReuseSameEventSourceSeveralTimes.

@Test
public void testReuseSameEventSourceSeveralTimes() {
    try (SseEventSource eventSource = withNoReconnect(Type.NO_CONTENT)) {
        eventSource.open();
        assertThat(eventSource.isOpen(), equalTo(false));
        eventSource.open();
        assertThat(eventSource.isOpen(), equalTo(false));
        assertThat(events.size(), equalTo(0));
    }
}
Also used : SseEventSource(javax.ws.rs.sse.SseEventSource) Test(org.junit.Test)

Example 28 with SseEventSource

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

the class SseEventSourceImplTest method testNoReconnectAndMixedEventsAreReceived.

@Test
public void testNoReconnectAndMixedEventsAreReceived() throws InterruptedException, IOException {
    try (SseEventSource eventSource = withNoReconnect(Type.EVENT_MIXED)) {
        eventSource.open();
        assertThat(eventSource.isOpen(), equalTo(true));
        // Allow the event processor to pull for events (150ms)
        Thread.sleep(150L);
    }
    await().atMost(Duration.ofMillis(500L)).untilAsserted(() -> assertThat(events.size(), equalTo(2)));
    assertThat(events.get(0).getName(), nullValue());
    assertThat(events.get(0).readData(), equalTo("just test data"));
    assertThat(events.get(1).getId(), equalTo("1"));
    assertThat(events.get(1).getReconnectDelay(), equalTo(10000L));
    assertThat(events.get(1).getComment(), equalTo("test comment"));
    assertThat(events.get(1).readData(), equalTo("test data"));
}
Also used : SseEventSource(javax.ws.rs.sse.SseEventSource) Test(org.junit.Test)

Example 29 with SseEventSource

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

the class SseEventSourceImplTest method testNoReconnectWhenNoContentIsReturned.

@Test
public void testNoReconnectWhenNoContentIsReturned() {
    try (SseEventSource eventSource = withNoReconnect(Type.NO_CONTENT)) {
        eventSource.open();
        assertThat(eventSource.isOpen(), equalTo(false));
        assertThat(events.size(), equalTo(0));
    }
}
Also used : SseEventSource(javax.ws.rs.sse.SseEventSource) Test(org.junit.Test)

Example 30 with SseEventSource

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

the class SseEventSourceImplTest method testReconnectAndNotAuthorized.

@Test
public void testReconnectAndNotAuthorized() throws InterruptedException, IOException {
    try (SseEventSource eventSource = withReconnect(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(2)));
    assertThat(events.size(), equalTo(0));
}
Also used : SseEventSource(javax.ws.rs.sse.SseEventSource) Test(org.junit.Test)

Aggregations

SseEventSource (javax.ws.rs.sse.SseEventSource)38 Test (org.junit.Test)34 WebTarget (javax.ws.rs.client.WebTarget)13 ArrayList (java.util.ArrayList)11 CountDownLatch (java.util.concurrent.CountDownLatch)4 JerseyTest (org.glassfish.jersey.test.JerseyTest)3 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 JsonObject (javax.json.JsonObject)1 Client (javax.ws.rs.client.Client)1 Response (javax.ws.rs.core.Response)1 InboundSseEvent (javax.ws.rs.sse.InboundSseEvent)1 Builder (javax.ws.rs.sse.SseEventSource.Builder)1 Book (org.apache.cxf.systest.jaxrs.resources.Book)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1