use of com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult in project Hystrix by Netflix.
the class HystrixCacheKeyGeneratorTest method testGenerateCacheKey_givenCacheKeyMethodWithNoArguments_shouldReturnEmptyCacheKey.
@Test
public void testGenerateCacheKey_givenCacheKeyMethodWithNoArguments_shouldReturnEmptyCacheKey() throws NoSuchMethodException {
// given
TestCacheClass testCacheClass = new TestCacheClass();
MetaHolder metaHolder = MetaHolder.builder().method(TestCacheClass.class.getMethod("cacheResultMethod")).args(new Object[] {}).obj(testCacheClass).build();
CacheInvocationContext<CacheResult> context = CacheInvocationContextFactory.createCacheResultInvocationContext(metaHolder);
HystrixCacheKeyGenerator keyGenerator = HystrixCacheKeyGenerator.getInstance();
// when
HystrixGeneratedCacheKey actual = keyGenerator.generateCacheKey(context);
// then
assertEquals(DefaultHystrixGeneratedCacheKey.EMPTY, actual);
}
use of com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult in project Hystrix by Netflix.
the class HystrixCacheKeyGeneratorTest method testGenerateCacheKey_givenUser_shouldReturnCorrectCacheKey.
@Test
public void testGenerateCacheKey_givenUser_shouldReturnCorrectCacheKey() throws NoSuchMethodException {
// given
TestCacheClass testCacheClass = new TestCacheClass();
String id = "1";
User user = new User();
user.setId(id);
Profile profile = new Profile("user name");
user.setProfile(profile);
String expectedKey = id + user.getProfile().getName();
MetaHolder metaHolder = MetaHolder.builder().method(TestCacheClass.class.getMethod("cacheResultMethod", String.class, User.class)).args(new Object[] { id, user }).obj(testCacheClass).build();
CacheInvocationContext<CacheResult> context = CacheInvocationContextFactory.createCacheResultInvocationContext(metaHolder);
HystrixCacheKeyGenerator keyGenerator = HystrixCacheKeyGenerator.getInstance();
// when
String actual = keyGenerator.generateCacheKey(context).getCacheKey();
// then
assertEquals(expectedKey, actual);
}
Aggregations