use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class BinaryMarshallerSelfTest method testClassWithoutPublicConstructor.
/**
* @throws Exception If failed.
*/
public void testClassWithoutPublicConstructor() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(NoPublicConstructor.class.getName()), new BinaryTypeConfiguration(NoPublicDefaultConstructor.class.getName()), new BinaryTypeConfiguration(ProtectedConstructor.class.getName())));
NoPublicConstructor npc = new NoPublicConstructor();
BinaryObject npc2 = marshal(npc, marsh);
assertEquals("test", npc2.<NoPublicConstructor>deserialize().val);
NoPublicDefaultConstructor npdc = new NoPublicDefaultConstructor(239);
BinaryObject npdc2 = marshal(npdc, marsh);
assertEquals(239, npdc2.<NoPublicDefaultConstructor>deserialize().val);
ProtectedConstructor pc = new ProtectedConstructor();
BinaryObject pc2 = marshal(pc, marsh);
assertEquals(ProtectedConstructor.class, pc2.<ProtectedConstructor>deserialize().getClass());
}
use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class BinaryMarshallerSelfTest method testBinaryCopyObject.
/**
* @throws Exception If failed.
*/
public void testBinaryCopyObject() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
SimpleObject obj = simpleObject();
BinaryObject po = marshal(obj, marsh);
SimpleObject newObj = new SimpleObject();
newObj.i = 12345;
newObj.fArr = new float[] { 5, 8, 0 };
newObj.str = "newStr";
BinaryObject copy = copy(po, F.<String, Object>asMap("inner", newObj));
assertEquals(newObj, copy.<BinaryObject>field("inner").deserialize());
SimpleObject obj0 = copy.deserialize();
assertEquals(newObj, obj0.inner);
}
use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class GridBinaryWildcardsSelfTest method checkOverrideNameMapper.
/**
* @param nameMapper Name mapper.
* @param mapper Mapper.
* @throws IgniteCheckedException If failed.
*/
private void checkOverrideNameMapper(BinaryNameMapper nameMapper, BinaryIdMapper mapper) throws IgniteCheckedException {
BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
typeCfg.setTypeName(CLASS2_FULL_NAME);
typeCfg.setNameMapper(new BinaryNameMapper() {
@Override
public String typeName(String clsName) {
return "type2";
}
@Override
public String fieldName(String fieldName) {
return "field2";
}
});
BinaryMarshaller marsh = binaryMarshaller(nameMapper, mapper, Arrays.asList(new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"), typeCfg));
BinaryContext ctx = binaryContext(marsh);
ConcurrentMap<Integer, BinaryInternalMapper> types = U.field(ctx, "typeId2Mapper");
assertEquals(3, types.size());
assertTrue(types.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, mapper)));
assertTrue(types.containsKey(typeId(INNER_CLASS_FULL_NAME, nameMapper, mapper)));
assertTrue(types.containsKey("type2".hashCode()));
Map<String, org.apache.ignite.internal.binary.BinaryInternalMapper> typeMappers = U.field(ctx, "cls2Mappers");
assertEquals("type2", typeMappers.get(CLASS2_FULL_NAME).nameMapper().typeName(CLASS2_FULL_NAME));
}
use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class GridBinaryWildcardsSelfTest method checkOverrideIdMapper.
/**
* @param nameMapper Name mapper.
* @param mapper Mapper.
* @throws IgniteCheckedException If failed.
*/
private void checkOverrideIdMapper(BinaryNameMapper nameMapper, BinaryIdMapper mapper) throws IgniteCheckedException {
BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
typeCfg.setTypeName(CLASS2_FULL_NAME);
typeCfg.setIdMapper(new BinaryIdMapper() {
@Override
public int typeId(String clsName) {
return 100;
}
@Override
public int fieldId(int typeId, String fieldName) {
return 0;
}
});
BinaryMarshaller marsh = binaryMarshaller(nameMapper, mapper, Arrays.asList(new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"), typeCfg));
BinaryContext ctx = binaryContext(marsh);
Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
assertEquals(3, typeIds.size());
assertTrue(typeIds.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, mapper)));
assertTrue(typeIds.containsKey(typeId(INNER_CLASS_FULL_NAME, nameMapper, mapper)));
assertTrue(typeIds.containsKey(100));
Map<String, org.apache.ignite.internal.binary.BinaryInternalMapper> typeMappers = U.field(ctx, "cls2Mappers");
assertEquals(100, typeMappers.get(CLASS2_FULL_NAME).idMapper().typeId(CLASS2_FULL_NAME));
}
use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class BinaryArrayIdentityResolverSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setMarshaller(new BinaryMarshaller());
BinaryConfiguration binCfg = new BinaryConfiguration();
BinaryTypeConfiguration binTypCfg1 = new BinaryTypeConfiguration();
BinaryTypeConfiguration binTypCfg2 = new BinaryTypeConfiguration();
binTypCfg1.setTypeName(InnerClass.class.getName());
binTypCfg2.setTypeName(InnerClassBinarylizable.class.getName());
List<BinaryTypeConfiguration> binTypCfgs = new ArrayList<>();
binTypCfgs.add(binTypCfg1);
binTypCfgs.add(binTypCfg2);
binCfg.setTypeConfigurations(binTypCfgs);
cfg.setBinaryConfiguration(binCfg);
return cfg;
}
Aggregations