Polish
This commit is contained in:
parent
ea2a98d009
commit
c578a30e90
|
@ -7,7 +7,6 @@ The `caches` endpoint provides access to the application's caches.
|
|||
|
||||
[[caches-all]]
|
||||
== Retrieving All Caches
|
||||
|
||||
To retrieve the application's caches, make a `GET` request to `/actuator/caches`, as
|
||||
shown in the following curl-based example:
|
||||
|
||||
|
@ -21,7 +20,6 @@ include::{snippets}caches/all/http-response.adoc[]
|
|||
|
||||
[[caches-all-response-structure]]
|
||||
=== Response Structure
|
||||
|
||||
The response contains details of the application's caches. The following table describes
|
||||
the structure of the response:
|
||||
|
||||
|
@ -32,7 +30,6 @@ include::{snippets}caches/all/response-fields.adoc[]
|
|||
|
||||
[[caches-named]]
|
||||
== Retrieving Caches by Name
|
||||
|
||||
To retrieve a cache by name, make a `GET` request to `/actuator/caches/{name}`,
|
||||
as shown in the following curl-based example:
|
||||
|
||||
|
@ -47,7 +44,6 @@ include::{snippets}caches/named/http-response.adoc[]
|
|||
|
||||
[[caches-named-request-structure]]
|
||||
=== Request Structure
|
||||
|
||||
If the requested name is specific enough to identify a single cache, no extra parameter is
|
||||
required. Otherwise, the `cacheManager` must be specified. The following table shows the
|
||||
supported query parameters:
|
||||
|
@ -59,7 +55,6 @@ include::{snippets}caches/named/request-parameters.adoc[]
|
|||
|
||||
[[caches-named-response-structure]]
|
||||
=== Response Structure
|
||||
|
||||
The response contains details of the requested cache. The following table describes the
|
||||
structure of the response:
|
||||
|
||||
|
@ -70,7 +65,6 @@ include::{snippets}caches/named/response-fields.adoc[]
|
|||
|
||||
[[caches-evict-all]]
|
||||
== Evict All Caches
|
||||
|
||||
To clear all available caches, make a `DELETE` request to `/actuator/caches` as shown in
|
||||
the following curl-based example:
|
||||
|
||||
|
@ -80,7 +74,6 @@ include::{snippets}caches/evict-all/curl-request.adoc[]
|
|||
|
||||
[[caches-evict-named]]
|
||||
== Evict a Cache by Name
|
||||
|
||||
To evict a particular cache, make a `DELETE` request to `/actuator/caches/{name}` as shown
|
||||
in the following curl-based example:
|
||||
|
||||
|
@ -93,7 +86,6 @@ specify which `Cache` should be cleared.
|
|||
|
||||
[[caches-evict-named-request-structure]]
|
||||
=== Request Structure
|
||||
|
||||
If the requested name is specific enough to identify a single cache, no extra parameter is
|
||||
required. Otherwise, the `cacheManager` must be specified. The following table shows the
|
||||
supported query parameters:
|
||||
|
|
|
@ -8,7 +8,6 @@ components.
|
|||
|
||||
[[integrationgraph-retrieving]]
|
||||
== Retrieving the Spring Integration graph
|
||||
|
||||
To retrieve the information about the application, make a `GET` request to
|
||||
`/actuator/integrationgraph`, as shown in the following curl-based example:
|
||||
|
||||
|
@ -22,7 +21,6 @@ include::{snippets}integrationgraph/graph/http-response.adoc[]
|
|||
|
||||
[[integrationgraph-retrieving-response-structure]]
|
||||
=== Response Structure
|
||||
|
||||
The response contains all Spring Integration components used within the application, as
|
||||
well as the links between them. More information about the structure can be found in the
|
||||
https://docs.spring.io/spring-integration/reference/html/system-management-chapter.html#integration-graph[reference
|
||||
|
@ -32,7 +30,6 @@ documentation].
|
|||
|
||||
[[integrationgraph-rebuilding]]
|
||||
== Rebuilding the Spring Integration graph
|
||||
|
||||
To rebuild the exposed graph, make a `POST` request to `/actuator/integrationgraph`, as
|
||||
shown in the following curl-based example:
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ import org.springframework.web.reactive.function.client.WebClient;
|
|||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for instrumentation of
|
||||
* {@link org.springframework.web.reactive.function.client.WebClient}.
|
||||
*
|
||||
* <p>
|
||||
* This is reusing the {@link io.micrometer.core.instrument.config.MeterFilter} defined in
|
||||
* {@link RestTemplateMetricsAutoConfiguration} for limiting the cardinality of "uri"
|
||||
|
|
|
@ -59,11 +59,13 @@ public class CachesEndpoint {
|
|||
@ReadOperation
|
||||
public CachesReport caches() {
|
||||
Map<String, Map<String, CacheDescriptor>> descriptors = new LinkedHashMap<>();
|
||||
getCacheEntries((name) -> true, (cacheManager) -> true).forEach((entry) -> {
|
||||
Map<String, CacheDescriptor> cmDescriptors = descriptors.computeIfAbsent(
|
||||
entry.getCacheManager(), (key) -> new LinkedHashMap<>());
|
||||
String cache = entry.getName();
|
||||
cmDescriptors.put(cache, new CacheDescriptor(entry.getTarget()));
|
||||
getCacheEntries(matchAll(), matchAll()).forEach((entry) -> {
|
||||
String cacheName = entry.getName();
|
||||
String cacheManager = entry.getCacheManager();
|
||||
Map<String, CacheDescriptor> cacheManagerDescriptors = descriptors
|
||||
.computeIfAbsent(cacheManager, (key) -> new LinkedHashMap<>());
|
||||
cacheManagerDescriptors.put(cacheName,
|
||||
new CacheDescriptor(entry.getTarget()));
|
||||
});
|
||||
return new CachesReport(descriptors);
|
||||
}
|
||||
|
@ -79,7 +81,7 @@ public class CachesEndpoint {
|
|||
@ReadOperation
|
||||
public CacheEntry cache(@Selector String cache, @Nullable String cacheManager) {
|
||||
return extractUniqueCacheEntry(cache,
|
||||
getCacheEntries((name) -> name.equals(cache), safeEqual(cacheManager)));
|
||||
getCacheEntries((name) -> name.equals(cache), isNameMatch(cacheManager)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,14 +89,13 @@ public class CachesEndpoint {
|
|||
*/
|
||||
@DeleteOperation
|
||||
public void clearCaches() {
|
||||
getCacheEntries((name) -> true, (cacheManagerName) -> true)
|
||||
.forEach(this::clearCache);
|
||||
getCacheEntries(matchAll(), matchAll()).forEach(this::clearCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the specific {@link Cache}.
|
||||
* @param cache then name of the cache
|
||||
* @param cacheManager the name of the cacheManager (can be {@code null}
|
||||
* @param cacheManager the name of the cacheManager (can be {@code null} to match all)
|
||||
* @return {@code true} if the cache was cleared or {@code false} if no such cache
|
||||
* exists
|
||||
* @throws NonUniqueCacheException if more than one cache with that name exist and no
|
||||
|
@ -102,7 +103,7 @@ public class CachesEndpoint {
|
|||
@DeleteOperation
|
||||
public boolean clearCache(@Selector String cache, @Nullable String cacheManager) {
|
||||
CacheEntry entry = extractUniqueCacheEntry(cache,
|
||||
getCacheEntries((name) -> name.equals(cache), safeEqual(cacheManager)));
|
||||
getCacheEntries((name) -> name.equals(cache), isNameMatch(cacheManager)));
|
||||
return (entry != null && clearCache(entry));
|
||||
}
|
||||
|
||||
|
@ -131,12 +132,13 @@ public class CachesEndpoint {
|
|||
entries.stream().map(CacheEntry::getCacheManager).distinct()
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
return (entries.isEmpty() ? null : entries.get(0));
|
||||
return (!entries.isEmpty() ? entries.get(0) : null);
|
||||
}
|
||||
|
||||
private boolean clearCache(CacheEntry entry) {
|
||||
String cacheName = entry.getName();
|
||||
Cache cache = this.cacheManagers.get(entry.getCacheManager()).getCache(cacheName);
|
||||
String cacheManager = entry.getCacheManager();
|
||||
Cache cache = this.cacheManagers.get(cacheManager).getCache(cacheName);
|
||||
if (cache != null) {
|
||||
cache.clear();
|
||||
return true;
|
||||
|
@ -144,9 +146,12 @@ public class CachesEndpoint {
|
|||
return false;
|
||||
}
|
||||
|
||||
private Predicate<String> safeEqual(String name) {
|
||||
return (name != null ? ((requested) -> requested.equals(name))
|
||||
: ((requested) -> true));
|
||||
private Predicate<String> isNameMatch(String name) {
|
||||
return (name != null ? ((requested) -> requested.equals(name)) : matchAll());
|
||||
}
|
||||
|
||||
private Predicate<String> matchAll() {
|
||||
return (name) -> true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,8 +34,9 @@ public class IntegrationGraphEndpoint {
|
|||
private final IntegrationGraphServer graphServer;
|
||||
|
||||
/**
|
||||
* Create a new {@code IntegrationGraphEndpoint} that exposes a graph containing all
|
||||
* the Spring Integration components in the given {@link IntegrationGraphServer}.
|
||||
* Create a new {@code IntegrationGraphEndpoint} instance that exposes a graph
|
||||
* containing all the Spring Integration components in the given
|
||||
* {@link IntegrationGraphServer}.
|
||||
* @param graphServer the integration graph server
|
||||
*/
|
||||
public IntegrationGraphEndpoint(IntegrationGraphServer graphServer) {
|
||||
|
|
|
@ -26,9 +26,9 @@ import org.springframework.integration.support.management.graph.Graph;
|
|||
import org.springframework.integration.support.management.graph.IntegrationGraphServer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.mock;
|
||||
import static org.mockito.BDDMockito.verify;
|
||||
import static org.mockito.BDDMockito.when;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Tests for {@link IntegrationGraphEndpoint}.
|
||||
|
@ -51,8 +51,7 @@ public class IntegrationGraphEndpointTests {
|
|||
@Test
|
||||
public void readOperationShouldReturnGraph() {
|
||||
Graph mockedGraph = mock(Graph.class);
|
||||
when(this.integrationGraphServer.getGraph()).thenReturn(mockedGraph);
|
||||
|
||||
given(this.integrationGraphServer.getGraph()).willReturn(mockedGraph);
|
||||
Graph graph = this.integrationGraphEndpoint.graph();
|
||||
verify(this.integrationGraphServer).getGraph();
|
||||
assertThat(graph).isEqualTo(mockedGraph);
|
||||
|
|
Loading…
Reference in New Issue