Search in sources :

Example 31 with BinaryTypeConfiguration

use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.

the class GridBinaryWildcardsSelfTest method checkOverrideJar.

/**
 * @param nameMapper Name mapper.
 * @param idMapper Mapper.
 * @throws IgniteCheckedException If failed.
 */
private void checkOverrideJar(BinaryNameMapper nameMapper, BinaryIdMapper idMapper) throws IgniteCheckedException {
    BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.GridBinaryTestClass2");
    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, idMapper, 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, idMapper)));
    Map<String, org.apache.ignite.internal.binary.BinaryInternalMapper> typeMappers = U.field(ctx, "cls2Mappers");
    assertEquals(3, typeMappers.size());
    assertEquals(nameMapper, typeMappers.get(CLASS2_FULL_NAME).nameMapper());
    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 32 with BinaryTypeConfiguration

use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.

the class GridBinaryWildcardsSelfTest method testTypeConfigurationsWithGlobalMapper.

/**
 * @throws Exception If failed.
 */
public void testTypeConfigurationsWithGlobalMapper() throws Exception {
    BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(false), new BinaryIdMapper() {

        @SuppressWarnings("IfMayBeConditional")
        @Override
        public int typeId(String clsName) {
            if (clsName.endsWith("1"))
                return 300;
            else if (clsName.endsWith("2"))
                return 400;
            else if (clsName.endsWith("InnerClass"))
                return 500;
            else
                return -500;
        }

        @Override
        public int fieldId(int typeId, String fieldName) {
            return 0;
        }
    }, Arrays.asList(new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"), new BinaryTypeConfiguration("unknown.*")));
    BinaryContext ctx = binaryContext(marsh);
    Map<String, org.apache.ignite.internal.binary.BinaryInternalMapper> typeMappers = U.field(ctx, "cls2Mappers");
    assertEquals(3, typeMappers.size());
    assertEquals(300, typeMappers.get(CLASS1_FULL_NAME).idMapper().typeId(CLASS1_FULL_NAME));
    assertEquals(400, typeMappers.get(CLASS2_FULL_NAME).idMapper().typeId(CLASS2_FULL_NAME));
    assertEquals(500, typeMappers.get(INNER_CLASS_FULL_NAME).idMapper().typeId(INNER_CLASS_FULL_NAME));
}
Also used : BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) BinaryIdMapper(org.apache.ignite.binary.BinaryIdMapper) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 33 with BinaryTypeConfiguration

use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.

the class BinaryEnumsSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    if (register) {
        BinaryConfiguration bCfg = new BinaryConfiguration();
        BinaryTypeConfiguration enumCfg = new BinaryTypeConfiguration(EnumType.class.getName());
        enumCfg.setEnum(true);
        if (igniteInstanceName.equals(WRONG_CONF_NODE_NAME))
            enumCfg.setEnumValues(F.asMap(EnumType.ONE.name(), EnumType.ONE.ordinal(), EnumType.TWO.name(), EnumType.ONE.ordinal()));
        else
            enumCfg.setEnumValues(F.asMap(EnumType.ONE.name(), EnumType.ONE.ordinal(), EnumType.TWO.name(), EnumType.TWO.ordinal()));
        bCfg.setTypeConfigurations(Arrays.asList(enumCfg, new BinaryTypeConfiguration(EnumHolder.class.getName())));
        cfg.setBinaryConfiguration(bCfg);
    }
    cfg.setMarshaller(new BinaryMarshaller());
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setName(CACHE_NAME);
    ccfg.setCacheMode(CacheMode.PARTITIONED);
    cfg.setCacheConfiguration(ccfg);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 34 with BinaryTypeConfiguration

use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.

the class BinaryFooterOffsetsAbstractSelfTest method beforeTest.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTest() throws Exception {
    super.beforeTest();
    ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration(), new NullLogger());
    marsh = new BinaryMarshaller();
    IgniteConfiguration iCfg = new IgniteConfiguration();
    BinaryConfiguration bCfg = new BinaryConfiguration();
    bCfg.setTypeConfigurations(Arrays.asList(new BinaryTypeConfiguration(TestObject.class.getName())));
    bCfg.setCompactFooter(compactFooter());
    iCfg.setBinaryConfiguration(bCfg);
    marsh.setContext(new MarshallerContextTestImpl(null));
    IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, iCfg);
}
Also used : NullLogger(org.apache.ignite.logger.NullLogger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) MarshallerContextTestImpl(org.apache.ignite.marshaller.MarshallerContextTestImpl)

Example 35 with BinaryTypeConfiguration

use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.

the class BinaryMarshallerSelfTest method testBinaryObject.

/**
 * @throws Exception If failed.
 */
public void testBinaryObject() throws Exception {
    BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
    SimpleObject obj = simpleObject();
    BinaryObject po = marshal(obj, marsh);
    BinaryObject po0 = marshalUnmarshal(po, marsh);
    assertTrue(po.hasField("b"));
    assertTrue(po.hasField("s"));
    assertTrue(po.hasField("i"));
    assertTrue(po.hasField("l"));
    assertTrue(po.hasField("f"));
    assertTrue(po.hasField("d"));
    assertTrue(po.hasField("c"));
    assertTrue(po.hasField("bool"));
    assertFalse(po.hasField("no_such_field"));
    assertEquals(obj, po.deserialize());
    assertEquals(obj, po0.deserialize());
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) 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