Search in sources :

Example 6 with CacheEntry

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

the class CacheVersionedEntryAbstractTest method testInvoke.

/**
     * @throws Exception If failed.
     */
public void testInvoke() throws Exception {
    Cache<Integer, String> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    final AtomicInteger invoked = new AtomicInteger();
    cache.invoke(100, new EntryProcessor<Integer, String, Object>() {

        @Override
        public Object process(MutableEntry<Integer, String> entry, Object... arguments) throws EntryProcessorException {
            invoked.incrementAndGet();
            CacheEntry<Integer, String> verEntry = entry.unwrap(CacheEntry.class);
            checkVersionedEntry(verEntry);
            return entry;
        }
    });
    assert invoked.get() > 0;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntryProcessorException(javax.cache.processor.EntryProcessorException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheEntry(org.apache.ignite.cache.CacheEntry)

Example 7 with CacheEntry

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

the class CacheVersionedEntryAbstractTest method testInvokeAll.

/**
     * @throws Exception If failed.
     */
public void testInvokeAll() throws Exception {
    Cache<Integer, String> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    Set<Integer> keys = new HashSet<>();
    for (int i = 0; i < ENTRIES_NUM; i++) keys.add(i);
    final AtomicInteger invoked = new AtomicInteger();
    cache.invokeAll(keys, new EntryProcessor<Integer, String, Object>() {

        @Override
        public Object process(MutableEntry<Integer, String> entry, Object... arguments) throws EntryProcessorException {
            invoked.incrementAndGet();
            CacheEntry<Integer, String> verEntry = entry.unwrap(CacheEntry.class);
            checkVersionedEntry(verEntry);
            return null;
        }
    });
    assert invoked.get() > 0;
}
Also used : CacheEntry(org.apache.ignite.cache.CacheEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntryProcessorException(javax.cache.processor.EntryProcessorException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashSet(java.util.HashSet)

Example 8 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")
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)

Example 9 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")
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)

Example 10 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")
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)

Aggregations

CacheEntry (org.apache.ignite.cache.CacheEntry)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 EntryProcessorException (javax.cache.processor.EntryProcessorException)6 LinkedHashSet (java.util.LinkedHashSet)5 IgniteCache (org.apache.ignite.IgniteCache)4 BinaryObject (org.apache.ignite.binary.BinaryObject)4 Set (java.util.Set)3 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 MutableEntry (javax.cache.processor.MutableEntry)2 Transaction (org.apache.ignite.transactions.Transaction)2 Collection (java.util.Collection)1 List (java.util.List)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Cache (javax.cache.Cache)1 CacheException (javax.cache.CacheException)1 Ignite (org.apache.ignite.Ignite)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1