Search in sources :

Example 46 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class IgnitePdsBinaryMetadataOnClusterRestartTest method testUpdatedBinaryMetadataIsPreservedOnJoinToOldCoordinator.

/**
 * @see <a href="https://issues.apache.org/jira/browse/IGNITE-7258">IGNITE-7258</a> refer to the following JIRA for more context about the problem verified by the test.
 */
public void testUpdatedBinaryMetadataIsPreservedOnJoinToOldCoordinator() throws Exception {
    Ignite ignite0 = startGridInASeparateWorkDir("A");
    Ignite ignite1 = startGridInASeparateWorkDir("B");
    ignite0.active(true);
    IgniteCache<Object, Object> cache0 = ignite0.cache(CACHE_NAME);
    BinaryObject bo = ignite0.binary().builder(DYNAMIC_TYPE_NAME).setField(DYNAMIC_INT_FIELD_NAME, 10).build();
    cache0.put(0, bo);
    stopGrid("A");
    IgniteCache<Object, Object> cache1 = ignite1.cache(CACHE_NAME);
    bo = ignite1.binary().builder(DYNAMIC_TYPE_NAME).setField(DYNAMIC_INT_FIELD_NAME, 20).setField(DYNAMIC_STR_FIELD_NAME, "str").build();
    cache1.put(1, bo);
    stopAllGrids();
    ignite0 = startGridInASeparateWorkDir("A");
    ignite1 = startGridInASeparateWorkDir("B");
    awaitPartitionMapExchange();
    cache0 = ignite0.cache(CACHE_NAME).withKeepBinary();
    BinaryObject bObj0 = (BinaryObject) cache0.get(0);
    assertEquals(10, (int) bObj0.field("intField"));
    cache1 = ignite1.cache(CACHE_NAME).withKeepBinary();
    BinaryObject bObj1 = (BinaryObject) cache1.get(1);
    assertEquals(20, (int) bObj1.field("intField"));
    assertEquals("str", bObj1.field("strField"));
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) Ignite(org.apache.ignite.Ignite) BinaryObject(org.apache.ignite.binary.BinaryObject)

Example 47 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class WithKeepBinaryCacheFullApiTest method testRemovePutGet.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("serial")
public void testRemovePutGet() throws Exception {
    runInAllDataModes(new TestRunnable() {

        @Override
        public void run() throws Exception {
            final IgniteCache cache = jcache().withKeepBinary();
            final Set keys = new LinkedHashSet() {

                {
                    for (int i = 0; i < CNT; i++) add(key(i));
                }
            };
            runInAllTxModes(new TestRunnable() {

                @Override
                public void run() throws Exception {
                    for (Object key : keys) cache.remove(key);
                }
            });
            runInAllTxModes(new TestRunnable() {

                @Override
                public void run() throws Exception {
                    for (Object key : keys) {
                        assertNull(cache.get(key));
                        assertNull(cache.getEntry(key));
                    }
                }
            });
            for (final Object key : keys) {
                runInAllTxModes(new TestRunnable() {

                    @Override
                    public void run() throws Exception {
                        Object val = value(valueOf(key));
                        cache.put(key, val);
                        BinaryObject retVal = (BinaryObject) cache.get(key);
                        assertEquals(val, retVal.deserialize());
                        CacheEntry<BinaryObject, BinaryObject> entry = cache.getEntry(key);
                        assertTrue(entry.getKey() instanceof BinaryObject);
                        assertEquals(val, entry.getValue().deserialize());
                        assertTrue(cache.remove(key));
                    }
                });
            }
        }
    }, PLANE_OBJECT, SERIALIZABLE);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteCache(org.apache.ignite.IgniteCache) BinaryObject(org.apache.ignite.binary.BinaryObject) EntryProcessorException(javax.cache.processor.EntryProcessorException)

Example 48 with BinaryObject

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()));
    }
}
Also used : EntryProcessorResult(javax.cache.processor.EntryProcessorResult) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 49 with BinaryObject

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())));
    }
}
Also used : EntryProcessorResult(javax.cache.processor.EntryProcessorResult) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 50 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class CacheKeepBinaryIterationTest method doTestScanQuery.

/**
 * @param ccfg Cache configuration.
 */
private void doTestScanQuery(final CacheConfiguration<Object, Object> ccfg, boolean keepBinary, boolean primitives) throws Exception {
    IgniteCache<Object, Object> cache = grid(0).createCache(ccfg);
    assertEquals(0, cache.size());
    try {
        for (int i = 0; i < KEYS; i++) if (primitives)
            cache.put(i, i);
        else
            cache.put(new QueryTestKey(i), new QueryTestValue(i));
        for (int i = 0; i < getServerNodeCount(); i++) {
            IgniteCache<Object, Object> cache0 = grid(i).cache(ccfg.getName());
            if (keepBinary)
                cache0 = cache0.withKeepBinary();
            ScanQuery<Object, Object> qry = new ScanQuery<>();
            qry.setLocal(true);
            int size = 0;
            try (QueryCursor<Cache.Entry<Object, Object>> cur = cache0.query(qry)) {
                for (Cache.Entry<Object, Object> e : cur) {
                    Object key = e.getKey();
                    Object val = e.getValue();
                    if (!primitives) {
                        assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary, keepBinary == key instanceof BinaryObject);
                        assertTrue("Got unexpected object: " + val.getClass() + ", keepBinary: " + keepBinary, keepBinary == val instanceof BinaryObject);
                    } else {
                        assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary, key instanceof Integer);
                        assertTrue("Got unexpected object: " + val.getClass() + ", keepBinary: " + keepBinary, val instanceof Integer);
                    }
                    ++size;
                }
            }
            assertTrue(size > 0);
        }
    } finally {
        if (ccfg.getEvictionPolicy() != null) {
            // TODO: IGNITE-3462. Fixes evictionPolicy issues at cache destroy.
            stopAllGrids();
            startGridsMultiThreaded(getServerNodeCount());
        } else
            grid(0).destroyCache(ccfg.getName());
    }
}
Also used : ScanQuery(org.apache.ignite.cache.query.ScanQuery) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteCache(org.apache.ignite.IgniteCache) Cache(javax.cache.Cache)

Aggregations

BinaryObject (org.apache.ignite.binary.BinaryObject)200 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)55 Ignite (org.apache.ignite.Ignite)28 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)26 IgniteCache (org.apache.ignite.IgniteCache)25 HashMap (java.util.HashMap)16 Cache (javax.cache.Cache)15 ArrayList (java.util.ArrayList)13 Map (java.util.Map)13 LinkedHashMap (java.util.LinkedHashMap)12 List (java.util.List)10 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)10 IgniteEx (org.apache.ignite.internal.IgniteEx)10 BinaryObjectBuilderImpl (org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)10 IgniteException (org.apache.ignite.IgniteException)9 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)9 UUID (java.util.UUID)8 BigInteger (java.math.BigInteger)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 BinaryType (org.apache.ignite.binary.BinaryType)7