use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class WithKeepBinaryCacheFullApiTest method checkInvokeAllAsyncResult.
/**
* @param cache Cache.
* @param resMap Result map.
* @param expRes Expected result.
* @param cacheVal Expected cache value for key.
* @param deserializeRes Deseriallize result flag.
*/
private void checkInvokeAllAsyncResult(IgniteCache cache, Map<Object, EntryProcessorResult<Object>> resMap, Object expRes, Object cacheVal, boolean deserializeRes) {
for (Map.Entry<Object, EntryProcessorResult<Object>> e : resMap.entrySet()) {
info("Key: " + e.getKey());
assertTrue("Wrong key type, binary object expected: " + e.getKey(), e.getKey() instanceof BinaryObject);
Object res = e.getValue().get();
// TODO IGNITE-2953: delete the following if when the issue wiil be fixed.
if (deserializeRes)
assertEquals(expRes, deserializeRes ? deserializeBinary(res) : res);
assertEquals(cacheVal, deserializeBinary(cache.getAsync(e.getKey()).get()));
}
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class GridCacheBinaryObjectsAbstractSelfTest method testGetAsync.
/**
* @throws Exception If failed.
*/
public void testGetAsync() throws Exception {
IgniteCache<Integer, TestObject> c = jcache(0);
for (int i = 0; i < ENTRY_CNT; i++) c.put(i, new TestObject(i));
for (int i = 0; i < ENTRY_CNT; i++) {
TestObject obj = c.getAsync(i).get();
assertNotNull(obj);
assertEquals(i, obj.val);
}
IgniteCache<Integer, BinaryObject> kpc = keepBinaryCache();
for (int i = 0; i < ENTRY_CNT; i++) {
BinaryObject po = kpc.getAsync(i).get();
assertEquals(i, (int) po.field("val"));
}
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class GridCacheBinaryObjectsAbstractSelfTest method testCircularReference.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
public void testCircularReference() throws Exception {
IgniteCache c = keepBinaryCache();
TestReferenceObject obj1 = new TestReferenceObject();
obj1.obj = new TestReferenceObject(obj1);
c.put(1, obj1);
BinaryObject po = (BinaryObject) c.get(1);
String str = po.toString();
log.info("toString: " + str);
assertNotNull(str);
BinaryNameMapper nameMapper = BinaryContext.defaultNameMapper();
if (cfg.getBinaryConfiguration() != null && cfg.getBinaryConfiguration().getNameMapper() != null)
nameMapper = cfg.getBinaryConfiguration().getNameMapper();
String typeName = nameMapper.typeName(TestReferenceObject.class.getName());
assertTrue("Unexpected toString: " + str, S.INCLUDE_SENSITIVE ? str.startsWith(typeName) && str.contains("obj=" + typeName + " [") : str.startsWith("BinaryObject") && str.contains("idHash=") && str.contains("hash="));
TestReferenceObject obj1_r = po.deserialize();
assertNotNull(obj1_r);
TestReferenceObject obj2_r = obj1_r.obj;
assertNotNull(obj2_r);
assertSame(obj1_r, obj2_r.obj);
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class GridCacheBinaryObjectsAbstractSelfTest method checkGetAsyncTx.
/**
* @param concurrency Concurrency.
* @param isolation Isolation.
*/
private void checkGetAsyncTx(TransactionConcurrency concurrency, TransactionIsolation isolation) {
if (atomicityMode() != TRANSACTIONAL)
return;
IgniteCache<Integer, TestObject> c = jcache(0);
IgniteCache<Integer, BinaryObject> kbCache = keepBinaryCache();
for (int i = 0; i < ENTRY_CNT; i++) c.put(i, new TestObject(i));
for (int i = 0; i < ENTRY_CNT; i++) {
try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) {
TestObject obj = c.getAsync(i).get();
assertEquals(i, obj.val);
tx.commit();
}
}
for (int i = 0; i < ENTRY_CNT; i++) {
try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) {
BinaryObject val = kbCache.getAsync(i).get();
assertFalse("Key=" + i, val instanceof BinaryObjectOffheapImpl);
assertEquals(i, (int) val.field("val"));
kbCache.putAsync(i, val).get();
tx.commit();
}
}
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class GridCacheBinaryObjectsAbstractSelfTest method checkGetTx.
/**
* @param concurrency Concurrency.
* @param isolation Isolation.
*/
private void checkGetTx(TransactionConcurrency concurrency, TransactionIsolation isolation) {
if (atomicityMode() != TRANSACTIONAL)
return;
IgniteCache<Integer, TestObject> c = jcache(0);
IgniteCache<Integer, BinaryObject> kbCache = keepBinaryCache();
for (int i = 0; i < ENTRY_CNT; i++) c.put(i, new TestObject(i));
for (int i = 0; i < ENTRY_CNT; i++) {
try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) {
TestObject obj = c.get(i);
assertEquals(i, obj.val);
tx.commit();
}
}
for (int i = 0; i < ENTRY_CNT; i++) {
try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) {
BinaryObject val = kbCache.get(i);
assertFalse("Key=" + i, val instanceof BinaryObjectOffheapImpl);
assertEquals(i, (int) val.field("val"));
kbCache.put(i, val);
tx.commit();
}
}
}
Aggregations