Java Code Examples for org.apache.ignite.IgniteCache#getEntry()

The following examples show how to use org.apache.ignite.IgniteCache#getEntry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridCacheVersionTopologyChangeTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param cache Cache.
 * @param vers Current versions.
 */
@SuppressWarnings("unchecked")
private void checkVersionIncrease(IgniteCache<Object, Object> cache, Map<Integer, Comparable> vers) {
    for (Integer k : vers.keySet()) {
        cache.put(k, k);

        Comparable curVer = vers.get(k);

        CacheEntry entry = cache.getEntry(k);

        if (entry != null) {
            Comparable newVer = entry.version();

            assertTrue(newVer.compareTo(curVer) > 0);

            vers.put(k, newVer);
        }
        else {
            CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class);

            assertEquals(0, ccfg.getBackups());
        }
    }
}
 
Example 2
Source File: CacheGetEntryAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param cache Cache.
 * @param i Key.
 * @param oneEntry If {@code true} then single entry is tested.
 */
private void checkRemoved(IgniteCache<Integer, TestValue> cache, int i, boolean oneEntry) {
    if (oneEntry) {
        CacheEntry<Integer, TestValue> e = cache.getEntry(i);

        assertNull(e);
    }
    else {
        Set<Integer> set = new HashSet<>();

        for (int j = 0; j < 10; j++)
            set.add(i + j);

        Collection<CacheEntry<Integer, TestValue>> es = cache.getEntries(set);

        assertTrue(es.isEmpty());
    }
}
 
Example 3
Source File: CacheGetEntryAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param cache Cache.
 * @param i Key.
 * @param oneEntry If {@code true} then single entry is tested.
 */
private void checkBinaryRemoved(IgniteCache<Integer, TestValue> cache, int i, boolean oneEntry) {
    IgniteCache<Integer, BinaryObject> cacheB = cache.withKeepBinary();

    if (oneEntry) {
        CacheEntry<Integer, BinaryObject> e = cacheB.getEntry(i);

        assertNull(e);
    }
    else {
        Set<Integer> set = new HashSet<>();

        for (int j = 0; j < 10; j++)
            set.add(i + j);

        Collection<CacheEntry<Integer, BinaryObject>> es = cacheB.getEntries(set);

        assertTrue(es.isEmpty());
    }
}
 
Example 4
Source File: CacheKeepBinaryWithInterceptorTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param ccfg Cache configuration.
 */
private void keepBinaryWithInterceptorPrimitives(CacheConfiguration ccfg) {
    ignite(0).createCache(ccfg);

    try {
        TestInterceptor2.onAfterRmv = 0;
        TestInterceptor2.onBeforeRmv = 0;
        TestInterceptor2.onAfterPut = 0;
        TestInterceptor2.onBeforePut = 0;
        TestInterceptor2.onGet = 0;

        IgniteCache cache = ignite(0).cache(DEFAULT_CACHE_NAME).withKeepBinary();

        cache.put(1, 10);

        cache.put(1, 10);

        Integer obj = (Integer)cache.get(1);
        assertEquals((Integer)10, obj);

        obj = (Integer)cache.getAsync(1).get();
        assertEquals((Integer)10, obj);

        Cache.Entry<Integer, Integer> e = (Cache.Entry)cache.getEntry(1);
        assertEquals((Integer)1, e.getKey());
        assertEquals((Integer)10, e.getValue());

        e = (Cache.Entry)cache.getEntryAsync(1).get();
        assertEquals((Integer)1, e.getKey());
        assertEquals((Integer)10, e.getValue());

        obj = (Integer)cache.getAndRemove(1);
        assertEquals((Integer)10, obj);

        cache.put(1, 10);

        assertTrue(cache.remove(1));

        assertTrue(TestInterceptor2.onAfterRmv > 0);
        assertTrue(TestInterceptor2.onBeforeRmv > 0);
        assertTrue(TestInterceptor2.onAfterPut > 0);
        assertTrue(TestInterceptor2.onBeforePut > 0);
        assertTrue(TestInterceptor2.onGet > 0);
    }
    finally {
        ignite(0).destroyCache(ccfg.getName());
    }
}
 
Example 5
Source File: IgnitePutGetEntryBenchmark.java    From ignite with Apache License 2.0 3 votes vote down vote up
/** {@inheritDoc} */
@Override public boolean test(Map<Object, Object> ctx) throws Exception {
    IgniteCache<Integer, Object> cache = cacheForOperation();

    int key = nextRandom(args.range());

    CacheEntry<Integer, Object> val = cache.getEntry(key);

    if (val != null)
        key = nextRandom(args.range());

    cache.put(key, new SampleValue(key));

    return true;
}
 
Example 6
Source File: IgniteCacheNoSyncForGetTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/** {@inheritDoc} */
@Override public Object call() throws Exception {
    IgniteCache cache = ignite.cache(cacheName);

    if (withExpiryPlc)
        cache = cache.withExpiryPolicy(ModifiedExpiryPolicy.factoryOf(Duration.FIVE_MINUTES).create());

    Object val = cache.get(key);

    CacheEntry e = cache.getEntry(key);

    assertEquals(val, e.getValue());

    return val;
}