Search in sources :

Example 1 with BinaryObjectOffheapImpl

use of org.apache.ignite.internal.binary.BinaryObjectOffheapImpl 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();
        }
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) Transaction(org.apache.ignite.transactions.Transaction) Map(java.util.Map) HashMap(java.util.HashMap) BinaryObjectOffheapImpl(org.apache.ignite.internal.binary.BinaryObjectOffheapImpl) HashSet(java.util.HashSet)

Example 2 with BinaryObjectOffheapImpl

use of org.apache.ignite.internal.binary.BinaryObjectOffheapImpl 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();
        }
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) Transaction(org.apache.ignite.transactions.Transaction) BinaryObjectOffheapImpl(org.apache.ignite.internal.binary.BinaryObjectOffheapImpl)

Example 3 with BinaryObjectOffheapImpl

use of org.apache.ignite.internal.binary.BinaryObjectOffheapImpl in project ignite by apache.

the class GridCacheBinaryObjectsAbstractSelfTest method checkGetAllAsyncTx.

/**
 * @param concurrency Concurrency.
 * @param isolation Isolation.
 */
private void checkGetAllAsyncTx(TransactionConcurrency concurrency, TransactionIsolation isolation) {
    if (atomicityMode() != TRANSACTIONAL)
        return;
    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; ) {
        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.getAllAsync(keys).get();
            assertEquals(10, objs.size());
            for (Map.Entry<Integer, TestObject> e : objs.entrySet()) assertEquals(e.getKey().intValue(), e.getValue().val);
            tx.commit();
        }
    }
    IgniteCache<Integer, BinaryObject> cache = keepBinaryCache();
    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 = cache.getAllAsync(keys).get();
            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"));
                assertFalse("Key=" + e.getKey(), val instanceof BinaryObjectOffheapImpl);
            }
            tx.commit();
        }
    }
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) BinaryObject(org.apache.ignite.binary.BinaryObject) Map(java.util.Map) HashMap(java.util.HashMap) BinaryObjectOffheapImpl(org.apache.ignite.internal.binary.BinaryObjectOffheapImpl) HashSet(java.util.HashSet)

Example 4 with BinaryObjectOffheapImpl

use of org.apache.ignite.internal.binary.BinaryObjectOffheapImpl 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();
        }
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) Transaction(org.apache.ignite.transactions.Transaction) BinaryObjectOffheapImpl(org.apache.ignite.internal.binary.BinaryObjectOffheapImpl)

Example 5 with BinaryObjectOffheapImpl

use of org.apache.ignite.internal.binary.BinaryObjectOffheapImpl in project ignite by apache.

the class BinaryPlainBinaryObject method writeTo.

/**
 * {@inheritDoc}
 */
@Override
public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx) {
    BinaryObject val = binaryObj;
    if (val instanceof BinaryObjectOffheapImpl)
        val = ((BinaryObjectOffheapImpl) val).heapCopy();
    writer.doWriteBinaryObject((BinaryObjectImpl) val);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectOffheapImpl(org.apache.ignite.internal.binary.BinaryObjectOffheapImpl)

Aggregations

BinaryObject (org.apache.ignite.binary.BinaryObject)5 BinaryObjectOffheapImpl (org.apache.ignite.internal.binary.BinaryObjectOffheapImpl)5 Transaction (org.apache.ignite.transactions.Transaction)4 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2