Search in sources :

Example 11 with LoggingTestSupport

use of com.hotels.styx.support.matchers.LoggingTestSupport in project styx by ExpediaGroup.

the class GraphiteReporterServiceTest method setUp.

@BeforeEach
public void setUp() {
    meterRegistry = new CompositeMeterRegistry();
    log = new LoggingTestSupport(GraphiteReporterService.class);
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) LoggingTestSupport(com.hotels.styx.support.matchers.LoggingTestSupport) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with LoggingTestSupport

use of com.hotels.styx.support.matchers.LoggingTestSupport in project styx by ExpediaGroup.

the class FsmEventProcessorTest method setUp.

@BeforeEach
public void setUp() {
    stateMachine = new StateMachine.Builder<String>().initialState("start").transition("start", TestEventOk.class, event -> "end").transition("start", TestEventError.class, event -> {
        throw new RuntimeException("Test exception message");
    }).onInappropriateEvent((x, y) -> "error").build();
    errorHandler = mock(BiConsumer.class);
    logger = new LoggingTestSupport(FsmEventProcessor.class);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) LoggingTestSupport(com.hotels.styx.support.matchers.LoggingTestSupport) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Matchers.any(org.mockito.Matchers.any) LoggingEventMatcher.loggingEvent(com.hotels.styx.support.matchers.LoggingEventMatcher.loggingEvent) AfterEach(org.junit.jupiter.api.AfterEach) ERROR(ch.qos.logback.classic.Level.ERROR) Matchers.eq(org.mockito.Matchers.eq) BiConsumer(java.util.function.BiConsumer) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Mockito.mock(org.mockito.Mockito.mock) LoggingTestSupport(com.hotels.styx.support.matchers.LoggingTestSupport) BiConsumer(java.util.function.BiConsumer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 13 with LoggingTestSupport

use of com.hotels.styx.support.matchers.LoggingTestSupport in project styx by ExpediaGroup.

the class HttpPipelineHandlerTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    logger = new LoggingTestSupport(HttpPipelineHandler.class);
    statsCollector = mock(RequestStatsCollector.class);
    errorListener = mock(HttpErrorStatusListener.class);
    ctx = mockCtx();
    responseObservable = EmitterProcessor.create();
    responseUnsubscribed = new AtomicBoolean(false);
    writerFuture = new CompletableFuture<>();
    responseWriter = mock(HttpResponseWriter.class);
    when(responseWriter.write(nullable(LiveHttpResponse.class))).thenReturn(writerFuture);
    responseWriterFactory = mock(HttpResponseWriterFactory.class);
    when(responseWriterFactory.create(nullable(ChannelHandlerContext.class))).thenReturn(responseWriter);
    pipeline = mock(HttpHandler.class);
    when(pipeline.handle(nullable(LiveHttpRequest.class), nullable(HttpInterceptor.Context.class))).thenReturn(new Eventual<>(Flux.from(responseObservable.doOnCancel(() -> responseUnsubscribed.set(true)))));
    request = get("/foo").id("REQUEST-1-ID").build();
    response = response().build();
    responseEnhancer = mock(ResponseEnhancer.class);
    when(responseEnhancer.enhance(nullable(LiveHttpResponse.Transformer.class), nullable(LiveHttpRequest.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]);
    when(responseEnhancer.enhance(nullable(LiveHttpResponse.class), nullable(LiveHttpRequest.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]);
    setupHandlerTo(ACCEPTING_REQUESTS);
}
Also used : ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) RequestStatsCollector(com.hotels.styx.server.RequestStatsCollector) HttpHandler(com.hotels.styx.api.HttpHandler) HttpErrorStatusListener(com.hotels.styx.server.HttpErrorStatusListener) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) HttpResponseWriterFactory(com.hotels.styx.server.netty.connectors.HttpPipelineHandler.HttpResponseWriterFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LoggingTestSupport(com.hotels.styx.support.matchers.LoggingTestSupport) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with LoggingTestSupport

use of com.hotels.styx.support.matchers.LoggingTestSupport in project styx by ExpediaGroup.

the class HttpResponseWriterTest method setUp.

@BeforeEach
public void setUp() {
    LOGGER = new LoggingTestSupport(HttpResponseWriter.class);
    contentObservable = EmitterProcessor.create();
    channelArgs = new ArrayDeque<>();
    channelRead = new AtomicBoolean(false);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LoggingTestSupport(com.hotels.styx.support.matchers.LoggingTestSupport) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 15 with LoggingTestSupport

use of com.hotels.styx.support.matchers.LoggingTestSupport in project styx by ExpediaGroup.

the class PluginLoadingForStartupTest method attemptsToLoadAllPluginsEvenIfSomePluginFactoriesCannotBeLoaded.

@Test
public void attemptsToLoadAllPluginsEvenIfSomePluginFactoriesCannotBeLoaded() {
    LoggingTestSupport log = new LoggingTestSupport(FailureHandling.class);
    String yaml = "" + "plugins:\n" + "  active: myPlugin1,myPlugin2,myPlugin3\n" + "  all:\n" + "    myPlugin1:\n" + "      factory:\n" + "        class: BadClassName\n" + "        classPath: " + FIXTURES_CLASS_PATH + "\n" + "    myPlugin2:\n" + "      factory:\n" + "        class: BadClassName\n" + "        classPath: " + FIXTURES_CLASS_PATH + "\n" + "    myPlugin3:\n" + "      factory:\n" + "        class: BadClassName\n" + "        classPath: " + FIXTURES_CLASS_PATH + "\n";
    Exception e = assertThrows(RuntimeException.class, () -> PluginLoadingForStartup.loadPlugins(environment(yaml)));
    assertThat(e.getMessage(), matchesPattern("3 plugin\\(s\\) could not be loaded: failedPlugins=\\[myPlugin1, myPlugin2, myPlugin3\\]; failureCauses=\\[" + "myPlugin1: com.hotels.styx.api.configuration.ConfigurationException: Could not load a plugin factory.*, " + "myPlugin2: com.hotels.styx.api.configuration.ConfigurationException: Could not load a plugin factory.*, " + "myPlugin3: com.hotels.styx.api.configuration.ConfigurationException: Could not load a plugin factory.*\\]"));
    assertThat(log.log(), hasItem(loggingEvent(ERROR, "Could not load plugin: pluginName=myPlugin1; factoryClass=.*", ConfigurationException.class, "Could not load a plugin factory for.*")));
    log.stop();
}
Also used : LoggingTestSupport(com.hotels.styx.support.matchers.LoggingTestSupport) ConfigurationException(com.hotels.styx.api.configuration.ConfigurationException) Test(org.junit.jupiter.api.Test)

Aggregations

LoggingTestSupport (com.hotels.styx.support.matchers.LoggingTestSupport)15 BeforeEach (org.junit.jupiter.api.BeforeEach)12 Test (org.junit.jupiter.api.Test)4 ConfigurationException (com.hotels.styx.api.configuration.ConfigurationException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ERROR (ch.qos.logback.classic.Level.ERROR)1 Clock (com.codahale.metrics.Clock)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Graphite (com.codahale.metrics.graphite.Graphite)1 EventBus (com.google.common.eventbus.EventBus)1 HttpHandler (com.hotels.styx.api.HttpHandler)1 HttpResponseStatus (com.hotels.styx.api.HttpResponseStatus)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)1 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)1 ActiveOrigins (com.hotels.styx.api.extension.ActiveOrigins)1 Origin (com.hotels.styx.api.extension.Origin)1 RemoteHost (com.hotels.styx.api.extension.RemoteHost)1 LoadBalancer (com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer)1 OriginHealthStatusMonitor (com.hotels.styx.client.healthcheck.OriginHealthStatusMonitor)1