use of com.hotels.styx.api.plugins.spi.Plugin in project styx by ExpediaGroup.
the class StyxServerTest method exposesAdminEndpoints.
@Test
public void exposesAdminEndpoints() {
setUpStyxAndPluginWithAdminPages(Map.of("adminPage1", (request, ctx) -> Eventual.of(LiveHttpResponse.response().header("AdminPage1", "yes").build()), "adminPage2", (request, ctx) -> Eventual.of(LiveHttpResponse.response().header("AdminPage2", "yes").build())));
HttpResponse response = doAdminRequest("/admin/plugins/plugin-with-admin-pages/adminPage1");
assertThat(response.status(), is(OK));
assertThat(response.header("AdminPage1"), isValue("yes"));
response = doAdminRequest("/admin/plugins/plugin-with-admin-pages/adminPage2");
assertThat(response.status(), is(OK));
assertThat(response.header("AdminPage2"), isValue("yes"));
}
use of com.hotels.styx.api.plugins.spi.Plugin in project styx by ExpediaGroup.
the class StyxServerTest method serverDoesNotStartUntilPluginsAreStarted.
@Test
public void serverDoesNotStartUntilPluginsAreStarted() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
StyxServer styxServer = styxServerWithPlugins(Map.of("slowlyStartingPlugin", new Plugin() {
@Override
public void styxStarting() {
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request1, Chain chain) {
return Eventual.of(response(OK).build());
}
}));
try {
styxServer.startAsync();
Thread.sleep(10);
assertThat(styxServer.proxyHttpAddress(), nullValue());
latch.countDown();
eventually(() -> assertThat(styxServer.proxyHttpAddress().getPort(), is(greaterThan(0))));
} finally {
stopIfRunning(styxServer);
}
}
use of com.hotels.styx.api.plugins.spi.Plugin in project styx by ExpediaGroup.
the class StyxServerTest method allPluginsAreStartedEvenIfSomeFail.
@Test
public void allPluginsAreStartedEvenIfSomeFail() {
StyxServer styxServer = null;
try {
Plugin pluginMock2 = mock(Plugin.class);
Plugin pluginMock4 = mock(Plugin.class);
styxServer = styxServerWithPlugins(Map.of("plug1", new NonStarterPlugin("plug1"), "plug2", pluginMock2, "plug3", new NonStarterPlugin("plug3"), "plug4", pluginMock4));
Service service = styxServer.startAsync();
eventually(() -> assertThat(service.state(), is(FAILED)));
assertThat(pssLog.log(), hasItem(loggingEvent(ERROR, "Error starting plugin 'plug1'", RuntimeException.class, "Plugin start test error: plug1")));
assertThat(pssLog.log(), hasItem(loggingEvent(ERROR, "Error starting plugin 'plug3'", RuntimeException.class, "Plugin start test error: plug3")));
verify(pluginMock2).styxStarting();
verify(pluginMock4).styxStarting();
} finally {
stopIfRunning(styxServer);
}
}
use of com.hotels.styx.api.plugins.spi.Plugin in project styx by ExpediaGroup.
the class StyxServerTest method stopsTheServerWhenPluginFailsToStart.
@Test
public void stopsTheServerWhenPluginFailsToStart() {
StyxServer styxServer = null;
try {
styxServer = styxServerWithPlugins(Map.of("foo", new NonStarterPlugin("foo"), "mockplugin3", mock(Plugin.class)));
Service service = styxServer.startAsync();
eventually(() -> assertThat(service.state(), is(FAILED)));
assertThat(pssLog.log(), hasItem(loggingEvent(ERROR, "Error starting plugin 'foo'", RuntimeException.class, "Plugin start test error: foo")));
assertThat(styxServer.state(), is(FAILED));
} finally {
stopIfRunning(styxServer);
}
}
use of com.hotels.styx.api.plugins.spi.Plugin in project styx by ExpediaGroup.
the class InstrumentedPluginTest method metricsAreNotRecordedWhenExceptionIsReturnedByChain.
@Test
public void metricsAreNotRecordedWhenExceptionIsReturnedByChain() {
String pluginName = "passThrough";
Chain chain = request -> error(new SomeException());
InstrumentedPlugin plugin = instrumentedPlugin(pluginName, PASS_THROUGH);
assertThatEventualHasErrorOnly(SomeException.class, plugin.intercept(someRequest, chain));
assertThat(getExceptionCount(pluginName, SOME_EXCEPTION), is(0.0));
assertThat(getErrorCount(pluginName), is(0.0));
}
Aggregations