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()));
}
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.")));
}
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();
}
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));
}
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()));
}
Aggregations