Search in sources :

Example 16 with DummyInMemoryStore

use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.

the class LocalModePassivationTest method testStoreAndLoadWithGetEntry.

public void testStoreAndLoadWithGetEntry() {
    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 dims = TestingUtil.getFirstStore(cache());
    long keysInCacheStore = dims.size();
    if (passivationEnabled) {
        assertEquals(numKeys, keysInDataContainer + keysInCacheStore);
    } else {
        assertEquals(numKeys, keysInCacheStore);
    }
    // check if keys survive restart
    cache().stop();
    cache().start();
    dims = TestingUtil.getFirstStore(cache());
    assertEquals(numKeys, dims.size());
    for (int i = 0; i < numKeys; i++) {
        assertEquals(i, cache.getAdvancedCache().getCacheEntry(i).getValue());
    }
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore)

Example 17 with DummyInMemoryStore

use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.

the class EvictionWithPassivationTest method putIntoStore.

private void putIntoStore(String key, String value) {
    AdvancedCache<String, String> testCache = cacheManager.<String, String>getCache(CACHE_NAME).getAdvancedCache();
    DummyInMemoryStore writer = TestingUtil.getFirstStore(testCache);
    Object writerKey = testCache.getKeyDataConversion().toStorage(key);
    Object writerValue = testCache.getValueDataConversion().toStorage(value);
    MarshallableEntry entry;
    if (Configurations.isTxVersioned(testCache.getCacheConfiguration())) {
        entry = MarshalledEntryUtil.createWithVersion(writerKey, writerValue, testCache);
    } else {
        entry = MarshalledEntryUtil.create(writerKey, writerValue, testCache);
    }
    writer.write(entry);
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry)

Example 18 with DummyInMemoryStore

use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.

the class RehashWithSharedStoreTest method testRehashes.

public void testRehashes() throws PersistenceException {
    MagicKey k = new MagicKey("k", c1);
    c1.put(k, "v");
    Cache<Object, String>[] owners = getOwners(k);
    log.infof("Initial owners list for key %s: %s", k, Arrays.asList(owners));
    // Ensure the loader is shared!
    for (Cache<Object, String> c : Arrays.asList(c1, c2, c3)) {
        DummyInMemoryStore dims = TestingUtil.getFirstStore(c);
        assertTrue("CacheStore on " + c + " should contain key " + k, dims.contains(k));
    }
    Cache<Object, String> primaryOwner = owners[0];
    if (getCacheStoreStats(primaryOwner, "write") == 0)
        primaryOwner = owners[1];
    for (Cache<Object, String> c : owners) {
        int numWrites = getCacheStoreStats(c, "write");
        assertEquals(1, numWrites);
    }
    log.infof("Stopping node %s", primaryOwner);
    caches.remove(primaryOwner);
    primaryOwner.stop();
    primaryOwner.getCacheManager().stop();
    TestingUtil.blockUntilViewsReceived(60000, false, caches);
    TestingUtil.waitForNoRebalance(caches);
    owners = getOwners(k);
    log.infof("After shutting one node down, owners list for key %s: %s", k, Arrays.asList(owners));
    assertEquals(numOwners, owners.length);
    for (Cache<Object, String> o : owners) {
        int numWrites = getCacheStoreStats(o, "write");
        assertEquals(1, numWrites);
        assertEquals("v", o.get(k));
    }
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) MagicKey(org.infinispan.distribution.MagicKey) Cache(org.infinispan.Cache)

Example 19 with DummyInMemoryStore

use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.

the class SharedStoreInvalidationDuringRehashTest method checkContentAndInvalidations.

private void checkContentAndInvalidations(boolean preload) {
    int clusterSize = getCacheManagers().size();
    HashMap<Object, Integer> currentOwners = new HashMap<>();
    for (int i = 0; i < clusterSize; i++) {
        Cache<String, String> testCache = manager(i).getCache(TEST_CACHE_NAME);
        DistributionManager dm = testCache.getAdvancedCache().getDistributionManager();
        DataContainer dataContainer = testCache.getAdvancedCache().getDataContainer();
        for (int j = 0; j < NUM_KEYS; j++) {
            String key = "key" + j;
            if (!dm.getCacheTopology().isReadOwner(key)) {
                if (!cacheMode.isScattered()) {
                    assertFalse("Key '" + key + "' is not owned by node " + address(i) + " but it still appears there", dataContainer.containsKey(key));
                }
            } else {
                currentOwners.put(key, i);
                if (preload) {
                    assertTrue("Key '" + key + "' is owned by node " + address(i) + " but it does not appear there", dataContainer.containsKey(key));
                }
            }
        }
    }
    DummyInMemoryStore store = TestingUtil.getFirstStore(cache(0, TEST_CACHE_NAME));
    for (int i = 0; i < NUM_KEYS; i++) {
        String key = "key" + i;
        assertTrue("Key " + key + " is missing from the shared store", store.keySet().contains(key));
    }
    if (cacheMode.isScattered()) {
        // In scattered cache the invalidation happens only on some entries and through InvalidateVersionsCommand
        return;
    }
    // Reset stats for the next check
    store.clearStats();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) DataContainer(org.infinispan.container.DataContainer) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DistributionManager(org.infinispan.distribution.DistributionManager)

Example 20 with DummyInMemoryStore

use of org.infinispan.persistence.dummy.DummyInMemoryStore in project infinispan by infinispan.

the class FlagsEnabledTest method assertLoadsAndReset.

private void assertLoadsAndReset(Cache<?, ?> cache1, int expected1, Cache<?, ?> cache2, int expected2) {
    DummyInMemoryStore store1 = getCacheStore(cache1);
    DummyInMemoryStore store2 = getCacheStore(cache2);
    assertEquals(expected1, (int) store1.stats().get("load"));
    assertEquals(expected2, (int) store2.stats().get("load"));
    store1.clearStats();
    store2.clearStats();
}
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