Search in sources :

Example 6 with Configuration

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

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

the class FileBackedBackendServicesRegistryFactoryTest method requiresOriginsFileToBeNonEmpty.

@Test
public void requiresOriginsFileToBeNonEmpty() {
    Configuration configuration = mockConfiguration(Optional.empty());
    Exception e = assertThrows(ConfigurationException.class, () -> new FileBackedBackendServicesRegistry.Factory().create(environment, configuration));
    assertTrue(e.getMessage().matches("missing .services.registry.factory.config.originsFile. config value for factory class FileBackedBackendServicesRegistry.Factory"));
}
Also used : Configuration(com.hotels.styx.api.configuration.Configuration) ConfigurationException(com.hotels.styx.api.configuration.ConfigurationException) Test(org.junit.jupiter.api.Test)

Example 8 with Configuration

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

the class FileBackedBackendServicesRegistryFactoryTest method mockConfiguration.

private Configuration mockConfiguration(Optional<String> path) {
    Configuration configuration = mock(Configuration.class);
    when(configuration.get(eq("originsFile"), eq(String.class))).thenReturn(path);
    return configuration;
}
Also used : Configuration(com.hotels.styx.api.configuration.Configuration)

Example 9 with Configuration

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

the class LoadBalancerFactoryProviderTest method errorsIfCannotFindTheFactoryClass.

@Test
public void errorsIfCannotFindTheFactoryClass() {
    String yaml = "" + "loadBalancing:\n" + "  strategy: awesome\n" + "  strategies:\n" + "    awesome:\n" + "      factory: {class: \"doesnot.really.exist\"}\n";
    Configuration configurations = new YamlConfig(yaml);
    assertThrows(RuntimeException.class, () -> newProvider(configurations).get());
}
Also used : YamlConfig(com.hotels.styx.infrastructure.configuration.yaml.YamlConfig) Configuration(com.hotels.styx.api.configuration.Configuration) Test(org.junit.jupiter.api.Test)

Example 10 with Configuration

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

the class LoadBalancerFactoryProviderTest method loadsTheConfiguredStrategy.

@Test
public void loadsTheConfiguredStrategy() {
    String yaml = "" + "loadBalancing:\n" + "  strategy: awesome\n" + "  strategies:\n" + "    awesome:\n" + "      factory: {class: \"com.hotels.styx.proxy.LoadBalancerFactoryProviderTest$NewAwesomeStrategy\"}\n";
    Configuration configuration = new YamlConfig(yaml);
    LoadBalancingStrategyFactoryProvider factoryProvider = newProvider(configuration);
    assertThat(factoryProvider.get(), is(instanceOf(NewAwesomeStrategy.class)));
}
Also used : YamlConfig(com.hotels.styx.infrastructure.configuration.yaml.YamlConfig) Configuration(com.hotels.styx.api.configuration.Configuration) Test(org.junit.jupiter.api.Test)

Aggregations

Configuration (com.hotels.styx.api.configuration.Configuration)13 Test (org.junit.jupiter.api.Test)9 ConfigurationException (com.hotels.styx.api.configuration.ConfigurationException)3 YamlConfig (com.hotels.styx.infrastructure.configuration.yaml.YamlConfig)3 MapBackedConfiguration (com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration)2 RetryPolicy (com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicy)2 FileMonitorSettings (com.hotels.styx.proxy.backends.file.FileChangeMonitor.FileMonitorSettings)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Environment (com.hotels.styx.Environment)1 StyxConfig (com.hotels.styx.StyxConfig)1 AdminServerConfig (com.hotels.styx.admin.AdminServerConfig)1 Environment (com.hotels.styx.api.Environment)1 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)1 ServiceFactory (com.hotels.styx.api.configuration.ServiceFactory)1 ActiveOrigins (com.hotels.styx.api.extension.ActiveOrigins)1 LoadBalancer (com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer)1 LoadBalancerFactory (com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancerFactory)1 RetryPolicyFactory (com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicyFactory)1 Pair (com.hotels.styx.common.Pair)1 Pair.pair (com.hotels.styx.common.Pair.pair)1