Search in sources :

Example 11 with Service

use of com.spotify.apollo.core.Service 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());
    }
}
Also used : RequestHandler(com.spotify.apollo.request.RequestHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Service(com.spotify.apollo.core.Service) IOException(java.io.IOException) OngoingRequest(com.spotify.apollo.request.OngoingRequest) Test(org.junit.Test)

Example 12 with Service

use of com.spotify.apollo.core.Service in project apollo by spotify.

the class HttpService method boot.

public static void boot(AppInit appInit, String serviceName, InstanceListener instanceListener, String... args) throws LoadingException {
    final Service service = usingAppInit(appInit, serviceName).build();
    boot(service, instanceListener, args);
}
Also used : Service(com.spotify.apollo.core.Service)

Example 13 with Service

use of com.spotify.apollo.core.Service 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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RequestHandler(com.spotify.apollo.request.RequestHandler) Service(com.spotify.apollo.core.Service) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with Service

use of com.spotify.apollo.core.Service in project apollo by spotify.

the class HttpServiceTest method testBrokenService.

@Test
public void testBrokenService() throws Exception {
    final Service service = HttpService.usingAppInit(new BrokenService(), "test").build();
    exception.expect(LoadingException.class);
    HttpService.boot(service, "run", "foo");
}
Also used : Service(com.spotify.apollo.core.Service) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Aggregations

Service (com.spotify.apollo.core.Service)14 Test (org.junit.Test)9 RequestHandler (com.spotify.apollo.request.RequestHandler)6 OngoingRequest (com.spotify.apollo.request.OngoingRequest)5 IOException (java.io.IOException)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Request (okhttp3.Request)3 HttpService (com.spotify.apollo.httpservice.HttpService)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 AppInit (com.spotify.apollo.AppInit)1 Environment (com.spotify.apollo.Environment)1 Request (com.spotify.apollo.Request)1 RequestMetadata (com.spotify.apollo.RequestMetadata)1 Response (com.spotify.apollo.Response)1 Status (com.spotify.apollo.Status)1 Services (com.spotify.apollo.core.Services)1 ApolloConfig (com.spotify.apollo.environment.ApolloConfig)1 MetaDescriptor (com.spotify.apollo.meta.MetaDescriptor)1 MetaModule (com.spotify.apollo.meta.MetaModule)1