Search in sources :

Example 41 with BinaryObjectBuilder

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

the class GridCacheStoreManagerDeserializationTest method testPartitionMove.

/**
 * Simulate case where is called
 * {@link org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry#clearInternal(
 * GridCacheVersion, GridCacheObsoleteEntryExtras)}
 *
 * @throws Exception If failed.
 */
public void testPartitionMove() throws Exception {
    final Ignite grid = startGrid("binaryGrid1");
    grid.createCache(CACHE_NAME);
    final BinaryObjectBuilder builder = grid.binary().builder("custom_type");
    final IgniteDataStreamer<BinaryObject, BinaryObject> streamer = grid.dataStreamer(CACHE_NAME);
    streamer.keepBinary(true);
    final int itemsNum = 10_000;
    for (int i = 0; i < itemsNum; i++) {
        final BinaryObject key = builder.setField("id", i).build();
        streamer.addData(key, key);
    }
    streamer.flush();
    streamer.close();
    streamer.future().get();
    assert store.map.size() == itemsNum;
    startGrid("binaryGrid2");
    startGrid("binaryGrid3");
    startGrid("binaryGrid4");
    Thread.sleep(10_000);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) Ignite(org.apache.ignite.Ignite) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 42 with BinaryObjectBuilder

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

the class GridCacheStoreManagerDeserializationTest method streamBinaryData.

/**
 * Create and add binary data via Streamer API.
 *
 * @param grid to get streamer.
 * @return test object (it is key and val).
 */
private BinaryObject streamBinaryData(final Ignite grid) {
    final IgniteDataStreamer<BinaryObject, BinaryObject> streamer = grid.dataStreamer(CACHE_NAME);
    streamer.keepBinary(true);
    final BinaryObjectBuilder builder = grid.binary().builder("custom_type");
    BinaryObject entity = null;
    for (int i = 0; i < 1; i++) {
        builder.setField("id", i);
        entity = builder.build();
        streamer.addData(entity, entity);
    }
    streamer.flush();
    streamer.close();
    streamer.future().get();
    return entity;
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 43 with BinaryObjectBuilder

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testShortField.

/**
 * @throws Exception If failed.
 */
public void testShortField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("shortField", (short) 1);
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    assertEquals((short) 1, po.<Short>field("shortField").shortValue());
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 44 with BinaryObjectBuilder

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testCharArrayField.

/**
 * @throws Exception If failed.
 */
public void testCharArrayField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("charArrayField", new char[] { 1, 2, 3 });
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    assertTrue(Arrays.equals(new char[] { 1, 2, 3 }, po.<char[]>field("charArrayField")));
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 45 with BinaryObjectBuilder

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testMapField.

/**
 * @throws Exception If failed.
 */
public void testMapField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("mapField", F.asMap(new Key(1), new Value(1), new Key(2), new Value(2)));
    builder.setField("mapField2", F.asMap(new Key(1), new Value(1), new Key(2), new Value(2)), Map.class);
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    // Test non-standard map.
    Map<Key, Value> map = po.field("mapField");
    assertEquals(2, map.size());
    for (Map.Entry<Key, Value> e : map.entrySet()) assertEquals(e.getKey().i, e.getValue().i);
    // Test binary map
    Map<BinaryObject, BinaryObject> map2 = po.field("mapField2");
    assertEquals(2, map2.size());
    for (Map.Entry<BinaryObject, BinaryObject> e : map2.entrySet()) assertEquals(e.getKey().<Key>deserialize().i, e.getValue().<Value>deserialize().i);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) Map(java.util.Map)

Aggregations

BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)83 BinaryObject (org.apache.ignite.binary.BinaryObject)63 Ignite (org.apache.ignite.Ignite)11 IgniteBinary (org.apache.ignite.IgniteBinary)8 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)7 Date (java.util.Date)4 HashMap (java.util.HashMap)4 BinaryType (org.apache.ignite.binary.BinaryType)4 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 GridQueryProperty (org.apache.ignite.internal.processors.query.GridQueryProperty)3 GridQueryTypeDescriptor (org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)3 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)3 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)3 Column (org.h2.table.Column)3 Field (java.lang.reflect.Field)2 SQLException (java.sql.SQLException)2 LinkedHashMap (java.util.LinkedHashMap)2 UUID (java.util.UUID)2