Package com.m3.memcached.facade

Examples of com.m3.memcached.facade.MemcachedClientPool


    }

  @Test
  public void getConfiguration_A$() throws Exception {
    MemcachedCacheResultInterceptor interceptor = new MemcachedCacheResultInterceptor();
    Configuration actual = interceptor.getConfiguration();
    assertThat(actual, is(nullValue()));
  }
View Full Code Here


        CacheResult annotation = getCacheResultAnnotation(invocation);
        if (annotation != null) {
            if (!isPoolInitialized) {
                initializePool();
            }
            MemcachedClient memcached = pool.getClient();
            String cacheKey = annotation.cacheKey().equals("") ? getCacheKey(invocation, isUsingRawKey()) : annotation.cacheKey();
            Object cachedObject = null;
            try {
                cachedObject = memcached.get(cacheKey);
            } catch (Throwable t) {
                if (log.isDebugEnabled()) {
                    log.debug("Failed to get a value from memcached servers. (" + cacheKey + ")", t);
                }
            }
            if (cachedObject != null) {
                return cachedObject;
            } else {
                Object value = invocation.proceed();
                try {
                    memcached.set(cacheKey, annotation.secondsToExpire(), value);
                } catch (Throwable t) {
                    if (log.isDebugEnabled()) {
                        log.debug("Failed to set a value to memcached servers. (" + cacheKey + " -> " + value + ")", t);
                    }
                }
View Full Code Here

    private MemcachedClientPool pool;

    private volatile boolean isPoolInitialized = false;

    public void initializePool() throws Exception {
        pool = new MemcachedClientPool(config);
        isPoolInitialized = true;
    }
View Full Code Here

        isPoolInitialized = true;
    }

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        CacheResult annotation = getCacheResultAnnotation(invocation);
        if (annotation != null) {
            if (!isPoolInitialized) {
                initializePool();
            }
            MemcachedClient memcached = pool.getClient();
            String cacheKey = annotation.cacheKey().equals("") ? getCacheKey(invocation, isUsingRawKey()) : annotation.cacheKey();
            Object cachedObject = null;
            try {
                cachedObject = memcached.get(cacheKey);
            } catch (Throwable t) {
                if (log.isDebugEnabled()) {
                    log.debug("Failed to get a value from memcached servers. (" + cacheKey + ")", t);
                }
            }
            if (cachedObject != null) {
                return cachedObject;
            } else {
                Object value = invocation.proceed();
                try {
                    memcached.set(cacheKey, annotation.secondsToExpire(), value);
                } catch (Throwable t) {
                    if (log.isDebugEnabled()) {
                        log.debug("Failed to set a value to memcached servers. (" + cacheKey + " -> " + value + ")", t);
                    }
                }
View Full Code Here

        assertThat(MemcachedCacheResultInterceptor.class, notNullValue());
    }

    @Test
    public void instantiation() throws Exception {
        MemcachedCacheResultInterceptor target = new MemcachedCacheResultInterceptor();
        assertThat(target, notNullValue());
    }
View Full Code Here

        return null;
    }

    @Test
    public void getCacheKey_A$MethodInvocation$boolean_raw() throws Exception {
        MemcachedCacheResultInterceptor interceptor = new MemcachedCacheResultInterceptor();
        MethodInvocation invocation = mock(MethodInvocation.class);
        Method method = this.getClass().getMethod("getSomething", String.class, String.class);
        when(invocation.getMethod()).thenReturn(method);
        when(invocation.getArguments()).thenReturn(new Object[] { "foo", "bar" });
        String actual = interceptor.getCacheKey(invocation, true);
        String expected = "com.m3.methodcache.interceptor.MemcachedCacheResultInterceptorTest#getSomething" +
                "(java.lang.String,java.lang.String)" +
                " throws java.lang.Exception_$$_" +
                "foo_$_bar_$_";
        assertThat(actual, is(equalTo(expected)));
View Full Code Here

        assertThat(actual, is(equalTo(expected)));
    }

    @Test
    public void getCacheKey_A$MethodInvocation$boolean_hash() throws Exception {
        MemcachedCacheResultInterceptor interceptor = new MemcachedCacheResultInterceptor();
        MethodInvocation invocation = mock(MethodInvocation.class);
        Method method = this.getClass().getMethod("getSomething", String.class, String.class);
        when(invocation.getMethod()).thenReturn(method);
        when(invocation.getArguments()).thenReturn(new Object[] { "foo", "bar" });
        String actual = interceptor.getCacheKey(invocation, false);
        String expected = "c0fdd32fbd47bfc945c2404725172b6b";
        assertThat(actual, is(equalTo(expected)));
    }
View Full Code Here

        assertThat(actual, is(equalTo(expected)));
    }

  @Test
  public void getConfiguration_A$() throws Exception {
    MemcachedCacheResultInterceptor interceptor = new MemcachedCacheResultInterceptor();
    Configuration actual = interceptor.getConfiguration();
    assertThat(actual, is(nullValue()));
  }
View Full Code Here

        }
    }

  @Test
  public void invoke_A$MethodInvocation() throws Throwable {
    MemcachedCacheResultInterceptor interceptor = new MemcachedCacheResultInterceptor();
    MethodInvocation invocation = mock(MethodInvocation.class);
        when(invocation.getMethod()).thenReturn(Foo.class.getDeclaredMethod("doSomething"));
        when(invocation.proceed()).thenReturn("foo");
    Object result = interceptor.invoke(invocation);
    Object expected = "foo";
    assertThat(result, is(equalTo(expected)));
  }
View Full Code Here

TOP

Related Classes of com.m3.memcached.facade.MemcachedClientPool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.