Search in sources :

Example 31 with BackendService

use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.

the class YamlApplicationsProviderTest method stickySessionEnabledWhenYamlStickySessionEnabledIsTrue.

@Test
public void stickySessionEnabledWhenYamlStickySessionEnabledIsTrue() {
    YamlApplicationsProvider config = loadFromPath("classpath:conf/origins/origins-for-configtest.yml");
    BackendService app = applicationFor(config, "webapp");
    assertThat(app.stickySessionConfig().stickySessionEnabled(), CoreMatchers.is(true));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 32 with BackendService

use of com.hotels.styx.api.extension.service.BackendService 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()));
}
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) 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)

Example 33 with BackendService

use of com.hotels.styx.api.extension.service.BackendService 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()));
}
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) 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)

Example 34 with BackendService

use of com.hotels.styx.api.extension.service.BackendService 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()));
}
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) BackendService(com.hotels.styx.api.extension.service.BackendService) 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)

Example 35 with BackendService

use of com.hotels.styx.api.extension.service.BackendService 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

BackendService (com.hotels.styx.api.extension.service.BackendService)37 Test (org.junit.jupiter.api.Test)36 Registry (com.hotels.styx.api.extension.service.spi.Registry)11 JustATestException (com.hotels.styx.support.JustATestException)8 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)7 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)7 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)7 MeterRegistry (com.hotels.styx.api.MeterRegistry)6 Resource (com.hotels.styx.api.Resource)6 MemoryBackedRegistry (com.hotels.styx.infrastructure.MemoryBackedRegistry)6 IOException (java.io.IOException)6 HttpHandler (com.hotels.styx.api.HttpHandler)5 ReloadResult (com.hotels.styx.api.extension.service.spi.Registry.ReloadResult)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 ByteArrayInputStream (java.io.ByteArrayInputStream)5 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)5 List (java.util.List)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5