Search in sources :

Example 6 with CacheResult

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);
}
Also used : MetaHolder(com.netflix.hystrix.contrib.javanica.command.MetaHolder) CacheResult(com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult) Test(org.junit.Test)

Example 7 with CacheResult

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);
}
Also used : MetaHolder(com.netflix.hystrix.contrib.javanica.command.MetaHolder) CacheResult(com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult) Test(org.junit.Test)

Aggregations

CacheResult (com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult)7 MetaHolder (com.netflix.hystrix.contrib.javanica.command.MetaHolder)6 Test (org.junit.Test)6 CacheKey (com.netflix.hystrix.contrib.javanica.cache.annotation.CacheKey)1 MethodExecutionAction (com.netflix.hystrix.contrib.javanica.command.MethodExecutionAction)1 AopUtils.getDeclaredMethod (com.netflix.hystrix.contrib.javanica.utils.AopUtils.getDeclaredMethod)1 Method (java.lang.reflect.Method)1