use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest method doTestGet.
/**
* @throws Exception Exception.
*/
private void doTestGet(boolean withKeepBinary) throws Exception {
try {
clientMode = false;
startGrid(0);
clientMode = true;
startGrid(1);
Class valCls = grid(1).configuration().getClassLoader().loadClass(TEST_VALUE);
assertTrue(grid(1).configuration().isClientMode());
assertFalse(grid(0).configuration().isClientMode());
IgniteCache cache1 = grid(1).cache(DEFAULT_CACHE_NAME);
IgniteCache cache0 = grid(0).cache(DEFAULT_CACHE_NAME);
if (withKeepBinary) {
cache1 = cache1.withKeepBinary();
cache0 = cache0.withKeepBinary();
}
cache1.put("key", valCls.newInstance());
if (withKeepBinary) {
BinaryObject obj = (BinaryObject) (cache0.get("key"));
try {
obj.deserialize();
fail("Exception did not happened.");
} catch (BinaryInvalidTypeException ignored) {
// No-op.
}
} else
try {
cache0.get("key");
fail("Exception did not happened.");
} catch (BinaryInvalidTypeException ignored) {
// No-op.
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class GridCacheBinaryObjectsAbstractSelfTest method checkGetAllTx.
/**
* @param concurrency Concurrency.
* @param isolation Isolation.
*/
private void checkGetAllTx(TransactionConcurrency concurrency, TransactionIsolation isolation) {
if (atomicityMode() != TRANSACTIONAL)
return;
IgniteCache<Integer, TestObject> c = jcache(0);
IgniteCache<Integer, BinaryObject> kpc = keepBinaryCache();
for (int i = 0; i < ENTRY_CNT; i++) c.put(i, new TestObject(i));
for (int i = 0; i < ENTRY_CNT; ) {
Set<Integer> keys = new HashSet<>();
for (int j = 0; j < 10; j++) keys.add(i++);
try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) {
Map<Integer, TestObject> objs = c.getAll(keys);
assertEquals(10, objs.size());
for (Map.Entry<Integer, TestObject> e : objs.entrySet()) assertEquals(e.getKey().intValue(), e.getValue().val);
tx.commit();
}
}
for (int i = 0; i < ENTRY_CNT; ) {
Set<Integer> keys = new HashSet<>();
for (int j = 0; j < 10; j++) keys.add(i++);
try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) {
Map<Integer, BinaryObject> objs = kpc.getAll(keys);
assertEquals(10, objs.size());
for (Map.Entry<Integer, BinaryObject> e : objs.entrySet()) {
BinaryObject val = e.getValue();
assertEquals(new Integer(e.getKey().intValue()), val.field("val"));
kpc.put(e.getKey(), val);
assertFalse("Key=" + i, val instanceof BinaryObjectOffheapImpl);
}
tx.commit();
}
}
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class GridCacheBinaryObjectsAbstractSelfTest method testCrossFormatObjectsIdentity.
/**
*
*/
@SuppressWarnings("unchecked")
public void testCrossFormatObjectsIdentity() {
IgniteCache c = binKeysCache();
c.put(new ComplexBinaryFieldsListHashedKey(), "zzz");
// Now let's build an identical key for get
BinaryObjectBuilder bldr = grid(0).binary().builder(ComplexBinaryFieldsListHashedKey.class.getName());
bldr.setField("firstField", 1);
bldr.setField("secondField", "value");
bldr.setField("thirdField", 0x1020304050607080L);
BinaryObject binKey = bldr.build();
assertEquals("zzz", c.get(binKey));
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class GridCacheBinaryObjectsAbstractSelfTest method testGet.
/**
* @throws Exception If failed.
*/
public void testGet() 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.get(i);
assertEquals(i, obj.val);
}
IgniteCache<Integer, BinaryObject> kpc = keepBinaryCache();
for (int i = 0; i < ENTRY_CNT; i++) {
BinaryObject po = kpc.get(i);
assertEquals(i, (int) po.field("val"));
}
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class WithKeepBinaryCacheFullApiTest method checkInvokeAllResult.
/**
* @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 checkInvokeAllResult(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);
if (cache.get(e.getKey()) == null)
cache.get(e.getKey());
assertEquals(cacheVal, deserializeBinary(cache.get(e.getKey())));
}
}
Aggregations