use of javax.ws.rs.sse.SseEventSource in project cxf by apache.
the class SseEventSourceImplTest method testNoReconnectAndNoEventsAreDetected.
@Test
public void testNoReconnectAndNoEventsAreDetected() throws InterruptedException, IOException {
try (SseEventSource eventSource = withNoReconnect(Type.EVENT_BAD_NEW_LINES)) {
eventSource.open();
assertThat(eventSource.isOpen(), equalTo(true));
// Allow the event processor to pull for events (150ms)
Thread.sleep(150L);
}
assertThat(events.size(), equalTo(0));
}
use of javax.ws.rs.sse.SseEventSource in project cxf by apache.
the class SseEventSourceImplTest method testConnectWithLastEventId.
@Test
public void testConnectWithLastEventId() throws InterruptedException, IOException {
try (SseEventSource eventSource = withNoReconnect(Type.EVENT_LAST_EVENT_ID, "10")) {
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("10"));
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 testNoReconnectAndCloseTheStreamWhileEventIsBeingReceived.
@Test
public void testNoReconnectAndCloseTheStreamWhileEventIsBeingReceived() throws InterruptedException, IOException {
try (SseEventSource eventSource = withNoReconnect(Type.BUSY)) {
eventSource.open();
assertThat(eventSource.isOpen(), equalTo(true));
// Allow the event processor to pull for events (200ms)
Thread.sleep(50L);
assertThat(eventSource.close(100L, TimeUnit.MILLISECONDS), equalTo(true));
assertThat(eventSource.isOpen(), equalTo(false));
}
}
use of javax.ws.rs.sse.SseEventSource in project jersey by jersey.
the class SseEventSinkToEventSourceTest method testWithSimpleSubscriber.
@Test
public void testWithSimpleSubscriber() {
transmitLatch = new CountDownLatch(MSG_COUNT);
final WebTarget endpoint = target().path("events");
final List<InboundSseEvent> results = new ArrayList<>();
try (final SseEventSource eventSource = SseEventSource.target(endpoint).build()) {
final CountDownLatch receivedLatch = new CountDownLatch(3 * MSG_COUNT);
eventSource.subscribe((event) -> {
results.add(event);
receivedLatch.countDown();
});
eventSource.open();
final boolean allTransmitted = transmitLatch.await(5000, TimeUnit.MILLISECONDS);
final boolean allReceived = receivedLatch.await(5000, TimeUnit.MILLISECONDS);
Assert.assertTrue(allTransmitted);
Assert.assertTrue(allReceived);
Assert.assertEquals(30, results.size());
} catch (final InterruptedException e) {
e.printStackTrace();
}
}
use of javax.ws.rs.sse.SseEventSource in project cxf by apache.
the class SseEventSourceImplTest method testTryToCloseWhileConnecting.
@Test
public void testTryToCloseWhileConnecting() throws ExecutionException, InterruptedException {
try (SseEventSource eventSource = withNoReconnect(Type.BUSY)) {
final Future<?> future = executor.submit(() -> eventSource.open());
// Wait a bit for open() to advance
Thread.sleep(50L);
eventSource.close();
assertThat(future.get(), equalTo(null));
assertThat(eventSource.isOpen(), equalTo(false));
}
}
Aggregations