Skip to content

Commit

Permalink
Add tests for CaffeineCacheMetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Mar 2, 2019
1 parent 054fbb0 commit 72eb10d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ repositories {
}

//ext['micrometer.version'] = '1.0.10-SNAPSHOT'
ext['micrometer.version'] = '1.2.0-SNAPSHOT'
ext['caffeine.version'] = '2.7.0'

dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")

compile("com.github.ben-manes.caffeine:caffeine")

testCompile("org.springframework.boot:spring-boot-starter-test")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.micrometer.core.instrument.binder.cache;

import com.github.benmanes.caffeine.cache.AsyncCache;
import com.github.benmanes.caffeine.cache.AsyncLoadingCache;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.github.benmanes.caffeine.cache.stats.CacheStats;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.junit.Test;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class CaffeineCacheMetricsTests {

@Test
public void monitorWithAsyncLoadingCache() {
LoadingCache loadingCache = mock(LoadingCache.class);
CacheStats stats = new CacheStats(0L, 0L, 0L, 0L, 0L, 0L, 0L);
when(loadingCache.stats()).thenReturn(stats);

AsyncLoadingCache asyncLoadingCache = mock(AsyncLoadingCache.class);
when(asyncLoadingCache.synchronous()).thenReturn(loadingCache);
CaffeineCacheMetrics.monitor(new SimpleMeterRegistry(), asyncLoadingCache, "test");
}

@Test
public void monitorWithAsyncCache() {
Cache cache = mock(Cache.class);
CacheStats stats = new CacheStats(0L, 0L, 0L, 0L, 0L, 0L, 0L);
when(cache.stats()).thenReturn(stats);

AsyncCache asyncCache = mock(AsyncCache.class);
when(asyncCache.synchronous()).thenReturn(cache);
CaffeineCacheMetrics.monitor(new SimpleMeterRegistry(),asyncCache, "test");
}

}

0 comments on commit 72eb10d

Please sign in to comment.