use of com.hotels.styx.api.Resource 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.Resource in project styx by ExpediaGroup.
the class FileBackedBackendServicesRegistryTest method yamlBackendReaderPropagatesExceptionWhenFailsToReadFromByteStream.
@Test
public void yamlBackendReaderPropagatesExceptionWhenFailsToReadFromByteStream() {
Resource resource = newResource("classpath:/backends/origins-with-invalid-path.yml");
assertThrows(RuntimeException.class, () -> new YAMLBackendServicesReader().read(bytes(resource.inputStream(), true)));
}
use of com.hotels.styx.api.Resource in project styx by ExpediaGroup.
the class FileBackedBackendServicesRegistryTest method yamlBackendReaderReadsBackendServicesFromByteStream.
@Test
public void yamlBackendReaderReadsBackendServicesFromByteStream() throws IOException {
Resource resource = newResource("classpath:/backends/origins.yml");
Iterable<BackendService> backendServices = new YAMLBackendServicesReader().read(bytes(resource.inputStream(), true));
assertThat(iterableToList(backendServices).size(), is(3));
}
use of com.hotels.styx.api.Resource in project styx by ExpediaGroup.
the class FileBackedBackendServicesRegistryTest method duplicatePathPrefixesCausesStartUpFailure.
@Test
public void duplicatePathPrefixesCausesStartUpFailure() throws InterruptedException, TimeoutException, IOException {
String configWithDupe = "" + "---\n" + "- id: \"first\"\n" + " path: \"/testpath/\"\n" + " origins:\n" + " - id: \"l1\"\n" + " host: \"localhost:60000\"\n" + "- id: \"second\"\n" + " path: \"/testpath/\"\n" + " origins:\n" + " - id: \"l2\"\n" + " host: \"localhost:60001\"";
Resource stubResource = mock(Resource.class);
when(stubResource.inputStream()).thenReturn(toInputStream(configWithDupe));
FileBackedBackendServicesRegistry registry = new FileBackedBackendServicesRegistry(stubResource, FileMonitor.DISABLED);
CompletableFuture<Void> status = registry.start();
assertThat(failureCause(status), is(instanceOf(ServiceFailureException.class)));
}
use of com.hotels.styx.api.Resource in project styx by ExpediaGroup.
the class FileBackedBackendServicesRegistryTest method duplicatePathPrefixesCausesReloadFailure.
@Test
public void duplicatePathPrefixesCausesReloadFailure() throws ExecutionException, InterruptedException, TimeoutException, IOException {
String configWithDupe = "" + "---\n" + "- id: \"first\"\n" + " path: \"/testpath/\"\n" + " origins:\n" + " - id: \"l1\"\n" + " host: \"localhost:60000\"\n" + "- id: \"second\"\n" + " path: \"/testpath/\"\n" + " origins:\n" + " - id: \"l2\"\n" + " host: \"localhost:60001\"";
Resource stubResource = mock(Resource.class);
when(stubResource.inputStream()).thenReturn(toInputStream(configWithDupe));
FileBackedBackendServicesRegistry registry = new FileBackedBackendServicesRegistry(stubResource, FileMonitor.DISABLED);
ReloadResult result = registry.reload().get(10, SECONDS);
assertThat(result.outcome(), is(FAILED));
assertThat(log.log(), hasItem(loggingEvent(ERROR, "Duplicate path '/testpath/' used for applications: 'first', 'second'")));
assertThat(result.message(), is("timestamp=NA, md5-hash=3cf21842c8dee594b646ea903fc09490, Reload failure."));
}
Aggregations