use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class GridCacheStoreManagerDeserializationTest method testPartitionMove.
/**
* Simulate case where is called
* {@link org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry#clearInternal(
* GridCacheVersion, GridCacheObsoleteEntryExtras)}
*
* @throws Exception If failed.
*/
public void testPartitionMove() throws Exception {
final Ignite grid = startGrid("binaryGrid1");
grid.createCache(CACHE_NAME);
final BinaryObjectBuilder builder = grid.binary().builder("custom_type");
final IgniteDataStreamer<BinaryObject, BinaryObject> streamer = grid.dataStreamer(CACHE_NAME);
streamer.keepBinary(true);
final int itemsNum = 10_000;
for (int i = 0; i < itemsNum; i++) {
final BinaryObject key = builder.setField("id", i).build();
streamer.addData(key, key);
}
streamer.flush();
streamer.close();
streamer.future().get();
assert store.map.size() == itemsNum;
startGrid("binaryGrid2");
startGrid("binaryGrid3");
startGrid("binaryGrid4");
Thread.sleep(10_000);
}
use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class GridCacheStoreManagerDeserializationTest method streamBinaryData.
/**
* Create and add binary data via Streamer API.
*
* @param grid to get streamer.
* @return test object (it is key and val).
*/
private BinaryObject streamBinaryData(final Ignite grid) {
final IgniteDataStreamer<BinaryObject, BinaryObject> streamer = grid.dataStreamer(CACHE_NAME);
streamer.keepBinary(true);
final BinaryObjectBuilder builder = grid.binary().builder("custom_type");
BinaryObject entity = null;
for (int i = 0; i < 1; i++) {
builder.setField("id", i);
entity = builder.build();
streamer.addData(entity, entity);
}
streamer.flush();
streamer.close();
streamer.future().get();
return entity;
}
use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class BinaryObjectBuilderDefaultMappersSelfTest method testShortField.
/**
* @throws Exception If failed.
*/
public void testShortField() throws Exception {
BinaryObjectBuilder builder = builder("Class");
builder.setField("shortField", (short) 1);
BinaryObject po = builder.build();
assertEquals(expectedHashCode("Class"), po.type().typeId());
assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
assertEquals((short) 1, po.<Short>field("shortField").shortValue());
}
use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class BinaryObjectBuilderDefaultMappersSelfTest method testCharArrayField.
/**
* @throws Exception If failed.
*/
public void testCharArrayField() throws Exception {
BinaryObjectBuilder builder = builder("Class");
builder.setField("charArrayField", new char[] { 1, 2, 3 });
BinaryObject po = builder.build();
assertEquals(expectedHashCode("Class"), po.type().typeId());
assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
assertTrue(Arrays.equals(new char[] { 1, 2, 3 }, po.<char[]>field("charArrayField")));
}
use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class BinaryObjectBuilderDefaultMappersSelfTest method testMapField.
/**
* @throws Exception If failed.
*/
public void testMapField() throws Exception {
BinaryObjectBuilder builder = builder("Class");
builder.setField("mapField", F.asMap(new Key(1), new Value(1), new Key(2), new Value(2)));
builder.setField("mapField2", F.asMap(new Key(1), new Value(1), new Key(2), new Value(2)), Map.class);
BinaryObject po = builder.build();
assertEquals(expectedHashCode("Class"), po.type().typeId());
assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
// Test non-standard map.
Map<Key, Value> map = po.field("mapField");
assertEquals(2, map.size());
for (Map.Entry<Key, Value> e : map.entrySet()) assertEquals(e.getKey().i, e.getValue().i);
// Test binary map
Map<BinaryObject, BinaryObject> map2 = po.field("mapField2");
assertEquals(2, map2.size());
for (Map.Entry<BinaryObject, BinaryObject> e : map2.entrySet()) assertEquals(e.getKey().<Key>deserialize().i, e.getValue().<Value>deserialize().i);
}
Aggregations