Search in sources :

Example 51 with BinaryTypeConfiguration

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());
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 52 with BinaryTypeConfiguration

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);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 53 with BinaryTypeConfiguration

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));
}
Also used : BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) BinaryNameMapper(org.apache.ignite.binary.BinaryNameMapper)

Example 54 with BinaryTypeConfiguration

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));
}
Also used : BinaryIdMapper(org.apache.ignite.binary.BinaryIdMapper) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 55 with BinaryTypeConfiguration

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;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) ArrayList(java.util.ArrayList) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Aggregations

BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)71 BinaryObject (org.apache.ignite.binary.BinaryObject)28 BinaryIdMapper (org.apache.ignite.binary.BinaryIdMapper)21 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)20 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)17 BinaryBasicNameMapper (org.apache.ignite.binary.BinaryBasicNameMapper)11 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)9 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)9 HashMap (java.util.HashMap)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)8 LinkedHashMap (java.util.LinkedHashMap)7 BinaryBasicIdMapper (org.apache.ignite.binary.BinaryBasicIdMapper)7 BigInteger (java.math.BigInteger)6 ArrayList (java.util.ArrayList)6 CacheKeyConfiguration (org.apache.ignite.cache.CacheKeyConfiguration)6 UUID (java.util.UUID)4 Date (java.util.Date)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3