Search in sources :

Example 6 with Environment

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

the class ApolloEnvironmentModuleTest method shouldSetUpConfig.

@Test
public void shouldSetUpConfig() throws Exception {
    final AtomicReference<Environment> envReference = new AtomicReference<>();
    final Map<String, String> env = ImmutableMap.of("APOLLO_APOLLO_DOMAIN", "my-domain");
    try (Service.Instance i = service.build().start(ZERO_ARGS, env)) {
        final ApolloEnvironment environment = ApolloEnvironmentModule.environment(i);
        final RequestHandler handler = environment.initialize(new EnvApp(envReference::set));
        assertNotNull(handler);
        final Environment e = envReference.get();
        assertNotNull(e);
        assertNotNull(e.config());
        // from ping.conf
        assertEquals("baz", e.config().getString("bar"));
        assertEquals("my-domain", e.domain());
    } catch (IOException e) {
        fail(e.getMessage());
    }
}
Also used : RequestHandler(com.spotify.apollo.request.RequestHandler) Environment(com.spotify.apollo.Environment) Service(com.spotify.apollo.core.Service) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteString(okio.ByteString) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with Environment

use of com.spotify.apollo.Environment 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());
    }
}
Also used : Response(com.spotify.apollo.Response) Request(com.spotify.apollo.Request) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) OngoingRequest(com.spotify.apollo.request.OngoingRequest) RequestHandler(com.spotify.apollo.request.RequestHandler) Assert.assertThat(org.junit.Assert.assertThat) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ByteString(okio.ByteString) Assert.fail(org.junit.Assert.fail) RequestMetadata(com.spotify.apollo.RequestMetadata) Service(com.spotify.apollo.core.Service) Environment(com.spotify.apollo.Environment) Status(com.spotify.apollo.Status) Before(org.junit.Before) Description(org.hamcrest.Description) ImmutableMap(com.google.common.collect.ImmutableMap) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Route(com.spotify.apollo.route.Route) Instant(java.time.Instant) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Consumer(java.util.function.Consumer) MetaModule(com.spotify.apollo.meta.MetaModule) Services(com.spotify.apollo.core.Services) Matcher(org.hamcrest.Matcher) RequestMetadataImpl(com.spotify.apollo.request.RequestMetadataImpl) Optional(java.util.Optional) AppInit(com.spotify.apollo.AppInit) Assert.assertEquals(org.junit.Assert.assertEquals) RequestHandler(com.spotify.apollo.request.RequestHandler) Service(com.spotify.apollo.core.Service) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteString(okio.ByteString) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with Environment

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

Example 9 with Environment

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

the class EnvironmentFactoryTest method customConfigResolverShouldWork.

@Test
public void customConfigResolverShouldWork() throws Exception {
    when(configResolver.getConfig(SERVICE_NAME)).thenReturn(configNode);
    final Environment environment = sut.withConfigResolver(configResolver).build().create(SERVICE_NAME, routingContext);
    assertEquals(configNode, environment.config());
}
Also used : Environment(com.spotify.apollo.Environment) Test(org.junit.Test)

Example 10 with Environment

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

the class EnvironmentFactoryTest method staticConfigShouldWork.

@Test
public void staticConfigShouldWork() throws Exception {
    final Environment environment = sut.withStaticConfig(configNode).build().create(SERVICE_NAME, routingContext);
    assertEquals(configNode, environment.config());
}
Also used : Environment(com.spotify.apollo.Environment) Test(org.junit.Test)

Aggregations

Environment (com.spotify.apollo.Environment)11 Test (org.junit.Test)10 Service (com.spotify.apollo.core.Service)5 IOException (java.io.IOException)5 ByteString (okio.ByteString)5 RequestHandler (com.spotify.apollo.request.RequestHandler)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 RoutingContext (com.spotify.apollo.environment.EnvironmentFactory.RoutingContext)2 AsyncHandler (com.spotify.apollo.route.AsyncHandler)2 Config (com.typesafe.config.Config)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 AppInit (com.spotify.apollo.AppInit)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 HttpService (com.spotify.apollo.httpservice.HttpService)1 LoadingException (com.spotify.apollo.httpservice.LoadingException)1 MetaModule (com.spotify.apollo.meta.MetaModule)1