Search in sources :

Example 16 with BinaryTypeConfiguration

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

the class BinaryMarshallerSelfTest method testCustomSerializer.

/**
     * @throws Exception If failed.
     */
public void testCustomSerializer() throws Exception {
    BinaryTypeConfiguration type = new BinaryTypeConfiguration(CustomSerializedObject1.class.getName());
    type.setSerializer(new CustomSerializer1());
    BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(type));
    CustomSerializedObject1 obj1 = new CustomSerializedObject1(10);
    BinaryObject po1 = marshal(obj1, marsh);
    assertEquals(20, po1.<CustomSerializedObject1>deserialize().val);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 17 with BinaryTypeConfiguration

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

the class BinaryMarshallerSelfTest method testTypeNamesSimpleNameMapper.

/**
     * @throws Exception If failed.
     */
public void testTypeNamesSimpleNameMapper() 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;
        }
    });
    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));
    BinaryContext ctx = binaryContext(marsh);
    // Full name hashCode.
    assertEquals("notconfiguredclass".hashCode(), ctx.typeId("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"));
    // 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 18 with BinaryTypeConfiguration

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

the class BinaryMarshallerSelfTest method testCustomIdMapper.

/**
     * @throws Exception If failed.
     */
public void testCustomIdMapper() throws Exception {
    BinaryTypeConfiguration type = new BinaryTypeConfiguration(CustomMappedObject1.class.getName());
    type.setIdMapper(new BinaryIdMapper() {

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

        @Override
        public int fieldId(int typeId, String fieldName) {
            assert typeId == 11111;
            if ("val1".equals(fieldName))
                return 22222;
            else if ("val2".equals(fieldName))
                return 33333;
            assert false : "Unknown field: " + fieldName;
            return 0;
        }
    });
    BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(type));
    CustomMappedObject1 obj1 = new CustomMappedObject1(10, "str");
    BinaryObjectExImpl po1 = marshal(obj1, marsh);
    assertEquals(11111, po1.type().typeId());
    assertEquals((Integer) 10, po1.field(22222));
    assertEquals("str", po1.field(33333));
    assertEquals(10, po1.<CustomMappedObject1>deserialize().val1);
    assertEquals("str", po1.<CustomMappedObject1>deserialize().val2);
}
Also used : BinaryIdMapper(org.apache.ignite.binary.BinaryIdMapper) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 19 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 20 with BinaryTypeConfiguration

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

the class BinaryMarshallerSelfTest method testBinaryCopyStringArray.

/**
     * @throws Exception If failed.
     */
public void testBinaryCopyStringArray() 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("strArr", new String[] { "str1", "str2" }));
    assertArrayEquals(new String[] { "str1", "str2" }, copy.<String[]>field("strArr"));
    SimpleObject obj0 = copy.deserialize();
    assertArrayEquals(new String[] { "str1", "str2" }, obj0.strArr);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Aggregations

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