@Override public MetadataValue<V> getWithMetadata(K key) { return delegate.getWithMetadata(key); }
@Override public boolean replace(K key, V oldValue, V newValue) { VersionedValue<V> versioned = delegate.getWithMetadata(key); if (versioned == null) { return false; } if (!oldValue.equals(versioned.getValue())) { return false; } return delegate.replaceWithVersion(key, newValue, versioned.getVersion()); }
@Override public boolean remove(Object key, Object oldValue) { @SuppressWarnings("unchecked") K k = (K) key; VersionedValue<V> versioned = delegate.getWithMetadata(k); if (versioned == null) { return false; } if (!oldValue.equals(versioned.getValue())) { return false; } return delegate.removeWithVersion(k, versioned.getVersion()); }
public static void testGetWithMetadata(RemoteCache<String, String> remoteCache) { assertNull(remoteCache.getWithMetadata(NON_EXISTENT_KEY)); }
setLeader(false); } else { version = cache.getWithMetadata(lockKey).getVersion(); LOGGER.debug("Lock refreshed key={} with new version={}", lockKey, version); version = cache.getWithMetadata(lockKey).getVersion(); version = cache.getWithMetadata(lockKey).getVersion();
public static void testPutGetWithMetadata(RemoteCache<String, String> remoteCache) { remoteCache.put(KEY1, VALUE1); assertNotNull(remoteCache.getWithMetadata(KEY1)); }
protected void createRemoteEntityInCache(K key, long eventVersion) { VersionedValue<SessionEntityWrapper<V>> remoteSessionVersioned = remoteCache.getWithMetadata(key); // Maybe can happen under some circumstances that remoteCache doesn't yet contain the value sent in the event (maybe just theoretically...) if (remoteSessionVersioned == null || remoteSessionVersioned.getValue() == null) { logger.debugf("Entity '%s' not present in remoteCache. Ignoring create", key.toString()); return; } V remoteSession = remoteSessionVersioned.getValue().getEntity(); SessionEntityWrapper<V> newWrapper = new SessionEntityWrapper<>(remoteSession); logger.debugf("Read session entity wrapper from the remote cache: %s", remoteSession.toString()); // Using putIfAbsent. Theoretic possibility that entity was already put to cache by someone else cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE, Flag.SKIP_CACHE_LOAD, Flag.IGNORE_RETURN_VALUES) .putIfAbsent(key, newWrapper); }
VersionedValue<SessionEntityWrapper<V>> remoteSessionVersioned = remoteCache.getWithMetadata(key);
@Test public void testReplaceOldValueWithLifespan() throws Exception { int lifespanInMillis = 10; remoteCache.put("aKey", "aValue"); VersionedValue previous = remoteCache.getWithMetadata("aKey"); assertTrue(remoteCache.replace("aKey", "aValue", "aNewValue", lifespanInMillis, TimeUnit.MILLISECONDS)); // version should have changed; value should have changed VersionedValue entry2 = remoteCache.getWithMetadata("aKey"); assertNotEquals(entry2.getVersion(), previous.getVersion()); assertEquals("aNewValue", entry2.getValue()); Thread.sleep(2 * lifespanInMillis); assertNull(remoteCache.getWithMetadata("aKey")); }
@Test public void testReplaceOldValueWithLifespanAndExpiration() throws Exception { int lifespanInMillis = 10; remoteCache.put("aKey", "aValue"); VersionedValue previous = remoteCache.getWithMetadata("aKey"); // Max idle should expire assertTrue(remoteCache.replace("aKey", "aValue", "aNewValue", lifespanInMillis, TimeUnit.MINUTES, lifespanInMillis, TimeUnit.MILLISECONDS)); // version should have changed; value should have changed VersionedValue entry2 = remoteCache.getWithMetadata("aKey"); assertNotEquals(entry2.getVersion(), previous.getVersion()); assertEquals("aNewValue", entry2.getValue()); Thread.sleep(2 * lifespanInMillis); assertNull(remoteCache.getWithMetadata("aKey")); }
@Test public void testReplaceOldValue() throws Exception { remoteCache.put("aKey", "aValue"); VersionedValue previous = remoteCache.getWithMetadata("aKey"); assertTrue(remoteCache.replace("aKey", "aValue", "aNewValue")); // version should have changed; value should have changed VersionedValue entry2 = remoteCache.getWithMetadata("aKey"); assertNotEquals(entry2.getVersion(), previous.getVersion()); assertEquals("aNewValue", entry2.getValue()); }
public void testMixedAccess() { remoteCache.put("k1", "v1"); String rv1 = remoteCache.get("k1"); assertEquals("v1", rv1); MetadataValue<String> mv1 = remoteCache.getWithMetadata("k1"); assertEquals("v1", mv1.getValue()); String cv1 = clientCache.get("k1"); assertEquals("v1", cv1); }
replaceIteration++; VersionedValue<SessionEntityWrapper<V>> versioned = remoteCache.getWithMetadata(key); if (versioned == null) { logger.warnf("Not found entity to replace for key '%s'", key);
@Test public void testGetWithMetadata() { remoteCache.put("k1", "v1", 10000000, TimeUnit.MICROSECONDS); // setting only lifespan remoteCache.put("k2", "v2", 10, TimeUnit.SECONDS, 10, TimeUnit.SECONDS); // lifespan + maxIdleTime MetadataValue<String> k1 = remoteCache.getWithMetadata("k1"); MetadataValue<String> k2 = remoteCache.getWithMetadata("k2"); assertEquals(k1.getValue(), "v1"); // microseconds converted to seconds assertEquals(k1.getLifespan(), 10); assertEquals(k1.getMaxIdle(), -1); assertEquals(k2.getValue(), "v2"); assertEquals(k2.getLifespan(), 10); assertEquals(k2.getMaxIdle(), 10); }
sourceRemoteCache.put("key3", "value2"); MetadataValue<String> key2Metadata = sourceRemoteCache.getWithMetadata("key2"); long k2Created = key2Metadata.getCreated(); MetadataValue<String> metadataEntry = targetRemoteCache.getWithMetadata("key"); assertNotNull(metadataEntry); MetadataValue<String> otherMetadataEntry = targetRemoteCache.getWithMetadata("key2"); assertNotNull(otherMetadataEntry); assertEquals(otherMetadataEntry.getLifespan(), 24 * 3600);
public void testMixedAccessWithLifespan() { remoteCache.put("k1", "v1", 120, TimeUnit.SECONDS); MetadataValue<String> mv1 = remoteCache.getWithMetadata("k1"); assertEquals("v1", mv1.getValue()); assertEquals(120, mv1.getLifespan()); String cv1 = clientCache.get("k1"); assertEquals("v1", cv1); InternalCacheEntry ice1 = clientCache.getAdvancedCache().getDataContainer().get("k1"); assertEquals(120000, ice1.getLifespan()); }
public void testSynchronization() throws Exception { RemoteCache<String, String> sourceRemoteCache = sourceCluster.getRemoteCache(TEST_CACHE); RemoteCache<String, String> targetRemoteCache = targetCluster.getRemoteCache(TEST_CACHE); for (char ch = 'A'; ch <= 'Z'; ch++) { String s = Character.toString(ch); sourceRemoteCache.put(s, s, 20, TimeUnit.SECONDS, 30, TimeUnit.SECONDS); } // Verify access to some of the data from the new cluster assertEquals("A", targetRemoteCache.get("A")); RollingUpgradeManager upgradeManager = targetCluster.getRollingUpgradeManager(TEST_CACHE); long count = upgradeManager.synchronizeData("hotrod"); assertEquals(26, count); assertEquals(sourceCluster.getEmbeddedCache(TEST_CACHE).size(), targetCluster.getEmbeddedCache(TEST_CACHE).size()); upgradeManager.disconnectSource("hotrod"); MetadataValue<String> metadataValue = targetRemoteCache.getWithMetadata("Z"); assertEquals(20, metadataValue.getLifespan()); assertEquals(30, metadataValue.getMaxIdle()); }
public void testMixedAccessWithLifespanAndMaxIdle() { remoteCache.put("k1", "v1", 120, TimeUnit.SECONDS, 30, TimeUnit.SECONDS); MetadataValue<String> mv1 = remoteCache.getWithMetadata("k1"); assertEquals("v1", mv1.getValue()); assertEquals(120, mv1.getLifespan()); assertEquals(30, mv1.getMaxIdle()); String cv1 = clientCache.get("k1"); assertEquals("v1", cv1); InternalCacheEntry ice1 = clientCache.getAdvancedCache().getDataContainer().get("k1"); assertEquals(120000, ice1.getLifespan()); assertEquals(30000, ice1.getMaxIdle()); }
assertEquals(sourceCluster.getEmbeddedCache(CACHE_NAME).size(), targetCluster.getEmbeddedCache(CACHE_NAME).size()); MetadataValue<String> metadataValue = targetRemoteCache.getWithMetadata("10"); assertEquals(10 * 60, metadataValue.getLifespan()); assertEquals(30 * 60, metadataValue.getMaxIdle());
assertEquals("AA", rc.get("keyA")); MetadataValue<String> meta = rc.getWithMetadata("keyA"); assertTrue(rc.replaceWithVersion("keyA", "AAA", meta.getVersion())); assertEquals("AAA", rc.get("keyA")); meta = rc.getWithMetadata("keyA");