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