public void testRemoteLoadFromCacheLoader() throws Exception { Cache<String, String> cache1 = cache(0, "clusteredCl"); Cache<String, String> cache2 = cache(1, "clusteredCl"); CacheWriter writer = TestingUtil.getFirstWriter(cache2); assertNull(cache1.get("key")); assertNull(cache2.get("key")); writer.write(new MarshalledEntryImpl("key", "value", null, cache2.getAdvancedCache().getComponentRegistry().getCacheMarshaller())); assertEquals(((CacheLoader)writer).load("key").getValue(), "value"); assertEquals(cache1.get("key"), "value"); } }
private static <K, V> void writeToStore(Cache<K, V> cache, K key, V value) { TestingUtil.getFirstWriter(cache).write(marshalledEntry(key, value, cache.getAdvancedCache().getComponentRegistry().getCacheMarshaller())); }
public void testGetOnlyQueriesCacheOnOwners() throws PersistenceException { // Make a key that own'ers is c1 and c2 final MagicKey k = getMagicKey(); final String v1 = "real-data"; final String v2 = "stale-data"; // Simulate c3 was by itself and someone wrote a value that is now stale CacheWriter store = (CacheWriter) TestingUtil.getFirstLoader(c3); store.write(new MarshalledEntryImpl(k, v2, null, extractGlobalMarshaller(c3.getCacheManager()))); c1.put(k, v1); assertEquals(v1, c3.get(k)); }
public void testGetOnlyQueriesCacheOnOwners() throws PersistenceException { // Make a key that own'ers is c1 and c2 final MagicKey k = getMagicKey(); final String v1 = "real-data"; final String v2 = "stale-data"; // Simulate c3 was by itself and someone wrote a value that is now stale CacheWriter store = (CacheWriter) TestingUtil.getFirstLoader(c3); store.write(new MarshalledEntryImpl(k, v2, null, extractGlobalMarshaller(c3.getCacheManager()))); c1.put(k, v1); assertEquals(v1, c3.get(k)); } }
private void putIntoStore(String key, String value) throws Exception { Cache<String, String> testCache = cacheManager.getCache(CACHE_NAME); CacheWriter<String, String> writer = TestingUtil.getFirstWriter(testCache); Object writerKey = key; Object writerValue = value; if (storage == StorageType.OFF_HEAP) { GlobalMarshaller gm = TestingUtil.extractGlobalMarshaller(testCache.getCacheManager()); writerKey = new WrappedByteArray(gm.objectToByteBuffer(key)); writerValue = new WrappedByteArray(gm.objectToByteBuffer(value)); } MarshalledEntry entry = new MarshalledEntryImpl(writerKey, writerValue, null, null); writer.write(entry); }