Refine search
public void clearLock() { Object lockOwner = noCacheStoreCache.get(keyOfLock); if (lockOwner == null || valueOfLock.equals(lockOwner)) { Object previousValue = noCacheStoreCache.remove(keyOfLock); log.tracef("Lock: %s removed for index: %s from %s (was %s)", lockName, indexName, valueOfLock, previousValue); } else { log.tracef("Lock: %s not cleared for index: %s from %s, was taken already by %s.", lockName, indexName, valueOfLock, lockOwner); } }
@Override public void call() { cache.put("k1", "v1"); cache.remove("k1"); assertEquals("cache size must be 0", 0, cache.getAdvancedCache().getDataContainer().size()); } });
public void testEvictAndRemove() throws PersistenceException { assertNotInCacheAndStore("k1", "k2"); cache.put("k1", "v1"); cache.put("k2", "v2", lifespan, MILLISECONDS); cache.evict("k1"); cache.evict("k2"); assertEquals("v1", cache.remove("k1")); assertEquals("v2", cache.remove("k2")); }
public void testMemcachedPutEmbeddedGet() throws Exception { // 1. Put with Memcached for (int i = 0; i != numEntries; i++) { Future<Boolean> f = cacheFactory2.getMemcachedClient().set("k" + i, 0, "v" + i); assertTrue(f.get(60, TimeUnit.SECONDS)); } // 2. Get with Embedded from a different node for (int i = 0; i != numEntries; i++) { assertEquals("v" + i, cacheFactory1.getEmbeddedCache().get("k" + i)); cacheFactory1.getEmbeddedCache().remove("k" + i); } }
private void testConditionalRemoveFrom(Ownership owneship) throws Exception { prepareTestData(); CacheQuery<Object> query = Search.getSearchManager(cache2).getQuery(new MatchAllDocsQuery()); Cache<Object, Person> cache = findCache(owneship, key1).orElse(cache2); cache.remove(key1, person1); assertEquals(query.list().size(), 2); assertEquals(countIndex(cache), 2); cache.remove(key1, person1); assertEquals(query.list().size(), 2); assertEquals(countIndex(cache), 2); cache = findCache(owneship, key3).orElse(cache2); cache.remove(key3); assertEquals(query.list().size(), 1); assertEquals(countIndex(cache), 1); StaticTestingErrorHandler.assertAllGood(cache1, cache2); }
public void testRemoteCacheListener() throws Exception { Integer age; RemoteListener lis = new RemoteListener(); cache2.addListener(lis); try { cache1.put("age", 38); // value on cache2 must be 38 age = (Integer) cache2.get("age"); assertNotNull("\"age\" obtained from cache2 must be non-null ", age); assertTrue("\"age\" must be 38", age == 38); cache1.remove("age"); } finally { cache2.removeListener(lis); } }
public void testEmbeddedPutIfAbsentHotRodGet() { final Integer key = 3; Cache<Integer, String> embedded = getEmbeddedCache(); RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache(); assertEquals(null, embedded.putIfAbsent(key, "v1")); assertEquals("v1", remote.get(key)); assertEquals("v1", embedded.putIfAbsent(key, "v2")); assertEquals("v1", remote.get(key)); assertEquals("v1", embedded.remove(key)); }
public void testPutIfAbsentFromMainOwner() { Object k = getKeyForCache(0); cache(0).put(k, "0"); cache(0).putIfAbsent(k, "1"); assertEquals(advancedCache(0).getDataContainer().get(k).getValue(), "0"); assertEquals(advancedCache(1).getDataContainer().get(k).getValue(), "0"); cache(0).remove(k); cache(0).putIfAbsent(k, "1"); assertEquals(advancedCache(0).getDataContainer().get(k).getValue(), "1"); assertEquals(advancedCache(1).getDataContainer().get(k).getValue(), "1"); } }
public void testPutIfAbsentAfterRemoveInTx() throws Exception { String key = "key_1", old_value = "old_value"; cache.put(key, old_value); assertEquals(old_value, cache.get(key)); TransactionManager tm = TestingUtil.getTransactionManager(cache); withTx(tm, () -> { assertEquals(old_value, cache.remove(key)); assertNull(cache.get(key)); assertEquals(cache.putIfAbsent(key, "new_value"), null); tm.setRollbackOnly(); return null; }); assertEquals(old_value, cache.get(key)); }
public void testEmbeddedPutHotRodGet() { final Integer key = 1; Cache<Integer, String> embedded = getEmbeddedCache(); RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache(); assertEquals(null, embedded.put(key, "v1")); assertEquals("v1", remote.get(key)); assertEquals("v1", embedded.put(key, "v2")); assertEquals("v2", remote.get(key)); assertEquals("v2", embedded.remove(key)); }
@Override public void call() { cache.put("k1", "v1"); cache.put("k2", "v2"); // force eviction of "k1" eventually(() -> store.load("k1") != null); // simulate slow back end store store.lock.lock(); try { cache.remove("k1"); TestingUtil.sleepThread(100); // wait until the first AsyncProcessor thread is blocked cache.remove("k1"); // make second AsyncProcessor thread burn asyncProcessorIds TestingUtil.sleepThread(200); // wait for reaper to collect InternalNullEntry assert null == cache.get("k1") : "cache must return k1 == null (was: " + cache.get("k1") + ")"; } finally { store.lock.unlock(); } } });
public void testRemove() throws Exception { doPutWithDisabledBlockingInterceptor(); cache("LON", 1).remove("k"); blockingInterceptor.invocationReceivedLatch.await(20000, TimeUnit.MILLISECONDS); assertNull(cache("LON", 0).get("k")); assertNull(cache("LON", 1).get("k")); assertEquals("v", backup("LON").get("k")); blockingInterceptor.waitingLatch.countDown(); eventuallyEquals(null, () -> backup("LON").get("k")); }
public void testRemoveFromNonOwner() { initAndTest(); Object retval = getFirstNonOwner("k1").remove("k1"); asyncWait("k1", RemoveCommand.class); if (testRetVals) assertEquals("value", retval); assertRemovedOnAllCaches("k1"); }
public void clearLock() { Object lockOwner = noCacheStoreCache.get(keyOfLock); if (lockOwner == null || valueOfLock.equals(lockOwner)) { Object previousValue = noCacheStoreCache.remove(keyOfLock); log.tracef("Lock: %s removed for index: %s from %s (was %s)", lockName, indexName, valueOfLock, previousValue); } else { log.tracef("Lock: %s not cleared for index: %s from %s, was taken already by %s.", lockName, indexName, valueOfLock, lockOwner); } }
public void testPutIfAbsentFromMainOwner() { Object k = getKeyForCache(0); cache(0).put(k, "0"); cache(0).putIfAbsent(k, "1"); assertEquals(advancedCache(0).getDataContainer().get(k).getValue(), "0"); assertEquals(advancedCache(1).getDataContainer().get(k).getValue(), "0"); cache(0).remove(k); cache(0).putIfAbsent(k, "1"); assertEquals(advancedCache(0).getDataContainer().get(k).getValue(), "1"); assertEquals(advancedCache(1).getDataContainer().get(k).getValue(), "1"); } }
public void testRepeatableReadWithNullRemoval() throws Exception { LockTestData tl = lockTestData; Cache<String, String> cache = tl.cache; TransactionManager tm = tl.tm; // start with an empty cache tm.begin(); cache.get("a"); Transaction tx = tm.suspend(); cache.put("a", "v2"); assertEquals(cache.get("a"), "v2"); tm.resume(tx); assertEquals(null, cache.get("a")); cache.remove("a"); Exceptions.expectException(RollbackException.class, tm::commit); assertEquals(cache.get("a"), "v2"); }
public void testEmbeddedRemoveHotRodGet() { final Integer key = 9; Cache<Integer, String> embedded = getEmbeddedCache(); RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache(); assertEquals(null, embedded.put(key, "v1")); assertEquals("v1", embedded.remove(key)); assertEquals(null, remote.get(key)); }