Search in sources :

Example 1 with MapBackedConfiguration

use of com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration in project styx by ExpediaGroup.

the class StyxBackendServiceClientFactoryTest method usesTheOriginSpecifiedInTheOriginsRestrictionCookie.

@Test
public void usesTheOriginSpecifiedInTheOriginsRestrictionCookie() {
    MapBackedConfiguration config = new MapBackedConfiguration();
    config.set("originRestrictionCookie", ORIGINS_RESTRICTION_COOKIE);
    environment = new Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).configuration(new StyxConfig(config)).build();
    BackendService backendService = newBackendServiceBuilder().origins(newOriginBuilder("localhost", 9091).id("x").build(), newOriginBuilder("localhost", 9092).id("y").build(), newOriginBuilder("localhost", 9093).id("z").build()).build();
    BackendServiceClient styxBackendServiceClient = new StyxBackendServiceClientFactory(environment).createClient(backendService, newOriginsInventoryBuilder(environment.centralisedMetrics(), backendService).hostClientFactory((pool) -> {
        if (pool.getOrigin().id().equals(id("x"))) {
            return hostClient(response(OK).header("X-Origin-Id", "x").build());
        } else if (pool.getOrigin().id().equals(id("y"))) {
            return hostClient(response(OK).header("X-Origin-Id", "y").build());
        } else {
            return hostClient(response(OK).header("X-Origin-Id", "z").build());
        }
    }).build(), new CachingOriginStatsFactory(environment.centralisedMetrics()));
    LiveHttpRequest requestz = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("z").toString())).build();
    LiveHttpRequest requestx = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("x").toString())).build();
    LiveHttpRequest requesty = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("y").toString())).build();
    LiveHttpResponse responsez = Mono.from(styxBackendServiceClient.sendRequest(requestz, requestContext())).block();
    LiveHttpResponse responsex = Mono.from(styxBackendServiceClient.sendRequest(requestx, requestContext())).block();
    LiveHttpResponse responsey = Mono.from(styxBackendServiceClient.sendRequest(requesty, requestContext())).block();
    assertThat(responsex.header("X-Origin-Id").get(), is("x"));
    assertThat(responsey.header("X-Origin-Id").get(), is("y"));
    assertThat(responsez.header("X-Origin-Id").get(), is("z"));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) StyxConfig(com.hotels.styx.StyxConfig) StyxBackendServiceClient(com.hotels.styx.client.StyxBackendServiceClient) BackendServiceClient(com.hotels.styx.client.BackendServiceClient) CachingOriginStatsFactory(com.hotels.styx.client.OriginStatsFactory.CachingOriginStatsFactory) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) OriginsInventory.newOriginsInventoryBuilder(com.hotels.styx.client.OriginsInventory.newOriginsInventoryBuilder) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) BackendService.newBackendServiceBuilder(com.hotels.styx.api.extension.service.BackendService.newBackendServiceBuilder) StickySessionConfig.newStickySessionConfigBuilder(com.hotels.styx.api.extension.service.StickySessionConfig.newStickySessionConfigBuilder) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MapBackedConfiguration(com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 2 with MapBackedConfiguration

use of com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration 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)

Example 3 with MapBackedConfiguration

use of com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration in project styx by ExpediaGroup.

the class ResponseInfoFormatTest method canConfigureCustomHeaderFormatWithVersion.

@Test
public void canConfigureCustomHeaderFormatWithVersion() {
    StyxHeaderConfig styxHeaderConfig = new StyxHeaderConfig(new StyxHeaderConfig.StyxHeader(null, "{VERSION};{REQUEST_ID};{INSTANCE}"), null, null);
    Environment environment = environment(new MapBackedConfiguration().set("styxHeaders", styxHeaderConfig));
    String info = new ResponseInfoFormat(environment).format(request);
    assertThat(info, is("STYX-dev.0.0;" + request.id() + ";noJvmRouteSet"));
}
Also used : StyxHeaderConfig(com.hotels.styx.client.StyxHeaderConfig) MapBackedConfiguration(com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with MapBackedConfiguration

use of com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration in project styx by ExpediaGroup.

the class StyxServerTest method styxConfig.

private static StyxConfig styxConfig() {
    ProxyServerConfig proxyConfig = new ProxyServerConfig.Builder().setHttpConnector(new HttpConnectorConfig(0)).build();
    AdminServerConfig adminConfig = new AdminServerConfig.Builder().setHttpConnector(new HttpConnectorConfig(0)).build();
    Configuration config = new MapBackedConfiguration(EMPTY_CONFIGURATION).set("admin", adminConfig).set("proxy", proxyConfig);
    return new StyxConfig(config);
}
Also used : AdminServerConfig(com.hotels.styx.admin.AdminServerConfig) Configuration(com.hotels.styx.api.configuration.Configuration) MapBackedConfiguration(com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration) ProxyServerConfig(com.hotels.styx.proxy.ProxyServerConfig) MapBackedConfiguration(com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration) HttpConnectorConfig(com.hotels.styx.server.HttpConnectorConfig)

Aggregations

MapBackedConfiguration (com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration)4 Test (org.junit.jupiter.api.Test)3 Configuration (com.hotels.styx.api.configuration.Configuration)2 StyxConfig (com.hotels.styx.StyxConfig)1 AdminServerConfig (com.hotels.styx.admin.AdminServerConfig)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)1 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)1 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)1 RetryPolicy (com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicy)1 BackendService (com.hotels.styx.api.extension.service.BackendService)1 BackendService.newBackendServiceBuilder (com.hotels.styx.api.extension.service.BackendService.newBackendServiceBuilder)1 StickySessionConfig.newStickySessionConfigBuilder (com.hotels.styx.api.extension.service.StickySessionConfig.newStickySessionConfigBuilder)1 BackendServiceClient (com.hotels.styx.client.BackendServiceClient)1 CachingOriginStatsFactory (com.hotels.styx.client.OriginStatsFactory.CachingOriginStatsFactory)1 OriginsInventory.newOriginsInventoryBuilder (com.hotels.styx.client.OriginsInventory.newOriginsInventoryBuilder)1 StyxBackendServiceClient (com.hotels.styx.client.StyxBackendServiceClient)1 StyxHeaderConfig (com.hotels.styx.client.StyxHeaderConfig)1 ProxyServerConfig (com.hotels.styx.proxy.ProxyServerConfig)1 HttpConnectorConfig (com.hotels.styx.server.HttpConnectorConfig)1