Search in sources :

Example 1 with MethodCache

use of com.newrelic.agent.util.MethodCache in project newrelic-java-agent by newrelic.

the class CacheServiceTest method getMethodCacheIdentity.

@Test
public void getMethodCacheIdentity() throws Exception {
    CacheService cacheService = ServiceFactory.getCacheService();
    MethodCache methodCache = cacheService.getMethodCache(TEST1_CLASS_NAME, GETFIELD1_METHOD_NAME, GETFIELD1_METHOD_DESC);
    MethodCache methodCache2 = cacheService.getMethodCache(TEST1_CLASS_NAME, GETFIELD1_METHOD_NAME, GETFIELD1_METHOD_DESC);
    Assert.assertEquals(methodCache, methodCache2);
}
Also used : MethodCache(com.newrelic.agent.util.MethodCache) Test(org.junit.Test)

Example 2 with MethodCache

use of com.newrelic.agent.util.MethodCache in project newrelic-java-agent by newrelic.

the class CacheServiceTest method getMethodCacheBasic.

@Test
public void getMethodCacheBasic() throws Exception {
    CacheService cacheService = ServiceFactory.getCacheService();
    MethodCache methodCache = cacheService.getMethodCache(TEST1_CLASS_NAME, GETFIELD1_METHOD_NAME, GETFIELD1_METHOD_DESC);
    String expectedField = "field1";
    Test1 test1 = new Test1(expectedField);
    Class<?> clazz = test1.getClass();
    Method method = methodCache.getDeclaredMethod(clazz);
    String actualField = (String) method.invoke(test1);
    Assert.assertEquals(expectedField, actualField);
}
Also used : MethodCache(com.newrelic.agent.util.MethodCache) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 3 with MethodCache

use of com.newrelic.agent.util.MethodCache in project newrelic-java-agent by newrelic.

the class CacheService method getMethodCache.

public MethodCache getMethodCache(String className, String methodName, String methodDesc) {
    ClassMethodSignature key = new ClassMethodSignature(className.replace('/', '.'), methodName, methodDesc);
    MethodCache methodCache = methodCaches.get(key);
    if (methodCache != null) {
        return methodCache;
    }
    methodCache = new MethodCache(methodName);
    MethodCache oldMethodCache = methodCaches.putIfAbsent(key, methodCache);
    return oldMethodCache == null ? methodCache : oldMethodCache;
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) MethodCache(com.newrelic.agent.util.MethodCache)

Aggregations

MethodCache (com.newrelic.agent.util.MethodCache)3 Test (org.junit.Test)2 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)1 Method (java.lang.reflect.Method)1