use of com.spotify.apollo.core.Service in project apollo by spotify.
the class HttpClientModuleTest method testOkHttpClientIsConfigured.
/**
* Ensure that the OkHttpClient instance provided by the module is configured as expected. This
* duplicates tests in {@link com.spotify.apollo.http.client.OkHttpClientProviderTest} but
* verifies that the provider is actually used.
*/
@Test
public void testOkHttpClientIsConfigured() throws Exception {
final Config config = ConfigFactory.parseString("http.client.connectTimeout: 7982");
final Service service = Services.usingName("test").withModule(HttpClientModule.create()).build();
try (Service.Instance i = service.start(new String[] {}, config)) {
final OkHttpClient underlying = i.resolve(OkHttpClient.class);
assertThat(underlying.connectTimeoutMillis(), is(7982));
}
}
use of com.spotify.apollo.core.Service in project apollo by spotify.
the class HttpServerModuleTest method testParsesQueryParameters.
@Test
public void testParsesQueryParameters() throws Exception {
int port = 9084;
try (Service.Instance instance = service().start(NO_ARGS, onPort(port))) {
HttpServer server = HttpServerModule.server(instance);
TestHandler testHandler = new TestHandler();
server.start(testHandler);
Request httpRequest = new Request.Builder().get().url(baseUrl(port) + "/query?a=foo&b=bar&b=baz").build();
okhttp3.Response response = okHttpClient.newCall(httpRequest).execute();
assertThat(response.code(), is(IM_A_TEAPOT.code()));
assertThat(testHandler.requests.size(), is(1));
final com.spotify.apollo.Request apolloRequest = testHandler.requests.get(0).request();
assertThat(apolloRequest.uri(), is("/query?a=foo&b=bar&b=baz"));
assertThat(apolloRequest.parameter("a"), is(Optional.of("foo")));
assertThat(apolloRequest.parameter("b"), is(Optional.of("bar")));
assertThat(apolloRequest.parameters().get("b"), is(asList("bar", "baz")));
assertThat(apolloRequest.parameter("c"), is(Optional.empty()));
}
}
use of com.spotify.apollo.core.Service 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.core.Service 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.core.Service in project apollo by spotify.
the class HttpServerModuleTest method testParsesHeadersParameters.
@Test
public void testParsesHeadersParameters() throws Exception {
int port = 9085;
try (Service.Instance instance = service().start(NO_ARGS, onPort(port))) {
HttpServer server = HttpServerModule.server(instance);
TestHandler testHandler = new TestHandler();
server.start(testHandler);
Request httpRequest = new Request.Builder().get().url(baseUrl(port) + "/headers").addHeader("Foo", "bar").addHeader("Repeat", "once").addHeader("Repeat", "twice").build();
okhttp3.Response response = okHttpClient.newCall(httpRequest).execute();
assertThat(response.code(), is(IM_A_TEAPOT.code()));
assertThat(testHandler.requests.size(), is(1));
final com.spotify.apollo.Request apolloRequest = testHandler.requests.get(0).request();
assertThat(apolloRequest.uri(), is("/headers"));
assertThat(apolloRequest.header("Foo"), is(Optional.of("bar")));
assertThat(apolloRequest.header("Repeat"), is(Optional.of("once,twice")));
assertThat(apolloRequest.header("Baz"), is(Optional.empty()));
System.out.println("apolloRequest.headers() = " + apolloRequest.headers());
}
}
Aggregations