use of com.hotels.styx.api.MicrometerRegistry in project styx by ExpediaGroup.
the class StyxBackendServiceClientFactoryTest method setUp.
@BeforeEach
public void setUp() {
connectionFactory = mock(Connection.Factory.class);
environment = new Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).build();
backendService = newBackendServiceBuilder().origins(newOriginBuilder("localhost", 8081).build()).build();
when(connectionFactory.createConnection(any(Origin.class), any(ConnectionSettings.class))).thenReturn(Mono.just(mock(Connection.class)));
}
use of com.hotels.styx.api.MicrometerRegistry in project styx by ExpediaGroup.
the class StyxBackendServiceClientFactoryTest method usesTheOriginSpecifiedInTheOriginsRestrictionCookie.
@Test
public void usesTheOriginSpecifiedInTheOriginsRestrictionCookie() {
MapBackedConfiguration config = new MapBackedConfiguration();
config.set("originRestrictionCookie", ORIGINS_RESTRICTION_COOKIE);
environment = new Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).configuration(new StyxConfig(config)).build();
BackendService backendService = newBackendServiceBuilder().origins(newOriginBuilder("localhost", 9091).id("x").build(), newOriginBuilder("localhost", 9092).id("y").build(), newOriginBuilder("localhost", 9093).id("z").build()).build();
BackendServiceClient styxBackendServiceClient = new StyxBackendServiceClientFactory(environment).createClient(backendService, newOriginsInventoryBuilder(environment.centralisedMetrics(), backendService).hostClientFactory((pool) -> {
if (pool.getOrigin().id().equals(id("x"))) {
return hostClient(response(OK).header("X-Origin-Id", "x").build());
} else if (pool.getOrigin().id().equals(id("y"))) {
return hostClient(response(OK).header("X-Origin-Id", "y").build());
} else {
return hostClient(response(OK).header("X-Origin-Id", "z").build());
}
}).build(), new CachingOriginStatsFactory(environment.centralisedMetrics()));
LiveHttpRequest requestz = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("z").toString())).build();
LiveHttpRequest requestx = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("x").toString())).build();
LiveHttpRequest requesty = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("y").toString())).build();
LiveHttpResponse responsez = Mono.from(styxBackendServiceClient.sendRequest(requestz, requestContext())).block();
LiveHttpResponse responsex = Mono.from(styxBackendServiceClient.sendRequest(requestx, requestContext())).block();
LiveHttpResponse responsey = Mono.from(styxBackendServiceClient.sendRequest(requesty, requestContext())).block();
assertThat(responsex.header("X-Origin-Id").get(), is("x"));
assertThat(responsey.header("X-Origin-Id").get(), is("y"));
assertThat(responsez.header("X-Origin-Id").get(), is("z"));
}
use of com.hotels.styx.api.MicrometerRegistry in project styx by ExpediaGroup.
the class FileBackedBackendServicesRegistryFactoryTest method instantiatesFromYaml.
@Test
public void instantiatesFromYaml() {
environment = new com.hotels.styx.Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).configuration(StyxConfig.fromYaml("config: {originsFile: '${CONFIG_LOCATION:classpath:}/conf/origins/backend-factory-origins.yml'}", false)).build();
JsonNodeConfig factoryConfig = new JsonNodeConfig(environment.configuration().get("config", JsonNode.class).get());
Registry registry = new FileBackedBackendServicesRegistry.Factory().create(environment, factoryConfig);
assertThat(registry != null, is(true));
}
use of com.hotels.styx.api.MicrometerRegistry in project styx by ExpediaGroup.
the class InterceptorPipelineBuilderTest method setUp.
@BeforeEach
public void setUp() {
environment = new Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).configuration(StyxConfig.defaultConfig()).build();
plugins = List.of(namedPlugin("plug1", (request, chain) -> chain.proceed(request).map(response -> response.newBuilder().header("plug1", "1").build())), namedPlugin("plug2", (request, chain) -> chain.proceed(request).map(response -> response.newBuilder().header("plug2", "1").build())));
handler = mock(RoutingObject.class);
when(handler.handle(any(LiveHttpRequest.class), any(HttpInterceptor.Context.class))).thenReturn(Eventual.of(response(OK).build()));
}
use of com.hotels.styx.api.MicrometerRegistry in project styx by ExpediaGroup.
the class StyxServerComponentsTest method loadsPlugins.
@Test
public void loadsPlugins() {
ConfiguredPluginFactory f1 = new ConfiguredPluginFactory("plugin1", any -> stubPlugin("MyResponse1"));
ConfiguredPluginFactory f2 = new ConfiguredPluginFactory("plugin2", any -> stubPlugin("MyResponse2"));
StyxServerComponents components = new StyxServerComponents.Builder().registry(new MicrometerRegistry(new CompositeMeterRegistry())).styxConfig(new StyxConfig()).pluginFactories(List.of(f1, f2)).build();
List<NamedPlugin> plugins = components.plugins();
List<String> names = plugins.stream().map(NamedPlugin::name).collect(toList());
assertThat(names, contains("plugin1", "plugin2"));
}
Aggregations