Search in sources :

Example 1 with CachedObjectSelector

use of org.exoplatform.services.cache.CachedObjectSelector in project kernel by exoplatform.

the class TestAbstractExoCache method testSelect.

public void testSelect() throws Exception {
    cache.put(new MyKey("a"), 1);
    cache.put(new MyKey("b"), 2);
    cache.put(new MyKey("c"), 3);
    final AtomicInteger count = new AtomicInteger();
    CachedObjectSelector<Serializable, Object> selector = new CachedObjectSelector<Serializable, Object>() {

        public void onSelect(ExoCache<? extends Serializable, ? extends Object> cache, Serializable key, ObjectCacheInfo<? extends Object> ocinfo) throws Exception {
            assertTrue(key.equals(new MyKey("a")) || key.equals(new MyKey("b")) || key.equals(new MyKey("c")));
            assertTrue(ocinfo.get().equals(1) || ocinfo.get().equals(2) || ocinfo.get().equals(3));
            count.incrementAndGet();
        }

        public boolean select(Serializable key, ObjectCacheInfo<? extends Object> ocinfo) {
            return true;
        }
    };
    cache.select(selector);
    assertEquals(3, count.intValue());
    cache.clearCache();
}
Also used : Serializable(java.io.Serializable) ExoCache(org.exoplatform.services.cache.ExoCache) CachedObjectSelector(org.exoplatform.services.cache.CachedObjectSelector) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObjectCacheInfo(org.exoplatform.services.cache.ObjectCacheInfo)

Example 2 with CachedObjectSelector

use of org.exoplatform.services.cache.CachedObjectSelector in project kernel by exoplatform.

the class TestDistributedExoCache method testSelect.

public void testSelect() throws Exception {
    cache.put(new MyKey("a"), 1);
    cache.put(new MyKey("b"), 2);
    cache.put(new MyKey("c"), 3);
    final AtomicInteger count = new AtomicInteger();
    CachedObjectSelector<Serializable, Object> selector = new CachedObjectSelector<Serializable, Object>() {

        public void onSelect(ExoCache<? extends Serializable, ? extends Object> cache, Serializable key, ObjectCacheInfo<? extends Object> ocinfo) throws Exception {
            assertTrue(key.equals(new MyKey("a")) || key.equals(new MyKey("b")) || key.equals(new MyKey("c")));
            assertTrue(ocinfo.get().equals(1) || ocinfo.get().equals(2) || ocinfo.get().equals(3));
            count.incrementAndGet();
        }

        public boolean select(Serializable key, ObjectCacheInfo<? extends Object> ocinfo) {
            return true;
        }
    };
    cache.select(selector);
    assertEquals(3, count.intValue());
}
Also used : Serializable(java.io.Serializable) ExoCache(org.exoplatform.services.cache.ExoCache) CachedObjectSelector(org.exoplatform.services.cache.CachedObjectSelector) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObjectCacheInfo(org.exoplatform.services.cache.ObjectCacheInfo)

Example 3 with CachedObjectSelector

use of org.exoplatform.services.cache.CachedObjectSelector in project kernel by exoplatform.

the class TestMCExoCache method testSelect.

public void testSelect() throws Exception {
    cache.put(new MyKey("a"), 1);
    cache.put(new MyKey("b"), 2);
    cache.put(new MyKey("c"), 3);
    final AtomicInteger count = new AtomicInteger();
    CachedObjectSelector<Serializable, Object> selector = new CachedObjectSelector<Serializable, Object>() {

        public void onSelect(ExoCache<? extends Serializable, ? extends Object> cache, Serializable key, ObjectCacheInfo<? extends Object> ocinfo) throws Exception {
            assertTrue(key.equals(new MyKey("a")) || key.equals(new MyKey("b")) || key.equals(new MyKey("c")));
            assertTrue(ocinfo.get().equals(1) || ocinfo.get().equals(2) || ocinfo.get().equals(3));
            count.incrementAndGet();
        }

        public boolean select(Serializable key, ObjectCacheInfo<? extends Object> ocinfo) {
            return true;
        }
    };
    try {
        cache.select(selector);
        assertEquals(3, count.intValue());
    } catch (UnsupportedOperationException e) {
    // OK
    }
}
Also used : Serializable(java.io.Serializable) ExoCache(org.exoplatform.services.cache.ExoCache) CachedObjectSelector(org.exoplatform.services.cache.CachedObjectSelector) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObjectCacheInfo(org.exoplatform.services.cache.ObjectCacheInfo)

Aggregations

Serializable (java.io.Serializable)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 CachedObjectSelector (org.exoplatform.services.cache.CachedObjectSelector)3 ExoCache (org.exoplatform.services.cache.ExoCache)3 ObjectCacheInfo (org.exoplatform.services.cache.ObjectCacheInfo)3