use of ee.jakarta.tck.ws.rs.common.util.Holder in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method connectionLostFor1500msTest.
/*
* @testName: connectionLostFor1500msTest
*
* @assertion_ids: JAXRS:JAVADOC:1242; JAXRS:JAVADOC:1197; JAXRS:JAVADOC:1198;
* JAXRS:JAVADOC:1199; JAXRS:JAVADOC:1200; JAXRS:JAVADOC:1201;
* JAXRS:JAVADOC:1202; JAXRS:JAVADOC:1241; JAXRS:JAVADOC:1240;
* JAXRS:JAVADOC:1236;
*
* @test_Strategy: reconnectingEvery should send request to the server just
* twice, once without response, once after reconnect timeout with a response
*/
@Test
public void connectionLostFor1500msTest() throws Fault {
resetUnavailableServer();
// set to wait 3 seconds
setRequestContentEntity("1");
setProperty(Property.REQUEST, buildRequest(Request.POST, "su/lost"));
setProperty(Property.REQUEST_HEADERS, buildContentType(MediaType.TEXT_PLAIN_TYPE));
setProperty(Property.SEARCH_STRING, "1");
invoke();
Holder<InboundSseEvent> holder = new Holder<>();
WebTarget target = ClientBuilder.newClient().target(getAbsoluteUrl("su/sselost"));
try (SseEventSource source = SseEventSource.target(target).reconnectingEvery(2000L, TimeUnit.MILLISECONDS).build()) {
source.register(holder::set);
source.open();
sleep = sleepUntilHolderGetsFilled(holder);
}
int cnt = getServerCount();
logTrace("Slept for", sleep * millis, "ms");
assertNotNull(holder.get(), "Message not received, reconnect was done", cnt - 1, "times.");
logTrace("Received message", holder.get().readData());
assertTrue(sleep > 3, "The message has been sent unexpectedly soon, sooner then 2000ms");
assertTrue(sleep < 5, "The message has been sent unexpectedly late, after 3000ms");
assertEquals(SSEMessage.MESSAGE, holder.get().readData(), "Unexpected message received", holder.get().readData());
assertEquals(cnt, 2, "Server was reconnected", cnt, "times, unexpectedly");
}
use of ee.jakarta.tck.ws.rs.common.util.Holder in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method defaultWaiting1s.
/* Run test */
/*
* @testName: defaultWaiting1s
*
* @assertion_ids: JAXRS:JAVADOC:1197; JAXRS:JAVADOC:1198; JAXRS:JAVADOC:1199;
* JAXRS:JAVADOC:1200; JAXRS:JAVADOC:1201; JAXRS:JAVADOC:1202;
* JAXRS:JAVADOC:1241; JAXRS:JAVADOC:1240; JAXRS:JAVADOC:1236;
*
* @test_Strategy: In addition to handling the standard connection loss
* failures, JAX-RS SseEventSource automatically deals with any HTTP 503
* Service Unavailable responses from an SSE endpoint, that contain a
* "Retry-After" HTTP header with a valid value. The HTTP 503 + "Retry-After"
* technique is often used by HTTP endpoints as a means of connection and
* traffic throttling. In case a HTTP 503 + "Retry-After" response is received
* in return to a connection request, JAX-RS SSE event source will
* automatically schedule a new reconnect attempt and use the received
* "Retry-After" HTTP header value as a one-time override of the reconnect
* delay.
*/
@Test
public void defaultWaiting1s() throws Fault {
// define
Holder<InboundSseEvent> holder = new Holder<>();
WebTarget target = ClientBuilder.newClient().target(getAbsoluteUrl("su/sse"));
// check its working
try (SseEventSource source = SseEventSource.target(target).build()) {
source.register(holder::set);
source.open();
sleepUntilHolderGetsFilled(holder);
} catch (Exception e) {
throw new Fault(e);
}
assertNotNull(holder.get(), "Holder was not filled");
logTrace("Received message", holder.get().readData());
holder.set(null);
// set to return 503
setProperty(Property.REQUEST, buildRequest(Request.GET, "su/available"));
setProperty(Property.SEARCH_STRING, "OK");
invoke();
try (SseEventSource source = SseEventSource.target(target).build()) {
source.register(holder::set);
source.open();
} catch (Exception e) {
throw new Fault(e);
}
assertNull(holder.get(), "The event should be sent after default 1s in retry, not sooner");
// SseEventSource.close() has been called
// set to return 503
setProperty(Property.REQUEST, buildRequest(Request.GET, "su/available"));
setProperty(Property.SEARCH_STRING, "OK");
invoke();
holder = querySSEEndpoint("su/sse");
logTrace("Received message", holder.get().readData());
logTrace("Slept for", sleep * millis, "ms");
assertTrue(sleep < 4, "The message has been sent unexpectedly late, after 2000ms");
}
use of ee.jakarta.tck.ws.rs.common.util.Holder in project jaxrs-api by eclipse-ee4j.
the class SSEJAXRSClient method querySSEEndpoint.
protected Holder<InboundSseEvent> querySSEEndpoint(String endpoint, BiConsumer<SseEventSource, Holder<InboundSseEvent>> registrator) throws Fault {
Holder<InboundSseEvent> holder = new Holder<>();
WebTarget target = ClientBuilder.newClient().target(getAbsoluteUrl(endpoint));
try (SseEventSource source = SseEventSource.target(target).build()) {
registrator.accept(source, holder);
source.open();
sleep = sleepUntilHolderGetsFilled(holder);
assertTrue(source.isOpen(), "SseEventSource#isOpen returns false");
// } catch (Fault f) {
// throw f;
} catch (Exception e) {
throw new Fault(e);
}
assertNotNull(holder.get(), "The message was not received");
return holder;
}
Aggregations