Search in sources :

Example 71 with DummyInMemoryStore

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

Example 72 with DummyInMemoryStore

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();
    }
}
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) MagicKey(org.infinispan.distribution.MagicKey) HashMap(java.util.HashMap) Map(java.util.Map) CheckPoint(org.infinispan.test.fwk.CheckPoint) Test(org.testng.annotations.Test)

Example 73 with DummyInMemoryStore

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

Example 74 with DummyInMemoryStore

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);
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) EntryVersion(org.infinispan.container.versioning.EntryVersion) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) Cache(org.infinispan.Cache)

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