use of com.hazelcast.internal.serialization.impl.GenericRecordQueryReader in project hazelcast by hazelcast.
the class CompactStreamSerializerValueReaderQuickTest method reusingTheReader_multipleCalls_stateResetCorrectly.
@Test
public void reusingTheReader_multipleCalls_stateResetCorrectly() throws IOException {
GenericRecordQueryReader reader = reader(PORSCHE);
assertEquals("rear", reader.read("wheels[1].name"));
assertEquals(300, reader.read("engine.power"));
assertEquals(46, reader.read("wheels[0].serial[0]"));
reader.read("wheels[0].serial[0]");
assertEquals("front", reader.read("wheels[0].name"));
assertEquals(45, reader.read("wheels[1].serial[0]"));
reader.read("name");
assertEquals(15, reader.read("engine.chip.power"));
assertEquals("Porsche", reader.read("name"));
}
use of com.hazelcast.internal.serialization.impl.GenericRecordQueryReader 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.GenericRecordQueryReader in project hazelcast by hazelcast.
the class DefaultPortableReaderSpecTest method reader.
//
// Hazelcast init Utilities
//
public GenericRecordQueryReader reader(Portable portable) throws IOException {
SerializationConfig serializationConfig = new SerializationConfig();
serializationConfig.addPortableFactory(TestPortableFactory.ID, new TestPortableFactory());
InternalSerializationService ss = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
// put fully initialised object to a map
// avoid the case where there's no class definition
ss.toData(P_NON_EMPTY);
ss.toData(G_NON_EMPTY);
ss.toData(N_NON_EMPTY);
Data data = ss.toData(portable);
return new GenericRecordQueryReader(ss.readAsInternalGenericRecord(data));
}
use of com.hazelcast.internal.serialization.impl.GenericRecordQueryReader in project hazelcast by hazelcast.
the class DefaultPortableReaderQuickTest method reusingTheReader_multipleCalls_stateResetCorrectly.
@Test
public void reusingTheReader_multipleCalls_stateResetCorrectly() throws IOException {
GenericRecordQueryReader reader = reader(PORSCHE);
assertEquals("rear", reader.read("wheels[1].name"));
assertEquals(300, reader.read("engine.power"));
assertEquals(46, reader.read("wheels[0].serial[0]"));
reader.read("wheels[0].serial[0]");
assertEquals("front", reader.read("wheels[0].name"));
assertEquals(45, reader.read("wheels[1].serial[0]"));
reader.read("name");
assertEquals(15, reader.read("engine.chip.power"));
assertEquals("Porsche", reader.read("name"));
}
use of com.hazelcast.internal.serialization.impl.GenericRecordQueryReader 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