Search in sources :

Example 6 with RetryPolicy

use of com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicy in project styx by ExpediaGroup.

the class StyxBackendServiceClientTest method mockRetryPolicy.

private RetryPolicy mockRetryPolicy(Boolean first, Boolean... outcomes) {
    RetryPolicy retryPolicy = mock(RetryPolicy.class);
    RetryPolicy.Outcome retryOutcome = mock(RetryPolicy.Outcome.class);
    when(retryOutcome.shouldRetry()).thenReturn(first, outcomes);
    RetryPolicy.Outcome[] retryOutcomes = stream(outcomes).map(outcome -> retryOutcome).toArray(RetryPolicy.Outcome[]::new);
    when(retryPolicy.evaluate(any(RetryPolicy.Context.class), any(LoadBalancer.class), any(LoadBalancer.Preferences.class))).thenReturn(retryOutcome).thenReturn(retryOutcome, retryOutcomes);
    return retryPolicy;
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) StepVerifier(reactor.test.StepVerifier) LiveHttpResponse.response(com.hotels.styx.api.LiveHttpResponse.response) Processor(org.reactivestreams.Processor) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) RemoteHost.remoteHost(com.hotels.styx.api.extension.RemoteHost.remoteHost) Support.requestContext(com.hotels.styx.support.Support.requestContext) Context(com.hotels.styx.api.HttpInterceptor.Context) Arrays.asList(java.util.Arrays.asList) Matchers.eq(org.mockito.Matchers.eq) StickySessionConfig.stickySessionDisabled(com.hotels.styx.api.extension.service.StickySessionConfig.stickySessionDisabled) LiveHttpRequest.get(com.hotels.styx.api.LiveHttpRequest.get) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) BAD_REQUEST(com.hotels.styx.api.HttpResponseStatus.BAD_REQUEST) HttpHandler(com.hotels.styx.api.HttpHandler) OriginUnreachableException(com.hotels.styx.api.exceptions.OriginUnreachableException) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) HttpHeaderNames(com.hotels.styx.api.HttpHeaderNames) LoadBalancer(com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer) Test(org.junit.jupiter.api.Test) Matchers.any(org.mockito.Matchers.any) CHUNKED(com.hotels.styx.api.HttpHeaderNames.CHUNKED) CONTENT_LENGTH(com.hotels.styx.api.HttpHeaderNames.CONTENT_LENGTH) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Mockito.inOrder(org.mockito.Mockito.inOrder) Origin(com.hotels.styx.api.extension.Origin) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) RequestCookie.requestCookie(com.hotels.styx.api.RequestCookie.requestCookie) Arrays.stream(java.util.Arrays.stream) Mockito.mock(org.mockito.Mockito.mock) RetryPolicy(com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicy) GENERIC_APP(com.hotels.styx.api.Id.GENERIC_APP) StickySessionConfig(com.hotels.styx.api.extension.service.StickySessionConfig) NOT_IMPLEMENTED(com.hotels.styx.api.HttpResponseStatus.NOT_IMPLEMENTED) UNAUTHORIZED(com.hotels.styx.api.HttpResponseStatus.UNAUTHORIZED) TRANSFER_ENCODING(com.hotels.styx.api.HttpHeaderNames.TRANSFER_ENCODING) ArgumentCaptor(org.mockito.ArgumentCaptor) RetryNTimes(com.hotels.styx.client.retry.RetryNTimes) NoAvailableHostsException(com.hotels.styx.api.exceptions.NoAvailableHostsException) EmitterProcessor(reactor.core.publisher.EmitterProcessor) BackendService(com.hotels.styx.api.extension.service.BackendService) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Eventual(com.hotels.styx.api.Eventual) Matchers.empty(org.hamcrest.Matchers.empty) InOrder(org.mockito.InOrder) INTERNAL_SERVER_ERROR(com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR) Publisher(org.reactivestreams.Publisher) Matchers(org.hamcrest.Matchers) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) HostAndPort(com.google.common.net.HostAndPort) HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) RemoteHost(com.hotels.styx.api.extension.RemoteHost) Mockito.verify(org.mockito.Mockito.verify) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) Flux(reactor.core.publisher.Flux) Mockito.never(org.mockito.Mockito.never) MeterRegistry(com.hotels.styx.api.MeterRegistry) OK(com.hotels.styx.api.HttpResponseStatus.OK) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) Id(com.hotels.styx.api.Id) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) LoadBalancer(com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer) RetryPolicy(com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicy)

Example 7 with RetryPolicy

use of com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicy in project styx by ExpediaGroup.

the class RetryPolicyFactoryTest method shouldCreateRetryPolicyAccordingToConfiguration.

@Test
public void shouldCreateRetryPolicyAccordingToConfiguration() {
    Configuration configuration = new MapBackedConfiguration().set("count", 2);
    RetryPolicy retryPolicy = new RetryPolicyFactory().create(environment, configuration);
    assertThat(retryPolicy, is(instanceOf(RetryNTimes.class)));
    assertThat(((RetryNTimes) retryPolicy).maxAttempts(), is(2));
}
Also used : Configuration(com.hotels.styx.api.configuration.Configuration) MapBackedConfiguration(com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration) MapBackedConfiguration(com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration) RetryPolicy(com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicy) Test(org.junit.jupiter.api.Test)

Aggregations

RetryPolicy (com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicy)7 Test (org.junit.jupiter.api.Test)7 Context (com.hotels.styx.api.HttpInterceptor.Context)5 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)5 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)5 LoadBalancer (com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer)5 OriginUnreachableException (com.hotels.styx.api.exceptions.OriginUnreachableException)4 Support.requestContext (com.hotels.styx.support.Support.requestContext)4 HostAndPort (com.google.common.net.HostAndPort)3 Eventual (com.hotels.styx.api.Eventual)3 HttpHandler (com.hotels.styx.api.HttpHandler)3 HttpHeaderNames (com.hotels.styx.api.HttpHeaderNames)3 CHUNKED (com.hotels.styx.api.HttpHeaderNames.CHUNKED)3 CONTENT_LENGTH (com.hotels.styx.api.HttpHeaderNames.CONTENT_LENGTH)3 TRANSFER_ENCODING (com.hotels.styx.api.HttpHeaderNames.TRANSFER_ENCODING)3 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)3 HttpResponseStatus (com.hotels.styx.api.HttpResponseStatus)3 BAD_REQUEST (com.hotels.styx.api.HttpResponseStatus.BAD_REQUEST)3 INTERNAL_SERVER_ERROR (com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR)3 NOT_IMPLEMENTED (com.hotels.styx.api.HttpResponseStatus.NOT_IMPLEMENTED)3