Search in sources :

Example 1 with StyxService

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

the class ServiceProvisionTest method loadsNewConfigurationFormat.

@Test
public void loadsNewConfigurationFormat() {
    Environment env = environmentWithConfig(yamlForServiceFactories);
    Map<String, StyxService> services = loadServices(env.configuration(), env, "multi", StyxService.class);
    assertThat(services.get("backendProvider"), instanceOf(BackendServiceProvider.class));
    assertThat(services.get("routingProvider"), instanceOf(RoutingObjectProvider.class));
}
Also used : Environment(com.hotels.styx.api.Environment) StyxService(com.hotels.styx.api.extension.service.spi.StyxService) AbstractStyxService(com.hotels.styx.api.extension.service.spi.AbstractStyxService) Test(org.junit.jupiter.api.Test)

Example 2 with StyxService

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

the class ServiceProvisionTest method isInstanceWorks.

@Test
public void isInstanceWorks() {
    Environment env = environmentWithConfig(yamlForServices);
    Map<String, StyxService> services = loadServices(env.configuration(), env, "multi", StyxService.class);
    assertThat(services.get("backendProvider"), instanceOf(BackendServiceProvider.class));
    assertThat(services.get("routingProvider"), instanceOf(RoutingObjectProvider.class));
}
Also used : Environment(com.hotels.styx.api.Environment) StyxService(com.hotels.styx.api.extension.service.spi.StyxService) AbstractStyxService(com.hotels.styx.api.extension.service.spi.AbstractStyxService) Test(org.junit.jupiter.api.Test)

Example 3 with StyxService

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

the class StyxServerComponentsTest method loadsServices.

@Test
public void loadsServices() {
    StyxServerComponents components = new StyxServerComponents.Builder().registry(new MicrometerRegistry(new CompositeMeterRegistry())).styxConfig(new StyxConfig()).services((env, routeDb) -> Map.of("service1", mock(StyxService.class), "service2", mock(StyxService.class))).build();
    Map<String, StyxService> services = components.services();
    assertThat(services.keySet(), containsInAnyOrder("service1", "service2"));
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) StyxService(com.hotels.styx.api.extension.service.spi.StyxService) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) StyxConfig(com.hotels.styx.StyxConfig) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) LoggingSetUp(com.hotels.styx.startup.StyxServerComponents.LoggingSetUp) Map(java.util.Map) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) Configuration(com.hotels.styx.api.configuration.Configuration) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Eventual(com.hotels.styx.api.Eventual) Plugin(com.hotels.styx.api.plugins.spi.Plugin) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) UTF_8(java.nio.charset.StandardCharsets.UTF_8) HttpResponse.response(com.hotels.styx.api.HttpResponse.response) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Matchers.any(org.mockito.Matchers.any) List(java.util.List) IsOptional.isValue(com.hotels.styx.support.matchers.IsOptional.isValue) Collectors.toList(java.util.stream.Collectors.toList) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Environment(com.hotels.styx.Environment) ConfiguredPluginFactory(com.hotels.styx.startup.extensions.ConfiguredPluginFactory) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) StyxConfig(com.hotels.styx.StyxConfig) StyxService(com.hotels.styx.api.extension.service.spi.StyxService) Test(org.junit.jupiter.api.Test)

Example 4 with StyxService

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

the class StyxServerTest method serverDoesNotStartIfServiceFails.

@Test
public void serverDoesNotStartIfServiceFails() {
    StyxServer styxServer = null;
    try {
        StyxService testService = registryThatFailsToStart();
        styxServer = styxServerWithBackendServiceRegistry(testService);
        Service serverService = styxServer.startAsync();
        eventually(() -> assertThat(serverService.state(), is(FAILED)));
        assertThat(styxServer.state(), is(FAILED));
    } finally {
        stopIfRunning(styxServer);
    }
}
Also used : StyxService(com.hotels.styx.api.extension.service.spi.StyxService) BackendService(com.hotels.styx.api.extension.service.BackendService) Service(com.google.common.util.concurrent.Service) StyxService(com.hotels.styx.api.extension.service.spi.StyxService) Test(org.junit.jupiter.api.Test)

Example 5 with StyxService

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

the class ServiceProviderHandlerTest method createTestStore.

private StyxObjectStore<StyxObjectRecord<StyxService>> createTestStore() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    StyxService mockService = mock(StyxService.class);
    StyxObjectStore<StyxObjectRecord<StyxService>> store = new StyxObjectStore<>();
    JsonNode config1 = mapper.readTree("{\"setting1\" : \"A\", \"setting2\" : \"A\"}");
    StyxObjectRecord<StyxService> rec1 = new StyxObjectRecord<>("Type1", new HashSet<>(Arrays.asList("this=that", "truth=false")), config1, mockService);
    store.insert("object1", rec1);
    JsonNode config2 = mapper.readTree("{\"setting1\" : \"B\", \"setting2\" : \"B\"}");
    StyxObjectRecord<StyxService> rec2 = new StyxObjectRecord<>("Type2", new HashSet<>(Arrays.asList("up=down", "weakness=strength")), config2, mockService);
    store.insert("object2", rec2);
    JsonNode config3 = mapper.readTree("{\"setting1\" : \"C\", \"setting2\" : \"C\"}");
    StyxObjectRecord<StyxService> rec3 = new StyxObjectRecord<>("Type3", new HashSet<>(Arrays.asList("black=white", "left=right")), config3, mockService);
    store.insert("object3", rec3);
    return store;
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) StyxObjectStore(com.hotels.styx.routing.db.StyxObjectStore) StyxService(com.hotels.styx.api.extension.service.spi.StyxService) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

StyxService (com.hotels.styx.api.extension.service.spi.StyxService)8 Test (org.junit.jupiter.api.Test)7 Environment (com.hotels.styx.api.Environment)4 AbstractStyxService (com.hotels.styx.api.extension.service.spi.AbstractStyxService)4 StyxConfig (com.hotels.styx.StyxConfig)2 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)2 CompositeMeterRegistry (io.micrometer.core.instrument.composite.CompositeMeterRegistry)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Service (com.google.common.util.concurrent.Service)1 Environment (com.hotels.styx.Environment)1 StyxObjectRecord (com.hotels.styx.StyxObjectRecord)1 Eventual (com.hotels.styx.api.Eventual)1 HttpResponse.response (com.hotels.styx.api.HttpResponse.response)1 Configuration (com.hotels.styx.api.configuration.Configuration)1 BackendService (com.hotels.styx.api.extension.service.BackendService)1 Plugin (com.hotels.styx.api.plugins.spi.Plugin)1 NamedPlugin (com.hotels.styx.proxy.plugin.NamedPlugin)1 StyxObjectStore (com.hotels.styx.routing.db.StyxObjectStore)1 LoggingSetUp (com.hotels.styx.startup.StyxServerComponents.LoggingSetUp)1