Search in sources :

Example 1 with ExposableJmxEndpoint

use of org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint in project spring-boot by spring-projects.

the class DefaultEndpointObjectNameFactoryTests method assertUniqueObjectName.

private void assertUniqueObjectName() {
    ExposableJmxEndpoint endpoint = endpoint(EndpointId.of("test"));
    String id = ObjectUtils.getIdentityHexString(endpoint);
    ObjectName objectName = generateObjectName(endpoint);
    assertThat(objectName.toString()).isEqualTo("org.springframework.boot:type=Endpoint,name=Test,identity=" + id);
}
Also used : ExposableJmxEndpoint(org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint) ObjectName(javax.management.ObjectName)

Example 2 with ExposableJmxEndpoint

use of org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint in project spring-boot by spring-projects.

the class JmxEndpointAutoConfigurationTests method jmxEndpointWithCustomEndpointObjectNameFactory.

@Test
void jmxEndpointWithCustomEndpointObjectNameFactory() {
    EndpointObjectNameFactory factory = mock(EndpointObjectNameFactory.class);
    this.contextRunner.withPropertyValues("spring.jmx.enabled=true").with(mockMBeanServer()).withBean(EndpointObjectNameFactory.class, () -> factory).run((context) -> {
        ArgumentCaptor<ExposableJmxEndpoint> argumentCaptor = ArgumentCaptor.forClass(ExposableJmxEndpoint.class);
        then(factory).should().getObjectName(argumentCaptor.capture());
        ExposableJmxEndpoint jmxEndpoint = argumentCaptor.getValue();
        assertThat(jmxEndpoint.getEndpointId().toLowerCaseString()).isEqualTo("test");
    });
}
Also used : ExposableJmxEndpoint(org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint) EndpointObjectNameFactory(org.springframework.boot.actuate.endpoint.jmx.EndpointObjectNameFactory) Test(org.junit.jupiter.api.Test)

Example 3 with ExposableJmxEndpoint

use of org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint in project spring-boot by spring-projects.

the class JmxEndpointDiscovererTests method getEndpointsWhenHasJmxExtensionWithNewOperationAddsExtraOperation.

@Test
void getEndpointsWhenHasJmxExtensionWithNewOperationAddsExtraOperation() {
    load(AdditionalOperationJmxEndpointConfiguration.class, (discoverer) -> {
        Map<EndpointId, ExposableJmxEndpoint> endpoints = discover(discoverer);
        assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
        Map<String, JmxOperation> operationByName = mapOperations(endpoints.get(EndpointId.of("test")).getOperations());
        assertThat(operationByName).containsOnlyKeys("getAll", "getSomething", "update", "deleteSomething", "getAnother");
        JmxOperation getAnother = operationByName.get("getAnother");
        assertThat(getAnother.getDescription()).isEqualTo("Get another thing");
        assertThat(getAnother.getOutputType()).isEqualTo(Object.class);
        assertThat(getAnother.getParameters()).isEmpty();
    });
}
Also used : JmxOperation(org.springframework.boot.actuate.endpoint.jmx.JmxOperation) ExposableJmxEndpoint(org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId) Test(org.junit.jupiter.api.Test)

Example 4 with ExposableJmxEndpoint

use of org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint in project spring-boot by spring-projects.

the class JmxEndpointDiscovererTests method getEndpointsWhenHasCacheWithTtlShouldCacheReadOperationWithTtlValue.

@Test
void getEndpointsWhenHasCacheWithTtlShouldCacheReadOperationWithTtlValue() {
    load(TestEndpoint.class, (id) -> 500L, (discoverer) -> {
        Map<EndpointId, ExposableJmxEndpoint> endpoints = discover(discoverer);
        assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
        Map<String, JmxOperation> operationByName = mapOperations(endpoints.get(EndpointId.of("test")).getOperations());
        assertThat(operationByName).containsOnlyKeys("getAll", "getSomething", "update", "deleteSomething");
        JmxOperation getAll = operationByName.get("getAll");
        assertThat(getInvoker(getAll)).isInstanceOf(CachingOperationInvoker.class);
        assertThat(((CachingOperationInvoker) getInvoker(getAll)).getTimeToLive()).isEqualTo(500);
    });
}
Also used : JmxOperation(org.springframework.boot.actuate.endpoint.jmx.JmxOperation) ExposableJmxEndpoint(org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId) CachingOperationInvoker(org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker) Test(org.junit.jupiter.api.Test)

Example 5 with ExposableJmxEndpoint

use of org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint in project spring-boot by spring-projects.

the class JmxEndpointDiscovererTests method getEndpointsShouldCacheReadOperations.

@Test
void getEndpointsShouldCacheReadOperations() {
    load(AdditionalOperationJmxEndpointConfiguration.class, (id) -> 500L, (discoverer) -> {
        Map<EndpointId, ExposableJmxEndpoint> endpoints = discover(discoverer);
        assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
        Map<String, JmxOperation> operationByName = mapOperations(endpoints.get(EndpointId.of("test")).getOperations());
        assertThat(operationByName).containsOnlyKeys("getAll", "getSomething", "update", "deleteSomething", "getAnother");
        JmxOperation getAll = operationByName.get("getAll");
        assertThat(getInvoker(getAll)).isInstanceOf(CachingOperationInvoker.class);
        assertThat(((CachingOperationInvoker) getInvoker(getAll)).getTimeToLive()).isEqualTo(500);
        JmxOperation getAnother = operationByName.get("getAnother");
        assertThat(getInvoker(getAnother)).isInstanceOf(CachingOperationInvoker.class);
        assertThat(((CachingOperationInvoker) getInvoker(getAnother)).getTimeToLive()).isEqualTo(500);
    });
}
Also used : JmxOperation(org.springframework.boot.actuate.endpoint.jmx.JmxOperation) ExposableJmxEndpoint(org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId) CachingOperationInvoker(org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker) Test(org.junit.jupiter.api.Test)

Aggregations

ExposableJmxEndpoint (org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint)7 Test (org.junit.jupiter.api.Test)5 EndpointId (org.springframework.boot.actuate.endpoint.EndpointId)4 JmxOperation (org.springframework.boot.actuate.endpoint.jmx.JmxOperation)4 CachingOperationInvoker (org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker)2 ObjectName (javax.management.ObjectName)1 EndpointObjectNameFactory (org.springframework.boot.actuate.endpoint.jmx.EndpointObjectNameFactory)1