Search in sources :

Example 6 with BinaryType

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

the class GridDefaultBinaryMappersBinaryMetaDataSelfTest method testBinaryMarshalAware.

/**
     * @throws Exception If failed.
     */
public void testBinaryMarshalAware() throws Exception {
    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(7, 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("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("decimal", meta.fieldTypeName("decVal"));
    assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType)

Example 7 with BinaryType

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

the class BinaryObjectBuilderAdditionalSelfTest method testMetadataChangingDoublePut2.

/**
     *
     */
public void testMetadataChangingDoublePut2() {
    BinaryObjectBuilderImpl mutableObj = wrap(new GridBinaryTestClasses.TestObjectContainer());
    mutableObj.setField("xx567", "a");
    mutableObj.setField("xx567", "b");
    mutableObj.build();
    BinaryType metadata = binaries().type(GridBinaryTestClasses.TestObjectContainer.class);
    assertEquals("String", metadata.fieldTypeName("xx567"));
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)

Example 8 with BinaryType

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

the class BinaryObjectBuilderAdditionalSelfTest method testMetadataChanging.

/**
     *
     */
public void testMetadataChanging() {
    GridBinaryTestClasses.TestObjectContainer c = new GridBinaryTestClasses.TestObjectContainer();
    BinaryObjectBuilderImpl mutableObj = wrap(c);
    mutableObj.setField("intField", 1);
    mutableObj.setField("intArrField", new int[] { 1 });
    mutableObj.setField("arrField", new String[] { "1" });
    mutableObj.setField("strField", "1");
    mutableObj.setField("colField", Lists.newArrayList("1"));
    mutableObj.setField("mapField", Maps.newHashMap(ImmutableMap.of(1, "1")));
    mutableObj.setField("enumField", GridBinaryTestClasses.TestObjectEnum.A);
    mutableObj.setField("enumArrField", new Enum[] { GridBinaryTestClasses.TestObjectEnum.A });
    mutableObj.build();
    BinaryType metadata = binaries().type(c.getClass());
    assertTrue(metadata.fieldNames().containsAll(Arrays.asList("intField", "intArrField", "arrField", "strField", "colField", "mapField", "enumField", "enumArrField")));
    assertEquals("int", metadata.fieldTypeName("intField"));
    assertEquals("int[]", metadata.fieldTypeName("intArrField"));
    assertEquals("String[]", metadata.fieldTypeName("arrField"));
    assertEquals("String", metadata.fieldTypeName("strField"));
    assertEquals("Collection", metadata.fieldTypeName("colField"));
    assertEquals("Map", metadata.fieldTypeName("mapField"));
    assertEquals("Enum", metadata.fieldTypeName("enumField"));
    assertEquals("Enum[]", metadata.fieldTypeName("enumArrField"));
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)

Example 9 with BinaryType

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testMetaData2.

/**
     * @throws Exception If failed.
     */
public void testMetaData2() throws Exception {
    BinaryObjectBuilder builder = builder("org.test.MetaTest2");
    builder.setField("objectField", "a", Object.class);
    BinaryObject bo = builder.build();
    BinaryType meta = bo.type();
    assertEquals(expectedTypeName("org.test.MetaTest2"), meta.typeName());
    assertEquals("Object", meta.fieldTypeName("objectField"));
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 10 with BinaryType

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

the class BinaryObjectBuilderAdditionalSelfTest method testMetadataChangingDoublePut.

/**
     *
     */
public void testMetadataChangingDoublePut() {
    BinaryObjectBuilderImpl mutableObj = wrap(new GridBinaryTestClasses.TestObjectContainer());
    mutableObj.setField("xx567", "a");
    mutableObj.setField("xx567", "b");
    mutableObj.build();
    BinaryType metadata = binaries().type(GridBinaryTestClasses.TestObjectContainer.class);
    assertEquals("String", metadata.fieldTypeName("xx567"));
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)

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