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));
}
}
use of org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor in project ignite by apache.
the class IgniteCacheObjectPutSelfTest method testPrimitiveValues.
/**
* @throws Exception If failed.
*/
@Test
public void testPrimitiveValues() throws Exception {
IgniteEx ignite = grid(0);
IgniteCache<Object, Object> cache = ignite.cache(CACHE_NAME);
for (int i = 0; i < 10; i++) cache.put(i, String.valueOf(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, 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((Integer) i, co1.value(coCtx, false));
CacheObject co2 = co.toCacheObject(coCtx, buf);
assertEquals(String.valueOf(i), co2.value(coCtx, false));
}
}
Aggregations