use of javax.ws.rs.sse.SseEventSource in project cxf by apache.
the class SseEventSourceImplTest method testNoReconnectWillBeScheduledWhenClosed.
@Test
public void testNoReconnectWillBeScheduledWhenClosed() throws InterruptedException {
try (SseEventSource eventSource = withReconnect(Type.NO_SERVER)) {
eventSource.open();
assertThat(eventSource.isOpen(), equalTo(false));
eventSource.close(1L, TimeUnit.SECONDS);
// Sleep a little bit to make sure for reconnect to reschedule (after 100ms)
Thread.sleep(150L);
assertThat(errors.size(), equalTo(1));
}
}
use of javax.ws.rs.sse.SseEventSource in project cxf by apache.
the class SseEventSourceImplTest method testNoReconnectAndMultilineDataEventIsReceived.
@Test
public void testNoReconnectAndMultilineDataEventIsReceived() throws InterruptedException, IOException {
try (SseEventSource eventSource = withNoReconnect(Type.EVENT_MULTILINE_DATA)) {
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(1)));
assertThat(events.get(0).getName(), nullValue());
assertThat(events.get(0).readData(), equalTo("just test data\nin multiple lines"));
}
use of javax.ws.rs.sse.SseEventSource in project cxf by apache.
the class SseEventSourceImplTest method testNoReconnectAndJustDataEventIsReceived.
@Test
public void testNoReconnectAndJustDataEventIsReceived() throws InterruptedException, IOException {
try (SseEventSource eventSource = withNoReconnect(Type.EVENT_JUST_DATA)) {
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(1)));
assertThat(events.get(0).getName(), nullValue());
assertThat(events.get(0).readData(), equalTo("just test data"));
}
use of javax.ws.rs.sse.SseEventSource in project cxf by apache.
the class SseEventSourceImplTest method testNoReconnectAndOneEventReceived.
@Test
public void testNoReconnectAndOneEventReceived() throws InterruptedException, IOException {
try (SseEventSource eventSource = withNoReconnect(Type.EVENT)) {
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(1)));
assertThat(events.get(0).getId(), equalTo("1"));
assertThat(events.get(0).getReconnectDelay(), equalTo(10000L));
assertThat(events.get(0).getComment(), equalTo("test comment"));
assertThat(events.get(0).readData(), equalTo("test data"));
}
use of javax.ws.rs.sse.SseEventSource in project cxf by apache.
the class SseEventSourceImplTest method testNoReconnectAndJustEventNameIsReceived.
@Test
public void testNoReconnectAndJustEventNameIsReceived() throws InterruptedException, IOException {
final Map<String, Object> properties = Collections.singletonMap(SseEventSourceImpl.DISCARD_INCOMPLETE_EVENTS, false);
try (SseEventSource eventSource = withNoReconnect(Type.EVENT_JUST_NAME, properties)) {
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(1)));
assertThat(events.get(0).getName(), equalTo("just name"));
}
Aggregations