de.codecentric.boot.admin.server.domain.values.Registration Java Examples

The following examples show how to use de.codecentric.boot.admin.server.domain.values.Registration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultServiceInstanceConverterTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void test_convert_with_metadata() {
    ServiceInstance service = new DefaultServiceInstance("test-1", "test", "localhost", 80, false);
    Map<String, String> metadata = new HashMap<>();
    metadata.put("health.path", "ping");
    metadata.put("management.context-path", "mgmt");
    metadata.put("management.port", "1234");
    metadata.put("management.address", "127.0.0.1");
    service.getMetadata().putAll(metadata);

    Registration registration = new DefaultServiceInstanceConverter().convert(service);

    assertThat(registration.getName()).isEqualTo("test");
    assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:80/");
    assertThat(registration.getManagementUrl()).isEqualTo("http://127.0.0.1:1234/mgmt");
    assertThat(registration.getHealthUrl()).isEqualTo("http://127.0.0.1:1234/mgmt/ping");
    assertThat(registration.getMetadata()).isEqualTo(metadata);
}
 
Example #2
Source File: AbstractInstanceRepositoryTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void should_run_compute_with_null() {
    //when
    InstanceId instanceId = InstanceId.of("foo");
    StepVerifier.create(repository.compute(instanceId, (key, application) -> {
        assertThat(application).isNull();
        return Mono.just(Instance.create(key).register(Registration.create("foo", "http://health").build()));
    }))
                .expectNext(Instance.create(instanceId)
                                    .register(Registration.create("foo", "http://health").build()))
                .verifyComplete();

    //then
    StepVerifier.create(repository.find(instanceId))
                .assertNext(loaded -> assertThat(loaded.getId()).isEqualTo(instanceId))
                .verifyComplete();
}
 
Example #3
Source File: InstanceTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void should_update_buildVersion() {
    Instance instance = Instance.create(InstanceId.of("id"));

    assertThat(instance.getBuildVersion()).isNull();

    Registration registration = Registration.create("foo-instance", "http://health")
                                            .metadata("version", "1.0.0")
                                            .build();
    instance = instance.register(registration).withInfo(Info.empty());
    assertThat(instance.getBuildVersion()).isEqualTo(BuildVersion.valueOf("1.0.0"));

    instance = instance.register(registration.toBuilder().clearMetadata().build());
    assertThat(instance.getBuildVersion()).isNull();

    instance = instance.withInfo(Info.from(singletonMap("build", singletonMap("version", "2.1.1"))));
    assertThat(instance.getBuildVersion()).isEqualTo(BuildVersion.valueOf("2.1.1"));

    instance = instance.deregister();
    assertThat(instance.getBuildVersion()).isNull();
}
 
Example #4
Source File: InstanceTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void should_extract_tags() {
    Instance instance = Instance.create(InstanceId.of("id"));

    assertThat(instance.getTags().getValues()).isEmpty();

    Registration registration = Registration.create("foo-instance", "http://health")
                                            .metadata("tags.environment", "test")
                                            .metadata("tags.region", "EU")
                                            .build();

    instance = instance.register(registration);
    assertThat(instance.getTags().getValues()).containsExactly(entry("environment", "test"), entry("region", "EU"));

    instance = instance.withInfo(Info.from(singletonMap("tags", singletonMap("region", "US-East"))));
    assertThat(instance.getTags().getValues()).containsExactly(
        entry("environment", "test"),
        entry("region", "US-East")
    );

    instance = instance.deregister();
    assertThat(instance.getTags().getValues()).isEmpty();

    instance = instance.register(registration.toBuilder().clearMetadata().build());
    assertThat(instance.getTags().getValues()).isEmpty();
}
 
Example #5
Source File: InstanceRegistrationUpdatedEventMixinTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void verifySerializeWithOnlyRequiredProperties() throws IOException {
	InstanceId id = InstanceId.of("test123");
	Instant timestamp = Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS);
	Registration registration = Registration.create("test", "http://localhost:9080/heath").build();

	InstanceRegistrationUpdatedEvent event = new InstanceRegistrationUpdatedEvent(id, 0L, timestamp, registration);

	JsonContent<InstanceRegistrationUpdatedEvent> jsonContent = jsonTester.write(event);
	assertThat(jsonContent).extractingJsonPathStringValue("$.instance").isEqualTo("test123");
	assertThat(jsonContent).extractingJsonPathNumberValue("$.version").isEqualTo(0);
	assertThat(jsonContent).extractingJsonPathNumberValue("$.timestamp").isEqualTo(1587751031.000000000);
	assertThat(jsonContent).extractingJsonPathStringValue("$.type").isEqualTo("REGISTRATION_UPDATED");
	assertThat(jsonContent).extractingJsonPathValue("$.registration").isNotNull();

	assertThat(jsonContent).extractingJsonPathStringValue("$.registration.name").isEqualTo("test");
	assertThat(jsonContent).extractingJsonPathStringValue("$.registration.managementUrl").isNull();
	assertThat(jsonContent).extractingJsonPathStringValue("$.registration.healthUrl")
			.isEqualTo("http://localhost:9080/heath");
	assertThat(jsonContent).extractingJsonPathStringValue("$.registration.serviceUrl").isNull();
	assertThat(jsonContent).extractingJsonPathStringValue("$.registration.source").isNull();
	assertThat(jsonContent).extractingJsonPathMapValue("$.registration.metadata").isEmpty();
}
 
Example #6
Source File: EurekaServiceInstanceConverterTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void convert_secure() {
    InstanceInfo instanceInfo = mock(InstanceInfo.class);
    when(instanceInfo.getSecureHealthCheckUrl()).thenReturn("");
    when(instanceInfo.getHealthCheckUrl()).thenReturn("http://localhost:80/mgmt/ping");
    EurekaServiceInstance service = mock(EurekaServiceInstance.class);
    when(service.getInstanceInfo()).thenReturn(instanceInfo);
    when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
    when(service.getServiceId()).thenReturn("test");
    when(service.getMetadata()).thenReturn(singletonMap("management.context-path", "/mgmt"));

    Registration registration = new EurekaServiceInstanceConverter().convert(service);

    assertThat(registration.getName()).isEqualTo("test");
    assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:80/");
    assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:80/mgmt");
    assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:80/mgmt/ping");
}
 
Example #7
Source File: InfoUpdaterTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_clear_info_on_exception() {
	this.updater = new InfoUpdater(this.repository, InstanceWebClient.builder().build());

	// given
	Instance instance = Instance.create(InstanceId.of("onl"))
			.register(Registration.create("foo", this.wireMock.url("/health")).build())
			.withEndpoints(Endpoints.single("info", this.wireMock.url("/info"))).withStatusInfo(StatusInfo.ofUp())
			.withInfo(Info.from(singletonMap("foo", "bar")));
	StepVerifier.create(this.repository.save(instance)).expectNextCount(1).verifyComplete();

	this.wireMock.stubFor(get("/info").willReturn(okJson("{ \"foo\": \"bar\" }").withFixedDelay(1500)));

	// when
	StepVerifier.create(this.eventStore).expectSubscription()
			.then(() -> StepVerifier.create(this.updater.updateInfo(instance.getId())).verifyComplete())
			// then
			.assertNext((event) -> assertThat(event).isInstanceOf(InstanceInfoChangedEvent.class)).thenCancel()
			.verify();

	StepVerifier.create(this.repository.find(instance.getId()))
			.assertNext((app) -> assertThat(app.getInfo()).isEqualTo(Info.empty())).verifyComplete();
}
 
Example #8
Source File: QueryIndexEndpointStrategy.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<Endpoints> detectEndpoints(Instance instance) {
    Registration registration = instance.getRegistration();
    String managementUrl = registration.getManagementUrl();
    if (managementUrl == null || Objects.equals(registration.getServiceUrl(), managementUrl)) {
        return Mono.empty();
    }

    return instanceWebClient.instance(instance)
                            .get()
                            .uri(managementUrl)
                            .exchange()
                            .flatMap(response -> {
                                if (response.statusCode().is2xxSuccessful() &&
                                    response.headers()
                                            .contentType()
                                            .map(actuatorMediaType::isCompatibleWith)
                                            .orElse(false)) {
                                    return response.bodyToMono(Response.class);
                                } else {
                                    return response.bodyToMono(Void.class).then(Mono.empty());
                                }
                            })
                            .flatMap(this::convert);
}
 
Example #9
Source File: InstanceNameNotificationFilterTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void test_filterByName() {
	NotificationFilter filter = new ApplicationNameNotificationFilter("foo", null);

	Instance filteredInstance = Instance.create(InstanceId.of("-"))
			.register(Registration.create("foo", "http://health").build());
	InstanceRegisteredEvent filteredEvent = new InstanceRegisteredEvent(filteredInstance.getId(),
			filteredInstance.getVersion(), filteredInstance.getRegistration());
	assertThat(filter.filter(filteredEvent, filteredInstance)).isTrue();

	Instance ignoredInstance = Instance.create(InstanceId.of("-"))
			.register(Registration.create("bar", "http://health").build());
	InstanceRegisteredEvent ignoredEvent = new InstanceRegisteredEvent(ignoredInstance.getId(),
			ignoredInstance.getVersion(), ignoredInstance.getRegistration());
	assertThat(filter.filter(ignoredEvent, ignoredInstance)).isFalse();
}
 
Example #10
Source File: InstanceIdNotificationFilterTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void test_filterByName() {
	NotificationFilter filter = new InstanceIdNotificationFilter(InstanceId.of("cafebabe"), null);

	Instance filteredInstance = Instance.create(InstanceId.of("cafebabe"))
			.register(Registration.create("foo", "http://health").build());
	InstanceRegisteredEvent filteredEvent = new InstanceRegisteredEvent(filteredInstance.getId(),
			filteredInstance.getVersion(), filteredInstance.getRegistration());
	assertThat(filter.filter(filteredEvent, filteredInstance)).isTrue();

	Instance ignoredInstance = Instance.create(InstanceId.of("-"))
			.register(Registration.create("foo", "http://health").build());
	InstanceRegisteredEvent ignoredEvent = new InstanceRegisteredEvent(ignoredInstance.getId(),
			ignoredInstance.getVersion(), ignoredInstance.getRegistration());
	assertThat(filter.filter(ignoredEvent, ignoredInstance)).isFalse();
}
 
Example #11
Source File: AbstractInstanceRepositoryTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void should_retry_computeIfPresent() {
    AtomicLong counter = new AtomicLong(3L);
    //given
    Instance instance1 = Instance.create(InstanceId.of("foo.1"))
                                 .register(Registration.create("foo", "http://health").build());
    StepVerifier.create(repository.save(instance1)).expectNextCount(1).verifyComplete();

    //when
    StepVerifier.create(repository.computeIfPresent(instance1.getId(),
        (key, application) -> counter.getAndDecrement() >
                              0L ? Mono.just(instance1) : Mono.just(application.withEndpoints(Endpoints.single(
            "info",
            "info"
        )))
    )).expectNext(instance1.withEndpoints(Endpoints.single("info", "info"))).verifyComplete();

    //then
    StepVerifier.create(repository.find(instance1.getId()))
                .assertNext(loaded -> assertThat(loaded.getEndpoints()).isEqualTo(Endpoints.single("info", "info")
                                                                                           .withEndpoint(
                                                                                               "health",
                                                                                               "http://health"
                                                                                           )))
                .verifyComplete();
}
 
Example #12
Source File: QueryIndexEndpointStrategyTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_endpoints_with_aligned_scheme() {
	// given
	Instance instance = Instance.create(InstanceId.of("id")).register(Registration
			.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());

	String host = "http://localhost:" + this.wireMock.httpsPort();
	String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"" + host
			+ "/mgmt/metrics/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"" + host
			+ "/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"" + host
			+ "/mgmt/stats\"},\"info\":{\"templated\":false,\"href\":\"" + host + "/mgmt/info\"}}}";

	this.wireMock.stubFor(get("/mgmt").willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)));

	QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);

	// when
	String secureHost = "https://localhost:" + this.wireMock.httpsPort();
	StepVerifier.create(strategy.detectEndpoints(instance))
			// then
			.expectNext(Endpoints.single("metrics", secureHost + "/mgmt/stats").withEndpoint("info",
					secureHost + "/mgmt/info"))//
			.verifyComplete();
}
 
Example #13
Source File: AbstractInstanceRepositoryTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void save() {
    //given
    Instance instance = Instance.create(InstanceId.of("foo"))
                                .register(Registration.create("name", "http://health").build());

    StepVerifier.create(repository.save(instance)).expectNext(instance).verifyComplete();

    //when/then
    StepVerifier.create(repository.find(instance.getId())).assertNext(loaded -> {
        assertThat(loaded.getId()).isEqualTo(instance.getId());
        assertThat(loaded.getVersion()).isEqualTo(instance.getVersion());
        assertThat(loaded.getRegistration()).isEqualTo(instance.getRegistration());
        assertThat(loaded.getInfo()).isEqualTo(instance.getInfo());
        assertThat(loaded.getStatusInfo()).isEqualTo(instance.getStatusInfo());
    }).verifyComplete();
}
 
Example #14
Source File: InfoUpdaterTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_retry() {
	// given
	Registration registration = Registration.create("foo", this.wireMock.url("/health")).build();
	Instance instance = Instance.create(InstanceId.of("onl")).register(registration)
			.withEndpoints(Endpoints.single("info", this.wireMock.url("/info"))).withStatusInfo(StatusInfo.ofUp());
	StepVerifier.create(this.repository.save(instance)).expectNextCount(1).verifyComplete();

	this.wireMock.stubFor(get("/info").inScenario("retry").whenScenarioStateIs(STARTED)
			.willReturn(aResponse().withFixedDelay(5000)).willSetStateTo("recovered"));

	String body = "{ \"foo\": \"bar\" }";
	this.wireMock.stubFor(get("/info").inScenario("retry").whenScenarioStateIs("recovered")
			.willReturn(okJson(body).withHeader("Content-Length", Integer.toString(body.length()))));

	// when
	StepVerifier.create(this.eventStore).expectSubscription()
			.then(() -> StepVerifier.create(this.updater.updateInfo(instance.getId())).verifyComplete())
			// then
			.assertNext((event) -> assertThat(event).isInstanceOf(InstanceInfoChangedEvent.class)).thenCancel()
			.verify();

	StepVerifier.create(this.repository.find(instance.getId()))
			.assertNext((app) -> assertThat(app.getInfo()).isEqualTo(Info.from(singletonMap("foo", "bar"))))
			.verifyComplete();
}
 
Example #15
Source File: QueryIndexEndpointStrategyTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_empty_on_empty_endpoints() {
	// given
	Instance instance = Instance.create(InstanceId.of("id")).register(Registration
			.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());

	String body = "{\"_links\":{}}";
	this.wireMock
			.stubFor(get("/mgmt").willReturn(okJson(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)));

	QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);

	// when
	StepVerifier.create(strategy.detectEndpoints(instance))
			// then
			.verifyComplete();
}
 
Example #16
Source File: QueryIndexEndpointStrategyTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_endpoints() {
    //given
    Instance instance = Instance.create(InstanceId.of("id"))
                                .register(Registration.create("test", wireMock.url("/mgmt/health"))
                                                      .managementUrl(wireMock.url("/mgmt"))
                                                      .build());

    String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"\\/mgmt\\/metrics\\/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"\\/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"\\/mgmt\\/stats\"},\"info\":{\"templated\":false,\"href\":\"\\/mgmt\\/info\"}}}";

    wireMock.stubFor(get("/mgmt").willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)
                                                     .withHeader("Content-Length",
                                                         Integer.toString(body.length())
                                                     )));

    QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(instanceWebClient);

    //when
    StepVerifier.create(strategy.detectEndpoints(instance))
                //then
                .expectNext(Endpoints.single("metrics", "/mgmt/stats").withEndpoint("info", "/mgmt/info"))//
                .verifyComplete();
}
 
Example #17
Source File: DefaultServiceInstanceConverterTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_convert_with_metadata() {
	ServiceInstance service = new DefaultServiceInstance("test-1", "test", "localhost", 80, false);
	Map<String, String> metadata = new HashMap<>();
	metadata.put("health.path", "ping");
	metadata.put("management.context-path", "mgmt");
	metadata.put("management.port", "1234");
	metadata.put("management.address", "127.0.0.1");
	service.getMetadata().putAll(metadata);

	Registration registration = new DefaultServiceInstanceConverter().convert(service);

	assertThat(registration.getName()).isEqualTo("test");
	assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:80");
	assertThat(registration.getManagementUrl()).isEqualTo("http://127.0.0.1:1234/mgmt");
	assertThat(registration.getHealthUrl()).isEqualTo("http://127.0.0.1:1234/mgmt/ping");
	assertThat(registration.getMetadata()).isEqualTo(metadata);
}
 
Example #18
Source File: InstanceRegistryTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void refresh() {
	// Given instance is already reegistered and has status and info.
	StatusInfo status = StatusInfo.ofUp();
	Info info = Info.from(singletonMap("foo", "bar"));
	Registration registration = Registration.create("abc", "http://localhost:8080/health").build();
	InstanceId id = idGenerator.generateId(registration);
	Instance app = Instance.create(id).register(registration).withStatusInfo(status).withInfo(info);
	StepVerifier.create(repository.save(app)).expectNextCount(1).verifyComplete();

	// When instance registers second time
	InstanceId refreshId = registry.register(Registration.create("abc", "http://localhost:8080/health").build())
			.block();

	assertThat(refreshId).isEqualTo(id);
	StepVerifier.create(registry.getInstance(id)).assertNext((registered) -> {
		// Then info and status are retained
		assertThat(registered.getInfo()).isEqualTo(info);
		assertThat(registered.getStatusInfo()).isEqualTo(status);
	}).verifyComplete();
}
 
Example #19
Source File: ProbeEndpointsStrategyTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_detect_endpoints() {
    //given
    Instance instance = Instance.create(InstanceId.of("id"))
                                .register(Registration.create("test", wireMock.url("/mgmt/health"))
                                                      .managementUrl(wireMock.url("/mgmt"))
                                                      .build());

    wireMock.stubFor(options(urlEqualTo("/mgmt/metrics")).willReturn(ok()));
    wireMock.stubFor(options(urlEqualTo("/mgmt/stats")).willReturn(ok()));
    wireMock.stubFor(options(urlEqualTo("/mgmt/info")).willReturn(ok()));
    wireMock.stubFor(options(urlEqualTo("/mgmt/non-exist")).willReturn(notFound()));

    ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy(instanceWebClient,
        new String[]{"metrics:stats", "metrics", "info", "non-exist"}
    );

    //when
    StepVerifier.create(strategy.detectEndpoints(instance))
                //then
                .expectNext(Endpoints.single("metrics", wireMock.url("/mgmt/stats"))
                                     .withEndpoint("info", wireMock.url("/mgmt/info")))//
                .verifyComplete();
}
 
Example #20
Source File: InstanceDiscoveryListenerTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void should_register_instance_when_new_service_instance_is_discovered() {
    when(discovery.getServices()).thenReturn(singletonList("service"));
    when(discovery.getInstances("service")).thenReturn(singletonList(new DefaultServiceInstance("test-1", "service",
        "localhost",
        80,
        false
    )));

    listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

    StepVerifier.create(registry.getInstances()).assertNext(application -> {
        Registration registration = application.getRegistration();
        assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:80/actuator/health");
        assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:80/actuator");
        assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:80/");
        assertThat(registration.getName()).isEqualTo("service");
    }).verifyComplete();


}
 
Example #21
Source File: ProbeEndpointsStrategyTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_detect_endpoints() {
	// given
	Instance instance = Instance.create(InstanceId.of("id")).register(Registration
			.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());

	this.wireMock.stubFor(options(urlEqualTo("/mgmt/metrics")).willReturn(ok()));
	this.wireMock.stubFor(options(urlEqualTo("/mgmt/stats")).willReturn(ok()));
	this.wireMock.stubFor(options(urlEqualTo("/mgmt/info")).willReturn(ok()));
	this.wireMock.stubFor(options(urlEqualTo("/mgmt/non-exist")).willReturn(notFound()));
	this.wireMock.stubFor(options(urlEqualTo("/mgmt/error")).willReturn(serverError()));
	this.wireMock.stubFor(
			options(urlEqualTo("/mgmt/exception")).willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE)));

	ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy(this.instanceWebClient,
			new String[] { "metrics:stats", "metrics", "info", "non-exist", "error", "exception" });

	// when
	StepVerifier.create(strategy.detectEndpoints(instance))
			// then
			.expectNext(Endpoints.single("metrics", this.wireMock.url("/mgmt/stats")).withEndpoint("info",
					this.wireMock.url("/mgmt/info")))//
			.verifyComplete();
}
 
Example #22
Source File: InstanceRegistryTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void refresh() {
    // Given instance is already reegistered and has status and info.
    StatusInfo status = StatusInfo.ofUp();
    Info info = Info.from(singletonMap("foo", "bar"));
    Registration registration = Registration.create("abc", "http://localhost:8080/health").build();
    InstanceId id = idGenerator.generateId(registration);
    Instance app = Instance.create(id).register(registration).withStatusInfo(status).withInfo(info);
    StepVerifier.create(repository.save(app)).expectNextCount(1).verifyComplete();

    // When instance registers second time
    InstanceId refreshId = registry.register(Registration.create("abc", "http://localhost:8080/health").build())
                                   .block();

    assertThat(refreshId).isEqualTo(id);
    StepVerifier.create(registry.getInstance(id)).assertNext(registered -> {
        // Then info and status are retained
        assertThat(registered.getInfo()).isEqualTo(info);
        assertThat(registered.getStatusInfo()).isEqualTo(status);
    }).verifyComplete();
}
 
Example #23
Source File: MicrosoftTeamsNotifierTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    instance = Instance.create(InstanceId.of(appId))
                       .register(Registration.create(appName, healthUrl)
                                             .managementUrl(managementUrl)
                                             .serviceUrl(serviceUrl)
                                             .build());

    repository = mock(InstanceRepository.class);
    when(repository.find(instance.getId())).thenReturn(Mono.just(instance));

    mockRestTemplate = mock(RestTemplate.class);
    notifier = new MicrosoftTeamsNotifier(repository);
    notifier.setRestTemplate(mockRestTemplate);
    notifier.setWebhookUrl(URI.create("http://example.com"));
}
 
Example #24
Source File: QueryIndexEndpointStrategyTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_endpoints() {
	// given
	Instance instance = Instance.create(InstanceId.of("id")).register(Registration
			.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());

	String host = "https://localhost:" + this.wireMock.httpsPort();
	String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"" + host
			+ "/mgmt/metrics/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"" + host
			+ "/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"" + host
			+ "/mgmt/stats\"},\"info\":{\"templated\":false,\"href\":\"" + host + "/mgmt/info\"}}}";

	this.wireMock.stubFor(get("/mgmt").willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)));

	QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);

	// when
	StepVerifier.create(strategy.detectEndpoints(instance))
			// then
			.expectNext(Endpoints.single("metrics", host + "/mgmt/stats").withEndpoint("info", host + "/mgmt/info"))//
			.verifyComplete();
}
 
Example #25
Source File: EurekaServiceInstanceConverterTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void convert_secure() {
	InstanceInfo instanceInfo = mock(InstanceInfo.class);
	when(instanceInfo.getSecureHealthCheckUrl()).thenReturn("");
	when(instanceInfo.getHealthCheckUrl()).thenReturn("http://localhost:80/mgmt/ping");
	EurekaServiceInstance service = mock(EurekaServiceInstance.class);
	when(service.getInstanceInfo()).thenReturn(instanceInfo);
	when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
	when(service.getServiceId()).thenReturn("test");
	when(service.getMetadata()).thenReturn(singletonMap("management.context-path", "/mgmt"));

	Registration registration = new EurekaServiceInstanceConverter().convert(service);

	assertThat(registration.getName()).isEqualTo("test");
	assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:80");
	assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:80/mgmt");
	assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:80/mgmt/ping");
}
 
Example #26
Source File: EurekaServiceInstanceConverterTest.java    From Moss with Apache License 2.0 5 votes vote down vote up
@Test
public void convert_missing_mgmtpath() {
    InstanceInfo instanceInfo = mock(InstanceInfo.class);
    when(instanceInfo.getHealthCheckUrl()).thenReturn("http://localhost:80/mgmt/ping");
    EurekaServiceInstance service = mock(EurekaServiceInstance.class);
    when(service.getInstanceInfo()).thenReturn(instanceInfo);
    when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
    when(service.getServiceId()).thenReturn("test");

    Registration registration = new EurekaServiceInstanceConverter().convert(service);

    assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:80/actuator");
}
 
Example #27
Source File: InstanceTest.java    From Moss with Apache License 2.0 5 votes vote down vote up
@Test
public void should_yield_same_status_from_replaying() {
    Registration registration = Registration.create("foo-instance", "http://health")
                                            .metadata("version", "1.0.0")
                                            .build();
    Instance instance = Instance.create(InstanceId.of("id"))
                                .register(registration.toBuilder().clearMetadata().build())
                                .register(registration)
                                .withEndpoints(Endpoints.single("info", "info"))
                                .withStatusInfo(StatusInfo.ofUp())
                                .withInfo(Info.from(singletonMap("foo", "bar")));

    Instance loaded = Instance.create(InstanceId.of("id")).apply(instance.getUnsavedEvents());
    assertThat(loaded.getUnsavedEvents()).isEmpty();
    assertThat(loaded.getRegistration()).isEqualTo(registration);
    assertThat(loaded.isRegistered()).isTrue();
    assertThat(loaded.getStatusInfo()).isEqualTo(StatusInfo.ofUp());
    assertThat(loaded.getStatusTimestamp()).isEqualTo(instance.getStatusTimestamp());
    assertThat(loaded.getInfo()).isEqualTo(Info.from(singletonMap("foo", "bar")));
    assertThat(loaded.getEndpoints()).isEqualTo(Endpoints.single("info", "info")
                                                         .withEndpoint("health", "http://health"));
    assertThat(loaded.getVersion()).isEqualTo(4L);
    assertThat(loaded.getBuildVersion()).isEqualTo(BuildVersion.valueOf("1.0.0"));

    Instance deregisteredInstance = instance.deregister();
    loaded = Instance.create(InstanceId.of("id")).apply(deregisteredInstance.getUnsavedEvents());
    assertThat(loaded.getUnsavedEvents()).isEmpty();
    assertThat(loaded.isRegistered()).isFalse();
    assertThat(loaded.getInfo()).isEqualTo(Info.empty());
    assertThat(loaded.getStatusInfo()).isEqualTo(StatusInfo.ofUnknown());
    assertThat(loaded.getStatusTimestamp()).isEqualTo(deregisteredInstance.getStatusTimestamp());
    assertThat(loaded.getEndpoints()).isEqualTo(Endpoints.empty());
    assertThat(loaded.getVersion()).isEqualTo(5L);
    assertThat(loaded.getBuildVersion()).isEqualTo(null);
}
 
Example #28
Source File: InstanceTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_yield_same_status_from_replaying() {
	Registration registration = Registration.create("foo-instance", "http://health").metadata("version", "1.0.0")
			.build();
	Instance instance = Instance.create(InstanceId.of("id"))
			.register(registration.toBuilder().clearMetadata().build()).register(registration)
			.withEndpoints(Endpoints.single("info", "info")).withStatusInfo(StatusInfo.ofUp())
			.withInfo(Info.from(singletonMap("foo", "bar")));

	Instance loaded = Instance.create(InstanceId.of("id")).apply(instance.getUnsavedEvents());
	assertThat(loaded.getUnsavedEvents()).isEmpty();
	assertThat(loaded.getRegistration()).isEqualTo(registration);
	assertThat(loaded.isRegistered()).isTrue();
	assertThat(loaded.getStatusInfo()).isEqualTo(StatusInfo.ofUp());
	assertThat(loaded.getStatusTimestamp()).isEqualTo(instance.getStatusTimestamp());
	assertThat(loaded.getInfo()).isEqualTo(Info.from(singletonMap("foo", "bar")));
	assertThat(loaded.getEndpoints())
			.isEqualTo(Endpoints.single("info", "info").withEndpoint("health", "http://health"));
	assertThat(loaded.getVersion()).isEqualTo(4L);
	assertThat(loaded.getBuildVersion()).isEqualTo(BuildVersion.valueOf("1.0.0"));

	Instance deregisteredInstance = instance.deregister();
	loaded = Instance.create(InstanceId.of("id")).apply(deregisteredInstance.getUnsavedEvents());
	assertThat(loaded.getUnsavedEvents()).isEmpty();
	assertThat(loaded.isRegistered()).isFalse();
	assertThat(loaded.getInfo()).isEqualTo(Info.empty());
	assertThat(loaded.getStatusInfo()).isEqualTo(StatusInfo.ofUnknown());
	assertThat(loaded.getStatusTimestamp()).isEqualTo(deregisteredInstance.getStatusTimestamp());
	assertThat(loaded.getEndpoints()).isEqualTo(Endpoints.empty());
	assertThat(loaded.getVersion()).isEqualTo(5L);
	assertThat(loaded.getBuildVersion()).isEqualTo(null);
}
 
Example #29
Source File: QueryIndexEndpointStrategyTest.java    From Moss with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_empty_when_mgmt_equals_service_url() {
    //given
    Instance instance = Instance.create(InstanceId.of("id"))
                                .register(Registration.create("test", wireMock.url("/app/health"))
                                                      .managementUrl(wireMock.url("/app"))
                                                      .serviceUrl(wireMock.url("/app"))
                                                      .build());

    QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(instanceWebClient);

    //when/then
    StepVerifier.create(strategy.detectEndpoints(instance)).verifyComplete();
    wireMock.verify(0, anyRequestedFor(urlPathEqualTo("/app")));
}
 
Example #30
Source File: DefaultServiceInstanceConverterTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_convert_with_custom_defaults() {
	DefaultServiceInstanceConverter converter = new DefaultServiceInstanceConverter();
	converter.setHealthEndpointPath("ping");
	converter.setManagementContextPath("mgmt");

	ServiceInstance service = new DefaultServiceInstance("test-1", "test", "localhost", 80, false);
	Registration registration = converter.convert(service);

	assertThat(registration.getName()).isEqualTo("test");
	assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:80");
	assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:80/mgmt");
	assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:80/mgmt/ping");
}