use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class PortableHookLoader method load.
private void load() {
try {
final Iterator<PortableHook> hooks = ServiceLoader.iterator(PortableHook.class, FACTORY_ID, classLoader);
while (hooks.hasNext()) {
PortableHook hook = hooks.next();
final PortableFactory factory = hook.createFactory();
if (factory != null) {
register(hook.getFactoryId(), factory);
}
final Collection<ClassDefinition> defs = hook.getBuiltinDefinitions();
if (defs != null && !defs.isEmpty()) {
definitions.addAll(defs);
}
}
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
if (configuredFactories != null) {
for (Map.Entry<Integer, ? extends PortableFactory> entry : configuredFactories.entrySet()) {
register(entry.getKey(), entry.getValue());
}
}
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class PortableUtilsTest method validateArrayType_array.
@Test
public void validateArrayType_array() {
// GIVEN
ClassDefinition cd = mock(ClassDefinition.class);
FieldDefinition fd = mock(FieldDefinition.class);
// WHEN
when(fd.getType()).thenReturn(FieldType.BOOLEAN_ARRAY);
// THEN - nothing thrown
PortableUtils.validateArrayType(cd, fd, "person.brain");
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class MetadataPortableResolverTest method test_resolveFieldsFromClassDefinition.
@Test
@Parameters({ "true, __key", "false, this" })
public void test_resolveFieldsFromClassDefinition(boolean key, String prefix) {
InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
ClassDefinition classDefinition = new ClassDefinitionBuilder(1, 2, 3).addStringField("string").addCharField("character").addBooleanField("boolean").addByteField("byte").addShortField("short").addIntField("int").addLongField("long").addFloatField("float").addDoubleField("double").addDecimalField("decimal").addTimeField("time").addDateField("date").addTimestampField("timestamp").addTimestampWithTimezoneField("timestampTz").addPortableField("object", new ClassDefinitionBuilder(4, 5, 6).build()).build();
ss.getPortableContext().registerClassDefinition(classDefinition);
Map<String, String> options = ImmutableMap.of((key ? OPTION_KEY_FACTORY_ID : OPTION_VALUE_FACTORY_ID), String.valueOf(classDefinition.getFactoryId()), (key ? OPTION_KEY_CLASS_ID : OPTION_VALUE_CLASS_ID), String.valueOf(classDefinition.getClassId()), (key ? OPTION_KEY_CLASS_VERSION : OPTION_VALUE_CLASS_VERSION), String.valueOf(classDefinition.getVersion()));
Stream<MappingField> resolvedFields = INSTANCE.resolveAndValidateFields(key, emptyList(), options, ss);
assertThat(resolvedFields).containsExactly(field("string", QueryDataType.VARCHAR, prefix + ".string"), field("character", QueryDataType.VARCHAR_CHARACTER, prefix + ".character"), field("boolean", QueryDataType.BOOLEAN, prefix + ".boolean"), field("byte", QueryDataType.TINYINT, prefix + ".byte"), field("short", QueryDataType.SMALLINT, prefix + ".short"), field("int", QueryDataType.INT, prefix + ".int"), field("long", QueryDataType.BIGINT, prefix + ".long"), field("float", QueryDataType.REAL, prefix + ".float"), field("double", QueryDataType.DOUBLE, prefix + ".double"), field("decimal", QueryDataType.DECIMAL, prefix + ".decimal"), field("time", QueryDataType.TIME, prefix + ".time"), field("date", QueryDataType.DATE, prefix + ".date"), field("timestamp", QueryDataType.TIMESTAMP, prefix + ".timestamp"), field("timestampTz", QueryDataType.TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME, prefix + ".timestampTz"), field("object", QueryDataType.OBJECT, prefix + ".object"));
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class MetadataPortableResolverTest method when_typeMismatchBetweenDeclaredAndClassDefinitionField_then_throws.
@Test
@Parameters({ "true, __key", "false, this" })
public void when_typeMismatchBetweenDeclaredAndClassDefinitionField_then_throws(boolean key, String prefix) {
InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
ClassDefinition classDefinition = new ClassDefinitionBuilder(1, 2, 3).addIntField("field").build();
ss.getPortableContext().registerClassDefinition(classDefinition);
Map<String, String> options = ImmutableMap.of((key ? OPTION_KEY_FACTORY_ID : OPTION_VALUE_FACTORY_ID), String.valueOf(classDefinition.getFactoryId()), (key ? OPTION_KEY_CLASS_ID : OPTION_VALUE_CLASS_ID), String.valueOf(classDefinition.getClassId()), (key ? OPTION_KEY_CLASS_VERSION : OPTION_VALUE_CLASS_VERSION), String.valueOf(classDefinition.getVersion()));
assertThatThrownBy(() -> INSTANCE.resolveAndValidateFields(key, singletonList(field("field", QueryDataType.VARCHAR, prefix + ".field")), options, ss)).isInstanceOf(QueryException.class).hasMessageContaining("Mismatch between declared and resolved type: field");
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class MetadataPortableResolverTest method when_userDeclaresField_then_itsNameHasPrecedenceOverClassDefinitionOne.
@Test
@Parameters({ "true, __key", "false, this" })
public void when_userDeclaresField_then_itsNameHasPrecedenceOverClassDefinitionOne(boolean key, String prefix) {
InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
ClassDefinition classDefinition = new ClassDefinitionBuilder(1, 2, 3).addIntField("field").build();
ss.getPortableContext().registerClassDefinition(classDefinition);
Map<String, String> options = ImmutableMap.of((key ? OPTION_KEY_FACTORY_ID : OPTION_VALUE_FACTORY_ID), String.valueOf(classDefinition.getFactoryId()), (key ? OPTION_KEY_CLASS_ID : OPTION_VALUE_CLASS_ID), String.valueOf(classDefinition.getClassId()), (key ? OPTION_KEY_CLASS_VERSION : OPTION_VALUE_CLASS_VERSION), String.valueOf(classDefinition.getVersion()));
Stream<MappingField> resolvedFields = INSTANCE.resolveAndValidateFields(key, singletonList(field("renamed_field", QueryDataType.INT, prefix + ".field")), options, ss);
assertThat(resolvedFields).containsExactly(field("renamed_field", QueryDataType.INT, prefix + ".field"));
}
Aggregations