Search in sources :

Example 6 with ReloadResult

use of com.hotels.styx.api.extension.service.spi.Registry.ReloadResult 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()));
}
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) JustATestException(com.hotels.styx.support.JustATestException) 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

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