use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class BinaryConfigurationConsistencySelfTest method customConfig.
/**
* @return Custom BinaryConfiguration.
* @param compactFooter Compact footer.
*/
private BinaryConfiguration customConfig(boolean compactFooter) {
BinaryConfiguration c = new BinaryConfiguration();
c.setIdMapper(new BinaryBasicIdMapper(true));
c.setSerializer(new BinarySerializer() {
@Override
public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException {
// No-op.
}
@Override
public void readBinary(Object obj, BinaryReader reader) throws BinaryObjectException {
// No-op.
}
});
c.setCompactFooter(compactFooter);
BinaryTypeConfiguration btc = new BinaryTypeConfiguration("org.MyClass");
btc.setIdMapper(BinaryContext.defaultIdMapper());
btc.setEnum(false);
btc.setSerializer(new BinarySerializer() {
@Override
public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException {
// No-op.
}
@Override
public void readBinary(Object obj, BinaryReader reader) throws BinaryObjectException {
// No-op.
}
});
c.setTypeConfigurations(Arrays.asList(btc));
return c;
}
use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class BinaryConfigurationCustomSerializerSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
cfg.setConnectorConfiguration(new ConnectorConfiguration());
cfg.setMarshaller(new BinaryMarshaller());
BinaryConfiguration binaryCfg = new BinaryConfiguration();
BinaryTypeConfiguration btc = new BinaryTypeConfiguration("org.MyClass");
btc.setIdMapper(BinaryContext.defaultIdMapper());
btc.setEnum(false);
// Set custom serializer that is unknown for Optimized marshaller.
btc.setSerializer(new MyBinarySerializer());
binaryCfg.setTypeConfigurations(Collections.singletonList(btc));
cfg.setBinaryConfiguration(binaryCfg);
// Set custom consistent ID that unknown for Optimized marshaller.
cfg.setConsistentId(new MyConsistentId("test"));
cfg.setCacheConfiguration(new CacheConfiguration("TEST"));
return cfg;
}
use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class BinaryFieldsAbstractSelfTest method createMarshaller.
/**
* Create marshaller.
*
* @return Binary marshaller.
* @throws Exception If failed.
*/
protected BinaryMarshaller createMarshaller() throws Exception {
BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration(), new NullLogger());
BinaryMarshaller marsh = new BinaryMarshaller();
BinaryConfiguration bCfg = new BinaryConfiguration();
bCfg.setCompactFooter(compactFooter());
bCfg.setTypeConfigurations(Arrays.asList(new BinaryTypeConfiguration(TestObject.class.getName()), new BinaryTypeConfiguration(TestOuterObject.class.getName()), new BinaryTypeConfiguration(TestInnerObject.class.getName())));
IgniteConfiguration iCfg = new IgniteConfiguration();
iCfg.setBinaryConfiguration(bCfg);
marsh.setContext(new MarshallerContextTestImpl(null));
IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, iCfg);
return marsh;
}
use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class BinaryMarshallerSelfTest method testBinaryCopyDoubleArray.
/**
* @throws Exception If failed.
*/
public void testBinaryCopyDoubleArray() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
SimpleObject obj = simpleObject();
BinaryObject po = marshal(obj, marsh);
BinaryObject copy = copy(po, F.<String, Object>asMap("dArr", new double[] { 1, 2, 3 }));
assertArrayEquals(new double[] { 1, 2, 3 }, copy.<double[]>field("dArr"), 0);
SimpleObject obj0 = copy.deserialize();
assertArrayEquals(new double[] { 1, 2, 3 }, obj0.dArr, 0);
}
use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class BinaryMarshallerSelfTest method testBinaryCopy.
/**
* @throws Exception If failed.
*/
public void testBinaryCopy() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
SimpleObject obj = simpleObject();
final BinaryObject po = marshal(obj, marsh);
assertEquals(obj, po.deserialize());
BinaryObject copy = copy(po, null);
assertEquals(obj, copy.deserialize());
copy = copy(po, new HashMap<String, Object>());
assertEquals(obj, copy.deserialize());
Map<String, Object> map = new HashMap<>(1, 1.0f);
map.put("i", 3);
copy = copy(po, map);
assertEquals((byte) 2, copy.<Byte>field("b").byteValue());
assertEquals((short) 2, copy.<Short>field("s").shortValue());
assertEquals(3, copy.<Integer>field("i").intValue());
assertEquals(2L, copy.<Long>field("l").longValue());
assertEquals(2.2f, copy.<Float>field("f").floatValue(), 0);
assertEquals(2.2d, copy.<Double>field("d").doubleValue(), 0);
assertEquals((char) 2, copy.<Character>field("c").charValue());
assertEquals(false, copy.<Boolean>field("bool").booleanValue());
SimpleObject obj0 = copy.deserialize();
assertEquals((byte) 2, obj0.b);
assertEquals((short) 2, obj0.s);
assertEquals(3, obj0.i);
assertEquals(2L, obj0.l);
assertEquals(2.2f, obj0.f, 0);
assertEquals(2.2d, obj0.d, 0);
assertEquals((char) 2, obj0.c);
assertEquals(false, obj0.bool);
map = new HashMap<>(3, 1.0f);
map.put("b", (byte) 3);
map.put("l", 3L);
map.put("bool", true);
copy = copy(po, map);
assertEquals((byte) 3, copy.<Byte>field("b").byteValue());
assertEquals((short) 2, copy.<Short>field("s").shortValue());
assertEquals(2, copy.<Integer>field("i").intValue());
assertEquals(3L, copy.<Long>field("l").longValue());
assertEquals(2.2f, copy.<Float>field("f").floatValue(), 0);
assertEquals(2.2d, copy.<Double>field("d").doubleValue(), 0);
assertEquals((char) 2, copy.<Character>field("c").charValue());
assertEquals(true, copy.<Boolean>field("bool").booleanValue());
obj0 = copy.deserialize();
assertEquals((byte) 3, obj0.b);
assertEquals((short) 2, obj0.s);
assertEquals(2, obj0.i);
assertEquals(3L, obj0.l);
assertEquals(2.2f, obj0.f, 0);
assertEquals(2.2d, obj0.d, 0);
assertEquals((char) 2, obj0.c);
assertEquals(true, obj0.bool);
map = new HashMap<>(8, 1.0f);
map.put("b", (byte) 3);
map.put("s", (short) 3);
map.put("i", 3);
map.put("l", 3L);
map.put("f", 3.3f);
map.put("d", 3.3d);
map.put("c", (char) 3);
map.put("bool", true);
copy = copy(po, map);
assertEquals((byte) 3, copy.<Byte>field("b").byteValue());
assertEquals((short) 3, copy.<Short>field("s").shortValue());
assertEquals(3, copy.<Integer>field("i").intValue());
assertEquals(3L, copy.<Long>field("l").longValue());
assertEquals(3.3f, copy.<Float>field("f").floatValue(), 0);
assertEquals(3.3d, copy.<Double>field("d").doubleValue(), 0);
assertEquals((char) 3, copy.<Character>field("c").charValue());
assertEquals(true, copy.<Boolean>field("bool").booleanValue());
obj0 = copy.deserialize();
assertEquals((byte) 3, obj0.b);
assertEquals((short) 3, obj0.s);
assertEquals(3, obj0.i);
assertEquals(3L, obj0.l);
assertEquals(3.3f, obj0.f, 0);
assertEquals(3.3d, obj0.d, 0);
assertEquals((char) 3, obj0.c);
assertEquals(true, obj0.bool);
// GridTestUtils.assertThrows(
// log,
// new Callable<Object>() {
// @Override public Object call() throws Exception {
// po.copy(F.<String, Object>asMap("i", false));
//
// return null;
// }
// },
// BinaryException.class,
// "Invalid value type for field: i"
// );
}
Aggregations