use of com.spotify.apollo.request.OngoingRequest in project apollo by spotify.
the class ApolloEnvironmentModuleTest method shouldUseEndpointRunnableFactoryDecorator.
@Test
public void shouldUseEndpointRunnableFactoryDecorator() throws Exception {
AtomicReference<String> lastResponseRef = new AtomicReference<>();
final Service service = this.service.withModule(new LastResponseModule(lastResponseRef)).build();
try (Service.Instance i = service.start()) {
final ApolloEnvironment environment = ApolloEnvironmentModule.environment(i);
final RequestHandler handler = environment.initialize(env -> {
env.routingEngine().registerAutoRoute(Route.sync("GET", "/", ctx -> "hello"));
});
assertNotNull(handler);
final FakeOngoingRequest ongoingRequest = ongoingRequest("http://foo");
handler.handle(ongoingRequest);
assertThat(ongoingRequest.getReply(), hasStatus(Status.GONE));
assertEquals("hello", lastResponseRef.get());
} catch (IOException e) {
fail(e.getMessage());
}
}
use of com.spotify.apollo.request.OngoingRequest in project apollo by spotify.
the class RequestLoggingDecoratorTest method collectLoggingEventsForRequest.
private List<LoggingEvent> collectLoggingEventsForRequest(OngoingRequest ongoingRequest) {
RequestRunnableFactory decorated = decorator.apply(delegateFactory);
decorated.create(ongoingRequest).run(EMPTY_CONTINUATION);
return testLogger.getLoggingEvents().stream().filter(event -> event.getLevel() == Level.INFO).collect(Collectors.toList());
}
use of com.spotify.apollo.request.OngoingRequest in project apollo by spotify.
the class AsyncContextOngoingRequestTest method shouldNotAllowOverridingDropHandling.
@Test
public void shouldNotAllowOverridingDropHandling() throws Exception {
OngoingRequest ongoingRequest = new Subclassed(REQUEST, asyncContext, logger);
ongoingRequest.drop();
verify(logger).accept(ongoingRequest, Optional.of(DROPPED));
}
use of com.spotify.apollo.request.OngoingRequest in project apollo by spotify.
the class HttpServerModuleTest method testCanStartRegularModule.
@Test
public void testCanStartRegularModule() throws Exception {
int port = 9083;
try (Service.Instance instance = service().start(NO_ARGS, onPort(port))) {
HttpServer server = HttpServerModule.server(instance);
assertCanNotConnect(port);
TestHandler testHandler = new TestHandler();
server.start(testHandler);
assertCanConnect(port);
Request request = new Request.Builder().get().url(baseUrl(port) + "/hello/world").build();
okhttp3.Response response = okHttpClient.newCall(request).execute();
assertThat(response.code(), is(IM_A_TEAPOT.code()));
assertThat(testHandler.requests.size(), is(1));
OngoingRequest incomingRequest = testHandler.requests.get(0);
assertThat(incomingRequest.request().uri(), is("/hello/world"));
server.close();
assertCanNotConnect(port);
}
}
use of com.spotify.apollo.request.OngoingRequest in project apollo by spotify.
the class ApolloEnvironmentModuleTest method shouldUseRequestRunnableFactoryDecorator.
@Test
public void shouldUseRequestRunnableFactoryDecorator() throws Exception {
final AtomicInteger counter = new AtomicInteger();
final Service service = this.service.withModule(new RequestInspectingModule("http://foo", counter)).build();
try (Service.Instance i = service.start()) {
final ApolloEnvironment environment = ApolloEnvironmentModule.environment(i);
final RequestHandler handler = environment.initialize(env -> {
});
assertNotNull(handler);
final OngoingRequest ongoingRequest = ongoingRequest("http://foo");
handler.handle(ongoingRequest);
assertEquals(1, counter.get());
handler.handle(ongoingRequest);
assertEquals(2, counter.get());
} catch (IOException e) {
fail(e.getMessage());
}
}
Aggregations