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"));
}
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);
}
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 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())));
}
}
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());
}
}
Aggregations