Search in sources :

Example 6 with IgniteCacheObjectProcessor

use of org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor in project ignite by apache.

the class IgniteCacheObjectPutSelfTest method testClassValues.

/**
     * @throws Exception If failed.
     */
public void testClassValues() throws Exception {
    IgniteEx ignite = grid(0);
    IgniteCache<Object, Object> cache = ignite.cache(CACHE_NAME);
    for (int i = 0; i < 10; i++) cache.put(new TestValue(i), new TestValue(i));
    IgniteCacheObjectProcessor co = ignite.context().cacheObjects();
    GridCacheAdapter<Object, Object> iCache = ignite.context().cache().internalCache(CACHE_NAME);
    GridCacheContext<Object, Object> cacheCtx = iCache.context();
    CacheObjectContext coCtx = cacheCtx.cacheObjectContext();
    ByteBuffer buf = ByteBuffer.allocate(2048);
    for (int i = 0; i < 10; i++) {
        KeyCacheObject key = co.toCacheKeyObject(coCtx, cacheCtx, new TestValue(i), false);
        GridCacheEntryEx entry = iCache.peekEx(key);
        assertNotNull(entry);
        assertTrue(entry.key().putValue(buf));
        assertTrue(entry.valueBytes().putValue(buf));
    }
    buf.flip();
    for (int i = 0; i < 10; i++) {
        CacheObject co1 = co.toCacheObject(coCtx, buf);
        assertEquals(new TestValue(i), co1.value(coCtx, false));
        CacheObject co2 = co.toCacheObject(coCtx, buf);
        assertEquals(new TestValue(i), co2.value(coCtx, false));
    }
}
Also used : IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) ByteBuffer(java.nio.ByteBuffer) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 7 with IgniteCacheObjectProcessor

use of org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor in project ignite by apache.

the class CacheGetEntryAbstractTest method compareVersionWithPrimaryNode.

/**
     * @param e Entry.
     * @param cache Cache.
     * @throws Exception If failed.
     */
private void compareVersionWithPrimaryNode(CacheEntry<Integer, ?> e, IgniteCache<Integer, TestValue> cache) throws Exception {
    CacheConfiguration cfg = cache.getConfiguration(CacheConfiguration.class);
    if (cfg.getCacheMode() != LOCAL) {
        Ignite prim = primaryNode(e.getKey(), cache.getName());
        GridCacheAdapter<Object, Object> cacheAdapter = ((IgniteKernal) prim).internalCache(cache.getName());
        if (cfg.getNearConfiguration() != null)
            cacheAdapter = ((GridNearCacheAdapter) cacheAdapter).dht();
        IgniteCacheObjectProcessor cacheObjects = cacheAdapter.context().cacheObjects();
        CacheObjectContext cacheObjCtx = cacheAdapter.context().cacheObjectContext();
        GridCacheEntryEx mapEntry = cacheAdapter.entryEx(cacheObjects.toCacheKeyObject(cacheObjCtx, cacheAdapter.context(), e.getKey(), true));
        mapEntry.unswap();
        assertNotNull("No entry for key: " + e.getKey(), mapEntry);
        assertEquals(mapEntry.version(), e.version());
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) Ignite(org.apache.ignite.Ignite) BinaryObject(org.apache.ignite.binary.BinaryObject) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 8 with IgniteCacheObjectProcessor

use of org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor in project ignite by apache.

the class LazyDataEntry method value.

/** {@inheritDoc} */
@Override
public CacheObject value() {
    if (val == null && valBytes != null) {
        GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
        if (cacheCtx == null)
            throw new IgniteException("Failed to find cache context for the given cache ID: " + cacheId);
        IgniteCacheObjectProcessor co = cctx.kernalContext().cacheObjects();
        val = co.toCacheObject(cacheCtx.cacheObjectContext(), valType, valBytes);
    }
    return val;
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteException(org.apache.ignite.IgniteException) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor)

Example 9 with IgniteCacheObjectProcessor

use of org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor in project ignite by apache.

the class IgniteCacheTtlCleanupSelfTest method testDeferredDeleteTtl.

/**
     * @throws Exception If failed.
     */
public void testDeferredDeleteTtl() throws Exception {
    IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME).withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 5)));
    int cnt = GridDhtLocalPartition.MAX_DELETE_QUEUE_SIZE / PART_NUM + 100;
    for (long i = 0; i < cnt; i++) grid(0).cache(DEFAULT_CACHE_NAME).put(i * PART_NUM, i);
    for (int i = 0; i < cnt; i++) cache.put(i * PART_NUM, i);
    // Wait 5 seconds.
    Thread.sleep(6_000);
    assertEquals(cnt, grid(0).cache(DEFAULT_CACHE_NAME).size());
    GridCacheAdapter<Object, Object> cacheAdapter = ((IgniteKernal) grid(0)).internalCache(DEFAULT_CACHE_NAME);
    IgniteCacheObjectProcessor cacheObjects = cacheAdapter.context().cacheObjects();
    CacheObjectContext cacheObjCtx = cacheAdapter.context().cacheObjectContext();
    for (int i = 0; i < 100; i++) assertNull(cacheAdapter.map().getEntry(cacheObjects.toCacheKeyObject(cacheObjCtx, null, i, true)));
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext)

Example 10 with IgniteCacheObjectProcessor

use of org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor in project ignite by apache.

the class GridBinaryAffinityKeySelfTest method checkAffinity.

/**
     * @param ignite Ignite.
     * @throws Exception If failed.
     */
private void checkAffinity(Ignite ignite) throws Exception {
    Affinity<Object> aff = ignite.affinity(DEFAULT_CACHE_NAME);
    GridAffinityProcessor affProc = ((IgniteKernal) ignite).context().affinity();
    IgniteCacheObjectProcessor cacheObjProc = ((IgniteKernal) ignite).context().cacheObjects();
    CacheObjectContext cacheObjCtx = cacheObjProc.contextForCache(ignite.cache(DEFAULT_CACHE_NAME).getConfiguration(CacheConfiguration.class));
    for (int i = 0; i < 1000; i++) {
        assertEquals(i, aff.affinityKey(i));
        assertEquals(i, aff.affinityKey(new TestObject(i)));
        assertEquals(i, aff.affinityKey(ignite.binary().toBinary(new TestObject(i))));
        assertEquals(i, aff.affinityKey(new AffinityKey(0, i)));
        BinaryObjectBuilder bldr = ignite.binary().builder("TestObject2");
        bldr.setField("affKey", i);
        assertEquals(i, aff.affinityKey(bldr.build()));
        CacheObject cacheObj = cacheObjProc.toCacheObject(cacheObjCtx, new TestObject(i), true);
        assertEquals(i, aff.affinityKey(cacheObj));
        assertEquals(aff.mapKeyToNode(i), aff.mapKeyToNode(new TestObject(i)));
        assertEquals(aff.mapKeyToNode(i), aff.mapKeyToNode(cacheObj));
        assertEquals(i, affProc.affinityKey(DEFAULT_CACHE_NAME, i));
        assertEquals(i, affProc.affinityKey(DEFAULT_CACHE_NAME, new TestObject(i)));
        assertEquals(i, affProc.affinityKey(DEFAULT_CACHE_NAME, cacheObj));
        assertEquals(affProc.mapKeyToNode(DEFAULT_CACHE_NAME, i), affProc.mapKeyToNode(DEFAULT_CACHE_NAME, new TestObject(i)));
        assertEquals(affProc.mapKeyToNode(DEFAULT_CACHE_NAME, i), affProc.mapKeyToNode(DEFAULT_CACHE_NAME, cacheObj));
        assertEquals(affProc.mapKeyToNode(DEFAULT_CACHE_NAME, new AffinityKey(0, i)), affProc.mapKeyToNode(DEFAULT_CACHE_NAME, i));
    }
}
Also used : GridAffinityProcessor(org.apache.ignite.internal.processors.affinity.GridAffinityProcessor) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

IgniteCacheObjectProcessor (org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor)11 IgniteException (org.apache.ignite.IgniteException)3 IgniteKernal (org.apache.ignite.internal.IgniteKernal)3 ByteBuffer (java.nio.ByteBuffer)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)2 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)2 CacheObjectBinaryProcessorImpl (org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl)2 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)1 Duration (javax.cache.expiry.Duration)1 Ignite (org.apache.ignite.Ignite)1 IgniteIllegalStateException (org.apache.ignite.IgniteIllegalStateException)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)1 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)1 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)1