Search in sources :

Example 11 with InstanceId

use of de.codecentric.boot.admin.server.domain.values.InstanceId in project spring-boot-admin by codecentric.

the class InstanceRegistryTest method deregister.

@Test
public void deregister() {
    InstanceId id = registry.register(Registration.create("abc", "http://localhost:8080/health").build()).block();
    registry.deregister(id).block();
    StepVerifier.create(registry.getInstance(id)).assertNext((app) -> assertThat(app.isRegistered()).isFalse()).verifyComplete();
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Info(de.codecentric.boot.admin.server.domain.values.Info) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Collections.singletonMap(java.util.Collections.singletonMap) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Test(org.junit.jupiter.api.Test)

Example 12 with InstanceId

use of de.codecentric.boot.admin.server.domain.values.InstanceId in project spring-boot-admin by codecentric.

the class ApplicationRegistryTest method getInstance.

private Instance getInstance(String applicationName, String version) {
    Registration registration = Registration.create(applicationName, "http://localhost:8080/health").metadata("version", version).build();
    InstanceId id = InstanceId.of("TEST" + applicationName);
    return Instance.create(id).register(registration);
}
Also used : InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Registration(de.codecentric.boot.admin.server.domain.values.Registration)

Example 13 with InstanceId

use of de.codecentric.boot.admin.server.domain.values.InstanceId in project spring-boot-admin by codecentric.

the class ApplicationRegistryTest method deregister.

@Test
public void deregister() {
    Instance instance1 = getInstance("App1");
    InstanceId instance1Id = instance1.getId();
    when(this.instanceRegistry.getInstances("App1")).thenReturn(Flux.just(instance1));
    when(this.instanceRegistry.deregister(instance1Id)).thenReturn(Mono.just(instance1Id));
    StepVerifier.create(this.applicationRegistry.deregister("App1")).assertNext((instanceId) -> assertThat(instanceId).isEqualTo(instance1Id)).verifyComplete();
    verify(this.instanceRegistry).deregister(instance1Id);
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) CsvSource(org.junit.jupiter.params.provider.CsvSource) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Application(de.codecentric.boot.admin.server.domain.entities.Application) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Flux(reactor.core.publisher.Flux) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InstanceEventPublisher(de.codecentric.boot.admin.server.eventstore.InstanceEventPublisher) BuildVersion(de.codecentric.boot.admin.server.domain.values.BuildVersion) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with InstanceId

use of de.codecentric.boot.admin.server.domain.values.InstanceId in project spring-boot-admin by codecentric.

the class AbstractInstanceRepositoryTest method should_run_compute_with_null.

@Test
public void should_run_compute_with_null() {
    InstanceId instanceId = InstanceId.of("app-1");
    Registration registration = Registration.create("app", "http://health").build();
    // when
    StepVerifier.create(this.repository.compute(this.instance1.getId(), (key, application) -> {
        assertThat(application).isNull();
        return Mono.just(Instance.create(key).register(registration));
    })).assertNext((v) -> {
        assertThat(v.getId()).isEqualTo(instanceId);
        assertThat(v.getRegistration()).isEqualTo(registration);
    }).verifyComplete();
    // then
    StepVerifier.create(this.repository.find(instanceId)).assertNext((v) -> {
        assertThat(v.getId()).isEqualTo(instanceId);
        assertThat(v.getRegistration()).isEqualTo(registration);
    }).verifyComplete();
}
Also used : Test(org.junit.jupiter.api.Test) Registration(de.codecentric.boot.admin.server.domain.values.Registration) AtomicLong(java.util.concurrent.atomic.AtomicLong) Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) StepVerifier(reactor.test.StepVerifier) AssertionFailedError(org.opentest4j.AssertionFailedError) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(reactor.core.publisher.Mono) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Example 15 with InstanceId

use of de.codecentric.boot.admin.server.domain.values.InstanceId in project spring-boot-admin by codecentric.

the class InstancesProxyController method endpointProxy.

@ResponseBody
@RequestMapping(path = INSTANCE_MAPPED_PATH, method = { RequestMethod.GET, RequestMethod.HEAD, RequestMethod.POST, RequestMethod.PUT, RequestMethod.PATCH, RequestMethod.DELETE, RequestMethod.OPTIONS })
public void endpointProxy(@PathVariable("instanceId") String instanceId, HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
    ServletServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
    Flux<DataBuffer> requestBody = DataBufferUtils.readInputStream(request::getBody, this.bufferFactory, 4096);
    InstanceWebProxy.ForwardRequest fwdRequest = createForwardRequest(request, requestBody, this.adminContextPath + INSTANCE_MAPPED_PATH);
    this.instanceWebProxy.forward(this.registry.getInstance(InstanceId.of(instanceId)), fwdRequest, (clientResponse) -> {
        ServerHttpResponse response = new ServletServerHttpResponse(servletResponse);
        response.setStatusCode(clientResponse.statusCode());
        response.getHeaders().addAll(this.httpHeadersFilter.filterHeaders(clientResponse.headers().asHttpHeaders()));
        try {
            OutputStream responseBody = response.getBody();
            response.flush();
            return clientResponse.body(BodyExtractors.toDataBuffers()).window(1).concatMap((body) -> writeAndFlush(body, responseBody)).then();
        } catch (IOException ex) {
            return Mono.error(ex);
        }
    }).block();
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) AdminController(de.codecentric.boot.admin.server.web.AdminController) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ServerHttpResponse(org.springframework.http.server.ServerHttpResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpHeaderFilter(de.codecentric.boot.admin.server.web.HttpHeaderFilter) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) InstanceRegistry(de.codecentric.boot.admin.server.services.InstanceRegistry) DataBufferUtils(org.springframework.core.io.buffer.DataBufferUtils) URI(java.net.URI) AntPathMatcher(org.springframework.util.AntPathMatcher) InstanceWebClient(de.codecentric.boot.admin.server.web.client.InstanceWebClient) OutputStream(java.io.OutputStream) PathMatcher(org.springframework.util.PathMatcher) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) HttpServletResponse(javax.servlet.http.HttpServletResponse) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) DataBuffer(org.springframework.core.io.buffer.DataBuffer) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Flux(reactor.core.publisher.Flux) BodyExtractors(org.springframework.web.reactive.function.BodyExtractors) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) HandlerMapping(org.springframework.web.servlet.HandlerMapping) InstanceWebProxy(de.codecentric.boot.admin.server.web.InstanceWebProxy) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory) BodyInserters(org.springframework.web.reactive.function.BodyInserters) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) InstanceWebProxy(de.codecentric.boot.admin.server.web.InstanceWebProxy) OutputStream(java.io.OutputStream) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) IOException(java.io.IOException) ServerHttpResponse(org.springframework.http.server.ServerHttpResponse) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) DataBuffer(org.springframework.core.io.buffer.DataBuffer) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)32 Test (org.junit.jupiter.api.Test)28 Instant (java.time.Instant)18 Registration (de.codecentric.boot.admin.server.domain.values.Registration)13 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 StepVerifier (reactor.test.StepVerifier)7 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)6 ArrayList (java.util.ArrayList)6 Mono (reactor.core.publisher.Mono)6 InstanceRepository (de.codecentric.boot.admin.server.domain.entities.InstanceRepository)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Flux (reactor.core.publisher.Flux)5 EventsourcingInstanceRepository (de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository)4 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)4 InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)4 Info (de.codecentric.boot.admin.server.domain.values.Info)4 InMemoryEventStore (de.codecentric.boot.admin.server.eventstore.InMemoryEventStore)4 Collections.singletonMap (java.util.Collections.singletonMap)4 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)4