Search in sources :

Example 11 with BinaryBasicIdMapper

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

the class BinaryMarshallerSelfTest method testTypeNamesSimpleNameMappers.

/**
     * @throws Exception If failed.
     */
public void testTypeNamesSimpleNameMappers() throws Exception {
    BinaryTypeConfiguration customType1 = new BinaryTypeConfiguration(Value.class.getName());
    customType1.setIdMapper(new BinaryIdMapper() {

        @Override
        public int typeId(String clsName) {
            return 300;
        }

        @Override
        public int fieldId(int typeId, String fieldName) {
            return 0;
        }
    });
    BinaryTypeConfiguration customType2 = new BinaryTypeConfiguration("org.gridgain.NonExistentClass1");
    customType2.setIdMapper(new BinaryIdMapper() {

        @Override
        public int typeId(String clsName) {
            return 400;
        }

        @Override
        public int fieldId(int typeId, String fieldName) {
            return 0;
        }
    });
    BinaryTypeConfiguration customType3 = new BinaryTypeConfiguration("NonExistentClass2");
    customType3.setIdMapper(new BinaryIdMapper() {

        @Override
        public int typeId(String clsName) {
            return 500;
        }

        @Override
        public int fieldId(int typeId, String fieldName) {
            return 0;
        }
    });
    BinaryTypeConfiguration customType4 = new BinaryTypeConfiguration("NonExistentClass0");
    customType4.setIdMapper(new BinaryIdMapper() {

        @Override
        public int typeId(String clsName) {
            return 0;
        }

        @Override
        public int fieldId(int typeId, String fieldName) {
            return 0;
        }
    });
    BinaryTypeConfiguration customType5 = new BinaryTypeConfiguration(DateClass1.class.getName());
    customType5.setNameMapper(new BinaryBasicNameMapper(false));
    customType5.setIdMapper(new BinaryBasicIdMapper(false));
    BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true), Arrays.asList(new BinaryTypeConfiguration(Key.class.getName()), new BinaryTypeConfiguration("org.gridgain.NonExistentClass3"), new BinaryTypeConfiguration("NonExistentClass4"), customType1, customType2, customType3, customType4, customType5));
    BinaryContext ctx = binaryContext(marsh);
    assertEquals("notconfiguredclass".hashCode(), ctx.typeId("NotConfiguredClass"));
    assertEquals("notconfiguredclass".hashCode(), ctx.typeId("org.blabla.NotConfiguredClass"));
    assertEquals("key".hashCode(), ctx.typeId(Key.class.getName()));
    assertEquals("nonexistentclass3".hashCode(), ctx.typeId("org.gridgain.NonExistentClass3"));
    assertEquals("nonexistentclass4".hashCode(), ctx.typeId("NonExistentClass4"));
    assertEquals(300, ctx.typeId(Value.class.getName()));
    assertEquals(400, ctx.typeId("org.gridgain.NonExistentClass1"));
    assertEquals(500, ctx.typeId("NonExistentClass2"));
    assertEquals(DateClass1.class.getName().hashCode(), ctx.typeId(DateClass1.class.getName()));
    // BinaryIdMapper.typeId() contract.
    assertEquals("nonexistentclass0".hashCode(), ctx.typeId("NonExistentClass0"));
}
Also used : BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) BinaryIdMapper(org.apache.ignite.binary.BinaryIdMapper) BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 12 with BinaryBasicIdMapper

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

the class BinaryBasicIdMapperSelfTest method testDefaultCase.

/**
     * @throws Exception If failed.
     */
public void testDefaultCase() throws Exception {
    BinaryBasicIdMapper mapper = new BinaryBasicIdMapper(false);
    assertEquals(GridBinaryTestClass1.class.getName().hashCode(), mapper.typeId(GridBinaryTestClass1.class.getName()));
    assertEquals((GridBinaryTestClass1.class.getName() + "$InnerClass").hashCode(), mapper.typeId(GridBinaryTestClass1.class.getName() + "$InnerClass"));
}
Also used : BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper) GridBinaryTestClass1(org.apache.ignite.internal.binary.test.GridBinaryTestClass1)

Example 13 with BinaryBasicIdMapper

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

the class BinaryBasicIdMapperSelfTest method testLowerCase.

/**
     * @throws Exception If failed.
     */
public void testLowerCase() throws Exception {
    BinaryBasicIdMapper mapper = new BinaryBasicIdMapper(true);
    assertEquals(GridBinaryTestClass1.class.getName().toLowerCase().hashCode(), mapper.typeId(GridBinaryTestClass1.class.getName()));
    assertEquals((GridBinaryTestClass1.class.getName() + "$InnerClass").toLowerCase().hashCode(), mapper.typeId(GridBinaryTestClass1.class.getName() + "$InnerClass"));
}
Also used : BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper) GridBinaryTestClass1(org.apache.ignite.internal.binary.test.GridBinaryTestClass1)

Example 14 with BinaryBasicIdMapper

use of org.apache.ignite.binary.BinaryBasicIdMapper 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;
}
Also used : BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper) BinaryWriter(org.apache.ignite.binary.BinaryWriter) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) BinaryReader(org.apache.ignite.binary.BinaryReader) BinarySerializer(org.apache.ignite.binary.BinarySerializer) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 15 with BinaryBasicIdMapper

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

the class BinaryMarshallerSelfTest method testSimpleNameLowerCaseMappers.

/**
     * @throws Exception If failed.
     */
public void testSimpleNameLowerCaseMappers() throws Exception {
    BinaryTypeConfiguration innerClassType = new BinaryTypeConfiguration(InnerMappedObject.class.getName());
    BinaryTypeConfiguration publicClassType = new BinaryTypeConfiguration(TestMappedObject.class.getName());
    BinaryTypeConfiguration typeWithCustomMapper = new BinaryTypeConfiguration(CustomMappedObject2.class.getName());
    typeWithCustomMapper.setIdMapper(new BinaryIdMapper() {

        @Override
        public int typeId(String clsName) {
            return 44444;
        }

        @Override
        public int fieldId(int typeId, String fieldName) {
            assert typeId == 44444;
            if ("val1".equals(fieldName))
                return 55555;
            else if ("val2".equals(fieldName))
                return 66666;
            assert false : "Unknown field: " + fieldName;
            return 0;
        }
    });
    BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true), Arrays.asList(innerClassType, publicClassType, typeWithCustomMapper));
    InnerMappedObject innerObj = new InnerMappedObject(10, "str1");
    BinaryObjectExImpl innerBo = marshal(innerObj, marsh);
    assertEquals("InnerMappedObject".toLowerCase().hashCode(), innerBo.type().typeId());
    assertEquals(10, innerBo.<CustomMappedObject1>deserialize().val1);
    assertEquals("str1", innerBo.<CustomMappedObject1>deserialize().val2);
    TestMappedObject publicObj = new TestMappedObject();
    BinaryObjectExImpl publicBo = marshal(publicObj, marsh);
    assertEquals("TestMappedObject".toLowerCase().hashCode(), publicBo.type().typeId());
    CustomMappedObject2 obj2 = new CustomMappedObject2(20, "str2");
    BinaryObjectExImpl po2 = marshal(obj2, marsh);
    assertEquals(44444, po2.type().typeId());
    assertEquals((Integer) 20, po2.field(55555));
    assertEquals("str2", po2.field(66666));
    assertEquals(20, po2.<CustomMappedObject2>deserialize().val1);
    assertEquals("str2", po2.<CustomMappedObject2>deserialize().val2);
}
Also used : BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper) BinaryIdMapper(org.apache.ignite.binary.BinaryIdMapper) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Aggregations

BinaryBasicIdMapper (org.apache.ignite.binary.BinaryBasicIdMapper)18 BinaryBasicNameMapper (org.apache.ignite.binary.BinaryBasicNameMapper)14 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)9 BinaryIdMapper (org.apache.ignite.binary.BinaryIdMapper)7 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)2 GridBinaryTestClass1 (org.apache.ignite.internal.binary.test.GridBinaryTestClass1)2 HashMap (java.util.HashMap)1 IgniteException (org.apache.ignite.IgniteException)1 BinaryNameMapper (org.apache.ignite.binary.BinaryNameMapper)1 BinaryReader (org.apache.ignite.binary.BinaryReader)1 BinarySerializer (org.apache.ignite.binary.BinarySerializer)1 BinaryWriter (org.apache.ignite.binary.BinaryWriter)1 PlatformConfiguration (org.apache.ignite.configuration.PlatformConfiguration)1 PlatformMemoryManagerImpl (org.apache.ignite.internal.processors.platform.memory.PlatformMemoryManagerImpl)1 Marshaller (org.apache.ignite.marshaller.Marshaller)1 PlatformCppConfiguration (org.apache.ignite.platform.cpp.PlatformCppConfiguration)1