use of com.hotels.styx.api.extension.service.spi.Registry.ReloadResult 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.ReloadResult 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."));
}
use of com.hotels.styx.api.extension.service.spi.Registry.ReloadResult 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()));
}
use of com.hotels.styx.api.extension.service.spi.Registry.ReloadResult in project styx by ExpediaGroup.
the class FileBackedRegistryTest method announcesNoMeaningfulChangesWhenFileDidNotChange.
@Test
public void announcesNoMeaningfulChangesWhenFileDidNotChange() throws Exception {
Resource configurationFile = mockResource("/styx/config", new ByteArrayInputStream(originalContent), 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()));
ReloadResult result = registry.reload().get();
assertThat(result, is(unchanged("timestamp=NA, md5-hash=c346e70114eff08dceb13562f9abaa48, Identical file content.")));
// Still only one invocation, because reload didn't introduce any changes to configuration
verify(listener).onChange(eq(changeSet().added(backendService).build()));
}
use of com.hotels.styx.api.extension.service.spi.Registry.ReloadResult in project styx by ExpediaGroup.
the class FileBackedRegistryTest method announcesChanges.
@Test
public void announcesChanges() throws Exception {
BackendService backendService1 = new BackendService.Builder().id("x").path("/x").build();
BackendService backendService2 = new BackendService.Builder().id("x").path("/y").build();
Resource configurationFile = mockResource("/styx/config", new ByteArrayInputStream(originalContent), new ByteArrayInputStream(newContent));
registry = new FileBackedRegistry<>(configurationFile, bytes -> {
if (new String(bytes).equals(new String(originalContent))) {
return List.of(backendService1);
} else {
return List.of(backendService2);
}
}, any -> true);
registry.addListener(listener);
verify(listener).onChange(eq(changeSet().build()));
await(registry.reload());
verify(listener).onChange(eq(changeSet().added(backendService1).build()));
ReloadResult result = registry.reload().get();
assertThat(result, is(reloaded("timestamp=NA, md5-hash=24996b9d53b21a60c35dcb7ca3fb331a, File reloaded.")));
assertThat(backendService1.equals(backendService2), is(false));
verify(listener).onChange(eq(changeSet().updated(backendService2).build()));
}
Aggregations