Search in sources :

Example 1 with AppInit

use of com.spotify.apollo.AppInit in project apollo by spotify.

the class HttpServiceTest method testCreateWithAppInit.

@Test
public void testCreateWithAppInit() throws Exception {
    final InstanceWaiter waiter = new InstanceWaiter();
    final CountDownLatch closed = new CountDownLatch(1);
    final AppInit appInit = env -> {
        counter.incrementAndGet();
        env.closer().register(closed::countDown);
    };
    new Thread(() -> {
        try {
            HttpService.boot(appInit, "test", waiter, "run", "foo");
        } catch (LoadingException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }).start();
    final Service.Instance instance = waiter.waitForInstance();
    instance.getSignaller().signalShutdown();
    instance.waitForShutdown();
    closed.await(5000, TimeUnit.SECONDS);
    assertEquals(1, counter.get());
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Response(com.spotify.apollo.Response) AsyncHandler(com.spotify.apollo.route.AsyncHandler) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Assert.assertThat(org.junit.Assert.assertThat) HttpRequestMetadata(com.spotify.apollo.http.server.HttpRequestMetadata) Future(java.util.concurrent.Future) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteString(okio.ByteString) Assert.fail(org.junit.Assert.fail) RequestMetadata(com.spotify.apollo.RequestMetadata) Service(com.spotify.apollo.core.Service) ExpectedException(org.junit.rules.ExpectedException) ExecutorService(java.util.concurrent.ExecutorService) Environment(com.spotify.apollo.Environment) Before(org.junit.Before) Request(okhttp3.Request) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) Route(com.spotify.apollo.route.Route) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Rule(org.junit.Rule) OkHttpClient(okhttp3.OkHttpClient) Assert.assertNull(org.junit.Assert.assertNull) AppInit(com.spotify.apollo.AppInit) Assert.assertEquals(org.junit.Assert.assertEquals) AppInit(com.spotify.apollo.AppInit) Service(com.spotify.apollo.core.Service) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

AppInit (com.spotify.apollo.AppInit)1 Environment (com.spotify.apollo.Environment)1 RequestMetadata (com.spotify.apollo.RequestMetadata)1 Response (com.spotify.apollo.Response)1 Service (com.spotify.apollo.core.Service)1 HttpRequestMetadata (com.spotify.apollo.http.server.HttpRequestMetadata)1 AsyncHandler (com.spotify.apollo.route.AsyncHandler)1 Route (com.spotify.apollo.route.Route)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1 ByteString (okio.ByteString)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1