/** * When trying to persist an unsupported object an exception is expected. */ public void persistUnsupportedObject() throws Exception { try { cacheStore.write(new MarshalledEntryImpl("key", "value", null, marshaller)); fail("exception is expected as PersonKey2StringMapper does not support strings"); } catch (UnsupportedKeyTypeException e) { //expected } //just check that an person object will be persisted okay cacheStore.write(new MarshalledEntryImpl(MIRCEA, "Cluj Napoca", null, marshaller)); }
public void testRepeatedLoads() throws PersistenceException { CountingStore countingCS = getCountingCacheStore(); store.write(new MarshalledEntryImpl("k1", "v1", null, extractGlobalMarshaller(cacheManager))); assert countingCS.numLoads == 0; assert countingCS.numContains == 0; assert "v1".equals(cache.get("k1")); assert countingCS.numLoads == 1 : "Expected 1, was " + countingCS.numLoads; assert countingCS.numContains == 0 : "Expected 0, was " + countingCS.numContains; assert "v1".equals(cache.get("k1")); assert countingCS.numLoads == 1 : "Expected 1, was " + countingCS.numLoads; assert countingCS.numContains == 0 : "Expected 0, was " + countingCS.numContains; }
public void testPurgeListenerIsNotified() throws Exception { InternalCacheEntry first = TestInternalCacheEntryFactory.create(MIRCEA, "val", 1000); cacheStore.write(marshalledEntry(first, marshaller)); assertRowCount(1); Thread.sleep(1100); AdvancedCacheWriter.PurgeListener purgeListener = mock(AdvancedCacheWriter.PurgeListener.class); cacheStore.purge(new WithinThreadExecutor(), purgeListener); verify(purgeListener).entryPurged(MIRCEA); assertRowCount(0); } }
@Override public void testReplaceExpiredEntry() throws Exception { cl.write(marshalledEntry(internalCacheEntry("k1", "v1", 100l))); timeService.advance(1101); assertNull(cl.load("k1")); long start = System.currentTimeMillis(); cl.write(marshalledEntry(internalCacheEntry("k1", "v2", 100l))); assertTrue(cl.load("k1").getValue().equals("v2") || TestingUtil.moreThanDurationElapsed(start, 100)); } }
@Override public void testReplaceExpiredEntry() throws Exception { cl.write(marshalledEntry(internalCacheEntry("k1", "v1", 100l))); // Hot Rod does not support milliseconds, so 100ms is rounded to the nearest second, // and so data is stored for 1 second here. Adjust waiting time accordingly. timeService.advance(1101); assertNull(cl.load("k1")); long start = System.currentTimeMillis(); cl.write(marshalledEntry(internalCacheEntry("k1", "v2", 100l))); assertTrue(cl.load("k1").getValue().equals("v2") || TestingUtil.moreThanDurationElapsed(start, 100)); } }
@Override public void testReplaceExpiredEntry() throws Exception { cl.write(marshalledEntry(internalCacheEntry("k1", "v1", 100))); // Hot Rod does not support milliseconds, so 100ms is rounded to the nearest second, // and so data is stored for 1 second here. Adjust waiting time accordingly. timeService.advance(1101); assertNull(cl.load("k1")); long start = System.currentTimeMillis(); cl.write(marshalledEntry(internalCacheEntry("k1", "v2", 100))); assertTrue(cl.load("k1").getValue().equals("v2") || TestingUtil.moreThanDurationElapsed(start, 100)); }
public void testPurgeExpired() throws Exception { InternalCacheEntry first = TestInternalCacheEntryFactory.create(MIRCEA, "val", 1000); InternalCacheEntry second = TestInternalCacheEntryFactory.create(MANIK, "val2"); cacheStore.write(marshalledEntry(first, marshaller)); cacheStore.write(marshalledEntry(second, marshaller)); assertRowCount(2); Thread.sleep(1100); cacheStore.purge(new WithinThreadExecutor(), null); assertRowCount(1); assertEquals("val2", cacheStore.load(MANIK).getValue()); }
@Override public void testReplaceExpiredEntry() throws Exception { InternalCacheEntry ice = internalCacheEntry("k1", "v1", 100); cl.write(marshalledEntry(ice)); // Hot Rod does not support milliseconds, so 100ms is rounded to the nearest second, // and so data is stored for 1 second here. Adjust waiting time accordingly. timeService.advance(1101); assertNull(cl.load("k1")); InternalCacheEntry ice2 = internalCacheEntry("k1", "v2", 100); cl.write(marshalledEntry(ice2)); assertEquals("v2", cl.load("k1").getValue()); }
public void testGetValue() throws Exception { assertStoreAccess(0, 0, 0); cache.put("key", "value"); assertStoreAccess(0, 1, 1); assert cache.get("key").equals("value"); assertStoreAccess(0, 1, 1); store.write(new MarshalledEntryImpl("a", "b", null, marshaller())); assert cache.get("a").equals("b"); assertStoreAccess(1, 1, 1); assert cache.get("no_such_key") == null; assertStoreAccess(1, 2, 1); }
public void testReplaceCommand() throws Exception { assertStoreAccess(0, 0, 0); cache.put("key", "value"); assertStoreAccess(0, 1, 1); assert cache.replace("key", "value2").equals("value"); assertStoreAccess(0, 1, 2); store.write(new MarshalledEntryImpl("a", "b", null, marshaller())); assert cache.replace("a", "c").equals("b"); assertStoreAccess(1, 1, 3); assert cache.replace("no_such_key", "c") == null; assertStoreAccess(1, 2, 3); }
public void testRemoveValue() throws Exception { assertStoreAccess(0, 0, 0); cache.put("key", "value"); assertStoreAccess(0, 1, 1); assert cache.get("key").equals("value"); assertStoreAccess(0, 1, 1); assert cache.remove("key").equals("value"); assertStoreAccess(0, 1, 1); cache.remove("no_such_key"); assertStoreAccess(0, 2, 1); store.write(new MarshalledEntryImpl("a", "b", null, marshaller())); assert cache.remove("a").equals("b"); assertStoreAccess(1, 2, 1); }
public void testReplaceEntry() { assertIsEmpty(); InternalCacheEntry ice = internalCacheEntry("k1", "v1", -1); cl.write(marshalledEntry(ice)); assertEquals("v1", unwrap(cl.load("k1").getValue())); InternalCacheEntry ice2 = internalCacheEntry("k1", "v2", -1); cl.write(marshalledEntry(ice2)); assertEquals("v2", unwrap(cl.load("k1").getValue())); }
public void testPutKeyValue() throws Exception { assertStoreAccess(0, 0, 0); cache.put("key", "value"); assertStoreAccess(0, 1, 1); cache.put("key", "value2"); assertStoreAccess(0, 1, 2); store.write(new MarshalledEntryImpl("a", "b", null, marshaller())); cache.put("a", "c"); assertStoreAccess(1, 1, 3); assert store.load("a").getValue().equals("c"); }
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 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 testLoadAndStoreImmortal() throws PersistenceException { assertIsEmpty(); cl.write(marshalledEntry("k", "v", null)); MarshalledEntry entry = cl.load("k"); assertEquals("v", unwrap(entry.getValue())); assertTrue("Expected an immortalEntry", entry.getMetadata() == null || entry.getMetadata().expiryTime() == -1 || entry.getMetadata().maxIdle() == -1); assertContains("k", true); assertFalse(cl.delete("k2")); }
public void testStoreLoadRemove() throws Exception { assertRowCount(0); assertNull("should not be present in the store", cacheStore.load(MIRCEA)); String value = "adsdsadsa"; cacheStore.write(new MarshalledEntryImpl(MIRCEA, value, null, marshaller)); assertRowCount(1); assertEquals(value, cacheStore.load(MIRCEA).getValue()); assertFalse(cacheStore.delete(MANIK)); assertEquals(value, cacheStore.load(MIRCEA).getValue()); assertRowCount(1); assertTrue(cacheStore.delete(MIRCEA)); assertRowCount(0); }