use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class LocalStreamIteratorWithPassivationTest method testConcurrentActivation.
@Test(enabled = false, description = "This requires supporting concurrent activation in cache loader interceptor")
public void testConcurrentActivation() 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<Map.Entry<String, String>> iterator = cache.entrySet().stream().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++;
}
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 CacheLoaderFunctionalTest method doPreloadingTest.
protected void doPreloadingTest(Configuration preloadingCfg, String cacheName) throws Exception {
assertTrue("Preload not enabled for preload test", preloadingCfg.persistence().preload());
cm.defineConfiguration(cacheName, preloadingCfg);
Cache<String, String> preloadingCache = getCache(cm, cacheName);
DummyInMemoryStore preloadingCacheLoader = TestingUtil.getFirstStore(preloadingCache);
assert preloadingCache.getCacheConfiguration().persistence().preload();
assertNotInCacheAndStore(preloadingCache, preloadingCacheLoader, "k1", "k2", "k3", "k4");
preloadingCache.getAdvancedCache().getTransactionManager().begin();
preloadingCache.put("k1", "v1");
preloadingCache.put("k2", "v2", lifespan, MILLISECONDS);
preloadingCache.put("k3", "v3");
preloadingCache.put("k4", "v4", lifespan, MILLISECONDS);
preloadingCache.getAdvancedCache().getTransactionManager().commit();
for (int i = 1; i < 5; i++) {
if (i % 2 == 1)
assertInCacheAndStore(preloadingCache, preloadingCacheLoader, "k" + i, "v" + i);
else
assertInCacheAndStore(preloadingCache, preloadingCacheLoader, "k" + i, "v" + i, lifespan);
}
DataContainer c = preloadingCache.getAdvancedCache().getDataContainer();
assertEquals(4, c.size());
preloadingCache.stop();
assertEquals(0, c.size());
preloadingCache.start();
// The old store's marshaller is not working any more
preloadingCacheLoader = TestingUtil.getFirstStore(preloadingCache);
assert preloadingCache.getCacheConfiguration().persistence().preload();
c = preloadingCache.getAdvancedCache().getDataContainer();
assertEquals(4, c.size());
for (int i = 1; i < 5; i++) {
if (i % 2 == 1)
assertInCacheAndStore(preloadingCache, preloadingCacheLoader, "k" + i, "v" + i);
else
assertInCacheAndStore(preloadingCache, preloadingCacheLoader, "k" + i, "v" + i, lifespan);
}
}
use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class PersistenceManagerAvailabilityTest method testCacheAvailability.
@Test(expectedExceptions = StoreUnavailableException.class)
public void testCacheAvailability() {
Cache<Object, Object> cache = createManagerAndGetCache(0);
cache.put(1, 1);
DummyInMemoryStore dims = TestingUtil.getFirstStore(cache);
dims.setAvailable(false);
PersistenceManager pm = TestingUtil.extractComponent(cache, PersistenceManager.class);
eventually(() -> !pm.isAvailable());
try {
cache.put(1, 2);
} catch (Exception e) {
assertEquals(1, cache.get(1));
throw e;
}
TestingUtil.killCaches();
}
use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class AsyncStoreTest method createStore.
private InitializationContext createStore() throws PersistenceException {
ConfigurationBuilder builder = TestCacheManagerFactory.getDefaultCacheConfiguration(false);
DummyInMemoryStoreConfigurationBuilder dummyCfg = builder.persistence().addStore(DummyInMemoryStoreConfigurationBuilder.class).storeName(AsyncStoreTest.class.getName()).segmented(false);
dummyCfg.async().enable();
InitializationContext ctx = PersistenceMockUtil.createContext(getClass(), builder.build(), marshaller);
DummyInMemoryStore underlying = new DummyInMemoryStore();
store = new AsyncNonBlockingStore(underlying);
CompletionStages.join(store.start(ctx));
return ctx;
}
use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.
the class SharedStoreTest method assertStoreDistinctInvocationAmount.
private void assertStoreDistinctInvocationAmount(Cache<?, ?> cache, int distinctInvocations) {
DummyInMemoryStore dims = TestingUtil.getFirstStore(cache);
assertEquals(distinctInvocations, dims.stats().values().stream().filter(i -> i > 0).count());
}
Aggregations