Search in sources :

Example 1 with FunctionalMap

use of org.infinispan.functional.FunctionalMap in project infinispan by infinispan.

the class CacheWriterTxModificationsTest method testCommit.

public void testCommit() throws Throwable {
    FunctionalMapImpl<Object, Object> functionalMap = FunctionalMapImpl.create(cache.getAdvancedCache());
    FunctionalMap.WriteOnlyMap<Object, Object> woMap = WriteOnlyMapImpl.create(functionalMap);
    FunctionalMap.ReadWriteMap<Object, Object> rwMap = ReadWriteMapImpl.create(functionalMap);
    DummyInMemoryStore store = TestingUtil.getFirstStore(cache);
    cache.putAll(mapOf("remove", "initial", "replace", "initial", "computeIfPresent", "initial", "woRemove", "initial", "rwRemove", "initial"));
    tm().begin();
    try {
        cache.put("put", "value");
        cache.putIfAbsent("putIfAbsent", "value");
        cache.remove("remove");
        cache.replace("replace", "value");
        cache.compute("compute", (k, v) -> "value");
        cache.computeIfAbsent("computeIfAbsent", k -> "value");
        cache.computeIfPresent("computeIfPresent", (k, v) -> "value");
        cache.putAll(mapOf("putAll", "value"));
        woMap.eval("woSet", entry -> entry.set("value"));
        woMap.eval("woRemove", entry -> entry.set("value"));
        woMap.eval("rwSet", entry -> entry.set("value"));
        woMap.eval("rwRemove", entry -> entry.set("value"));
    } finally {
        tm().commit();
    }
    DataContainer<Object, Object> dataContainer = cache.getAdvancedCache().getDataContainer();
    dataContainer.forEach(entry -> {
        MarshallableEntry storeEntry = store.loadEntry(entry.getKey());
        assertNotNull("Missing store entry: " + entry.getKey(), storeEntry);
        assertEquals(entry.getValue(), storeEntry.getValue());
    });
    store.keySet().forEach(k -> {
        assertEquals(store.loadEntry(k).getValue(), dataContainer.get(k).getValue());
    });
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) FunctionalMap(org.infinispan.functional.FunctionalMap) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry)

Aggregations

FunctionalMap (org.infinispan.functional.FunctionalMap)1 DummyInMemoryStore (org.infinispan.persistence.dummy.DummyInMemoryStore)1 MarshallableEntry (org.infinispan.persistence.spi.MarshallableEntry)1