Search in sources :

Example 11 with CacheEntry

use of org.apache.ignite.cache.CacheEntry in project ignite by apache.

the class WithKeepBinaryCacheFullApiTest method testPutAllGetAll.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("serial")
@Test
public void testPutAllGetAll() throws Exception {
    runInAllDataModes(new TestRunnable() {

        @Override
        public void run() throws Exception {
            final IgniteCache cache = jcache().withKeepBinary();
            final Set keys = new LinkedHashSet() {

                {
                    for (int i = 0; i < CNT; i++) add(key(i));
                }
            };
            runInAllTxModes(new TestRunnable() {

                @Override
                public void run() throws Exception {
                    for (Object val : cache.getAll(keys).values()) assertNull(val);
                }
            });
            runInAllTxModes(new TestRunnable() {

                @Override
                public void run() throws Exception {
                    Collection<CacheEntry> entries = cache.<CacheEntry>getEntries(keys);
                    for (CacheEntry e : entries) assertNull(e.getValue());
                }
            });
            runInAllTxModes(new TestRunnable() {

                @Override
                public void run() throws Exception {
                    Map keyValMap = new LinkedHashMap() {

                        {
                            for (Object key : keys) {
                                Object val = value(valueOf(key));
                                put(key, val);
                            }
                        }
                    };
                    cache.putAll(keyValMap);
                    Set<Map.Entry<BinaryObject, BinaryObject>> set = cache.getAll(keys).entrySet();
                    for (Map.Entry<BinaryObject, BinaryObject> e : set) {
                        Object expVal = value(valueOf(e.getKey().deserialize()));
                        assertEquals(expVal, e.getValue().deserialize());
                    }
                    Collection<CacheEntry<BinaryObject, BinaryObject>> entries = cache.getEntries(keys);
                    for (CacheEntry<BinaryObject, BinaryObject> e : entries) {
                        assertTrue(e.getKey() instanceof BinaryObject);
                        Object expVal = value(valueOf(e.getKey().deserialize()));
                        assertEquals(expVal, e.getValue().deserialize());
                    }
                    cache.removeAll(keys);
                }
            });
        }
    }, PLANE_OBJECT, SERIALIZABLE);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) IgniteCache(org.apache.ignite.IgniteCache) CacheEntry(org.apache.ignite.cache.CacheEntry) EntryProcessorException(javax.cache.processor.EntryProcessorException) LinkedHashMap(java.util.LinkedHashMap) CacheEntry(org.apache.ignite.cache.CacheEntry) MutableEntry(javax.cache.processor.MutableEntry) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test) IgniteCacheConfigVariationsAbstractTest(org.apache.ignite.testframework.junits.IgniteCacheConfigVariationsAbstractTest)

Example 12 with CacheEntry

use of org.apache.ignite.cache.CacheEntry in project ignite by apache.

the class WithKeepBinaryCacheFullApiTest method testPutAllGetAllAsync.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("serial")
@Test
public void testPutAllGetAllAsync() throws Exception {
    runInAllDataModes(new TestRunnable() {

        @Override
        public void run() throws Exception {
            final IgniteCache cache = jcache().withKeepBinary();
            final Set keys = new LinkedHashSet() {

                {
                    for (int i = 0; i < CNT; i++) add(key(i));
                }
            };
            runInAllTxModes(new TestRunnable() {

                @Override
                public void run() throws Exception {
                    Map res = (Map) cache.getAllAsync(keys).get();
                    for (Object val : res.values()) assertNull(val);
                }
            });
            runInAllTxModes(new TestRunnable() {

                @Override
                public void run() throws Exception {
                    Collection<CacheEntry> entries = (Collection<CacheEntry>) cache.<CacheEntry>getEntriesAsync(keys).get();
                    for (CacheEntry e : entries) assertNull(e.getValue());
                }
            });
            runInAllTxModes(new TestRunnable() {

                @Override
                public void run() throws Exception {
                    Map keyValMap = new LinkedHashMap() {

                        {
                            for (Object key : keys) {
                                Object val = value(valueOf(key));
                                put(key, val);
                            }
                        }
                    };
                    cache.putAllAsync(keyValMap).get();
                    Set<Map.Entry<BinaryObject, BinaryObject>> set = ((Map) cache.getAllAsync(keys).get()).entrySet();
                    for (Map.Entry<BinaryObject, BinaryObject> e : set) {
                        Object expVal = value(valueOf(e.getKey().deserialize()));
                        assertEquals(expVal, e.getValue().deserialize());
                    }
                    Collection<CacheEntry<BinaryObject, BinaryObject>> entries = (Collection<CacheEntry<BinaryObject, BinaryObject>>) cache.getEntriesAsync(keys).get();
                    for (CacheEntry<BinaryObject, BinaryObject> e : entries) {
                        assertTrue(e.getKey() instanceof BinaryObject);
                        Object expVal = value(valueOf(e.getKey().deserialize()));
                        assertEquals(expVal, e.getValue().deserialize());
                    }
                    cache.removeAllAsync(keys).get();
                }
            });
        }
    }, PLANE_OBJECT, SERIALIZABLE);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) IgniteCache(org.apache.ignite.IgniteCache) CacheEntry(org.apache.ignite.cache.CacheEntry) EntryProcessorException(javax.cache.processor.EntryProcessorException) LinkedHashMap(java.util.LinkedHashMap) CacheEntry(org.apache.ignite.cache.CacheEntry) MutableEntry(javax.cache.processor.MutableEntry) BinaryObject(org.apache.ignite.binary.BinaryObject) Collection(java.util.Collection) BinaryObject(org.apache.ignite.binary.BinaryObject) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test) IgniteCacheConfigVariationsAbstractTest(org.apache.ignite.testframework.junits.IgniteCacheConfigVariationsAbstractTest)

Example 13 with CacheEntry

use of org.apache.ignite.cache.CacheEntry in project ignite by apache.

the class WithKeepBinaryCacheFullApiTest method testRemovePutGetAsync.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("serial")
@Test
public void testRemovePutGetAsync() throws Exception {
    runInAllDataModes(new TestRunnable() {

        @Override
        public void run() throws Exception {
            final IgniteCache cache = jcache().withKeepBinary();
            final Set keys = new LinkedHashSet() {

                {
                    for (int i = 0; i < CNT; i++) add(key(i));
                }
            };
            runInAllTxModes(new TestRunnable() {

                @Override
                public void run() throws Exception {
                    for (Object key : keys) cache.removeAsync(key).get();
                }
            });
            runInAllTxModes(new TestRunnable() {

                @Override
                public void run() throws Exception {
                    for (Object key : keys) {
                        assertNull(cache.getAsync(key).get());
                        assertNull(cache.getEntryAsync(key).get());
                    }
                }
            });
            for (final Object key : keys) {
                runInAllTxModes(new TestRunnable() {

                    @Override
                    public void run() throws Exception {
                        Object val = value(valueOf(key));
                        cache.putAsync(key, val).get();
                        BinaryObject retVal = (BinaryObject) cache.getAsync(key).get();
                        assertEquals(val, retVal.deserialize());
                        CacheEntry<BinaryObject, BinaryObject> e = (CacheEntry<BinaryObject, BinaryObject>) cache.getEntryAsync(key).get();
                        assertEquals(key, deserializeBinary(e.getKey()));
                        assertEquals(val, e.getValue().deserialize());
                    }
                });
            }
        }
    }, PLANE_OBJECT, SERIALIZABLE);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteCache(org.apache.ignite.IgniteCache) BinaryObject(org.apache.ignite.binary.BinaryObject) CacheEntry(org.apache.ignite.cache.CacheEntry) EntryProcessorException(javax.cache.processor.EntryProcessorException) Test(org.junit.Test) IgniteCacheConfigVariationsAbstractTest(org.apache.ignite.testframework.junits.IgniteCacheConfigVariationsAbstractTest)

Aggregations

CacheEntry (org.apache.ignite.cache.CacheEntry)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 EntryProcessorException (javax.cache.processor.EntryProcessorException)6 Test (org.junit.Test)6 LinkedHashSet (java.util.LinkedHashSet)5 IgniteCache (org.apache.ignite.IgniteCache)4 BinaryObject (org.apache.ignite.binary.BinaryObject)4 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Set (java.util.Set)3 IgniteCacheConfigVariationsAbstractTest (org.apache.ignite.testframework.junits.IgniteCacheConfigVariationsAbstractTest)3 HashSet (java.util.HashSet)2 MutableEntry (javax.cache.processor.MutableEntry)2 Transaction (org.apache.ignite.transactions.Transaction)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1