use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class WriteBehindFaultToleranceTest method testBlockingOnStoreAvailabilityChange.
public void testBlockingOnStoreAvailabilityChange() throws InterruptedException, ExecutionException, TimeoutException {
Cache<Object, Object> cache = createManagerAndGetCache(false, 1);
PollingPersistenceManager pm = new PollingPersistenceManager();
PersistenceManager oldPersistenceManager = TestingUtil.replaceComponent(cache, PersistenceManager.class, pm, true);
oldPersistenceManager.stop();
NonBlockingStore<?, ?> asyncStore = TestingUtil.getStore(cache, 0, false);
DummyInMemoryStore dims = TestingUtil.getStore(cache, 0, true);
dims.setAvailable(true);
cache.put(1, 1);
eventually(() -> dims.loadEntry(1) != null);
assertEquals(1, dims.size());
dims.setAvailable(false);
assertFalse(dims.checkAvailable());
int pollCount = pm.pollCount.get();
// Wait until the store's availability has been checked before asserting that the pm is still available
eventually(() -> pm.pollCount.get() > pollCount);
// PM & AsyncWriter should still be available as the async modification queue is not full
assertTrue(join(asyncStore.isAvailable()));
assertNotNull(TestingUtil.extractField((asyncStore), "delegateAvailableFuture"));
assertTrue(pm.isAvailable());
Future<Void> f = fork(() -> {
// Add entries >= modification queue size so that store is no longer available
// The async store creates 2 batches:
// 1. modification 1 returns immediately, but stays in the queue until DIMS becomes available again
// 2. modifications 2-5 block in the async store because the modification queue is full
// The async store waits for the DIMS to become available before completing the 1st batch
// After PersistenceManagerImpl sees the store is unavailable, it becomes unavailable itself
// and later writes never reach the async store (until PMI becomes available again).
cache.putAll(intMap(0, 5));
});
assertEquals(1, dims.size());
eventually(() -> !pm.isAvailable());
// PM and writer should not be available as the async modification queue is now oversubscribed and the delegate is still unavailable
Exceptions.expectException(StoreUnavailableException.class, () -> cache.putAll(intMap(10, 20)));
assertEquals(1, dims.size());
// Make the delegate available and ensure that the initially queued modifications exist in the store
dims.setAvailable(true);
assertTrue(join(asyncStore.isAvailable()));
eventually(pm::isAvailable);
f.get(10, TimeUnit.SECONDS);
// Now that PMI is available again, a new write will succeed
cache.putAll(intMap(5, 10));
// Ensure that the putAll(10..20) operation truly failed
eventuallyEquals(IntSets.immutableRangeSet(10), dims::keySet);
}
use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class ClusterCacheLoaderTest method testRemoteLoadFromCacheLoader.
public void testRemoteLoadFromCacheLoader() throws Exception {
Cache<String, String> cache1 = cache(0, "clusteredCl");
Cache<String, String> cache2 = cache(1, "clusteredCl");
DummyInMemoryStore writer = TestingUtil.getStore(cache2, 1, false);
assertNull(cache1.get("key"));
assertNull(cache2.get("key"));
writer.write(MarshalledEntryUtil.create("key", "value", cache2));
assertEquals(writer.loadEntry("key").getValue(), "value");
assertEquals(cache1.get("key"), "value");
}
use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class ConcurrentLoadAndEvictTest method testEvictBeforeRead.
public void testEvictBeforeRead() throws PersistenceException, ExecutionException, InterruptedException {
cache = cacheManager.getCache();
cache.put("a", "b");
assert cache.get("a").equals("b");
DummyInMemoryStore cl = TestingUtil.getFirstStore(cache);
MarshallableEntry se = cl.loadEntry("a");
assert se != null;
assert se.getValue().equals("b");
// clear the cache
cache.getAdvancedCache().withFlags(SKIP_CACHE_STORE).clear();
se = cl.loadEntry("a");
assert se != null;
assert se.getValue().equals("b");
// now attempt a concurrent get and evict.
sdi.enabled = true;
log.info("test::doing the get");
// call the get
Future<String> future = fork(new Callable<String>() {
@Override
public String call() throws Exception {
return (String) cache.get("a");
}
});
// now run the evict.
log.info("test::before the evict");
cache.evict("a");
log.info("test::after the evict");
// make sure the get call, which would have gone past the cache loader interceptor first, gets the correct value.
assert future.get().equals("b");
// disable the SlowDownInterceptor
sdi.enabled = false;
// and check that the key actually has been evicted
assert !TestingUtil.extractComponent(cache, InternalDataContainer.class).containsKey("a");
}
use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class LocalConditionalCommandTest method initStore.
private void initStore(Cache<String, String> cache) {
writeToStore(cache, key, value1);
DummyInMemoryStore store = TestingUtil.getFirstStore(cache);
assertTrue(store.contains(key));
cacheLoaderInterceptor(cache).resetStatistics();
}
use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class LocalModePassivationTest method testStoreAndLoad.
public void testStoreAndLoad() throws Exception {
final int numKeys = 300;
for (int i = 0; i < numKeys; i++) {
cache().put(i, i);
}
int keysInDataContainer = cache().getAdvancedCache().getDataContainer().size();
// some keys got evicted
assertTrue(keysInDataContainer != numKeys);
DummyInMemoryStore store = TestingUtil.getFirstStore(cache());
long keysInCacheStore = store.size();
if (passivationEnabled) {
assertEquals(numKeys, keysInDataContainer + keysInCacheStore);
} else {
assertEquals(numKeys, keysInCacheStore);
}
// check if keys survive restart
cache().stop();
cache().start();
store = TestingUtil.getFirstStore(cache());
assertEquals(numKeys, store.size());
for (int i = 0; i < numKeys; i++) {
assertEquals(i, cache().get(i));
}
}
Aggregations