Ejemplo n.º 1
0
  public void testRootNodePersistence() throws CacheLoaderException {
    cache.put(ROOT, "key", "value");
    assert "value".equals(cache.get(ROOT, "key"));
    assert store.containsKey(new NodeKey(ROOT, DATA));
    assert "value".equals(nodeContentsInCacheStore(store, ROOT).get("key"));
    assert store.containsKey(new NodeKey(ROOT, STRUCTURE));

    cache.stop();
    cache.start();
    assert "value".equals(cache.get(ROOT, "key"));

    assert store.containsKey(new NodeKey(ROOT, DATA));
    assert "value".equals(nodeContentsInCacheStore(store, ROOT).get("key"));
    assert store.containsKey(new NodeKey(ROOT, STRUCTURE));
  }
Ejemplo n.º 2
0
  public void testPersistence() throws CacheLoaderException {
    cache.put("/a/b/c", "key", "value");
    assert "value".equals(cache.get("/a/b/c", "key"));

    assert store.containsKey(new NodeKey(Fqn.fromString("/a/b/c"), DATA));
    assert "value".equals(nodeContentsInCacheStore(store, Fqn.fromString("/a/b/c")).get("key"));
    assert store.containsKey(new NodeKey(Fqn.fromString("/a/b/c"), STRUCTURE));

    cache.stop();
    cache.start();
    assert "value".equals(cache.get("/a/b/c", "key"));
    assert store.containsKey(new NodeKey(Fqn.fromString("/a/b/c"), DATA));
    assert "value".equals(nodeContentsInCacheStore(store, Fqn.fromString("/a/b/c")).get("key"));
    assert store.containsKey(new NodeKey(Fqn.fromString("/a/b/c"), STRUCTURE));
  }
  public void testLoading() throws CacheLoaderException {
    assertNotInCacheAndStore("k1", "k2", "k3", "k4");
    for (int i = 1; i < 5; i++) store.store(TestInternalCacheEntryFactory.create("k" + i, "v" + i));
    for (int i = 1; i < 5; i++) assert cache.get("k" + i).equals("v" + i);
    // make sure we have no stale locks!!
    assertNoLocks(cache);

    for (int i = 1; i < 5; i++) cache.evict("k" + i);
    // make sure we have no stale locks!!
    assertNoLocks(cache);

    assert cache.putIfAbsent("k1", "v1-SHOULD-NOT-STORE").equals("v1");
    assert cache.remove("k2").equals("v2");
    assert cache.replace("k3", "v3-REPLACED").equals("v3");
    assert cache.replace("k4", "v4", "v4-REPLACED");
    // make sure we have no stale locks!!
    assertNoLocks(cache);

    assert cache.size() == 3
        : "Expected the cache to contain 3 elements but contained " + cache.size();

    for (int i = 1; i < 5; i++) cache.evict("k" + i);
    // make sure we have no stale locks!!
    assertNoLocks(cache);

    assert cache.isEmpty(); // cache size ops will not trigger a load

    cache.clear(); // this should propagate to the loader though
    assertNotInCacheAndStore("k1", "k2", "k3", "k4");
    // make sure we have no stale locks!!
    assertNoLocks(cache);
  }
 private void assertInCacheAndNotInStore(Cache cache, CacheStore store, Object... keys)
     throws CacheLoaderException {
   for (Object key : keys) {
     assert cache.getAdvancedCache().getDataContainer().containsKey(key, null)
         : "Cache should not contain key " + key;
     assert !store.containsKey(key) : "Store should contain key " + key;
   }
 }
 private void assertInCacheAndStore(
     Cache cache, CacheStore store, Object key, Object value, long lifespanMillis)
     throws CacheLoaderException {
   InternalCacheEntry se = cache.getAdvancedCache().getDataContainer().get(key, null);
   testStoredEntry(se, value, lifespanMillis, "Cache", key);
   se = store.load(key);
   testStoredEntry(se, value, lifespanMillis, "Store", key);
 }
  public void testLoadingToMemory() throws CacheLoaderException {
    assertNotInCacheAndStore("k1", "k2");
    store.store(TestInternalCacheEntryFactory.create("k1", "v1"));
    store.store(TestInternalCacheEntryFactory.create("k2", "v2"));

    assertInStoreNotInCache("k1", "k2");

    assert "v1".equals(cache.get("k1"));
    assert "v2".equals(cache.get("k2"));

    assertInCacheAndStore("k1", "v1");
    assertInCacheAndStore("k2", "v2");

    store.remove("k1");
    store.remove("k2");

    assertInCacheAndNotInStore("k1", "k2");
    assert "v1".equals(cache.get("k1"));
    assert "v2".equals(cache.get("k2"));
  }
 @AfterMethod
 public void afterMethod() throws CacheLoaderException {
   if (cache != null) cache.clear();
   if (store != null) store.clear();
 }
Ejemplo n.º 8
0
 @SuppressWarnings("unchecked")
 private Map<String, String> nodeContentsInCacheStore(CacheStore cs, Fqn fqn)
     throws CacheLoaderException {
   return (Map<String, String>) cs.load(new NodeKey(fqn, DATA)).getValue();
 }