Search in sources :

Example 1 with Registry

use of com.hotels.styx.api.extension.service.spi.Registry in project styx by ExpediaGroup.

the class FileBackedRegistryTest method announcesInitialStateWhenStarts.

@Test
public void announcesInitialStateWhenStarts() throws IOException {
    Resource configurationFile = mockResource("/styx/config", new ByteArrayInputStream(originalContent));
    registry = new FileBackedRegistry<>(configurationFile, bytes -> List.of(backendService), any -> true);
    registry.addListener(listener);
    await(registry.reload());
    verify(listener).onChange(eq(changeSet().added(backendService).build()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Registry(com.hotels.styx.api.extension.service.spi.Registry) ReloadResult(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult) UTF_8(java.nio.charset.StandardCharsets.UTF_8) StyxFutures.await(com.hotels.styx.common.StyxFutures.await) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ReloadResult.unchanged(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.unchanged) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(com.hotels.styx.api.Resource) JustATestException(com.hotels.styx.support.JustATestException) Matchers.eq(org.mockito.Matchers.eq) BackendService(com.hotels.styx.api.extension.service.BackendService) ReloadResult.reloaded(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.reloaded) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Mockito.mock(org.mockito.Mockito.mock) ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(com.hotels.styx.api.Resource) Test(org.junit.jupiter.api.Test)

Example 2 with Registry

use of com.hotels.styx.api.extension.service.spi.Registry in project styx by ExpediaGroup.

the class FileBackedRegistryTest method modifyTimeProviderHandlesExceptions.

@Test
public void modifyTimeProviderHandlesExceptions() throws Exception {
    registry = new FileBackedRegistry<>(mockResource("/styx/config", new ByteArrayInputStream(originalContent)), bytes -> List.of(new BackendService.Builder().id("x").path("/x").build()), any -> true);
    registry.addListener(listener);
    verify(listener).onChange(eq(changeSet().build()));
    ReloadResult result = registry.reload().get();
    assertThat(result, is(reloaded("timestamp=NA, md5-hash=c346e70114eff08dceb13562f9abaa48, File reloaded.")));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Registry(com.hotels.styx.api.extension.service.spi.Registry) ReloadResult(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult) UTF_8(java.nio.charset.StandardCharsets.UTF_8) StyxFutures.await(com.hotels.styx.common.StyxFutures.await) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ReloadResult.unchanged(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.unchanged) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(com.hotels.styx.api.Resource) JustATestException(com.hotels.styx.support.JustATestException) Matchers.eq(org.mockito.Matchers.eq) BackendService(com.hotels.styx.api.extension.service.BackendService) ReloadResult.reloaded(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.reloaded) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Mockito.mock(org.mockito.Mockito.mock) ByteArrayInputStream(java.io.ByteArrayInputStream) ReloadResult(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult) Test(org.junit.jupiter.api.Test)

Example 3 with Registry

use of com.hotels.styx.api.extension.service.spi.Registry in project styx by ExpediaGroup.

the class StyxPipelineFactory method configuredPipeline.

private RoutingObject configuredPipeline(RoutingObjectFactory.Context routingObjectFactoryContext) {
    boolean requestTracking = environment.configuration().get("requestTracking", Boolean.class).orElse(false);
    Optional<JsonNode> rootHandlerNode = environment.configuration().get("httpPipeline", JsonNode.class);
    if (rootHandlerNode.isPresent()) {
        return Builtins.build(List.of("httpPipeline"), routingObjectFactoryContext, toRoutingConfigNode(rootHandlerNode.get()));
    }
    Registry<BackendService> registry = (Registry<BackendService>) services.get("backendServiceRegistry");
    return new StaticPipelineFactory(environment, registry != null ? registry : new MemoryBackedRegistry<>(), plugins, executor, requestTracking).build();
}
Also used : StaticPipelineFactory(com.hotels.styx.routing.StaticPipelineFactory) BackendService(com.hotels.styx.api.extension.service.BackendService) JsonNode(com.fasterxml.jackson.databind.JsonNode) Registry(com.hotels.styx.api.extension.service.spi.Registry) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry)

Example 4 with Registry

use of com.hotels.styx.api.extension.service.spi.Registry in project styx by ExpediaGroup.

the class FileBackedBackendServicesRegistryFactoryTest method instantiatesFromYaml.

@Test
public void instantiatesFromYaml() {
    environment = new com.hotels.styx.Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).configuration(StyxConfig.fromYaml("config: {originsFile: '${CONFIG_LOCATION:classpath:}/conf/origins/backend-factory-origins.yml'}", false)).build();
    JsonNodeConfig factoryConfig = new JsonNodeConfig(environment.configuration().get("config", JsonNode.class).get());
    Registry registry = new FileBackedBackendServicesRegistry.Factory().create(environment, factoryConfig);
    assertThat(registry != null, is(true));
}
Also used : MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) JsonNodeConfig(com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Registry(com.hotels.styx.api.extension.service.spi.Registry) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) Test(org.junit.jupiter.api.Test)

Example 5 with Registry

use of com.hotels.styx.api.extension.service.spi.Registry in project styx by ExpediaGroup.

the class FileBackedRegistryTest method announcesNoMeaningfulChangesWhenNoSemanticChanges.

@Test
public void announcesNoMeaningfulChangesWhenNoSemanticChanges() throws Exception {
    Resource configurationFile = mockResource("/styx/config", new ByteArrayInputStream(originalContent));
    registry = new FileBackedRegistry<>(configurationFile, bytes -> List.of(backendService), any -> true);
    registry.addListener(listener);
    await(registry.reload());
    verify(listener).onChange(eq(changeSet().added(backendService).build()));
    when(configurationFile.inputStream()).thenReturn(new ByteArrayInputStream(newContent));
    ReloadResult result = registry.reload().get();
    assertThat(result, is(unchanged("timestamp=NA, md5-hash=24996b9d53b21a60c35dcb7ca3fb331a, No semantic changes.")));
    // Still only one invocation, because reload didn't introduce any changes to configuration
    verify(listener).onChange(eq(changeSet().added(backendService).build()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Registry(com.hotels.styx.api.extension.service.spi.Registry) ReloadResult(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult) UTF_8(java.nio.charset.StandardCharsets.UTF_8) StyxFutures.await(com.hotels.styx.common.StyxFutures.await) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ReloadResult.unchanged(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.unchanged) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(com.hotels.styx.api.Resource) JustATestException(com.hotels.styx.support.JustATestException) Matchers.eq(org.mockito.Matchers.eq) BackendService(com.hotels.styx.api.extension.service.BackendService) ReloadResult.reloaded(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.reloaded) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Mockito.mock(org.mockito.Mockito.mock) ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(com.hotels.styx.api.Resource) ReloadResult(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult) Test(org.junit.jupiter.api.Test)

Aggregations

Registry (com.hotels.styx.api.extension.service.spi.Registry)8 BackendService (com.hotels.styx.api.extension.service.BackendService)7 Test (org.junit.jupiter.api.Test)7 Resource (com.hotels.styx.api.Resource)6 ReloadResult (com.hotels.styx.api.extension.service.spi.Registry.ReloadResult)6 ReloadResult.reloaded (com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.reloaded)6 ReloadResult.unchanged (com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.unchanged)6 StyxFutures.await (com.hotels.styx.common.StyxFutures.await)6 JustATestException (com.hotels.styx.support.JustATestException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IOException (java.io.IOException)6 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)6 List (java.util.List)6 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)6 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)6 Matchers.is (org.hamcrest.Matchers.is)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 Matchers.eq (org.mockito.Matchers.eq)6 Mockito.mock (org.mockito.Mockito.mock)6 Mockito.verify (org.mockito.Mockito.verify)6