Search in sources :

Example 16 with FieldDefinition

use of com.hazelcast.nio.serialization.FieldDefinition in project hazelcast by hazelcast.

the class PortableUtilsTest method validateFactoryAndClass_incompatibleClassId.

@Test
public void validateFactoryAndClass_incompatibleClassId() {
    // GIVEN
    int factoryId = 1;
    int classId = 2;
    FieldDefinition fd = mock(FieldDefinition.class);
    // WHEN ids are compatible
    when(fd.getFactoryId()).thenReturn(factoryId);
    when(fd.getClassId()).thenReturn(classId + 1);
    // THEN - ex thrown
    expected.expect(IllegalArgumentException.class);
    PortableUtils.validateFactoryAndClass(fd, factoryId, classId, "person.brain");
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with FieldDefinition

use of com.hazelcast.nio.serialization.FieldDefinition in project hazelcast by hazelcast.

the class ClassAndFieldDefinitionTest method testClassDef_getField_properIndex.

@Test
public void testClassDef_getField_properIndex() throws Exception {
    for (int i = 0; i < classDefinition.getFieldCount(); i++) {
        FieldDefinition field = classDefinition.getField(i);
        assertNotNull(field);
    }
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with FieldDefinition

use of com.hazelcast.nio.serialization.FieldDefinition in project hazelcast by hazelcast.

the class ClassAndFieldDefinitionTest method testFieldDef_getter_setter.

@Test
public void testFieldDef_getter_setter() throws Exception {
    FieldDefinition field0 = classDefinition.getField(0);
    FieldDefinition field = classDefinition.getField("f1");
    FieldDefinitionImpl fd = new FieldDefinitionImpl(9, "name", FieldType.PORTABLE, 5, 6, 7);
    FieldDefinitionImpl fd_nullName = new FieldDefinitionImpl(10, null, FieldType.PORTABLE, 15, 16, 17);
    assertEquals(field, field0);
    assertEquals(0, field.getFactoryId());
    assertEquals(0, field.getClassId());
    assertEquals(3, field.getVersion());
    assertEquals(0, field.getIndex());
    assertEquals("f1", field.getName());
    assertEquals(FieldType.BYTE, field.getType());
    assertEquals(5, fd.getFactoryId());
    assertEquals(6, fd.getClassId());
    assertEquals(7, fd.getVersion());
    assertEquals(9, fd.getIndex());
    assertEquals("name", fd.getName());
    assertEquals(FieldType.PORTABLE, fd.getType());
    assertEquals(15, fd_nullName.getFactoryId());
    assertEquals(16, fd_nullName.getClassId());
    assertEquals(17, fd_nullName.getVersion());
    assertEquals(10, fd_nullName.getIndex());
    assertEquals(null, fd_nullName.getName());
    assertEquals(FieldType.PORTABLE, fd_nullName.getType());
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with FieldDefinition

use of com.hazelcast.nio.serialization.FieldDefinition in project hazelcast by hazelcast.

the class PortablePositionFactoryTest method createSinglePortablePosition_withIndex.

@Test
public void createSinglePortablePosition_withIndex() {
    // GIVEN
    FieldDefinition fd = new FieldDefinitionImpl(1, "field", FieldType.PORTABLE, 0);
    int streamPosition = 100;
    int factoryId = 123, classId = 546;
    int index = 27, len = 30;
    boolean leaf = true;
    // WHEN
    PortablePosition p = PortablePositionFactory.createSinglePortablePosition(fd, streamPosition, factoryId, classId, index, len, leaf);
    // THEN
    assertFalse(p.isNull());
    assertFalse(p.isEmpty());
    assertFalse(p.isNullOrEmpty());
    assertFalse(p.isNull());
    assertEquals(leaf, p.isLeaf());
    assertFalse(p.isAny());
    assertEquals(fd.getType(), p.getType());
    assertEquals(len, p.getLen());
    assertEquals(classId, p.getClassId());
    assertEquals(factoryId, p.getFactoryId());
    assertEquals(index, p.getIndex());
    assertEquals(streamPosition, p.getStreamPosition());
    assertFalse(p.isMultiPosition());
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 20 with FieldDefinition

use of com.hazelcast.nio.serialization.FieldDefinition in project hazelcast by hazelcast.

the class PortableUtilsTest method validateFactoryAndClass_compatible.

@Test
public void validateFactoryAndClass_compatible() {
    // GIVEN
    int factoryId = 1;
    int classId = 2;
    FieldDefinition fd = mock(FieldDefinition.class);
    // WHEN ids are compatible
    when(fd.getFactoryId()).thenReturn(factoryId);
    when(fd.getClassId()).thenReturn(classId);
    // THEN - nothing thrown
    PortableUtils.validateFactoryAndClass(fd, factoryId, classId, "person.brain");
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)32 ParallelTest (com.hazelcast.test.annotation.ParallelTest)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Test (org.junit.Test)11 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)5 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2 PortableContext (com.hazelcast.internal.serialization.PortableContext)1 DefaultPortableReader (com.hazelcast.internal.serialization.impl.DefaultPortableReader)1 Data (com.hazelcast.nio.serialization.Data)1 Portable (com.hazelcast.nio.serialization.Portable)1 PortableReader (com.hazelcast.nio.serialization.PortableReader)1