use of org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl in project ignite by apache.
the class BinaryObjectBuilderDefaultMappersSelfTest method testOffheapBinary.
/**
* @throws Exception If failed.
*/
public void testOffheapBinary() throws Exception {
BinaryObjectBuilder builder = builder("Class");
builder.setField("i", 111);
builder.setField("f", 111.111f);
builder.setField("iArr", new int[] { 1, 2, 3 });
builder.setField("obj", new Key(1));
builder.setField("col", Arrays.asList(new Value(1), new Value(2)), Collection.class);
BinaryObject po = builder.build();
byte[] arr = ((CacheObjectBinaryProcessorImpl) (grid(0)).context().cacheObjects()).marshal(po);
long ptr = GridUnsafe.allocateMemory(arr.length + 5);
try {
long ptr0 = ptr;
GridUnsafe.putBoolean(null, ptr0++, false);
int len = arr.length;
if (BIG_ENDIAN)
GridUnsafe.putIntLE(ptr0, len);
else
GridUnsafe.putInt(ptr0, len);
GridUnsafe.copyHeapOffheap(arr, GridUnsafe.BYTE_ARR_OFF, ptr0 + 4, arr.length);
BinaryObject offheapObj = (BinaryObject) ((CacheObjectBinaryProcessorImpl) (grid(0)).context().cacheObjects()).unmarshal(ptr, false);
assertEquals(BinaryObjectOffheapImpl.class, offheapObj.getClass());
assertEquals(expectedHashCode("Class"), offheapObj.type().typeId());
assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), offheapObj.hashCode());
assertEquals(111, offheapObj.<Integer>field("i").intValue());
assertEquals(111.111f, offheapObj.<Float>field("f").floatValue(), 0);
assertTrue(Arrays.equals(new int[] { 1, 2, 3 }, offheapObj.<int[]>field("iArr")));
assertEquals(1, offheapObj.<BinaryObject>field("obj").<Key>deserialize().i);
List<BinaryObject> list = offheapObj.field("col");
assertEquals(2, list.size());
assertEquals(1, list.get(0).<Value>deserialize().i);
assertEquals(2, list.get(1).<Value>deserialize().i);
assertEquals(po, offheapObj);
assertEquals(offheapObj, po);
} finally {
GridUnsafe.freeMemory(ptr);
}
}
use of org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl in project ignite by apache.
the class BinaryObjectBuilderDefaultMappersSelfTest method testSetBinaryObject.
/**
*/
public void testSetBinaryObject() {
// Prepare marshaller context.
CacheObjectBinaryProcessorImpl proc = ((CacheObjectBinaryProcessorImpl) (grid(0)).context().cacheObjects());
proc.marshal(new GridBinaryTestClasses.TestObjectContainer());
proc.marshal(new GridBinaryTestClasses.TestObjectAllTypes());
// Actual test.
BinaryObject binaryObj = builder(GridBinaryTestClasses.TestObjectContainer.class.getName()).setField("foo", toBinary(new GridBinaryTestClasses.TestObjectAllTypes())).build();
assertTrue(binaryObj.<GridBinaryTestClasses.TestObjectContainer>deserialize().foo instanceof GridBinaryTestClasses.TestObjectAllTypes);
}
use of org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl in project ignite by apache.
the class ClientBinaryTypePutRequest method process.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public ClientResponse process(ClientConnectionContext ctx) {
BinaryContext binCtx = ((CacheObjectBinaryProcessorImpl) ctx.kernalContext().cacheObjects()).binaryContext();
binCtx.updateMetadata(meta.typeId(), meta);
return super.process(ctx);
}
Aggregations