@Test public void testInvalidPut() throws Exception { Cache cache = cacheManagers.get(0).getCache("P006"); // add 1st 4 elements for(int i = 0; i < 4; i++){ cache.put(cacheManagers.get(0).getAddress().toString()+"-"+i, "42"); } // lets check if all elements arrived AdvancedCacheLoader cs1 = (AdvancedCacheLoader) TestingUtil.getCacheLoader(cache); Set<Object> keys = PersistenceUtil.toKeySet(cs1, null); Assert.assertEquals(keys.size(), 4); // now start 2nd node addClusterEnabledCacheManager(getCB()).defineConfiguration("P006", getCB().build()); waitForClusterToForm("P006"); cache = cacheManagers.get(1).getCache("P006"); // add next 4 elements for(int i = 0; i < 4; i++){ cache.put(cacheManagers.get(1).getAddress().toString()+"-"+i, "42"); } Set mergedKeys = new HashSet(); // add keys from all cache stores AdvancedCacheLoader cs2 = (AdvancedCacheLoader) TestingUtil.getCacheLoader(cache); log.debugf("Load from cache store via cache 1"); mergedKeys.addAll(PersistenceUtil.toKeySet(cs1, null)); log.debugf("Load from cache store via cache 2"); mergedKeys.addAll(PersistenceUtil.toKeySet(cs2, null)); Assert.assertEquals(mergedKeys.size(), 8); }
public void testPutAllBatch() throws Exception { int numberOfEntries = 100; String cacheName = "testPutAllBatch"; ConfigurationBuilder cb = new ConfigurationBuilder(); cb.read(cacheManager.getDefaultCacheConfiguration()); createCacheStoreConfig(cb.persistence(), false); cacheManager.defineConfiguration(cacheName, cb.build()); Cache<String, Object> cache = cacheManager.getCache(cacheName); Map<String, Object> entriesMap = IntStream.range(0, numberOfEntries).boxed() .collect(Collectors.toMap(Object::toString, i -> wrap(i.toString(), "Val"+i))); cache.putAll(entriesMap); assertEquals(numberOfEntries, cache.size()); CacheLoader cl = TestingUtil.getCacheLoader(cache); if (cl != null) IntStream.range(0, numberOfEntries).forEach(i -> assertNotNull(cl.load(Integer.toString(i)))); }
@BeforeClass public void setUp() { cfg = TestCacheManagerFactory.getDefaultCacheConfiguration(true); cfg .persistence() .passivation(true) .addStore(DummyInMemoryStoreConfigurationBuilder.class); cm = TestCacheManagerFactory.createCacheManager(cfg); cache = cm.getCache(); store = (AdvancedLoadWriteStore) TestingUtil.getCacheLoader(cache); tm = TestingUtil.getTransactionManager(cache); }
@BeforeMethod public void setUp() { cfg = new ConfigurationBuilder(); cfg .persistence() .passivation(true) .addStore(DummyInMemoryStoreConfigurationBuilder.class) .storeName(this.getClass().getName()) .purgeOnStartup(false) .memory().storageType(storage); cm = TestCacheManagerFactory.createCacheManager(cfg); cache = cm.getCache(); store = (AdvancedLoadWriteStore) TestingUtil.getCacheLoader(cache); tm = TestingUtil.getTransactionManager(cache); }
@Override public void call() { Cache<Object, Object> cache = cm.getCache(); CacheLoader cacheLoader = TestingUtil.getCacheLoader(cache); assertSame(RestStore.class, cacheLoader.getClass()); cache.put("k", "v"); assertEquals(1, cacheManager.getCache().size()); cache.stop(); assertEquals(1, cacheManager.getCache().size()); } });
protected void assertNumberOfEntries(int cacheIndex, DeltaAwareAccessor daa) throws Exception { AdvancedCacheLoader loader = (AdvancedCacheLoader) TestingUtil.getCacheLoader(cache(cacheIndex)); assertEquals(daa.isFineGrained() ? 6 : 2, PersistenceUtil.count(loader, null)); // two entries in store DataContainer dataContainer = cache(cacheIndex).getAdvancedCache().getDataContainer(); assertEquals(1, dataContainer.size()); // only one entry in memory (the other one was evicted) }
cache.put("a", "b"); assert cache.get("a").equals("b"); CacheLoader cl = TestingUtil.getCacheLoader(cache); assert cl != null; MarshalledEntry se = cl.load("a");
@Override protected void assertNumberOfEntries(int cacheIndex, DeltaAwareAccessor daa) throws Exception { AdvancedCacheLoader cacheStore = (AdvancedCacheLoader) TestingUtil.getCacheLoader(cache(cacheIndex)); assertEquals(daa.isFineGrained() ? 5 : 1, PersistenceUtil.count(cacheStore, null)); // one entry in store DataContainer dataContainer = cache(cacheIndex).getAdvancedCache().getDataContainer(); assertEquals(1, dataContainer.size()); // only one entry in memory (the other one was evicted) } }
@Override protected void assertNumberOfEntries(int cacheIndex, DeltaAwareAccessor daa) throws Exception { AdvancedCacheLoader cacheStore = (AdvancedCacheLoader) TestingUtil.getCacheLoader(cache(cacheIndex)); assertEquals(daa.isFineGrained() ? 5 : 1, PersistenceUtil.count(cacheStore, null)); // one entry in store DataContainer dataContainer = cache(cacheIndex).getAdvancedCache().getDataContainer(); assertEquals(1, dataContainer.size()); // only one entry in memory (the other one was evicted) } }
@Override public void call() { Cache<Object, Object> cache = cm.getCache(); CacheLoader cacheLoader = TestingUtil.getCacheLoader(cache); assert cacheLoader != null; assert cacheLoader instanceof RemoteStore; cache.put("k", "v"); assertEquals(1, cacheManager.getCache().size()); cache.stop(); assertEquals(1, cacheManager.getCache().size()); } });
public void testStoreAndLoad() throws Exception { final int numKeys = 300; for (int i = 0; i < numKeys; i++) { cache().put(i, i); } int keysInDataContainer = cache().getAdvancedCache().getDataContainer().keySet().size(); assertTrue(keysInDataContainer != numKeys); // some keys got evicted AdvancedLoadWriteStore store = (AdvancedLoadWriteStore) TestingUtil.getCacheLoader(cache()); int keysInCacheStore = PersistenceUtil.count(store, null); if (passivationEnabled) { assertEquals(numKeys, keysInDataContainer + keysInCacheStore); } else { assertEquals(numKeys, keysInCacheStore); } // check if keys survive restart cache().stop(); cache().start(); store = (AdvancedLoadWriteStore) TestingUtil.getCacheLoader(cache()); assertEquals(numKeys, PersistenceUtil.count(store, null)); for (int i = 0; i < numKeys; i++) { assertEquals(i, cache().get(i)); } }
AdvancedLoadWriteStore store = (AdvancedLoadWriteStore) TestingUtil.getCacheLoader(cache()); int keysInCacheStore = PersistenceUtil.count(store, null); cache().start(); store = (AdvancedLoadWriteStore) TestingUtil.getCacheLoader(cache()); assertEquals(numKeys, PersistenceUtil.count(store, null));
public void testActivationDuringEvict() throws Exception { DataContainer dc = cache.getAdvancedCache().getDataContainer(); CacheLoader cl = TestingUtil.getCacheLoader(cache);
public void testExpirationOfStoreWhenDataNotInMemory() throws Exception { String key = "k"; cache.put(key, "v", 10, TimeUnit.MILLISECONDS); removeFromContainer(key); // At this point data should only be in store - we assume size won't ressurect value into memory assertEquals(1, cache.size()); assertEquals(0, listener.getInvocationCount()); timeService.advance(11); assertNull(cache.get(key)); // Stores do not expire entries on load, thus we need to purge them manager.processExpiration(); assertEquals(1, listener.getInvocationCount()); CacheEntryExpiredEvent event = listener.getEvents().iterator().next(); assertEquals(Event.Type.CACHE_ENTRY_EXPIRED, event.getType()); assertEquals(cache, event.getCache()); assertFalse(event.isPre()); assertNotNull(event.getKey()); // The dummy store produces value and metadata so lets make sure if (TestingUtil.getCacheLoader(cache) instanceof AdvancedCacheExpirationWriter) { assertEquals("v", event.getValue()); assertNotNull(event.getMetadata()); } }
@Test(groups = "unstable") public void testPurgeOnStartup() throws PersistenceException { ConfigurationBuilder purgingCfg = new ConfigurationBuilder(); purgingCfg.read(cfg.build()); purgingCfg.persistence().clearStores().addStore(DummyInMemoryStoreConfigurationBuilder.class) .storeName("purgingCache").purgeOnStartup(true); cm.defineConfiguration("purgingCache", purgingCfg.build()); Cache<String, String> purgingCache = getCache(cm, "purgingCache"); AdvancedCacheLoader purgingLoader = (AdvancedCacheLoader) TestingUtil.getCacheLoader(purgingCache); assertNotInCacheAndStore(purgingCache, purgingLoader, "k1", "k2", "k3", "k4"); purgingCache.put("k1", "v1"); purgingCache.put("k2", "v2", lifespan, MILLISECONDS); purgingCache.put("k3", "v3"); purgingCache.put("k4", "v4", lifespan, MILLISECONDS); for (int i = 1; i < 5; i++) { if (i % 2 == 1) assertInCacheAndStore(purgingCache, purgingLoader, "k" + i, "v" + i); else assertInCacheAndStore(purgingCache, purgingLoader, "k" + i, "v" + i, lifespan); } DataContainer c = purgingCache.getAdvancedCache().getDataContainer(); assertEquals(4, c.size()); purgingCache.stop(); assertEquals(0, c.size()); purgingCache.start(); purgingLoader = (AdvancedCacheLoader) TestingUtil.getCacheLoader(purgingCache); c = purgingCache.getAdvancedCache().getDataContainer(); assertEquals(0, c.size()); assertNotInCacheAndStore(purgingCache, purgingLoader, "k1", "k2", "k3", "k4"); }
cm.defineConfiguration(cacheName, preloadingCfg); Cache<String, String> preloadingCache = getCache(cm, cacheName); AdvancedCacheLoader preloadingCacheLoader = (AdvancedCacheLoader) TestingUtil.getCacheLoader(preloadingCache); preloadingCacheLoader = (AdvancedCacheLoader) TestingUtil.getCacheLoader(preloadingCache); assert preloadingCache.getCacheConfiguration().persistence().preload(); c = preloadingCache.getAdvancedCache().getDataContainer();
public void testPersistence() throws PersistenceException { cache.put("k", "v"); assertEquals("v", cache.get("k")); cache.evict("k"); assertTrue(store.contains(getInternalKey("k"))); assertEquals("v", cache.get("k")); assertFalse(store.contains(getInternalKey("k"))); cache.stop(); cache.start(); // The old store's marshaller is not working any more store = (AdvancedLoadWriteStore) TestingUtil.getCacheLoader(cache); assertTrue(store.contains(getInternalKey("k"))); assertEquals("v", cache.get("k")); assertFalse(store.contains(getInternalKey("k"))); }
AdvancedCacheLoader preloadingCacheLoader = (AdvancedCacheLoader) TestingUtil.getCacheLoader(preloadingCache); preloadingCacheLoader = (AdvancedCacheLoader) TestingUtil.getCacheLoader(preloadingCache);