Package org.springframework.cache

Examples of org.springframework.cache.Cache


    assertTrue(isEmpty(cache));
  }

  @Test
  public void removeAllWithException() {
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(name.getMethodName());
    cache.put(key, new Object());

    try {
      service.removeAllWithException(true);
      fail("Should have thrown an exception");
    }
View Full Code Here


    assertTrue(isEmpty(cache));
  }

  @Test
  public void removeAllWithExceptionVetoRemove() {
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(name.getMethodName());
    cache.put(key, new Object());

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

    assertNotNull(cache.get(key));
  }

  @Test
  public void earlyRemoveAll() {
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(name.getMethodName());
    cache.put(key, new Object());

    service.earlyRemoveAll();

    assertTrue(isEmpty(cache));
  }
View Full Code Here

    assertTrue(isEmpty(cache));
  }

  @Test
  public void earlyRemoveAllWithException() {
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(name.getMethodName());
    cache.put(key, new Object());

    try {
      service.earlyRemoveAllWithException(true);
      fail("Should have thrown an exception");
    }
View Full Code Here

    assertTrue(isEmpty(cache));
  }

  @Test
  public void earlyRemoveAllWithExceptionVetoRemove() {
    Cache cache = getCache(DEFAULT_CACHE);

    Object key = createKey(name.getMethodName());
    cache.put(key, new Object());

    try {
      service.earlyRemoveAllWithException(false);
      fail("Should have thrown an exception");
    }
View Full Code Here

  private Object createKey(Object... params) {
    return SimpleKeyGenerator.generateKey(params);
  }

  private Cache getCache(String name) {
    Cache cache = cacheManager.getCache(name);
    assertNotNull("required cache " + name + " does not exist", cache);
    return cache;
  }
View Full Code Here

    new TransactionAwareCacheDecorator(null);
  }

  @Test
  public void regularOperationsOnTarget() {
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);
    assertEquals(target.getName(), cache.getName());
    assertEquals(target.getNativeCache(), cache.getNativeCache());

    Object key = new Object();
    target.put(key, "123");
    assertEquals("123", cache.get(key).get());
    assertEquals("123", cache.get(key, String.class));

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

    assertNull(target.get(key));
  }

  @Test
  public void putNonTransactional() {
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);

    Object key = new Object();
    cache.put(key, "123");
    assertEquals("123", target.get(key, String.class));
  }
View Full Code Here

    assertEquals("123", target.get(key, String.class));
  }

  @Test
  public void putTransactional() {
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);

    TransactionStatus status = txManager.getTransaction(new DefaultTransactionAttribute(
        TransactionDefinition.PROPAGATION_REQUIRED));

    Object key = new Object();
    cache.put(key, "123");
    assertNull(target.get(key));
    txManager.commit(status);

    assertEquals("123", target.get(key, String.class));
  }
View Full Code Here

    assertEquals("123", target.get(key, String.class));
  }

  @Test
  public void putIfAbsent() { // no transactional support for putIfAbsent
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);

    Object key = new Object();
    assertNull(cache.putIfAbsent(key, "123"));
    assertEquals("123", target.get(key, String.class));
    assertEquals("123", cache.putIfAbsent(key, "456").get());
    assertEquals("123", target.get(key, String.class)); // unchanged
  }
View Full Code Here

TOP

Related Classes of org.springframework.cache.Cache

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.