use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class GridCacheBinaryObjectsAbstractSelfTest method checkTransform.
/**
* @param key Key.
* @throws Exception If failed.
*/
private void checkTransform(Integer key) throws Exception {
log.info("Transform: " + key);
IgniteCache<Integer, BinaryObject> c = keepBinaryCache();
try {
c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
@Override
public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
BinaryObject val = e.getValue();
assertNull("Unexpected value: " + val, val);
return null;
}
});
jcache(0).put(key, new TestObject(1));
c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
@Override
public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
BinaryObject val = e.getValue();
assertNotNull("Unexpected value: " + val, val);
assertEquals(new Integer(1), val.field("val"));
Ignite ignite = e.unwrap(Ignite.class);
IgniteBinary binaries = ignite.binary();
BinaryObjectBuilder builder = binaries.builder(val);
builder.setField("val", 2);
e.setValue(builder.build());
return null;
}
});
BinaryObject obj = c.get(key);
assertEquals(new Integer(2), obj.field("val"));
c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
@Override
public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
BinaryObject val = e.getValue();
assertNotNull("Unexpected value: " + val, val);
assertEquals(new Integer(2), val.field("val"));
e.setValue(val);
return null;
}
});
obj = c.get(key);
assertEquals(new Integer(2), obj.field("val"));
c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
@Override
public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
BinaryObject val = e.getValue();
assertNotNull("Unexpected value: " + val, val);
assertEquals(new Integer(2), val.field("val"));
e.remove();
return null;
}
});
assertNull(c.get(key));
} finally {
c.remove(key);
}
}
use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class GridDataStreamerImplSelfTest method testAddBinaryCreatedWithBuilder.
/**
* Tries to propagate cache with binary objects created using the builder.
*
* @throws Exception If failed.
*/
public void testAddBinaryCreatedWithBuilder() throws Exception {
try {
binaries = true;
startGrids(2);
awaitPartitionMapExchange();
Ignite g0 = grid(0);
IgniteDataStreamer<Integer, BinaryObject> dataLdr = g0.dataStreamer(DEFAULT_CACHE_NAME);
for (int i = 0; i < 500; i++) {
BinaryObjectBuilder obj = g0.binary().builder("NoExistedClass");
obj.setField("id", i);
obj.setField("name", String.valueOf("name = " + i));
dataLdr.addData(i, obj.build());
}
dataLdr.close(false);
assertEquals(500, g0.cache(DEFAULT_CACHE_NAME).size(CachePeekMode.ALL));
assertEquals(500, grid(1).cache(DEFAULT_CACHE_NAME).size(CachePeekMode.ALL));
} finally {
G.stopAll(true);
}
}
Aggregations