Search in sources :

Example 1 with AnnotatedElementKey

use of cn.taketoday.context.expression.AnnotatedElementKey in project today-infrastructure by TAKETODAY.

the class ExpressionEvaluatorTests method testMultipleCachingEval.

@Test
public void testMultipleCachingEval() {
    AnnotatedClass target = new AnnotatedClass();
    Method method = ReflectionUtils.findMethod(AnnotatedClass.class, "multipleCaching", Object.class, Object.class);
    Object[] args = new Object[] { new Object(), new Object() };
    Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test"));
    EvaluationContext evalCtx = this.eval.createEvaluationContext(caches, method, args, target, target.getClass(), method, CacheOperationExpressionEvaluator.NO_RESULT, null);
    Collection<CacheOperation> ops = getOps("multipleCaching");
    Iterator<CacheOperation> it = ops.iterator();
    AnnotatedElementKey key = new AnnotatedElementKey(method, AnnotatedClass.class);
    Object keyA = this.eval.key(it.next().getKey(), key, evalCtx);
    Object keyB = this.eval.key(it.next().getKey(), key, evalCtx);
    assertThat(keyA).isEqualTo(args[0]);
    assertThat(keyB).isEqualTo(args[1]);
}
Also used : ConcurrentMapCache(cn.taketoday.cache.concurrent.ConcurrentMapCache) Method(java.lang.reflect.Method) EvaluationContext(cn.taketoday.expression.EvaluationContext) AnnotatedElementKey(cn.taketoday.context.expression.AnnotatedElementKey) Test(org.junit.jupiter.api.Test)

Example 2 with AnnotatedElementKey

use of cn.taketoday.context.expression.AnnotatedElementKey in project today-framework by TAKETODAY.

the class ExpressionEvaluatorTests method testMultipleCachingEval.

@Test
public void testMultipleCachingEval() {
    AnnotatedClass target = new AnnotatedClass();
    Method method = ReflectionUtils.findMethod(AnnotatedClass.class, "multipleCaching", Object.class, Object.class);
    Object[] args = new Object[] { new Object(), new Object() };
    Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test"));
    EvaluationContext evalCtx = this.eval.createEvaluationContext(caches, method, args, target, target.getClass(), method, CacheOperationExpressionEvaluator.NO_RESULT, null);
    Collection<CacheOperation> ops = getOps("multipleCaching");
    Iterator<CacheOperation> it = ops.iterator();
    AnnotatedElementKey key = new AnnotatedElementKey(method, AnnotatedClass.class);
    Object keyA = this.eval.key(it.next().getKey(), key, evalCtx);
    Object keyB = this.eval.key(it.next().getKey(), key, evalCtx);
    assertThat(keyA).isEqualTo(args[0]);
    assertThat(keyB).isEqualTo(args[1]);
}
Also used : ConcurrentMapCache(cn.taketoday.cache.concurrent.ConcurrentMapCache) Method(java.lang.reflect.Method) EvaluationContext(cn.taketoday.expression.EvaluationContext) AnnotatedElementKey(cn.taketoday.context.expression.AnnotatedElementKey) Test(org.junit.jupiter.api.Test)

Aggregations

ConcurrentMapCache (cn.taketoday.cache.concurrent.ConcurrentMapCache)2 AnnotatedElementKey (cn.taketoday.context.expression.AnnotatedElementKey)2 EvaluationContext (cn.taketoday.expression.EvaluationContext)2 Method (java.lang.reflect.Method)2 Test (org.junit.jupiter.api.Test)2