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;
}
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");
}
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);
}
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);
}
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();
}
});
}
Aggregations