Search in sources :

Example 6 with JustATestException

use of com.hotels.styx.support.JustATestException in project styx by ExpediaGroup.

the class EventualTest method createFromError.

@Test
public void createFromError() {
    Eventual<String> eventual = Eventual.error(new JustATestException());
    StepVerifier.create(eventual).expectError(RuntimeException.class).verify();
}
Also used : JustATestException(com.hotels.styx.support.JustATestException) Test(org.junit.jupiter.api.Test)

Example 7 with JustATestException

use of com.hotels.styx.support.JustATestException in project styx by ExpediaGroup.

the class FileBackedBackendServicesRegistryTest method serviceStarts_logsInfoWhenReloadFails.

@Test
public void serviceStarts_logsInfoWhenReloadFails() {
    FileBackedRegistry<BackendService> delegate = mock(FileBackedRegistry.class);
    when(delegate.fileName()).thenReturn("/monitored/origins.yml");
    when(delegate.reload()).thenReturn(completedFuture(failed("md5-hash: 9034890345289043, Failed to load file", new JustATestException())));
    registry = new FileBackedBackendServicesRegistry(delegate, FileMonitor.DISABLED);
    try {
        registry.startService().get();
    } catch (Throwable any) {
    // pass
    } finally {
        assertThat(log.lastMessage(), is(loggingEvent(ERROR, "Backend services reload failed. reason='Initial load', md5-hash: 9034890345289043, Failed to load file, file='/monitored/origins.yml'", JustATestException.class, JustATestException.DEFAULT_MESSAGE)));
    }
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) JustATestException(com.hotels.styx.support.JustATestException) Test(org.junit.jupiter.api.Test)

Example 8 with JustATestException

use of com.hotels.styx.support.JustATestException in project styx by ExpediaGroup.

the class FileBackedRegistryTest method completesWithExceptionWhenErrorsDuringReload.

@Test
public void completesWithExceptionWhenErrorsDuringReload() throws Exception {
    Resource configurationFile = mockResource("/styx/config", new ByteArrayInputStream(originalContent), new ByteArrayInputStream(newContent));
    registry = new FileBackedRegistry<>(configurationFile, bytes -> {
        if (new String(bytes).equals(new String(originalContent))) {
            return List.of(backendService);
        } else {
            throw new JustATestException();
        }
    }, any -> true);
    registry.addListener(listener);
    ReloadResult outcome = await(registry.reload());
    assertThat(outcome, is(reloaded("timestamp=NA, md5-hash=c346e70114eff08dceb13562f9abaa48, File reloaded.")));
    verify(listener).onChange(eq(changeSet().added(backendService).build()));
    outcome = await(registry.reload());
    assertThat(outcome.outcome(), is(Registry.Outcome.FAILED));
    assertThat(outcome.message(), is("timestamp=NA, md5-hash=24996b9d53b21a60c35dcb7ca3fb331a, Reload failure."));
    assertThat(outcome.cause().get(), instanceOf(RuntimeException.class));
    // Noting changed
    verify(listener).onChange(eq(changeSet().added(backendService).build()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Registry(com.hotels.styx.api.extension.service.spi.Registry) ReloadResult(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult) UTF_8(java.nio.charset.StandardCharsets.UTF_8) StyxFutures.await(com.hotels.styx.common.StyxFutures.await) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ReloadResult.unchanged(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.unchanged) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(com.hotels.styx.api.Resource) JustATestException(com.hotels.styx.support.JustATestException) Matchers.eq(org.mockito.Matchers.eq) BackendService(com.hotels.styx.api.extension.service.BackendService) ReloadResult.reloaded(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.reloaded) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Mockito.mock(org.mockito.Mockito.mock) JustATestException(com.hotels.styx.support.JustATestException) ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(com.hotels.styx.api.Resource) ReloadResult(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult) Test(org.junit.jupiter.api.Test)

Example 9 with JustATestException

use of com.hotels.styx.support.JustATestException in project styx by ExpediaGroup.

the class HttpPipelineHandlerTest method anotherExceptionInSendingResponseState.

@Test
public void anotherExceptionInSendingResponseState() throws Exception {
    // In Sending Response state,
    // A non-IO exception bubbles up the Netty pipeline
    setupHandlerTo(SENDING_RESPONSE);
    handler.exceptionCaught(ctx, new JustATestException());
    assertThat(responseUnsubscribed.get(), is(true));
    verify(statsCollector).onTerminate(request.id());
    assertThat(handler.state(), is(TERMINATED));
}
Also used : JustATestException(com.hotels.styx.support.JustATestException) Test(org.junit.jupiter.api.Test)

Aggregations

JustATestException (com.hotels.styx.support.JustATestException)9 Test (org.junit.jupiter.api.Test)9 BackendService (com.hotels.styx.api.extension.service.BackendService)4 IOException (java.io.IOException)2 Matchers.eq (org.mockito.Matchers.eq)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verify (org.mockito.Mockito.verify)2 HttpResponse (com.hotels.styx.api.HttpResponse)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)1 Resource (com.hotels.styx.api.Resource)1 Registry (com.hotels.styx.api.extension.service.spi.Registry)1 ReloadResult (com.hotels.styx.api.extension.service.spi.Registry.ReloadResult)1 ReloadResult.reloaded (com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.reloaded)1 ReloadResult.unchanged (com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.unchanged)1 ServiceFailureException (com.hotels.styx.api.extension.service.spi.ServiceFailureException)1 StyxClientException (com.hotels.styx.client.StyxClientException)1 StyxFutures.await (com.hotels.styx.common.StyxFutures.await)1 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1