protected final void assertContains(Object k, boolean expected) { assertEquals("contains(" + k + ")", expected, cl.contains(k)); }
private void assertNotInCacheAndStore(Object... keys) throws PersistenceException { for (Object key : keys) { assert !cache.getAdvancedCache().getDataContainer().containsKey(key) : "Cache should not contain key " + key; assert !store.contains(key) : "Store should not contain key " + key; } }
public void testReadOnlyCacheStore() throws PersistenceException { TestingUtil.writeToAllStores("k1", "v1", cache); TestingUtil.writeToAllStores("k2", "v2", cache); assert !store.contains("k1") : "READ ONLY - Store should NOT contain k1 key."; assert !store.contains("k2") : "READ ONLY - Store should NOT contain k2 key."; // put into cache but not into read only store cache.put("k1", "v1"); cache.put("k2", "v2"); assert "v1".equals(cache.get("k1")); assert "v2".equals(cache.get("k2")); assert !store.contains("k1") : "READ ONLY - Store should NOT contain k1 key."; assert !store.contains("k2") : "READ ONLY - Store should NOT contain k2 key."; assert !TestingUtil.deleteFromAllStores("k1", cache) : "READ ONLY - Remove operation should return false (no op)"; assert !TestingUtil.deleteFromAllStores("k2", cache) : "READ ONLY - Remove operation should return false (no op)"; assert !TestingUtil.deleteFromAllStores("k3", cache) : "READ ONLY - Remove operation should return false (no op)"; assert "v1".equals(cache.get("k1")); assert "v2".equals(cache.get("k2")); cache.remove("k1"); cache.remove("k2"); assert cache.get("k1") == null; assert cache.get("k2") == null; } }
private void assertInCacheNotInStore(Object key, Object value, long lifespanMillis) throws PersistenceException { InternalCacheValue se = cache.getAdvancedCache().getDataContainer().get(key).toInternalCacheValue(); testStoredEntry(se, value, lifespanMillis, "Cache", key); assert !store.contains(key) : "Key " + key + " should not be in store!"; }
public void testActivationOnPutMap(Method m) throws Exception { assertActivationCount(0); assert cache.get(k(m)) == null; assertActivationCount(0); loader.write(new MarshalledEntryImpl(k(m), v(m), null, marshaller())); assert loader.contains(k(m)); Map<String, String> toAdd = new HashMap<String, String>(); toAdd.put(k(m), v(m, 2)); cache.putAll(toAdd); assertActivationCount(1); assert cache.get(k(m)).equals(v(m, 2)); assert !loader.contains(k(m)); }
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"))); }
public void testActivationOnGet(Method m) throws Exception { assertActivationCount(0); assert cache.get(k(m)) == null; assertActivationCount(0); loader.write(new MarshalledEntryImpl(k(m), v(m), null, marshaller())); assert loader.contains(k(m)); assert cache.get(k(m)).equals(v(m)); assertActivationCount(1); assert !loader.contains(k(m)); }
public void testActivationOnReplace(Method m) throws Exception { assertActivationCount(0); assert cache.get(k(m)) == null; assertActivationCount(0); loader.write(new MarshalledEntryImpl(k(m), v(m), null, marshaller())); assert loader.contains(k(m)); assert cache.replace(k(m), v(m, 2)).equals(v(m)); assertActivationCount(1); assert !loader.contains(k(m)); }
public void testActivationOnPut(Method m) throws Exception { assertActivationCount(0); assert cache.get(k(m)) == null; assertActivationCount(0); loader.write(new MarshalledEntryImpl(k(m), v(m), null, marshaller())); assert loader.contains(k(m)); cache.put(k(m), v(m, 2)); assert cache.get(k(m)).equals(v(m, 2)); assertActivationCount(1); assert !loader.contains(k(m)) : "this should only be persisted on evict"; }
public void testEviction(Method m) throws Exception { assertEvictions(0); assert cache.get(k(m, "1")) == null; cache.put(k(m, "1"), v(m, 1)); //test explicit evict command cache.evict(k(m, "1")); assert loader.contains(k(m, "1")) : "the entry should have been evicted"; assertEvictions(1); assert cache.get(k(m, "1")).equals(v(m, 1)); //test implicit eviction cache.put(k(m, "2"), v(m, 2)); assert loader.contains(k(m, "1")) : "the entry should have been evicted"; assertEvictions(2); }
public void testPersistence() throws PersistenceException, ParseException { verifyFullTextHasMatches(0); Country italy = new Country(); italy.countryName = "Italy"; City rome = new City(); rome.name = "Rome"; italy.cities.add(rome); cache.put("IT", italy); assert ! store.contains("IT"); verifyFullTextHasMatches(1); cache.evict("IT"); assert store.contains("IT"); InternalCacheEntry internalCacheEntry = cache.getAdvancedCache().getDataContainer().get("IT"); assert internalCacheEntry==null; verifyFullTextHasMatches(1); Country country = cache.get("IT"); assert country != null; assert "Italy".equals(country.countryName); verifyFullTextHasMatches(1); cache.stop(); assert search.unwrap(SearchIntegrator.class).isStopped(); TestingUtil.killCacheManagers(cm); // Now let's check the entry is not re-indexed during data preloading: recreateCacheManager(); // People should generally use a persistent index; we use RAMDirectory for // test cleanup, so for our configuration it needs now to contain zero // matches: on filesystem it would be exactly one as expected (two when ISPN-1179 was open) verifyFullTextHasMatches(0); }
public void testLoadAndStoreBytesValues() throws PersistenceException, IOException, InterruptedException { assertIsEmpty(); WrappedBytes key = new WrappedByteArray(getMarshaller().objectToByteBuffer(new Pojo().role("key"))); WrappedBytes key2 = new WrappedByteArray(getMarshaller().objectToByteBuffer(new Pojo().role("key2"))); WrappedBytes value = new WrappedByteArray(getMarshaller().objectToByteBuffer(new Pojo().role("value"))); assertFalse(cl.contains(key)); cl.write(new MarshalledEntryImpl<Object, Object>(key, value, null, getMarshaller())); assertEquals(value, cl.load(key).getValue()); MarshalledEntry entry = cl.load(key); assertTrue("Expected an immortalEntry", entry.getMetadata() == null || entry.getMetadata().expiryTime() == -1 || entry.getMetadata().maxIdle() == -1); assertContains(key, true); assertFalse(cl.delete(key2)); assertTrue(cl.delete(key)); }