Search in sources :

Example 56 with BinaryTypeConfiguration

use of org.apache.ignite.binary.BinaryTypeConfiguration 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 57 with BinaryTypeConfiguration

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

the class BinaryConfigurationCustomSerializerSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    cfg.setConnectorConfiguration(new ConnectorConfiguration());
    cfg.setMarshaller(new BinaryMarshaller());
    BinaryConfiguration binaryCfg = new BinaryConfiguration();
    BinaryTypeConfiguration btc = new BinaryTypeConfiguration("org.MyClass");
    btc.setIdMapper(BinaryContext.defaultIdMapper());
    btc.setEnum(false);
    // Set custom serializer that is unknown for Optimized marshaller.
    btc.setSerializer(new MyBinarySerializer());
    binaryCfg.setTypeConfigurations(Collections.singletonList(btc));
    cfg.setBinaryConfiguration(binaryCfg);
    // Set custom consistent ID that unknown for Optimized marshaller.
    cfg.setConsistentId(new MyConsistentId("test"));
    cfg.setCacheConfiguration(new CacheConfiguration("TEST"));
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) ConnectorConfiguration(org.apache.ignite.configuration.ConnectorConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 58 with BinaryTypeConfiguration

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

the class BinaryFieldsAbstractSelfTest method createMarshaller.

/**
 * Create marshaller.
 *
 * @return Binary marshaller.
 * @throws Exception If failed.
 */
protected BinaryMarshaller createMarshaller() throws Exception {
    BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration(), new NullLogger());
    BinaryMarshaller marsh = new BinaryMarshaller();
    BinaryConfiguration bCfg = new BinaryConfiguration();
    bCfg.setCompactFooter(compactFooter());
    bCfg.setTypeConfigurations(Arrays.asList(new BinaryTypeConfiguration(TestObject.class.getName()), new BinaryTypeConfiguration(TestOuterObject.class.getName()), new BinaryTypeConfiguration(TestInnerObject.class.getName())));
    IgniteConfiguration iCfg = new IgniteConfiguration();
    iCfg.setBinaryConfiguration(bCfg);
    marsh.setContext(new MarshallerContextTestImpl(null));
    IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, iCfg);
    return marsh;
}
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 59 with BinaryTypeConfiguration

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

the class BinaryMarshallerSelfTest method testBinaryCopyDoubleArray.

/**
 * @throws Exception If failed.
 */
public void testBinaryCopyDoubleArray() 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("dArr", new double[] { 1, 2, 3 }));
    assertArrayEquals(new double[] { 1, 2, 3 }, copy.<double[]>field("dArr"), 0);
    SimpleObject obj0 = copy.deserialize();
    assertArrayEquals(new double[] { 1, 2, 3 }, obj0.dArr, 0);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 60 with BinaryTypeConfiguration

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

the class BinaryMarshallerSelfTest method testBinaryCopy.

/**
 * @throws Exception If failed.
 */
public void testBinaryCopy() throws Exception {
    BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
    SimpleObject obj = simpleObject();
    final BinaryObject po = marshal(obj, marsh);
    assertEquals(obj, po.deserialize());
    BinaryObject copy = copy(po, null);
    assertEquals(obj, copy.deserialize());
    copy = copy(po, new HashMap<String, Object>());
    assertEquals(obj, copy.deserialize());
    Map<String, Object> map = new HashMap<>(1, 1.0f);
    map.put("i", 3);
    copy = copy(po, map);
    assertEquals((byte) 2, copy.<Byte>field("b").byteValue());
    assertEquals((short) 2, copy.<Short>field("s").shortValue());
    assertEquals(3, copy.<Integer>field("i").intValue());
    assertEquals(2L, copy.<Long>field("l").longValue());
    assertEquals(2.2f, copy.<Float>field("f").floatValue(), 0);
    assertEquals(2.2d, copy.<Double>field("d").doubleValue(), 0);
    assertEquals((char) 2, copy.<Character>field("c").charValue());
    assertEquals(false, copy.<Boolean>field("bool").booleanValue());
    SimpleObject obj0 = copy.deserialize();
    assertEquals((byte) 2, obj0.b);
    assertEquals((short) 2, obj0.s);
    assertEquals(3, obj0.i);
    assertEquals(2L, obj0.l);
    assertEquals(2.2f, obj0.f, 0);
    assertEquals(2.2d, obj0.d, 0);
    assertEquals((char) 2, obj0.c);
    assertEquals(false, obj0.bool);
    map = new HashMap<>(3, 1.0f);
    map.put("b", (byte) 3);
    map.put("l", 3L);
    map.put("bool", true);
    copy = copy(po, map);
    assertEquals((byte) 3, copy.<Byte>field("b").byteValue());
    assertEquals((short) 2, copy.<Short>field("s").shortValue());
    assertEquals(2, copy.<Integer>field("i").intValue());
    assertEquals(3L, copy.<Long>field("l").longValue());
    assertEquals(2.2f, copy.<Float>field("f").floatValue(), 0);
    assertEquals(2.2d, copy.<Double>field("d").doubleValue(), 0);
    assertEquals((char) 2, copy.<Character>field("c").charValue());
    assertEquals(true, copy.<Boolean>field("bool").booleanValue());
    obj0 = copy.deserialize();
    assertEquals((byte) 3, obj0.b);
    assertEquals((short) 2, obj0.s);
    assertEquals(2, obj0.i);
    assertEquals(3L, obj0.l);
    assertEquals(2.2f, obj0.f, 0);
    assertEquals(2.2d, obj0.d, 0);
    assertEquals((char) 2, obj0.c);
    assertEquals(true, obj0.bool);
    map = new HashMap<>(8, 1.0f);
    map.put("b", (byte) 3);
    map.put("s", (short) 3);
    map.put("i", 3);
    map.put("l", 3L);
    map.put("f", 3.3f);
    map.put("d", 3.3d);
    map.put("c", (char) 3);
    map.put("bool", true);
    copy = copy(po, map);
    assertEquals((byte) 3, copy.<Byte>field("b").byteValue());
    assertEquals((short) 3, copy.<Short>field("s").shortValue());
    assertEquals(3, copy.<Integer>field("i").intValue());
    assertEquals(3L, copy.<Long>field("l").longValue());
    assertEquals(3.3f, copy.<Float>field("f").floatValue(), 0);
    assertEquals(3.3d, copy.<Double>field("d").doubleValue(), 0);
    assertEquals((char) 3, copy.<Character>field("c").charValue());
    assertEquals(true, copy.<Boolean>field("bool").booleanValue());
    obj0 = copy.deserialize();
    assertEquals((byte) 3, obj0.b);
    assertEquals((short) 3, obj0.s);
    assertEquals(3, obj0.i);
    assertEquals(3L, obj0.l);
    assertEquals(3.3f, obj0.f, 0);
    assertEquals(3.3d, obj0.d, 0);
    assertEquals((char) 3, obj0.c);
    assertEquals(true, obj0.bool);
// GridTestUtils.assertThrows(
// log,
// new Callable<Object>() {
// @Override public Object call() throws Exception {
// po.copy(F.<String, Object>asMap("i", false));
// 
// return null;
// }
// },
// BinaryException.class,
// "Invalid value type for field: i"
// );
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) BigInteger(java.math.BigInteger) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) BinaryObject(org.apache.ignite.binary.BinaryObject)

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