use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class ClusteredConditionalCommandTest method initStore.
private void initStore(CacheHelper<String, String> cacheHelper, boolean shared) {
DummyInMemoryStore primaryStore = cacheHelper.cacheStore(Ownership.PRIMARY);
DummyInMemoryStore backupStore = cacheHelper.cacheStore(Ownership.BACKUP);
DummyInMemoryStore nonOwnerStore = cacheHelper.cacheStore(Ownership.NON_OWNER);
if (shared) {
writeToStore(cacheHelper, Ownership.PRIMARY, key, value1);
assertTrue(primaryStore.contains(key));
if (backupStore != null) {
assertTrue(backupStore.contains(key));
}
assertTrue(nonOwnerStore.contains(key));
} else {
writeToStore(cacheHelper, Ownership.PRIMARY, key, value1);
assertTrue(primaryStore.contains(key));
if (backupStore != null) {
writeToStore(cacheHelper, Ownership.BACKUP, key, value1);
assertTrue(backupStore.contains(key));
}
assertFalse(nonOwnerStore.contains(key));
}
cacheHelper.resetStats(Ownership.PRIMARY);
cacheHelper.resetStats(Ownership.BACKUP);
cacheHelper.resetStats(Ownership.NON_OWNER);
}
use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class DistributedStreamIteratorWithPassivationTest method testConcurrentActivation.
@Test(enabled = false, description = "This requires supporting concurrent activation in cache loader interceptor")
public void testConcurrentActivation() 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);
// Put this in after the cache has been updated
originalValues.put(loaderKey, loaderValue);
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;
});
Iterator<Map.Entry<MagicKey, String>> iterator = cache0.entrySet().stream().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++;
}
assertEquals(count, 4);
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 DistributedStreamIteratorWithPassivationTest method testConcurrentActivationWithConverter.
@Test(enabled = false, description = "This requires supporting concurrent activation in cache loader interceptor")
public void testConcurrentActivationWithConverter() 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);
// Put this in after the cache has been updated
originalValues.put(loaderKey, loaderValue);
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;
});
Iterator<CacheEntry<MagicKey, String>> iterator = cache0.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<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, 4);
for (Map.Entry<MagicKey, 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(cache0, PersistenceManager.class, pm, true, true);
}
sm.stop();
}
}
use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class Utils method assertInStores.
public static void assertInStores(List<? extends Cache> caches, String key, String value) {
EntryVersion ownerVersion = null;
for (Cache c : caches) {
DummyInMemoryStore store = TestingUtil.<DummyInMemoryStore, Object, Object>getFirstStore(c);
if (isOwner(c, key)) {
assertIsInContainerImmortal(c, key);
MarshallableEntry me = store.loadEntry(key);
assertEquals(me.getValue(), value);
ownerVersion = me.getMetadata().version();
}
}
assertNotNull(ownerVersion);
if (caches.size() == 1) {
return;
}
int equalVersions = 0;
for (Cache c : caches) {
DummyInMemoryStore store = TestingUtil.<DummyInMemoryStore, Object, Object>getFirstStore(c);
if (!isOwner(c, key)) {
MarshallableEntry me = store.loadEntry(key);
if (me != null && me.getMetadata() != null && ownerVersion.equals(me.getMetadata().version())) {
assertEquals(me.getValue(), value);
++equalVersions;
}
}
}
assertEquals(equalVersions, 1);
}
Aggregations