use of com.hotels.styx.api.extension.service.spi.Registry 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 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()));
}
use of com.hotels.styx.api.extension.service.spi.Registry in project styx by ExpediaGroup.
the class FileBackedRegistryTest method completesWithExceptionWhenErrorsDuringReload.
@Test
public void completesWithExceptionWhenErrorsDuringReload() throws Exception {
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(backendService);
} else {
throw new JustATestException();
}
}, any -> true);
registry.addListener(listener);
ReloadResult outcome = await(registry.reload());
assertThat(outcome, is(reloaded("timestamp=NA, md5-hash=c346e70114eff08dceb13562f9abaa48, File reloaded.")));
verify(listener).onChange(eq(changeSet().added(backendService).build()));
outcome = await(registry.reload());
assertThat(outcome.outcome(), is(Registry.Outcome.FAILED));
assertThat(outcome.message(), is("timestamp=NA, md5-hash=24996b9d53b21a60c35dcb7ca3fb331a, Reload failure."));
assertThat(outcome.cause().get(), instanceOf(RuntimeException.class));
// Noting changed
verify(listener).onChange(eq(changeSet().added(backendService).build()));
}
Aggregations