use of javax.ws.rs.ServiceUnavailableException in project oci-java-sdk by oracle.
the class CircuitBreakerConfigurationTest method validateCircuitBreakerConfigurationWithDefaultValues.
@Test
public void validateCircuitBreakerConfigurationWithDefaultValues() {
CircuitBreakerConfiguration config = CircuitBreakerConfiguration.builder().build();
JaxRsCircuitBreakerImpl circuitBreaker = new JaxRsCircuitBreakerImpl(config);
CircuitBreakerConfig internalConfig = circuitBreaker.getInternalCircuitBreakerConfig();
assertEquals(internalConfig.getFailureRateThreshold(), CircuitBreakerConfiguration.DEFAULT_FAILURE_RATE_THRESHOLD, 0.1);
assertEquals(internalConfig.getSlowCallRateThreshold(), CircuitBreakerConfiguration.DEFAULT_SLOW_CALL_RATE_THRESHOLD, 0.1);
assertEquals(internalConfig.getSlowCallDurationThreshold(), Duration.ofMinutes(CircuitBreakerConfiguration.DEFAULT_SLOW_CALL_DURATION_THRESHOLD));
assertEquals(internalConfig.getPermittedNumberOfCallsInHalfOpenState(), CircuitBreakerConfiguration.DEFAULT_PERMITTED_CALLS_IN_HALF_OPEN_STATE);
assertEquals(internalConfig.getSlidingWindowType(), CircuitBreakerConfig.SlidingWindowType.TIME_BASED);
assertEquals(internalConfig.getSlidingWindowSize(), CircuitBreakerConfiguration.DEFAULT_SLIDING_WINDOW_SIZE);
assertEquals(internalConfig.getMinimumNumberOfCalls(), CircuitBreakerConfiguration.DEFAULT_MINIMUM_NUMBER_OF_CALLS);
assertEquals(internalConfig.getWaitDurationInOpenState(), Duration.ofSeconds(CircuitBreakerConfiguration.DEFAULT_WAIT_DURATION_IN_OPEN_STATE));
assertTrue(internalConfig.isAutomaticTransitionFromOpenToHalfOpenEnabled());
Response response503 = mock(Response.class);
Mockito.when(response503.getStatus()).thenReturn(503);
HttpStatusErrorException ex = new HttpStatusErrorException(response503);
Predicate<Throwable> recordExceptionPredicate = internalConfig.getRecordExceptionPredicate();
assertTrue(recordExceptionPredicate.test(ex));
assertTrue(recordExceptionPredicate.test(new ServiceUnavailableException()));
assertTrue(recordExceptionPredicate.test(new InternalServerErrorException()));
assertTrue(recordExceptionPredicate.test(new ProcessingException("test")));
Set<Integer> recordHttpStatuses = circuitBreaker.getRecordHttpStatuses();
assertTrue(recordHttpStatuses.contains(CircuitBreakerConfiguration.INTERNAL_SERVER_ERROR));
assertTrue(recordHttpStatuses.contains(CircuitBreakerConfiguration.SERVICE_UNAVAILABLE));
assertTrue(recordHttpStatuses.contains(CircuitBreakerConfiguration.TOO_MANY_REQUESTS));
assertTrue(recordHttpStatuses.contains(CircuitBreakerConfiguration.BAD_GATEWAY));
assertTrue(recordHttpStatuses.contains(CircuitBreakerConfiguration.GATEWAY_TIMEOUT));
assertEquals(recordHttpStatuses.size(), 5);
}
use of javax.ws.rs.ServiceUnavailableException in project cxf by apache.
the class DateHeaderProviderTest method testToFromSimpleString.
@Test
public void testToFromSimpleString() {
Date retry = new Date();
ServiceUnavailableException ex = new ServiceUnavailableException(retry);
Date retry2 = ex.getRetryTime(new Date());
assertEquals(HttpUtils.toHttpDate(retry), HttpUtils.toHttpDate(retry2));
}
use of javax.ws.rs.ServiceUnavailableException in project jersey by jersey.
the class ItemStoreResource method itemEvents.
/**
* Connect or re-connect to SSE event stream.
*
* @param lastEventId Value of custom SSE HTTP <tt>{@value SseFeature#LAST_EVENT_ID_HEADER}</tt> header.
* Defaults to {@code -1} if not set.
* @return new SSE event output stream representing the (re-)established SSE client connection.
* @throws InternalServerErrorException in case replaying missed events to the reconnected output stream fails.
* @throws ServiceUnavailableException in case the reconnect delay is set to a positive value.
*/
@GET
@Path("events")
@Produces(SseFeature.SERVER_SENT_EVENTS)
public EventOutput itemEvents(@HeaderParam(SseFeature.LAST_EVENT_ID_HEADER) @DefaultValue("-1") int lastEventId) {
final EventOutput eventOutput = new EventOutput();
if (lastEventId >= 0) {
LOGGER.info("Received last event id :" + lastEventId);
// decide the reconnect handling strategy based on current reconnect delay value.
final long delay = reconnectDelay;
if (delay > 0) {
LOGGER.info("Non-zero reconnect delay [" + delay + "] - responding with HTTP 503.");
throw new ServiceUnavailableException(delay);
} else {
LOGGER.info("Zero reconnect delay - reconnecting.");
replayMissedEvents(lastEventId, eventOutput);
}
}
if (!broadcaster.add(eventOutput)) {
LOGGER.severe("!!! Unable to add new event output to the broadcaster !!!");
// let's try to force a 5s delayed client reconnect attempt
throw new ServiceUnavailableException(5L);
}
return eventOutput;
}
use of javax.ws.rs.ServiceUnavailableException in project jersey by jersey.
the class ItemStoreResource method itemEvents.
/**
* Connect or re-connect to SSE event stream.
*
* @param lastEventId Value of custom SSE HTTP <tt>{@value SseFeature#LAST_EVENT_ID_HEADER}</tt> header.
* Defaults to {@code -1} if not set.
* @return new SSE event output stream representing the (re-)established SSE client connection.
* @throws InternalServerErrorException in case replaying missed events to the reconnected output stream fails.
* @throws ServiceUnavailableException in case the reconnect delay is set to a positive value.
*/
@GET
@Path("events")
@Produces(SseFeature.SERVER_SENT_EVENTS)
public EventOutput itemEvents(@HeaderParam(SseFeature.LAST_EVENT_ID_HEADER) @DefaultValue("-1") int lastEventId) {
final EventOutput eventOutput = new EventOutput();
if (lastEventId >= 0) {
LOGGER.info("Received last event id :" + lastEventId);
// decide the reconnect handling strategy based on current reconnect delay value.
final long delay = reconnectDelay;
if (delay > 0) {
LOGGER.info("Non-zero reconnect delay [" + delay + "] - responding with HTTP 503.");
throw new ServiceUnavailableException(delay);
} else {
LOGGER.info("Zero reconnect delay - reconnecting.");
replayMissedEvents(lastEventId, eventOutput);
}
}
if (!broadcaster.add(eventOutput)) {
LOGGER.severe("!!! Unable to add new event output to the broadcaster !!!");
// let's try to force a 5s delayed client reconnect attempt
throw new ServiceUnavailableException(5L);
}
return eventOutput;
}
use of javax.ws.rs.ServiceUnavailableException in project robozonky by RoboZonky.
the class SessionTest method investmentFailed.
@Test
void investmentFailed() {
final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
final Authenticated auth = mockAuthentication(z);
final RecommendedLoan r = AbstractZonkyLeveragingTest.mockLoanDescriptor().recommend(200).get();
final Exception thrown = new ServiceUnavailableException();
final Investor p = mock(Investor.class);
doThrow(thrown).when(p).invest(eq(r), anyBoolean());
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final Session t = new Session(portfolio, Collections.emptySet(), p, auth);
assertThatThrownBy(() -> t.invest(r)).isSameAs(thrown);
}
Aggregations