Package org.springframework.cache

Examples of org.springframework.cache.Cache$ValueWrapper


    Object o1 = new Object();

    Object r1 = service.multiCache(o1);
    Object r2 = service.multiCache(o1);

    Cache primary = cm.getCache("primary");
    Cache secondary = cm.getCache("secondary");

    assertSame(r1, r2);
    assertSame(r1, primary.get(o1).get());
    assertSame(r1, secondary.get(o1).get());

    service.multiEvict(o1);
    assertNull(primary.get(o1));
    assertNull(secondary.get(o1));

    Object r3 = service.multiCache(o1);
    Object r4 = service.multiCache(o1);
    assertNotSame(r1, r3);
    assertSame(r3, r4);

    assertSame(r3, primary.get(o1).get());
    assertSame(r4, secondary.get(o1).get());
  }
View Full Code Here


  }

  @Test
  public void cacheException() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(EXCEPTION_CACHE);

    Object key = createKey(keyItem);
    assertNull(cache.get(key));

    try {
      service.cacheWithException(keyItem, true);
      fail("Should have thrown an exception");
    }
    catch (UnsupportedOperationException e) {
      // This is what we expect
    }

    Cache.ValueWrapper result = cache.get(key);
    assertNotNull(result);
    assertEquals(UnsupportedOperationException.class, result.get().getClass());
  }
View Full Code Here

  }

  @Test
  public void cacheExceptionVetoed() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(EXCEPTION_CACHE);

    Object key = createKey(keyItem);
    assertNull(cache.get(key));

    try {
      service.cacheWithException(keyItem, false);
      fail("Should have thrown an exception");
    }
    catch (NullPointerException e) {
      // This is what we expect
    }
    assertNull(cache.get(key));
  }
View Full Code Here

  }

  @Test
  public void cacheCheckedException() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(EXCEPTION_CACHE);

    Object key = createKey(keyItem);
    assertNull(cache.get(key));

    try {
      service.cacheWithCheckedException(keyItem, true);
      fail("Should have thrown an exception");
    }
    catch (IOException e) {
      // This is what we expect
    }

    Cache.ValueWrapper result = cache.get(key);
    assertNotNull(result);
    assertEquals(IOException.class, result.get().getClass());
  }
View Full Code Here

  }

  @Test
  public void cacheWithCustomCacheResolver() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(keyItem);
    service.cacheWithCustomCacheResolver(keyItem);

    assertNull(cache.get(key)); // Cache in mock cache
  }
View Full Code Here

  }

  @Test
  public void cacheWithCustomKeyGenerator() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(keyItem);
    service.cacheWithCustomKeyGenerator(keyItem, "ignored");

    assertNull(cache.get(key));
  }
View Full Code Here

  }

  @Test
  public void put() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(keyItem);
    Object value = new Object();
    assertNull(cache.get(key));

    service.put(keyItem, value);

    Cache.ValueWrapper result = cache.get(key);
    assertNotNull(result);
    assertEquals(value, result.get());
  }
View Full Code Here

  }

  @Test
  public void putWithException() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(keyItem);
    Object value = new Object();
    assertNull(cache.get(key));

    try {
      service.putWithException(keyItem, value, true);
      fail("Should have thrown an exception");
    }
    catch (UnsupportedOperationException e) {
      // This is what we expect
    }

    Cache.ValueWrapper result = cache.get(key);
    assertNotNull(result);
    assertEquals(value, result.get());
  }
View Full Code Here

  }

  @Test
  public void putWithExceptionVetoPut() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(keyItem);
    Object value = new Object();
    assertNull(cache.get(key));

    try {
      service.putWithException(keyItem, value, false);
      fail("Should have thrown an exception");
    }
    catch (NullPointerException e) {
      // This is what we expect
    }
    assertNull(cache.get(key));
  }
View Full Code Here

  }

  @Test
  public void earlyPut() {
    String keyItem = name.getMethodName();
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(keyItem);
    Object value = new Object();
    assertNull(cache.get(key));

    service.earlyPut(keyItem, value);

    Cache.ValueWrapper result = cache.get(key);
    assertNotNull(result);
    assertEquals(value, result.get());
  }
View Full Code Here

TOP

Related Classes of org.springframework.cache.Cache$ValueWrapper

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.