Search in sources :

Example 26 with DummyInMemoryStore

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

the class DistSyncStoreNotSharedTest method prepareClearTest.

private void prepareClearTest() throws PersistenceException {
    for (Cache<Object, String> c : caches) assert c.isEmpty() : "Data container " + c + " should be empty, instead it contains keys " + c.keySet();
    for (int i = 0; i < 5; i++) {
        getOwners("k" + i)[0].put("k" + i, "value" + i);
    }
    // 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) {
        assertFalse(c.isEmpty());
        DummyInMemoryStore store = TestingUtil.getFirstStore(c);
        for (int i = 0; i < 5; i++) {
            String key = "k" + i;
            if (isOwner(c, key)) {
                assertTrue("Cache store " + c + " does not contain key " + key, store.contains(key));
            }
        }
    }
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore)

Example 27 with DummyInMemoryStore

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

the class DistSyncStoreNotSharedTest method testPutFromNonOwner.

public void testPutFromNonOwner(Method m) throws Exception {
    String key = k(m), value = "value2";
    Cache<Object, String> nonOwner = getFirstNonOwner(key);
    Cache<Object, String> owner = getFirstOwner(key);
    DummyInMemoryStore nonOwnerLoader = TestingUtil.getFirstStore(nonOwner);
    DummyInMemoryStore ownerLoader = TestingUtil.getFirstStore(owner);
    assertFalse(nonOwnerLoader.contains(key));
    assertFalse(ownerLoader.contains(key));
    Object retval = nonOwner.put(key, value);
    assertInStores(key, value, true);
    if (testRetVals)
        assert retval == null;
    assertOnAllCachesAndOwnership(key, value);
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore)

Example 28 with DummyInMemoryStore

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

the class DistSyncStoreNotSharedTest method testGetFromNonOwnerWithFlags.

public void testGetFromNonOwnerWithFlags(Method m) throws Exception {
    String key = k(m), value = "value2";
    Cache<Object, String> nonOwner = getFirstNonOwner(key);
    Cache<Object, String> owner = getFirstOwner(key);
    DummyInMemoryStore ownerLoader = TestingUtil.getFirstStore(owner);
    owner.put(key, value);
    assertEquals(value, ownerLoader.loadEntry(key).getValue());
    owner.getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE).clear();
    assertEquals(value, ownerLoader.loadEntry(key).getValue());
    assertNull(owner.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD).get(key));
    assertNull(nonOwner.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD).get(key));
    assertEquals(value, nonOwner.get(key));
    // need to do the get() on all the owners first to load the values, otherwise assertOwnershipAndNonOwnership might fail
    assertOnAllCaches(key, value);
    assertOwnershipAndNonOwnership(key, true);
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore)

Example 29 with DummyInMemoryStore

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

the class DistSyncStoreNotSharedTest method testAtomicPutIfAbsentFromNonOwnerWithFlag.

public void testAtomicPutIfAbsentFromNonOwnerWithFlag(Method m) throws Exception {
    String key = k(m), value = "value";
    String replaced = getFirstNonOwner(key).getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE).putIfAbsent(key, value);
    assertNull(replaced);
    // interesting case: fails to put as value exists, put actually missing in Store
    replaced = getFirstNonOwner(key).putIfAbsent(key, value);
    assertEquals(replaced, value);
    for (Cache<Object, String> c : caches) {
        assertEquals(replaced, c.get(key));
        DummyInMemoryStore store = TestingUtil.getFirstStore(c);
        assertFalse(store.contains(key));
    }
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore)

Example 30 with DummyInMemoryStore

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

the class DistSyncStoreSharedTest method testPutFromOwner.

public void testPutFromOwner() throws Exception {
    String key = "k5", value = "value5";
    for (Cache<Object, String> c : caches) assert c.isEmpty();
    Cache[] owners = getOwners(key);
    Object retval = owners[0].put(key, value);
    asyncWait(key, PutKeyValueCommand.class);
    DummyInMemoryStore store = TestingUtil.<DummyInMemoryStore, Object, Object>getFirstStore(owners[0]);
    assertIsInContainerImmortal(owners[0], key);
    assert store.contains(key);
    for (int i = 1; i < owners.length; i++) {
        store = TestingUtil.<DummyInMemoryStore, Object, Object>getFirstStore(owners[i]);
        assertIsInContainerImmortal(owners[i], key);
        assert store.contains(key);
    }
    for (Cache<Object, String> c : caches) {
        store = TestingUtil.getFirstStore(c);
        if (isOwner(c, key)) {
            assertIsInContainerImmortal(c, key);
        }
        assert store.contains(key);
        assertNumberOfInvocations(store, "write", 1);
    }
    if (testRetVals)
        assert retval == null;
    assertOnAllCachesAndOwnership(key, value);
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) 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