@Override public Object[] factory() { return new Object[] { new FunctionalCachestoreTest().persistence(true).passivation(false), new FunctionalCachestoreTest().persistence(true).passivation(true) }; }
@Test(dataProvider = "owningModeAndWriteMethod") public void testWriteLoad(boolean isSourceOwner, WriteMethod method) throws Exception { Object key = getKey(isSourceOwner, DIST); List<Cache<Object, Object>> owners = caches(DIST).stream() .filter(cache -> cache.getAdvancedCache().getDistributionManager().getLocality(key).isLocal()) .collect(Collectors.toList()); (view, nil) -> view.set("value"), getClass()); assertInvocations(2); caches(DIST).forEach(cache -> assertEquals(cache.get(key), "value", getAddress(cache).toString())); advanceGenerationsAndAwait(10, TimeUnit.SECONDS); caches(DIST).forEach(cache -> cache.evict(key)); caches(DIST).forEach(cache -> assertFalse(cache.getAdvancedCache().getDataContainer().containsKey(key), getAddress(cache).toString())); owners.forEach(cache -> { DummyInMemoryStore store = getStore(cache); assertTrue(store.contains(key), getAddress(cache).toString()); }); resetInvocationCount(); assertInvocations(2); } else { assertInvocations(1);
@Test(dataProvider = "owningModeAndReadMethod") public void testReadLoad(boolean isSourceOwner, ReadMethod method) { Object key = getKey(isSourceOwner, DIST); List<Cache<Object, Object>> owners = caches(DIST).stream() .filter(cache -> cache.getAdvancedCache().getDistributionManager().getLocality(key).isLocal()) .collect(Collectors.toList()); assertTrue(method.eval(key, ro, view -> { assertFalse(view.find().isPresent()); return true; })); // we can't add from read-only cache, so we put manually: cache(0, DIST).put(key, "value"); caches(DIST).forEach(cache -> assertEquals(cache.get(key), "value", getAddress(cache).toString())); caches(DIST).forEach(cache -> cache.evict(key)); caches(DIST).forEach(cache -> assertFalse(cache.getAdvancedCache().getDataContainer().containsKey(key), getAddress(cache).toString())); owners.forEach(cache -> { Set<DummyInMemoryStore> stores = cache.getAdvancedCache().getComponentRegistry().getComponent(PersistenceManager.class).getStores(DummyInMemoryStore.class); DummyInMemoryStore store = stores.iterator().next(); assertTrue(store.contains(key), getAddress(cache).toString()); }); assertEquals(method.eval(key, ro, view -> { assertTrue(view.find().isPresent()); assertEquals(view.get(), "value"); return "OK"; }), "OK"); } }
@Test(dataProvider = "writeMethods") public void testWriteLoadLocal(WriteMethod method) { Integer key = 1; method.eval(key, lwo, lrw, view -> { assertFalse(view.find().isPresent()); return null; }, (view, nil) -> view.set("value"), getClass()); assertInvocations(1); Cache<Integer, String> cache = cacheManagers.get(0).getCache(); assertEquals(cache.get(key), "value"); cache.evict(key); assertFalse(cache.getAdvancedCache().getDataContainer().containsKey(key)); DummyInMemoryStore store = getStore(cache); assertTrue(store.contains(key)); method.eval(key, lwo, lrw, view -> { assertTrue(view.find().isPresent()); assertEquals(view.get(), "value"); return null; }, (view, nil) -> {}, getClass()); assertInvocations(2); }