Search in sources :

Example 16 with InternalGenericRecord

use of com.hazelcast.internal.serialization.impl.InternalGenericRecord in project hazelcast by hazelcast.

the class PortableUpsertTargetTest method when_doesNotInjectIntoObject_then_insertsNull.

@Test
@Parameters(method = "objectClassDefinitions")
@SuppressWarnings("unused")
public void when_doesNotInjectIntoObject_then_insertsNull(ClassDefinition classDefinition, Object value, Function<InternalGenericRecord, Object> valueExtractor) throws IOException {
    UpsertTarget target = new PortableUpsertTarget(classDefinition);
    target.init();
    Object portable = target.conclude();
    InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
    InternalGenericRecord record = ss.readAsInternalGenericRecord(ss.toData(portable));
    assertThat(valueExtractor.apply(record)).isNull();
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 17 with InternalGenericRecord

use of com.hazelcast.internal.serialization.impl.InternalGenericRecord in project hazelcast by hazelcast.

the class ExtractorGetter method getValue.

@Override
@SuppressWarnings("unchecked")
Object getValue(Object target) throws Exception {
    Object extractionTarget = target;
    // This part will be improved in 3.7 to avoid extra allocation
    DefaultValueCollector collector = new DefaultValueCollector();
    if (target instanceof Data) {
        InternalGenericRecord record = serializationService.readAsInternalGenericRecord((Data) target);
        extractionTarget = new GenericRecordQueryReader(record);
    }
    extractor.extract(extractionTarget, arguments, collector);
    return collector.getResult();
}
Also used : DefaultValueCollector(com.hazelcast.query.impl.DefaultValueCollector) GenericRecordQueryReader(com.hazelcast.internal.serialization.impl.GenericRecordQueryReader) Data(com.hazelcast.internal.serialization.Data) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord)

Example 18 with InternalGenericRecord

use of com.hazelcast.internal.serialization.impl.InternalGenericRecord in project hazelcast by hazelcast.

the class GenericRecordTest method testGenericRecordToStringValidJson.

@Test
public void testGenericRecordToStringValidJson() throws IOException {
    CompactSerializationConfig compactSerializationConfig = new CompactSerializationConfig();
    compactSerializationConfig.setEnabled(true);
    InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setConfig(new SerializationConfig().setCompactSerializationConfig(compactSerializationConfig)).build();
    MainDTO expectedDTO = createMainDTO();
    expectedDTO.nullableBool = null;
    expectedDTO.p.localDateTimes[0] = null;
    Data data = serializationService.toData(expectedDTO);
    assertTrue(data.isCompact());
    // internal generic record created on the servers on query
    InternalGenericRecord internalGenericRecord = serializationService.readAsInternalGenericRecord(data);
    String string = internalGenericRecord.toString();
    Json.parse(string);
    // generic record read from a remote instance without classes on the classpath
    List<String> excludes = Collections.singletonList("example.serialization");
    FilteringClassLoader classLoader = new FilteringClassLoader(excludes, null);
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(classLoader);
        InternalSerializationService ss2 = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setClassLoader(classLoader).setConfig(new SerializationConfig().setCompactSerializationConfig(new CompactSerializationConfig())).build();
        GenericRecord genericRecord = ss2.toObject(data);
        Json.parse(genericRecord.toString());
        // generic record build by API
        GenericRecord apiGenericRecord = createCompactGenericRecord(expectedDTO);
        Json.parse(apiGenericRecord.toString());
    } finally {
        Thread.currentThread().setContextClassLoader(contextClassLoader);
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) MainDTO(example.serialization.MainDTO) CompactTestUtil.createMainDTO(com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createMainDTO) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) CompactTestUtil.createCompactGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createCompactGenericRecord) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

InternalGenericRecord (com.hazelcast.internal.serialization.impl.InternalGenericRecord)18 Test (org.junit.Test)15 Data (com.hazelcast.internal.serialization.Data)10 SqlRow (com.hazelcast.sql.SqlRow)8 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)7 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)6 BigDecimal (java.math.BigDecimal)4 GenericRecordQueryReader (com.hazelcast.internal.serialization.impl.GenericRecordQueryReader)3 Parameters (junitparams.Parameters)3 CompactTestUtil.createCompactGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createCompactGenericRecord)2 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)2 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)2 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)1 SerializationConfig (com.hazelcast.config.SerializationConfig)1 CompactInternalGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactInternalGenericRecord)1 CompactTestUtil.createMainDTO (com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createMainDTO)1 PortableGenericRecord (com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord)1