Search in sources :

Example 1 with LoggingTestSupport

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

the class OriginRestrictionLoadBalancingStrategyTest method setUp.

@BeforeEach
public void setUp() {
    delegate = mock(LoadBalancer.class);
    when(delegate.choose(any(LoadBalancer.Preferences.class))).thenReturn(Optional.of(origins.get(0)));
    strategy = new OriginRestrictionLoadBalancingStrategy(new ActiveOrigins() {

        @Override
        public Iterable<RemoteHost> snapshot() {
            return origins;
        }

        @Override
        public String getApplicationId() {
            return null;
        }

        @Override
        public List<Origin> origins() {
            return null;
        }
    }, delegate);
    log = new LoggingTestSupport(OriginRestrictionLoadBalancingStrategy.class);
}
Also used : Origin(com.hotels.styx.api.extension.Origin) ActiveOrigins(com.hotels.styx.api.extension.ActiveOrigins) RemoteHost(com.hotels.styx.api.extension.RemoteHost) LoadBalancer(com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer) LoggingTestSupport(com.hotels.styx.support.matchers.LoggingTestSupport) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with LoggingTestSupport

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

the class OriginsInventoryTest method setUp.

@BeforeEach
public void setUp() {
    meterRegistry = new MicrometerRegistry(new SimpleMeterRegistry());
    logger = new LoggingTestSupport(OriginsInventory.class);
    monitor = mock(OriginHealthStatusMonitor.class);
    eventBus = mock(EventBus.class);
    inventory = new OriginsInventory(eventBus, GENERIC_APP, monitor, connectionFactory, hostClientFactory, new CentralisedMetrics(meterRegistry));
}
Also used : MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) OriginHealthStatusMonitor(com.hotels.styx.client.healthcheck.OriginHealthStatusMonitor) EventBus(com.google.common.eventbus.EventBus) LoggingTestSupport(com.hotels.styx.support.matchers.LoggingTestSupport) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with LoggingTestSupport

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

the class ExceptionStatusMapperTest method exceptionMayNotBeMappedToMultipleExceptions.

@Test
public void exceptionMayNotBeMappedToMultipleExceptions() {
    ExceptionStatusMapper mapper = new ExceptionStatusMapper.Builder().add(BAD_GATEWAY, Exception1.class).add(GATEWAY_TIMEOUT, DoubleMappedException.class).build();
    LoggingTestSupport support = new LoggingTestSupport(ExceptionStatusMapper.class);
    Optional<HttpResponseStatus> status;
    try {
        status = mapper.statusFor(new DoubleMappedException());
    } finally {
        assertThat(support.lastMessage(), is(loggingEvent(ERROR, "Multiple matching statuses for throwable=" + quote(DoubleMappedException.class.getName()) + " statuses=\\[502 Bad Gateway, 504 Gateway Timeout\\]")));
    }
    assertThat(status, isAbsent());
}
Also used : HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) LoggingTestSupport(com.hotels.styx.support.matchers.LoggingTestSupport) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with LoggingTestSupport

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

the class GraphiteReporterTest method setUp.

@BeforeEach
public void setUp() {
    Clock clock = mock(Clock.class);
    graphite = mock(Graphite.class);
    MetricRegistry registry = mock(MetricRegistry.class);
    when(clock.getTime()).thenReturn(TIMESTAMP * 1000);
    reporter = forRegistry(registry).withClock(clock).prefixedWith("prefix").convertRatesTo(SECONDS).convertDurationsTo(MILLISECONDS).filter(MetricFilter.ALL).build(graphite);
    logging = new LoggingTestSupport(GraphiteReporter.class);
}
Also used : Graphite(com.codahale.metrics.graphite.Graphite) MetricRegistry(com.codahale.metrics.MetricRegistry) Clock(com.codahale.metrics.Clock) LoggingTestSupport(com.hotels.styx.support.matchers.LoggingTestSupport) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with LoggingTestSupport

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

the class HttpErrorStatusCauseLoggerTest method setUp.

@BeforeEach
public void setUp() {
    loggingTestSupport = new LoggingTestSupport(HttpErrorStatusCauseLogger.class);
    httpErrorStatusCauseLogger = new HttpErrorStatusCauseLogger(httpMessageFormatter);
}
Also used : LoggingTestSupport(com.hotels.styx.support.matchers.LoggingTestSupport) BeforeEach(org.junit.jupiter.api.BeforeEach)

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