use of com.hotels.styx.support.JustATestException in project styx by ExpediaGroup.
the class HttpPipelineHandlerTest method discardsOnErrorForEarlierRequestsInWaitingForResponseState.
@Test
public void discardsOnErrorForEarlierRequestsInWaitingForResponseState() throws Exception {
setUpFor2Requests();
handler.channelRead0(ctx, request);
assertThat(handler.state(), is(WAITING_FOR_RESPONSE));
responseObservable.onNext(response);
assertThat(handler.state(), is(SENDING_RESPONSE));
writerFuture.complete(null);
assertThat(handler.state(), is(ACCEPTING_REQUESTS));
handler.channelRead0(ctx, request2);
assertThat(handler.state(), is(WAITING_FOR_RESPONSE));
responseObservable.onError(new JustATestException());
assertThat(handler.state(), is(WAITING_FOR_RESPONSE));
}
use of com.hotels.styx.support.JustATestException in project styx by ExpediaGroup.
the class HttpPipelineHandlerTest method mapsStyxClientExceptionToInternalServerErrorInWaitingForResponseState.
@Test
public void mapsStyxClientExceptionToInternalServerErrorInWaitingForResponseState() throws Exception {
// In Waiting For Response state,
// The response observable emits a StyxClientException.
// Then, respond with INTERNAL_SERVER_ERROR and close the channel.
setupHandlerTo(WAITING_FOR_RESPONSE);
responseObservable.onError(new StyxClientException("Client error occurred", new JustATestException()));
assertThat(responseUnsubscribed.get(), is(true));
ArgumentCaptor<LiveHttpResponse> captor = ArgumentCaptor.forClass(LiveHttpResponse.class);
verify(responseWriter).write(captor.capture());
HttpResponse response = Mono.from(captor.getValue().aggregate(100)).block();
assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
assertThat(response.header(CONNECTION), is(Optional.of("close")));
assertThat(response.header(CONTENT_LENGTH), is(Optional.of("29")));
assertThat(response.bodyAs(UTF_8), is("Site temporarily unavailable."));
writerFuture.complete(null);
verify(statsCollector).onComplete(request.id(), 500);
verify(errorListener).proxyErrorOccurred(any(LiveHttpRequest.class), any(InetSocketAddress.class), eq(INTERNAL_SERVER_ERROR), any(RuntimeException.class));
// NOTE: channel closure is not verified. This is because cannot mock channel future.
verify(ctx).close();
assertThat(handler.state(), is(TERMINATED));
}
use of com.hotels.styx.support.JustATestException in project styx by ExpediaGroup.
the class QueueDrainingEventProcessorTest method handlesEventProcessorExceptions.
@Test
public void handlesEventProcessorExceptions() throws Exception {
for (int i = 0; i < 1000; i++) {
CyclicBarrier barrier1 = new CyclicBarrier(2);
CyclicBarrier barrier2 = new CyclicBarrier(2);
CyclicBarrier barrier3 = new CyclicBarrier(2);
QueueDrainingEventProcessor eventProcessor = new QueueDrainingEventProcessor((event) -> ((Consumer<Void>) event).accept(null), false);
startThread(() -> {
Consumer<Void> lockEvent = consumerEvent((x) -> {
await(barrier1);
try {
throw new JustATestException();
} finally {
await(barrier2);
}
});
eventProcessor.submit(lockEvent);
});
barrier1.await();
Consumer<Void> event2 = mock(Consumer.class);
eventProcessor.submit(consumerEvent(x -> {
event2.accept(null);
await(barrier3);
}));
await(barrier2);
await(barrier3);
verify(event2).accept(eq(null));
}
}
use of com.hotels.styx.support.JustATestException in project styx by ExpediaGroup.
the class FileBackedBackendServicesRegistryTest method fileChanged_logsInfoWhenFailsToReadFile.
@Test
public void fileChanged_logsInfoWhenFailsToReadFile() throws Exception {
FileBackedRegistry<BackendService> delegate = mock(FileBackedRegistry.class);
when(delegate.fileName()).thenReturn("/monitored/origins.yml");
when(delegate.reload()).thenReturn(completedFuture(reloaded("md5-hash: 9034890345289043, Successfully reloaded"))).thenReturn(completedFuture(failed("md5-hash: 9034890345289043, Failed to reload", new JustATestException())));
registry = new FileBackedBackendServicesRegistry(delegate, FileMonitor.DISABLED);
registry.startService().get();
registry.fileChanged();
assertThat(log.lastMessage(), is(loggingEvent(ERROR, "Backend services reload failed. reason='File Monitor', md5-hash: 9034890345289043, Failed to reload, file='/monitored/origins.yml'", JustATestException.class, JustATestException.DEFAULT_MESSAGE)));
}
use of com.hotels.styx.support.JustATestException in project styx by ExpediaGroup.
the class FileBackedBackendServicesRegistryTest method serviceStarts_failsToStartWhenReloadFails.
@Test
public void serviceStarts_failsToStartWhenReloadFails() {
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);
Exception e = assertThrows(ExecutionException.class, () -> registry.startService().get());
assertEquals("java.lang.RuntimeException: com.hotels.styx.support.JustATestException: This is not a real exception. We are just testing exception handling", e.getMessage());
}
Aggregations