Search in sources :

Example 1 with SchemaService

use of com.hazelcast.internal.serialization.impl.compact.SchemaService in project hazelcast by hazelcast.

the class CompactStreamSerializerValueReaderQuickTest method reader.

// 
// Utilities
// 
public GenericRecordQueryReader reader(Car car) throws IOException {
    SchemaService schemaService = CompactTestUtil.createInMemorySchemaService();
    SerializationConfig serializationConfig = new SerializationConfig();
    serializationConfig.setCompactSerializationConfig(new CompactSerializationConfig().setEnabled(true));
    InternalSerializationService ss = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).setSchemaService(schemaService).build();
    Data data = ss.toData(car);
    return new GenericRecordQueryReader(ss.readAsInternalGenericRecord(data));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) SchemaService(com.hazelcast.internal.serialization.impl.compact.SchemaService) SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) GenericRecordQueryReader(com.hazelcast.internal.serialization.impl.GenericRecordQueryReader) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService)

Example 2 with SchemaService

use of com.hazelcast.internal.serialization.impl.compact.SchemaService in project hazelcast by hazelcast.

the class CompactStreamSerializerValueReaderSpecTest method executeTestScenario.

@Test
@SuppressWarnings("unchecked")
public void executeTestScenario() throws Exception {
    // handle result
    Object resultToMatch = expectedResult;
    if (expectedResult instanceof Class) {
        // expected exception case
        expected.expect(isA((Class) expectedResult));
    } else if (expectedResult instanceof List) {
        // just convenience -> if result is a list if will be compared to an array, so it has to be converted
        resultToMatch = ((List) resultToMatch).toArray();
    }
    // print test scenario for debug purposes
    // it makes debugging easier since all scenarios are generated
    printlnScenarioDescription(resultToMatch);
    SchemaService schemaService = CompactTestUtil.createInMemorySchemaService();
    SerializationConfig serializationConfig = new SerializationConfig();
    serializationConfig.setCompactSerializationConfig(new CompactSerializationConfig().setEnabled(true));
    InternalSerializationService ss = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).setSchemaService(schemaService).build();
    Data data = ss.toData(inputObject);
    GenericRecordQueryReader reader = new GenericRecordQueryReader(ss.readAsInternalGenericRecord(data));
    Object result = reader.read(pathToRead);
    if (result instanceof MultiResult) {
        MultiResult multiResult = (MultiResult) result;
        if (multiResult.getResults().size() == 1 && multiResult.getResults().get(0) == null && multiResult.isNullEmptyTarget()) {
            // explode null in case of a single multi-result target result
            result = null;
        } else {
            // in case of multi result while invoking generic "read" method deal with the multi results
            result = ((MultiResult) result).getResults().toArray();
        }
    }
    assertThat(result, equalTo(resultToMatch));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) MultiResult(com.hazelcast.query.impl.getters.MultiResult) SchemaService(com.hazelcast.internal.serialization.impl.compact.SchemaService) SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) GenericRecordQueryReader(com.hazelcast.internal.serialization.impl.GenericRecordQueryReader) GroupObject(com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.GroupObject) PrimitiveObject(com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.PrimitiveObject) NestedGroupObject(com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.NestedGroupObject) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)2 SerializationConfig (com.hazelcast.config.SerializationConfig)2 Data (com.hazelcast.internal.serialization.Data)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 GenericRecordQueryReader (com.hazelcast.internal.serialization.impl.GenericRecordQueryReader)2 SchemaService (com.hazelcast.internal.serialization.impl.compact.SchemaService)2 GroupObject (com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.GroupObject)1 NestedGroupObject (com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.NestedGroupObject)1 PrimitiveObject (com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.PrimitiveObject)1 MultiResult (com.hazelcast.query.impl.getters.MultiResult)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 SlowTest (com.hazelcast.test.annotation.SlowTest)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Test (org.junit.Test)1