Search in sources :

Example 6 with DummyInMemoryStore

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();
    }
}
Also used : HashMap(java.util.HashMap) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) CheckPoint(org.infinispan.test.fwk.CheckPoint) DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) CacheEntry(org.infinispan.container.entries.CacheEntry) TestObjectStreamMarshaller(org.infinispan.marshall.TestObjectStreamMarshaller) HashMap(java.util.HashMap) Map(java.util.Map) CheckPoint(org.infinispan.test.fwk.CheckPoint) Test(org.testng.annotations.Test)

Example 7 with DummyInMemoryStore

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);
    }
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) DataContainer(org.infinispan.container.DataContainer)

Example 8 with DummyInMemoryStore

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();
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) CacheException(org.infinispan.commons.CacheException) StoreUnavailableException(org.infinispan.persistence.spi.StoreUnavailableException) PersistenceException(org.infinispan.persistence.spi.PersistenceException) SingleCacheManagerTest(org.infinispan.test.SingleCacheManagerTest) Test(org.testng.annotations.Test)

Example 9 with DummyInMemoryStore

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;
}
Also used : AsyncNonBlockingStore(org.infinispan.persistence.async.AsyncNonBlockingStore) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) DummyInMemoryStoreConfigurationBuilder(org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder) DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) InitializationContext(org.infinispan.persistence.spi.InitializationContext) DummyInMemoryStoreConfigurationBuilder(org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)

Example 10 with DummyInMemoryStore

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());
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore)

Aggregations

DummyInMemoryStore (org.infinispan.persistence.dummy.DummyInMemoryStore)74 PersistenceManager (org.infinispan.persistence.manager.PersistenceManager)14 Test (org.testng.annotations.Test)13 MarshallableEntry (org.infinispan.persistence.spi.MarshallableEntry)11 HashMap (java.util.HashMap)9 TestObjectStreamMarshaller (org.infinispan.marshall.TestObjectStreamMarshaller)7 Map (java.util.Map)6 Cache (org.infinispan.Cache)6 DataContainer (org.infinispan.container.DataContainer)6 CacheEntry (org.infinispan.container.entries.CacheEntry)6 ImmortalCacheEntry (org.infinispan.container.entries.ImmortalCacheEntry)6 CheckPoint (org.infinispan.test.fwk.CheckPoint)6 MagicKey (org.infinispan.distribution.MagicKey)5 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)4 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)4 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)4 Set (java.util.Set)3 PersistenceException (org.infinispan.persistence.spi.PersistenceException)3 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2