Search in sources :

Example 21 with DummyInMemoryStore

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

the class CacheManagerTest method testRemoveCacheLocal.

public void testRemoveCacheLocal(Method m) {
    EmbeddedCacheManager manager = getManagerWithStore(m, false, false);
    try {
        Cache<String, String> cache = manager.getCache("cache");
        cache.put(k(m, 1), v(m, 1));
        cache.put(k(m, 2), v(m, 2));
        cache.put(k(m, 3), v(m, 3));
        DummyInMemoryStore store = getDummyStore(cache);
        DataContainer<?, ?> data = getDataContainer(cache);
        assertFalse(store.isEmpty());
        assertTrue(0 != data.size());
        manager.administration().removeCache("cache");
        assertEquals(0, DummyInMemoryStore.getStoreDataSize(store.getStoreName()));
        assertEquals(0, data.size());
        // Try removing the cache again, it should be a no-op
        manager.administration().removeCache("cache");
        assertEquals(0, DummyInMemoryStore.getStoreDataSize(store.getStoreName()));
        assertEquals(0, data.size());
    } finally {
        manager.stop();
    }
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore)

Example 22 with DummyInMemoryStore

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

the class DistSyncStoreSharedTest method testClear.

public void testClear() throws Exception {
    for (Cache<Object, String> c : caches) assert c.isEmpty();
    for (int i = 0; i < 5; i++) {
        getOwners("k" + i)[0].put("k" + i, "value" + i);
        asyncWait("k" + i, PutKeyValueCommand.class);
    }
    // this will fill up L1 as well
    for (int i = 0; i < 5; i++) assertOnAllCachesAndOwnership("k" + i, "value" + i);
    for (Cache<Object, String> c : caches) assert !c.isEmpty();
    c1.clear();
    asyncWait(null, ClearCommand.class);
    for (Cache<Object, String> c : caches) assert c.isEmpty();
    /* We only check c1 because on a shared situation, no matter where the clear is called,
       * it should clear the whole store regardless. Bear in mind that in the test, even though
       * the cache store is shared, each cache has each own cache store, that allows for checking
       * who execute puts, removes...etc. */
    DummyInMemoryStore store = TestingUtil.getFirstStore(c1);
    // DummyInMemoryStore is segmented, so only 1 clear should be invoked
    assertNumberOfInvocations(store, "clear", 1);
    for (int i = 0; i < 5; i++) {
        String key = "k" + i;
        assert !store.contains(key);
    }
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore)

Example 23 with DummyInMemoryStore

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

the class PessimisticDistSyncTxStoreSharedTest method testInvalidPut.

@Test
public void testInvalidPut() throws Exception {
    Cache<String, String> cache = cacheManagers.get(0).getCache("P006");
    IntSet allSegments = IntSets.immutableRangeSet(cache.getCacheConfiguration().clustering().hash().numSegments());
    // add 1st 4 elements
    for (int i = 0; i < 4; i++) {
        cache.put(cacheManagers.get(0).getAddress().toString() + "-" + i, "42");
    }
    // lets check if all elements arrived
    DummyInMemoryStore cs1 = TestingUtil.getFirstStore(cache);
    Set<Object> keys = PersistenceUtil.toKeySet(cs1, allSegments, null);
    Assert.assertEquals(keys.size(), 4);
    // now start 2nd node
    addClusterEnabledCacheManager(getCB()).defineConfiguration("P006", getCB().build());
    waitForClusterToForm("P006");
    cache = cacheManagers.get(1).getCache("P006");
    // add next 4 elements
    for (int i = 0; i < 4; i++) {
        cache.put(cacheManagers.get(1).getAddress().toString() + "-" + i, "42");
    }
    Set mergedKeys = new HashSet();
    // add keys from all cache stores
    DummyInMemoryStore cs2 = TestingUtil.getFirstStore(cache);
    log.debugf("Load from cache store via cache 1");
    mergedKeys.addAll(PersistenceUtil.toKeySet(cs1, allSegments, null));
    log.debugf("Load from cache store via cache 2");
    mergedKeys.addAll(PersistenceUtil.toKeySet(cs2, allSegments, null));
    Assert.assertEquals(mergedKeys.size(), 8);
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) Set(java.util.Set) HashSet(java.util.HashSet) IntSet(org.infinispan.commons.util.IntSet) IntSet(org.infinispan.commons.util.IntSet) HashSet(java.util.HashSet) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest) Test(org.testng.annotations.Test)

Example 24 with DummyInMemoryStore

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

the class DistSyncStoreNotSharedTest method testGetOnlyQueriesCacheOnOwners.

public void testGetOnlyQueriesCacheOnOwners() throws PersistenceException {
    // Make a key that own'ers is c1 and c2
    final MagicKey k = getMagicKey();
    final String v1 = "real-data";
    final String v2 = "stale-data";
    // Simulate a cache had it by itself and someone wrote a value that is now stale
    Cache<Object, String> c = getFirstOwner(k);
    DummyInMemoryStore store = TestingUtil.getFirstStore(c);
    store.write(MarshalledEntryUtil.create(k, v2, c3));
    getFirstNonOwner(k).put(k, v1);
    assertEquals(v1, c.get(k));
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore)

Example 25 with DummyInMemoryStore

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

the class DistSyncStoreNotSharedTest method assertRemovedFromStores.

protected void assertRemovedFromStores(String key) {
    for (Cache<Object, String> c : caches) {
        DummyInMemoryStore store = TestingUtil.getFirstStore(c);
        MarshallableEntry me = store.loadEntry(key);
        // handle possible tombstones
        assert me == null || me.getValue() == null;
    }
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry)

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