Search in sources :

Example 1 with Environment

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

the class ServiceRunner method configure.

static void configure(final Environment environment) {
    final Config config = environment.config();
    final URI modelPath = URI.create(config.getString("iris.model"));
    final URI settingsPath = URI.create(config.getString("iris.settings"));
    try {
        IrisPrediction.configure(modelPath, settingsPath);
    } catch (final IOException e) {
        throw new RuntimeException(String.format("Could not load model! Model path: `%s`, settings path `%s`.", modelPath, settingsPath));
    }
    final EndPoints endPoints = new EndPoints();
    environment.routingEngine().registerRoutes(endPoints.routes().map(r -> r.withPrefix("/predict")));
}
Also used : LoadingException(com.spotify.apollo.httpservice.LoadingException) HttpService(com.spotify.apollo.httpservice.HttpService) Config(com.typesafe.config.Config) IOException(java.io.IOException) URI(java.net.URI) Service(com.spotify.apollo.core.Service) Environment(com.spotify.apollo.Environment) Config(com.typesafe.config.Config) IOException(java.io.IOException) URI(java.net.URI)

Example 2 with Environment

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

the class EnvironmentFactoryTest method shouldResolveThroughResolver.

@Test
public void shouldResolveThroughResolver() throws Exception {
    when(resolver.resolve(String.class)).thenReturn("hello world");
    final Environment environment = sut.build().create(SERVICE_NAME, routingContext);
    final String resolve = environment.resolve(String.class);
    assertEquals("hello world", resolve);
}
Also used : Environment(com.spotify.apollo.Environment) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ByteString(okio.ByteString) Test(org.junit.Test)

Example 3 with Environment

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

the class EnvironmentFactoryTest method shouldThrowIfUsedAfterInit.

@Test
public void shouldThrowIfUsedAfterInit() throws Exception {
    final EnvironmentFactory factory = sut.build();
    final RoutingContext routingContext = factory.createRoutingContext();
    final Environment environment = factory.create(SERVICE_NAME, routingContext);
    final Route<AsyncHandler<Response<ByteString>>> route = Route.sync("GET", "/f1", handler());
    environment.routingEngine().registerRoute(route);
    final Iterable<Object> objects = routingContext.endpointObjects();
    assertTrue(Iterables.contains(objects, route));
    try {
        environment.routingEngine().registerRoute(route);
        fail("should throw");
    } catch (Exception e) {
        assertThat(e.getMessage(), containsString("already been initialized"));
    }
}
Also used : RoutingContext(com.spotify.apollo.environment.EnvironmentFactory.RoutingContext) AsyncHandler(com.spotify.apollo.route.AsyncHandler) ByteString(okio.ByteString) Environment(com.spotify.apollo.Environment) Test(org.junit.Test)

Example 4 with Environment

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

the class EnvironmentFactoryTest method shouldCollectRegisteredRoutes.

@Test
public void shouldCollectRegisteredRoutes() throws Exception {
    final EnvironmentFactory factory = sut.build();
    final RoutingContext routingContext = factory.createRoutingContext();
    final Environment environment = factory.create(SERVICE_NAME, routingContext);
    final Route<AsyncHandler<Response<ByteString>>> route1 = Route.sync("GET", "/f1", handler());
    final Route<AsyncHandler<Response<ByteString>>> route2 = Route.sync("GET", "/2", handler());
    final Route<AsyncHandler<Response<ByteString>>> route3 = Route.sync("GET", "/3", handler());
    environment.routingEngine().registerRoute(route1).registerRoute(route2);
    environment.routingEngine().registerRoute(route3);
    final Iterable<Object> objects = routingContext.endpointObjects();
    assertTrue(Iterables.contains(objects, route1));
    assertTrue(Iterables.contains(objects, route2));
    assertTrue(Iterables.contains(objects, route3));
}
Also used : RoutingContext(com.spotify.apollo.environment.EnvironmentFactory.RoutingContext) AsyncHandler(com.spotify.apollo.route.AsyncHandler) ByteString(okio.ByteString) Environment(com.spotify.apollo.Environment) Test(org.junit.Test)

Example 5 with Environment

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

the class ApolloEnvironmentModuleTest method shouldGetFunctioningEnvironment.

@Test
public void shouldGetFunctioningEnvironment() 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(new EnvApp(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)

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