Search in sources :

Example 6 with ClassDefinition

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

the class PortableContextImpl method getFieldDefinition.

@Override
public // TODO cache the result
FieldDefinition getFieldDefinition(ClassDefinition classDef, String name) {
    FieldDefinition fd = classDef.getField(name);
    if (fd == null) {
        if (name.contains(".")) {
            String[] fieldNames = NESTED_FIELD_PATTERN.split(name);
            if (fieldNames.length <= 1) {
                return fd;
            }
            ClassDefinition currentClassDef = classDef;
            for (int i = 0; i < fieldNames.length; i++) {
                fd = currentClassDef.getField(fieldNames[i]);
                if (fd == null) {
                    fd = currentClassDef.getField(extractAttributeNameNameWithoutArguments(fieldNames[i]));
                }
                // This is not enough to fully implement issue: https://github.com/hazelcast/hazelcast/issues/3927
                if (i == fieldNames.length - 1) {
                    break;
                }
                if (fd == null) {
                    throw new IllegalArgumentException("Unknown field: " + name);
                }
                currentClassDef = lookupClassDefinition(fd.getFactoryId(), fd.getClassId(), fd.getVersion());
                if (currentClassDef == null) {
                    throw new IllegalArgumentException("Not a registered Portable field: " + fd);
                }
            }
        } else {
            fd = classDef.getField(extractAttributeNameNameWithoutArguments(name));
        }
    }
    return fd;
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition)

Example 7 with ClassDefinition

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

the class PortableUtilsTest method validateArrayType_notArray.

@Test
public void validateArrayType_notArray() {
    // GIVEN
    ClassDefinition cd = mock(ClassDefinition.class);
    FieldDefinition fd = mock(FieldDefinition.class);
    // WHEN
    when(fd.getType()).thenReturn(FieldType.BOOLEAN);
    // THEN - ex thrown
    expected.expect(IllegalArgumentException.class);
    PortableUtils.validateArrayType(cd, fd, "person.brain");
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with ClassDefinition

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

the class PortableUtilsTest method unknownFieldException.

@Test
public void unknownFieldException() {
    // GIVEN
    BufferObjectDataInput in = mock(BufferObjectDataInput.class);
    ClassDefinition cd = mock(ClassDefinition.class);
    PortableNavigatorContext ctx = new PortableNavigatorContext(in, cd, null);
    // WHEN
    HazelcastSerializationException ex = PortableUtils.createUnknownFieldException(ctx, "person.brain");
    // THEN
    assertNotNull(ex);
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with ClassDefinition

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

the class PortableUtilsTest method wrongUseOfAnyOperationException.

@Test
public void wrongUseOfAnyOperationException() {
    // GIVEN
    BufferObjectDataInput in = mock(BufferObjectDataInput.class);
    ClassDefinition cd = mock(ClassDefinition.class);
    PortableNavigatorContext ctx = new PortableNavigatorContext(in, cd, null);
    // WHEN
    IllegalArgumentException ex = PortableUtils.createWrongUseOfAnyOperationException(ctx, "person.brain");
    // THEN
    assertNotNull(ex);
}
Also used : ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with ClassDefinition

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

the class AbstractNearCacheSerializationCountTest method prepareSerializationConfig.

/**
     * Adds the serialization configuration for the used {@link Portable} domain object to the given {@link SerializationConfig}.
     *
     * @param serializationConfig the given {@link SerializationConfig} for the {@link DataStructureAdapter}
     */
protected static void prepareSerializationConfig(SerializationConfig serializationConfig) {
    ClassDefinition classDefinition = new ClassDefinitionBuilder(SerializationCountingData.FACTORY_ID, SerializationCountingData.CLASS_ID).build();
    serializationConfig.addClassDefinition(classDefinition);
    serializationConfig.addPortableFactory(SerializationCountingData.FACTORY_ID, new PortableFactory() {

        @Override
        public Portable create(int classId) {
            return new SerializationCountingData();
        }
    });
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder)

Aggregations

ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)70 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)37 Test (org.junit.Test)25 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)16 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)15 QuickTest (com.hazelcast.test.annotation.QuickTest)15 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)7 GenericRecordBuilder (com.hazelcast.nio.serialization.GenericRecordBuilder)7 Parameters (junitparams.Parameters)7 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)6 MappingField (com.hazelcast.sql.impl.schema.MappingField)6 Portable (com.hazelcast.nio.serialization.Portable)5 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 SerializationConfig (com.hazelcast.config.SerializationConfig)3 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)3 Data (com.hazelcast.internal.serialization.Data)3 BufferObjectDataInput (com.hazelcast.nio.BufferObjectDataInput)3