use of com.spotify.apollo.request.RequestHandler 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.RequestHandler in project apollo by spotify.
the class App method main.
public static void main(String... args) throws IOException, InterruptedException {
Service service = Services.usingName("test").withModule(HttpServerModule.create()).withModule(HttpClientModule.create()).build();
try (Service.Instance instance = service.start(args)) {
final RequestHandler handler = new Handler();
HttpServerModule.server(instance).start(handler);
LOG.info("Started service '{}'", service.getServiceName());
final String string = instance.getConfig().getString("config.key");
LOG.info("Value of config.key: {}", string);
instance.waitForShutdown();
LOG.info("Stopping service '{}'", service.getServiceName());
}
}
use of com.spotify.apollo.request.RequestHandler 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());
}
}
use of com.spotify.apollo.request.RequestHandler in project apollo by spotify.
the class ApolloEnvironmentModuleTest method shouldGetFunctioningEnvironmentInAppInit.
@Test
public void shouldGetFunctioningEnvironmentInAppInit() throws Exception {
final AtomicReference<Environment> envReference = new AtomicReference<>();
try (Service.Instance i = service.build().start()) {
final ApolloEnvironment environment = ApolloEnvironmentModule.environment(i);
final RequestHandler handler = environment.initialize(envReference::set);
assertNotNull(handler);
final Environment e = envReference.get();
validateEnv(e);
} catch (IOException e) {
fail(e.getMessage());
}
}
use of com.spotify.apollo.request.RequestHandler in project apollo by spotify.
the class HttpServiceModuleTest method shouldInitAndDestroyApplication.
@Test
public void shouldInitAndDestroyApplication() throws Exception {
final AtomicBoolean init = new AtomicBoolean();
final AtomicBoolean destroy = new AtomicBoolean();
final App app = new App(init, destroy);
try (Service.Instance i = service(app).start()) {
final RequestHandler handler = HttpServiceModule.requestHandler(i);
assertNotNull(handler);
} catch (IOException e) {
fail(e.getMessage());
}
assertTrue(init.get());
assertTrue(destroy.get());
}
Aggregations