Search in sources :

Example 21 with BinaryType

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

the class GridDefaultBinaryMappersBinaryMetaDataSelfTest method testSerializedObject.

/**
     * @throws Exception If failed.
     */
public void testSerializedObject() throws Exception {
    TestObject1 obj = new TestObject1();
    obj.intVal = 10;
    obj.strVal = "str";
    obj.arrVal = new byte[] { 2, 4, 6 };
    obj.obj1Val = null;
    obj.obj2Val = new TestObject2();
    obj.decVal = BigDecimal.ZERO;
    obj.decArrVal = new BigDecimal[] { BigDecimal.ONE };
    BinaryObject po = binaries().toBinary(obj);
    info(po.toString());
    BinaryType meta = po.type();
    assertNotNull(meta);
    assertEquals(expectedTypeName(TestObject1.class.getName()), meta.typeName());
    Collection<String> fields = meta.fieldNames();
    assertEquals(7, fields.size());
    assertTrue(fields.contains("intVal"));
    assertTrue(fields.contains("strVal"));
    assertTrue(fields.contains("arrVal"));
    assertTrue(fields.contains("obj1Val"));
    assertTrue(fields.contains("obj2Val"));
    assertTrue(fields.contains("decVal"));
    assertTrue(fields.contains("decArrVal"));
    assertEquals("int", meta.fieldTypeName("intVal"));
    assertEquals("String", meta.fieldTypeName("strVal"));
    assertEquals("byte[]", meta.fieldTypeName("arrVal"));
    assertEquals("Object", meta.fieldTypeName("obj1Val"));
    assertEquals("Object", meta.fieldTypeName("obj2Val"));
    assertEquals("decimal", meta.fieldTypeName("decVal"));
    assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) BinaryObject(org.apache.ignite.binary.BinaryObject)

Example 22 with BinaryType

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

the class GridDefaultBinaryMappersBinaryMetaDataSelfTest method testMerge.

/**
     * @throws Exception If failed.
     */
public void testMerge() throws Exception {
    binaries().toBinary(new TestObject2());
    idx = 1;
    binaries().toBinary(new TestObject2());
    BinaryType meta = binaries().type(TestObject2.class);
    assertNotNull(meta);
    assertEquals(expectedTypeName(TestObject2.class.getName()), meta.typeName());
    Collection<String> fields = meta.fieldNames();
    assertEquals(9, fields.size());
    assertTrue(fields.contains("boolVal"));
    assertTrue(fields.contains("dateVal"));
    assertTrue(fields.contains("uuidArrVal"));
    assertTrue(fields.contains("objVal"));
    assertTrue(fields.contains("mapVal"));
    assertTrue(fields.contains("charVal"));
    assertTrue(fields.contains("colVal"));
    assertTrue(fields.contains("decVal"));
    assertTrue(fields.contains("decArrVal"));
    assertEquals("boolean", meta.fieldTypeName("boolVal"));
    assertEquals("Date", meta.fieldTypeName("dateVal"));
    assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
    assertEquals("Object", meta.fieldTypeName("objVal"));
    assertEquals("Map", meta.fieldTypeName("mapVal"));
    assertEquals("char", meta.fieldTypeName("charVal"));
    assertEquals("Collection", meta.fieldTypeName("colVal"));
    assertEquals("decimal", meta.fieldTypeName("decVal"));
    assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType)

Example 23 with BinaryType

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

the class GridCacheClientNodeBinaryObjectMetadataMultinodeTest method testFailoverOnStart.

/**
     * @throws Exception If failed.
     */
public void testFailoverOnStart() throws Exception {
    startGrids(4);
    IgniteBinary binaries = ignite(0).binary();
    IgniteCache<Object, Object> cache = ignite(0).cache(DEFAULT_CACHE_NAME).withKeepBinary();
    for (int i = 0; i < 1000; i++) {
        BinaryObjectBuilder builder = binaries.builder("type-" + i);
        builder.setField("f0", i);
        cache.put(i, builder.build());
    }
    client = true;
    final CyclicBarrier barrier = new CyclicBarrier(6);
    final AtomicInteger startIdx = new AtomicInteger(4);
    IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            barrier.await();
            Ignite ignite = startGrid(startIdx.getAndIncrement());
            assertTrue(ignite.configuration().isClientMode());
            log.info("Started node: " + ignite.name());
            return null;
        }
    }, 5, "start-thread");
    barrier.await();
    U.sleep(ThreadLocalRandom.current().nextInt(10, 100));
    for (int i = 0; i < 3; i++) stopGrid(i);
    fut.get();
    assertEquals(6, ignite(3).cluster().nodes().size());
    for (int i = 3; i < 7; i++) {
        log.info("Check metadata on node: " + i);
        boolean client = i > 3;
        assertEquals((Object) client, ignite(i).configuration().isClientMode());
        binaries = ignite(i).binary();
        final IgniteBinary p0 = binaries;
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                Collection<BinaryType> metaCol = p0.types();
                return metaCol.size() == 1000;
            }
        }, getTestTimeout());
        Collection<BinaryType> metaCol = binaries.types();
        assertEquals(1000, metaCol.size());
        Set<String> names = new HashSet<>();
        for (BinaryType meta : metaCol) {
            assertTrue(names.add(meta.typeName()));
            assertNull(meta.affinityKeyFieldName());
            assertEquals(1, meta.fieldNames().size());
        }
        assertEquals(1000, names.size());
    }
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteBinary(org.apache.ignite.IgniteBinary) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Collection(java.util.Collection) Ignite(org.apache.ignite.Ignite) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) ConcurrentHashSet(org.eclipse.jetty.util.ConcurrentHashSet) HashSet(java.util.HashSet)

Example 24 with BinaryType

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

the class GridCacheClientNodeBinaryObjectMetadataTest method testBinaryMetadataOnClient.

/**
     * @throws Exception If failed.
     */
public void testBinaryMetadataOnClient() throws Exception {
    Ignite ignite0 = ignite(gridCount() - 1);
    assertTrue(ignite0.configuration().isClientMode());
    Ignite ignite1 = ignite(0);
    assertFalse(ignite1.configuration().isClientMode());
    Affinity<Object> aff0 = ignite0.affinity(DEFAULT_CACHE_NAME);
    Affinity<Object> aff1 = ignite1.affinity(DEFAULT_CACHE_NAME);
    for (int i = 0; i < 100; i++) {
        TestObject1 obj1 = new TestObject1(i, i + 1);
        assertEquals(aff1.mapKeyToPrimaryAndBackups(obj1), aff0.mapKeyToPrimaryAndBackups(obj1));
        TestObject2 obj2 = new TestObject2(i, i + 1);
        assertEquals(aff1.mapKeyToPrimaryAndBackups(obj2), aff0.mapKeyToPrimaryAndBackups(obj2));
    }
    Collection<BinaryType> meta1 = ignite1.binary().types();
    Collection<BinaryType> meta2 = ignite1.binary().types();
    assertEquals(meta1.size(), meta2.size());
    for (BinaryType m1 : meta1) {
        boolean found = false;
        for (BinaryType m2 : meta1) {
            if (m1.typeName().equals(m2.typeName())) {
                assertEquals(m1.affinityKeyFieldName(), m2.affinityKeyFieldName());
                assertEquals(m1.fieldNames(), m2.fieldNames());
                found = true;
                break;
            }
        }
        assertTrue(found);
    }
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) Ignite(org.apache.ignite.Ignite)

Aggregations

BinaryType (org.apache.ignite.binary.BinaryType)24 BinaryObject (org.apache.ignite.binary.BinaryObject)8 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)4 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 BinaryField (org.apache.ignite.binary.BinaryField)3 BinaryObjectEx (org.apache.ignite.internal.binary.BinaryObjectEx)3 BinaryObjectBuilderImpl (org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)3 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)3 HashSet (java.util.HashSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Ignite (org.apache.ignite.Ignite)2 IgniteBinary (org.apache.ignite.IgniteBinary)2 BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)2 SB (org.apache.ignite.internal.util.typedef.internal.SB)2 ConcurrentHashSet (org.eclipse.jetty.util.ConcurrentHashSet)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1