@Override public MarshalledEntry<K, V> load(Object key) throws PersistenceException { byte[] bytes = this.remoteCache.get(this.marshall(key)); if (bytes == null) { return null; } Map.Entry<ByteBuffer, ByteBuffer> entry = this.unmarshallValue(bytes); return this.ctx.getMarshalledEntryFactory().newMarshalledEntry(key, entry.getKey(), entry.getValue()); }
public void testNamedCache() { cache.put("pete", "British"); cache.put("manik", "Sri Lankan"); assertEquals(cache.getName(), "small"); assertEquals(cache.get("pete"), "British"); assertEquals(cache.get("manik"), "Sri Lankan"); // here we check that the cache injection with the @Small qualifier works // like the injection with the @Remote qualifier assertEquals(cacheWithQualifier.getName(), "small"); assertEquals(cacheWithQualifier.get("pete"), "British"); assertEquals(cacheWithQualifier.get("manik"), "Sri Lankan"); }
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); }
@Override public Status read(String table, String recordKey, Set<String> fields, Map<String, ByteIterator> result) { String compositKey = createKey(table, recordKey); try { Map<String, String> values = cache().get(compositKey); if (values == null || values.isEmpty()) { return Status.NOT_FOUND; } if (fields == null) { //get all field/value pairs StringByteIterator.putAllAsByteIterators(result, values); } else { for (String field : fields) { String value = values.get(field); if (value != null) { result.put(field, new StringByteIterator(value)); } } } return Status.OK; } catch (Exception e) { LOGGER.error(e); return Status.ERROR; } }
@Override public V get(Object key) { V v = delegate.get(key); if (v == null) { stats.incrementCacheMisses(); } else { stats.incrementCacheHits(); } stats.incrementCacheGets(); return v; }
@Override public V get(K key) { checkNotClosed(); checkNotNull(key, "key"); V value = cacheWithCacheStore.get(key); if (value != null) { updateTTLForAccessed(cache, key, value); } return value; }
@Test public void testEvictionNone() { RemoteCache<String, String> rc = remoteCacheManager.getCache("none"); rc.clear(); storeKeys(rc, "A", "B", "C"); rc.put("keyD", "D"); assertEquals(4, rc.size()); assertEquals("A", rc.get("keyA")); assertEquals("B", rc.get("keyB")); assertEquals("C", rc.get("keyC")); assertEquals("D", rc.get("keyD")); }
public void testEntryWrapping() throws Exception { remoteSourceCache.put("k1", "v1"); remoteSourceCache.put("k2", "v2"); assertHotRodEquals(serverCacheManager, "k1", "v1"); assertHotRodEquals(serverCacheManager, "k2", "v2"); String v1 = remoteTargetCache.get("k1"); assertEquals("v1", v1); String v2 = remoteTargetCache.get("k2"); assertEquals("v2", v2); }
@Test public void testSimpleScriptExecutionWithParams() throws IOException { RemoteCache<String, String> remoteCache = remoteCacheManager.getCache(COMPATIBILITY_CACHE_NAME); addScripts("test.js"); Map<String, Object> parameters = new HashMap<>(); parameters.put("key", "parameter"); parameters.put("value", "value"); int result = remoteCache.execute("test.js", parameters); assertEquals(1, result); assertEquals("value", remoteCache.get("parameter")); }
public void testEmbeddedPutHotRodGet() throws Exception { final byte[] key = "8".getBytes(); final String value = "v1"; // 1. Put with Embedded assertNull(cacheFactory2.getEmbeddedCache().put(key, value)); // 2. Get with HotRod assertEquals(value, cacheFactory1.getHotRodCache().get(key)); }
public void testEmbeddedPutHotRodGet() throws Exception { final String key = "8"; final byte[] value = "v1".getBytes(); // 1. Put with Embedded assertNull(cacheFactory2.getEmbeddedCache().put(key, value)); // 2. Get with HotRod assertArrayEquals(value, (byte[]) cacheFactory1.getHotRodCache().get(key)); }
@Test public void testPutGetCustomObject() throws Exception { final Person p = new Person("Martin"); remoteCache.put("k1", p); assertEquals(p, remoteCache.get("k1")); }
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 testEmbeddedPutHotRodGetFromL1() { Cache<Integer, String> embedded1 = cacheFactory1.getEmbeddedCache(); Cache<Integer, String> embedded2 = cacheFactory2.getEmbeddedCache(); Integer key = getSplitIntKeyForServer(cacheFactory1.getHotrodServer(), cacheFactory2.getHotrodServer(), null); // Put it owner, forcing the remote node to get it from L1 embedded1.put(key, "uno"); // Should get it from L1 assertEquals("uno", cacheFactory1.getHotRodCache().get(key)); assertEquals("uno", cacheFactory1.getHotRodCache().get(key)); }
private void doPutGet(RemoteInfinispanMBeans s, RemoteCache<Object, Object> c) { assertEquals(0, s.cache.getNumberOfEntriesInMemory()); for (int i = 0; i < 10; i++) { c.put("k" + i, "v" + i); } for (int i = 0; i < 10; i++) { assertEquals("v" + i, c.get("k" + i)); } assertEquals(10, s.cache.getNumberOfEntriesInMemory()); }
@Test public void shouldPassWithAuth() throws Exception { SecurityConfigurationHelper config = new SecurityConfigurationHelper("DIGEST-MD5"); config.forIspnServer(server).withServerName("node0"); config.forCredentials(EXECUTOR_LOGIN, EXECUTOR_PASSWORD); RemoteCacheManager rcm = new RemoteCacheManager(config.build(), true); RemoteCache remoteCache = rcm.getCache(LocalAuthTestServerTask.CACHE_NAME); String result = (String) remoteCache.execute(LocalAuthTestServerTask.NAME, Collections.emptyMap()); assertEquals(LocalAuthTestServerTask.EXECUTED_VALUE, result); assertEquals(true, remoteCache.get(LocalAuthTestServerTask.KEY)); }
public void testEmbeddedRemoveConditionalHotRodGet() { final Integer key = 11; Cache<Integer, String> embedded = getEmbeddedCache(); RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache(); assertEquals(null, embedded.put(key, "v1")); assertFalse(embedded.remove(key, "vX")); assertTrue(embedded.remove(key, "v1")); assertEquals(null, remote.get(key)); }
public void testEmbeddedReplaceConditionalHotRodGet() { final Integer key = 7; Cache<Integer, String> embedded = getEmbeddedCache(); RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache(); assertEquals(null, embedded.put(key, "v1")); assertTrue(embedded.replace(key, "v1", "v2")); assertEquals("v2", remote.get(key)); assertEquals("v2", embedded.remove(key)); }