org.springframework.boot.actuate.metrics.cache.CacheMeterBinderProvider Java Examples

The following examples show how to use org.springframework.boot.actuate.metrics.cache.CacheMeterBinderProvider. 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: MemcachedCacheMeterBinderProviderConfigurationTest.java    From memcached-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void whenCachingNotEnabledThenCacheStatisticsNotLoaded() {
    loadContext(EmptyConfiguration.class);

    assertThatThrownBy(() ->
            this.context.getBean("memcachedCacheMeterBinderProvider", CacheMeterBinderProvider.class)
    )
            .isInstanceOf(NoSuchBeanDefinitionException.class)
            .hasMessage("No bean named 'memcachedCacheMeterBinderProvider' available");
}
 
Example #2
Source File: MemcachedCacheMeterBinderProviderConfigurationTest.java    From memcached-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void whenCacheTypeIsNoneThenCacheStatisticsNotLoaded() {
    loadContext(CacheConfiguration.class, "spring.cache.type=none");

    assertThatThrownBy(() ->
            this.context.getBean("memcachedCacheMeterBinderProvider", CacheMeterBinderProvider.class)
    )
            .isInstanceOf(NoSuchBeanDefinitionException.class)
            .hasMessage("No bean named 'memcachedCacheMeterBinderProvider' available");
}
 
Example #3
Source File: MemcachedCacheMeterBinderProviderConfigurationTest.java    From memcached-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void whenNoCustomCacheManagerThenCacheStatisticsLoaded() {
    loadContext(MemcachedAutoConfigurationTest.CacheConfiguration.class);

    CacheMeterBinderProvider provider = this.context.getBean("memcachedCacheMeterBinderProvider", CacheMeterBinderProvider.class);

    assertThat(provider).isNotNull();
}
 
Example #4
Source File: MemcachedCacheMeterBinderProviderConfigurationTest.java    From memcached-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void whenMemcachedCacheManagerBeanThenCacheStatisticsLoaded() {
    loadContext(CacheWithMemcachedCacheManagerConfiguration.class);

    CacheMeterBinderProvider provider = this.context.getBean(
            "memcachedCacheMeterBinderProvider", CacheMeterBinderProvider.class);

    assertThat(provider).isNotNull();

    CacheManager cacheManager = this.context.getBean(CacheManager.class);
    Cache books = cacheManager.getCache("books");

    MeterBinder metrics = provider.getMeterBinder(books, expectedTag);

    MeterRegistry registry = new SimpleMeterRegistry();
    metrics.bindTo(registry);

    FunctionCounter hits = registry.get("cache.gets").tags(expectedTag).tag("result", "hit").functionCounter();
    FunctionCounter misses = registry.get("cache.gets").tags(expectedTag).tag("result", "miss").functionCounter();
    FunctionCounter puts = registry.get("cache.puts").tags(expectedTag).functionCounter();
    double availableServersCount = registry.get("available_servers_count").gauge().value();

    assertThat(hits.count()).isEqualTo(0);
    assertThat(misses.count()).isEqualTo(0);
    assertThat(puts.count()).isEqualTo(0);
    assertThat(availableServersCount).isEqualTo(1.0);

    getCacheKeyValues(books, "a", "b", "b", "c", "d", "c", "a", "a", "a", "d");

    assertThat(hits.count()).isEqualTo(6);
    assertThat(misses.count()).isEqualTo(4);
    assertThat(puts.count()).isEqualTo(0);
    assertThat(availableServersCount).isEqualTo(1.0);
}