@Override public boolean delete(Object key) { return this.remoteCache.withFlags(Flag.FORCE_RETURN_VALUE).remove(this.marshall(key)) != null; }
@Override public RemoteCache<K, V> withFlags(Flag... flags) { delegate.withFlags(flags); return this; }
@Override BasicCache<String, Serializable> getCache() { // Flags are per-invocation! return remoteCache.withFlags(Flag.FORCE_RETURN_VALUE); }
@Override public boolean delete(Object key) { return this.remoteCache.withFlags(Flag.FORCE_RETURN_VALUE).remove(this.marshall(key)) != null; }
public static void testReplaceWitFlagAsync(RemoteCache<String, String> remoteCache) throws Exception { remoteCache.put(KEY1, VALUE1); assertEquals( VALUE1, remoteCache.withFlags(Flag.FORCE_RETURN_VALUE).replaceAsync(KEY1, "replace value") .get(ASYNC_TIMEOUT, TimeUnit.SECONDS)); }
public void testHotRodReplaceEmbeddedGet() { final Integer key = 6; Cache<Integer, String> embedded = getEmbeddedCache(); RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache(); assertEquals(null, remote.withFlags(Flag.FORCE_RETURN_VALUE).replace(key, "v1")); assertEquals(null, remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, "v1")); assertEquals("v1", remote.withFlags(Flag.FORCE_RETURN_VALUE).replace(key, "v2")); assertEquals("v2", embedded.get(key)); }
public void testHotRodRemoveEmbeddedGet() { final Integer key = 10; Cache<Integer, String> embedded = getEmbeddedCache(); RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache(); assertEquals(null, remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, "v1")); assertEquals("v1", remote.withFlags(Flag.FORCE_RETURN_VALUE).remove(key)); assertEquals(null, embedded.get(key)); }
public void testHotRodRemoveConditionalEmbeddedGet() { final Integer key = 12; Cache<Integer, String> embedded = getEmbeddedCache(); RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache(); assertEquals(null, remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, "v1")); VersionedValue<String> versioned = remote.getVersioned(key); assertFalse(remote.withFlags(Flag.FORCE_RETURN_VALUE).removeWithVersion(key, Long.MAX_VALUE)); assertTrue(remote.withFlags(Flag.FORCE_RETURN_VALUE).removeWithVersion(key, versioned.getVersion())); assertEquals(null, embedded.get(key)); }
public void testHotRodPutEmbeddedGet() throws Exception { final String key = "4"; final byte[] value = "v1".getBytes(); // 1. Put with HotRod RemoteCache<Object, Object> remote = cacheFactory1.getHotRodCache(); assertNull(remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, value)); // 2. Get with Embedded assertArrayEquals(value, (byte[]) cacheFactory2.getEmbeddedCache().get(key)); }
public void testHotRodPutIfAbsentEmbeddedGet() { final Integer key = 4; Cache<Integer, String> embedded = getEmbeddedCache(); RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache(); assertEquals(null, remote.withFlags(Flag.FORCE_RETURN_VALUE).putIfAbsent(key, "v1")); assertEquals("v1", embedded.get(key)); assertEquals(null, remote.putIfAbsent(key, "v2")); assertEquals("v1", remote.withFlags(Flag.FORCE_RETURN_VALUE).putIfAbsent(key, "v2")); assertEquals("v1", embedded.get(key)); assertEquals("v1", remote.withFlags(Flag.FORCE_RETURN_VALUE).remove(key)); }
public void testHotRodPutEmbeddedGet() { final Integer key = 2; RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache(); Cache<Integer, String> embedded = getEmbeddedCache(); assertEquals(null, remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, "v1")); assertEquals("v1", embedded.get(key)); assertEquals(null, remote.put(key, "v2")); assertEquals("v2", remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, "v3")); assertEquals("v3", embedded.get(key)); assertEquals("v3", remote.withFlags(Flag.FORCE_RETURN_VALUE).remove(key)); }
public void testHotRodPutEmbeddedGet() throws Exception { final byte[] key = "4".getBytes(); final String value = "v1"; // 1. Put with HotRod RemoteCache<Object, Object> remote = cacheFactory1.getHotRodCache(); assertNull(remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, value)); // 2. Get with Embedded assertEquals(value, cacheFactory2.getEmbeddedCache().get(key)); }
public void testHotRodReplace() throws Exception { final String key = "5"; final byte[] value1 = "v1".getBytes(); final byte[] value2 = "v2".getBytes(); // 1. Put with HotRod RemoteCache<Object, Object> remote = cacheFactory1.getHotRodCache(); assertNull(remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, value1)); // 2. Replace with HotRod VersionedValue versioned = cacheFactory1.getHotRodCache().getVersioned(key); assertTrue(cacheFactory1.getHotRodCache().replaceWithVersion(key, value2, versioned.getVersion())); }
public void testHotRodPutMemcachedGet() throws IOException { final String key = "1"; // 1. Put with Hot Rod RemoteCache<String, String> remote = cacheFactory.getHotRodCache(); assertEquals(null, remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, "v1")); // 2. Read with Memcached MemcachedClient memcached = new MemcachedClient("localhost", cacheFactory.getMemcachedPort()); try { assertEquals("v1".getBytes(), memcached.getBytes(key)); } finally { memcached.close(); } }
public void testHotRodRemove() throws Exception { final byte[] key = "7".getBytes(); final String value = "v1"; // 1. Put with HotRod RemoteCache<Object, Object> remote = cacheFactory1.getHotRodCache(); assertNull(remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, value)); // 2. Removed with HotRod VersionedValue versioned = cacheFactory1.getHotRodCache().getVersioned(key); assertTrue(cacheFactory1.getHotRodCache().removeWithVersion(key, versioned.getVersion())); }
public void testCustomObjectHotRodPutEmbeddedRestGet() throws Exception { final String key = "4"; Person p = new Person("Martin"); // 1. Put with Hot Rod RemoteCache<String, Object> remote = cacheFactory.getHotRodCache(); assertEquals(null, remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, p)); // 2. Get with Embedded assertEquals(p, cacheFactory.getEmbeddedCache().get(key)); // 3. Get with REST HttpMethod get = new GetMethod(cacheFactory.getRestUrl() + "/" + key); get.setRequestHeader("Accept", "application/x-java-serialized-object"); cacheFactory.getRestClient().executeMethod(get); assertEquals(get.getStatusText(), HttpStatus.SC_OK, get.getStatusCode()); // REST finds the Java POJO in-memory and returns the Java serialized version assertEquals(p, new ObjectInputStream(get.getResponseBodyAsStream()).readObject()); }
public void testHotRodReplace() throws Exception { final byte[] key = "5".getBytes(); final String value1 = "v1"; final String value2 = "v2"; // 1. Put with HotRod RemoteCache<Object, Object> remote = cacheFactory1.getHotRodCache(); assertNull(remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, value1)); // 2. Replace with HotRod VersionedValue versioned = cacheFactory1.getHotRodCache().getVersioned(key); assertTrue(cacheFactory1.getHotRodCache().replaceWithVersion(key, value2, versioned.getVersion())); }
public void testHotRodRemove() throws Exception { final String key = "7"; final byte[] value = "v1".getBytes(); // 1. Put with HotRod RemoteCache<Object, Object> remote = cacheFactory1.getHotRodCache(); assertNull(remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, value)); // 2. Remove with HotRod VersionedValue versioned = cacheFactory1.getHotRodCache().getVersioned(key); assertTrue(cacheFactory1.getHotRodCache().removeWithVersion(key, versioned.getVersion())); }
@Test public void testWithFlags() throws IOException { assertNull(remoteCache.put("aKey", "aValue")); assertTrue(remoteCache.containsKey("aKey")); assertEquals("aValue", remoteCache.get("aKey")); // should not return return old value assertNull(remoteCache.put("aKey", "anotherValue")); assertEquals("anotherValue", remoteCache.get("aKey")); // now should return old value assertEquals("anotherValue", remoteCache.withFlags(Flag.FORCE_RETURN_VALUE).put("aKey", "yetAnotherValue")); }
public void testHotRodReplaceConditionalEmbeddedGet() { final Integer key = 8; Cache<Integer, String> embedded = getEmbeddedCache(); RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache(); assertEquals(null, remote.put(key, "v1")); VersionedValue<String> versioned = remote.getVersioned(key); assertEquals("v1", versioned.getValue()); assertTrue(0 != versioned.getVersion()); assertFalse(remote.replaceWithVersion(key, "v2", Long.MAX_VALUE)); assertTrue(remote.replaceWithVersion(key, "v2", versioned.getVersion())); assertEquals("v2", embedded.get(key)); assertEquals("v2", remote.withFlags(Flag.FORCE_RETURN_VALUE).remove(key)); }