Search in sources :

Example 26 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class StatusUpdaterTest method test_updateStatusForApplications.

@Test
public void test_updateStatusForApplications() throws InterruptedException {
    updater.setStatusLifetime(100L);
    Application app1 = Application.create("foo").withId("id-1").withHealthUrl("health-1").build();
    store.save(app1);
    // Let the StatusInfo of id-1 expire
    Thread.sleep(120L);
    Application app2 = Application.create("foo").withId("id-2").withHealthUrl("health-2").build();
    store.save(app2);
    when(applicationOps.getHealth(eq(app1))).thenReturn(ResponseEntity.ok((Map<String, Serializable>) null));
    updater.updateStatusForAllApplications();
    assertThat(store.find("id-1").getStatusInfo().getStatus(), CoreMatchers.is("UP"));
    verify(applicationOps, never()).getHealth(eq(app2));
}
Also used : Application(de.codecentric.boot.admin.model.Application) Map(java.util.Map) Test(org.junit.Test)

Example 27 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class ApplicationHeadersFilterTest method test_add_headers_on_matching_route_only.

@Test
public void test_add_headers_on_matching_route_only() {
    Application application = Application.create("test").withHealthUrl("/health").build();
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.add("test", "qwertz");
    when(routeLocator.getMatchingRoute("/health")).thenReturn(new ApplicationRoute(application, null, null, null, null));
    when(headerProvider.getHeaders(application)).thenReturn(httpHeaders);
    RequestContext context = creteRequestContext("/health");
    RequestContext.testSetCurrentContext(context);
    filter.run();
    assertThat(context.getZuulRequestHeaders().get("test"), is("qwertz"));
    context = creteRequestContext("/foobar");
    RequestContext.testSetCurrentContext(context);
    filter.run();
    assertThat(context.getZuulRequestHeaders().get("test"), nullValue());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) RequestContext(com.netflix.zuul.context.RequestContext) Application(de.codecentric.boot.admin.model.Application) ApplicationRoute(de.codecentric.boot.admin.zuul.ApplicationRouteLocator.ApplicationRoute) Test(org.junit.Test)

Example 28 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class ApplicationRegistryTest method register.

@Test
public void register() throws Exception {
    Application app = registry.register(Application.create("abc").withHealthUrl("http://localhost:8080/health").build());
    assertEquals("http://localhost:8080/health", app.getHealthUrl());
    assertEquals("abc", app.getName());
    assertNotNull(app.getId());
}
Also used : Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 29 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class ApplicationRegistryTest method refresh.

@Test
public void refresh() throws Exception {
    // Given application is already reegistered and has status and info.
    StatusInfo status = StatusInfo.ofUp();
    Info info = Info.from(singletonMap("foo", "bar"));
    Application app = Application.create("abc").withHealthUrl("http://localhost:8080/health").withStatusInfo(status).withInfo(info).build();
    String id = idGenerator.generateId(app);
    store.save(Application.copyOf(app).withId(id).build());
    // When application registers second time
    Application registered = registry.register(Application.create("abc").withHealthUrl("http://localhost:8080/health").build());
    // Then info and status are retained
    assertThat(registered.getInfo(), sameInstance(info));
    assertThat(registered.getStatusInfo(), sameInstance(status));
}
Also used : StatusInfo(de.codecentric.boot.admin.model.StatusInfo) StatusInfo(de.codecentric.boot.admin.model.StatusInfo) Info(de.codecentric.boot.admin.model.Info) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 30 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class ApplicationRegistryTest method getApplicationsByName.

@Test
public void getApplicationsByName() throws Exception {
    Application app = registry.register(Application.create("abc").withHealthUrl("http://localhost/health").build());
    Application app2 = registry.register(Application.create("abc").withHealthUrl("http://localhost:8081/health").build());
    Application app3 = registry.register(Application.create("zzz").withHealthUrl("http://localhost:8082/health").build());
    Collection<Application> applications = registry.getApplicationsByName("abc");
    assertEquals(2, applications.size());
    assertTrue(applications.contains(app));
    assertTrue(applications.contains(app2));
    assertFalse(applications.contains(app3));
}
Also used : Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Aggregations

Application (de.codecentric.boot.admin.model.Application)36 Test (org.junit.Test)27 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)7 ServiceInstance (org.springframework.cloud.client.ServiceInstance)7 ClientApplicationRegisteredEvent (de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent)5 ClientApplicationDeregisteredEvent (de.codecentric.boot.admin.event.ClientApplicationDeregisteredEvent)4 InstanceInfo (com.netflix.appinfo.InstanceInfo)3 ClientApplicationEvent (de.codecentric.boot.admin.event.ClientApplicationEvent)3 StatusInfo (de.codecentric.boot.admin.model.StatusInfo)3 Collection (java.util.Collection)3 Map (java.util.Map)3 EurekaServiceInstance (org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance)3 HttpHeaders (org.springframework.http.HttpHeaders)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 Collections.singletonMap (java.util.Collections.singletonMap)2 HttpEntity (org.springframework.http.HttpEntity)2 RequestContext (com.netflix.zuul.context.RequestContext)1 ClientApplicationStatusChangedEvent (de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent)1