use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class CacheWriterTxModificationsTest method testCommit.
public void testCommit() throws Throwable {
FunctionalMapImpl<Object, Object> functionalMap = FunctionalMapImpl.create(cache.getAdvancedCache());
FunctionalMap.WriteOnlyMap<Object, Object> woMap = WriteOnlyMapImpl.create(functionalMap);
FunctionalMap.ReadWriteMap<Object, Object> rwMap = ReadWriteMapImpl.create(functionalMap);
DummyInMemoryStore store = TestingUtil.getFirstStore(cache);
cache.putAll(mapOf("remove", "initial", "replace", "initial", "computeIfPresent", "initial", "woRemove", "initial", "rwRemove", "initial"));
tm().begin();
try {
cache.put("put", "value");
cache.putIfAbsent("putIfAbsent", "value");
cache.remove("remove");
cache.replace("replace", "value");
cache.compute("compute", (k, v) -> "value");
cache.computeIfAbsent("computeIfAbsent", k -> "value");
cache.computeIfPresent("computeIfPresent", (k, v) -> "value");
cache.putAll(mapOf("putAll", "value"));
woMap.eval("woSet", entry -> entry.set("value"));
woMap.eval("woRemove", entry -> entry.set("value"));
woMap.eval("rwSet", entry -> entry.set("value"));
woMap.eval("rwRemove", entry -> entry.set("value"));
} finally {
tm().commit();
}
DataContainer<Object, Object> dataContainer = cache.getAdvancedCache().getDataContainer();
dataContainer.forEach(entry -> {
MarshallableEntry storeEntry = store.loadEntry(entry.getKey());
assertNotNull("Missing store entry: " + entry.getKey(), storeEntry);
assertEquals(entry.getValue(), storeEntry.getValue());
});
store.keySet().forEach(k -> {
assertEquals(store.loadEntry(k).getValue(), dataContainer.get(k).getValue());
});
}
use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class DistributedStreamIteratorWithPassivationTest method testConcurrentActivationWithFilter.
@Test(enabled = false, description = "This requires supporting concurrent activation in cache loader interceptor")
public // TODO: this test needs to be redone to take into account filtering as well, after we support activated entries
void testConcurrentActivationWithFilter() throws InterruptedException, ExecutionException, TimeoutException {
final Cache<MagicKey, String> cache0 = cache(0, CACHE_NAME);
Cache<MagicKey, String> cache1 = cache(1, CACHE_NAME);
Cache<MagicKey, String> cache2 = cache(2, CACHE_NAME);
Map<MagicKey, String> originalValues = new HashMap<>();
originalValues.put(new MagicKey(cache0), "cache0");
originalValues.put(new MagicKey(cache1), "cache1");
originalValues.put(new MagicKey(cache2), "cache2");
final MagicKey loaderKey = new MagicKey(cache0);
final String loaderValue = "loader0";
cache0.putAll(originalValues);
PersistenceManager persistenceManager = TestingUtil.extractComponent(cache0, PersistenceManager.class);
DummyInMemoryStore store = persistenceManager.getStores(DummyInMemoryStore.class).iterator().next();
TestObjectStreamMarshaller sm = new TestObjectStreamMarshaller();
PersistenceManager pm = null;
try {
store.write(MarshalledEntryUtil.create(loaderKey, loaderValue, sm));
final CheckPoint checkPoint = new CheckPoint();
pm = waitUntilAboutToProcessStoreTask(cache0, checkPoint);
Future<Void> future = fork(() -> {
// Wait until loader is invoked
checkPoint.awaitStrict("pre_process_on_all_stores_invoked", 10, TimeUnit.SECONDS);
// Now force the entry to be moved to the in memory
assertEquals(loaderValue, cache0.get(loaderKey));
checkPoint.triggerForever("pre_process_on_all_stores_released");
return null;
});
KeyValueFilter<MagicKey, String> filter = (Serializable & KeyValueFilter<MagicKey, String>) (k, v, m) -> originalValues.containsKey(k);
Iterator<CacheEntry<MagicKey, String>> iterator = cache0.getAdvancedCache().cacheEntrySet().stream().filter(CacheFilters.predicate(filter)).iterator();
// we need this count since the map will replace same key'd value
int count = 0;
Map<MagicKey, String> results = new HashMap<>();
while (iterator.hasNext()) {
Map.Entry<MagicKey, String> entry = iterator.next();
results.put(entry.getKey(), entry.getValue());
count++;
}
// We shouldn't have found the value in the loader
assertEquals(count, 3);
assertEquals(originalValues, results);
future.get(10, TimeUnit.SECONDS);
} finally {
if (pm != null) {
TestingUtil.replaceComponent(cache0, PersistenceManager.class, pm, true, true);
}
sm.stop();
}
}
use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class BaseStreamIteratorWithLoaderTest method insertDefaultValues.
private Map<Object, String> insertDefaultValues(boolean includeLoaderEntry) {
Cache<Object, String> cache0 = cache(0);
Map<Object, String> originalValues = new HashMap<>();
Object loaderKey;
if (cacheMode.needsStateTransfer()) {
Cache<Object, String> cache1 = cache(1);
Cache<Object, String> cache2 = cache(2);
originalValues.put(new MagicKey(cache0), "cache0");
originalValues.put(new MagicKey(cache1), "cache1");
originalValues.put(new MagicKey(cache2), "cache2");
loaderKey = new MagicKey(cache2);
} else {
originalValues.put(1, "value0");
originalValues.put(2, "value1");
originalValues.put(3, "value2");
loaderKey = 4;
}
cache0.putAll(originalValues);
DummyInMemoryStore store = TestingUtil.getFirstStore(cache0);
TestObjectStreamMarshaller sm = new TestObjectStreamMarshaller(sci);
try {
String loaderValue = "loader-value";
store.write(MarshalledEntryUtil.create(loaderKey, loaderValue, sm));
if (includeLoaderEntry) {
originalValues.put(loaderKey, loaderValue);
}
} finally {
sm.stop();
}
return originalValues;
}
use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class LocalStreamIteratorWithPassivationTest method testConcurrentActivationWithFilter.
@Test(enabled = false, description = "This requires supporting concurrent activation in cache loader interceptor")
public void testConcurrentActivationWithFilter() throws InterruptedException, ExecutionException, TimeoutException {
final Cache<String, String> cache = cache(0, CACHE_NAME);
Map<String, String> originalValues = new HashMap<>();
originalValues.put(cache.toString() + 1, "cache0");
originalValues.put(cache.toString() + 2, "cache1");
originalValues.put(cache.toString() + 3, "cache2");
final String loaderKey = cache.toString() + " in loader";
final String loaderValue = "loader0";
final String filteredLoaderKey = cache.toString() + " in loader1";
final String filteredLoaderValue = "loader1";
cache.putAll(originalValues);
// Put this in after the cache has been updated
originalValues.put(loaderKey, loaderValue);
PersistenceManager persistenceManager = TestingUtil.extractComponent(cache, PersistenceManager.class);
DummyInMemoryStore store = persistenceManager.getStores(DummyInMemoryStore.class).iterator().next();
TestObjectStreamMarshaller sm = new TestObjectStreamMarshaller();
PersistenceManager pm = null;
try {
store.write(MarshalledEntryUtil.create(loaderKey, loaderValue, sm));
store.write(MarshalledEntryUtil.create(filteredLoaderKey, filteredLoaderValue, sm));
final CheckPoint checkPoint = new CheckPoint();
pm = waitUntilAboutToProcessStoreTask(cache, checkPoint);
Future<Void> future = fork(() -> {
// Wait until loader is invoked
checkPoint.awaitStrict("pre_process_on_all_stores_invoked", 10, TimeUnit.SECONDS);
// Now force the entry to be moved to the in memory
assertEquals(loaderValue, cache.get(loaderKey));
checkPoint.triggerForever("pre_process_on_all_stores_released");
return null;
});
Iterator<CacheEntry<String, String>> iterator = cache.getAdvancedCache().cacheEntrySet().stream().filter(CacheFilters.predicate((k, v, m) -> originalValues.containsKey(k))).iterator();
// we need this count since the map will replace same key'd value
int count = 0;
Map<String, String> results = new HashMap<>();
while (iterator.hasNext()) {
Map.Entry<String, String> entry = iterator.next();
results.put(entry.getKey(), entry.getValue());
count++;
}
// We shouldn't have found the value in the loader
assertEquals(4, count);
assertEquals(originalValues, results);
future.get(10, TimeUnit.SECONDS);
} finally {
if (pm != null) {
TestingUtil.replaceComponent(cache, PersistenceManager.class, pm, true, true);
}
sm.stop();
}
}
use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class LocalStreamIteratorWithPassivationTest method testConcurrentActivationWithConverter.
@Test(enabled = false, description = "This requires supporting concurrent activation in cache loader interceptor")
public void testConcurrentActivationWithConverter() throws InterruptedException, ExecutionException, TimeoutException {
final Cache<String, String> cache = cache(0, CACHE_NAME);
Map<String, String> originalValues = new HashMap<>();
originalValues.put(cache.toString() + 1, "cache0");
originalValues.put(cache.toString() + 2, "cache1");
originalValues.put(cache.toString() + 3, "cache2");
final String loaderKey = cache.toString() + " in loader";
final String loaderValue = "loader0";
cache.putAll(originalValues);
// Put this in after the cache has been updated
originalValues.put(loaderKey, loaderValue);
PersistenceManager persistenceManager = TestingUtil.extractComponent(cache, PersistenceManager.class);
DummyInMemoryStore store = persistenceManager.getStores(DummyInMemoryStore.class).iterator().next();
TestObjectStreamMarshaller sm = new TestObjectStreamMarshaller();
PersistenceManager pm = null;
try {
store.write(MarshalledEntryUtil.create(loaderKey, loaderValue, sm));
final CheckPoint checkPoint = new CheckPoint();
pm = waitUntilAboutToProcessStoreTask(cache, checkPoint);
Future<Void> future = fork(() -> {
// Wait until loader is invoked
checkPoint.awaitStrict("pre_process_on_all_stores_invoked", 10, TimeUnit.SECONDS);
// Now force the entry to be moved to the in memory
assertEquals(loaderValue, cache.get(loaderKey));
checkPoint.triggerForever("pre_process_on_all_stores_released");
return null;
});
Iterator<CacheEntry<String, String>> iterator = cache.getAdvancedCache().cacheEntrySet().stream().map(CacheFilters.function(new StringTruncator(1, 3))).iterator();
// we need this count since the map will replace same key'd value
int count = 0;
Map<String, String> results = new HashMap<>();
while (iterator.hasNext()) {
Map.Entry<String, String> entry = iterator.next();
results.put(entry.getKey(), entry.getValue());
count++;
}
// We shouldn't have found the value in the loader
assertEquals(4, count);
for (Map.Entry<String, String> entry : originalValues.entrySet()) {
assertEquals(entry.getValue().substring(1, 4), results.get(entry.getKey()));
}
future.get(10, TimeUnit.SECONDS);
} finally {
if (pm != null) {
TestingUtil.replaceComponent(cache, PersistenceManager.class, pm, true, true);
}
sm.stop();
}
}
Aggregations