use of com.hazelcast.config.CompactSerializationConfig in project hazelcast by hazelcast.
the class QueryTest method testIndexForComparableAttributes.
public void testIndexForComparableAttributes(IndexType indexType) throws IOException {
Config config = new Config();
MapConfig mapConfig = new MapConfig();
mapConfig.setName("map");
config.getSerializationConfig().setCompactSerializationConfig(new CompactSerializationConfig().setEnabled(true));
IndexConfig indexConfig = new IndexConfig();
indexConfig.addAttribute("firstLimb.name");
indexConfig.setType(indexType);
mapConfig.addIndexConfig(indexConfig);
config.addMapConfig(mapConfig);
HazelcastInstance instance = createHazelcastInstance(config);
IMap map = instance.getMap("map");
for (int i = 0; i < 10; i++) {
map.put(i, BOND);
}
Collection result = map.values(Predicates.equal("firstLimb.name", "left-hand"));
assertEquals(10, result.size());
for (Object value : result) {
ComplexTestDataStructure.Limb firstLimb = ((ComplexTestDataStructure.Person) value).firstLimb;
assertEquals("left-hand", firstLimb.name);
}
}
use of com.hazelcast.config.CompactSerializationConfig in project hazelcast by hazelcast.
the class QueryTest method testIndexNotSupportedForObjectAttributes.
@Test(expected = IllegalArgumentException.class)
public void testIndexNotSupportedForObjectAttributes() throws IOException {
Config config = new Config();
MapConfig mapConfig = new MapConfig();
mapConfig.setName("map");
config.getSerializationConfig().setCompactSerializationConfig(new CompactSerializationConfig().setEnabled(true));
IndexConfig indexConfig = new IndexConfig();
indexConfig.addAttribute("firstLimb");
indexConfig.setType(IndexType.SORTED);
mapConfig.addIndexConfig(indexConfig);
config.addMapConfig(mapConfig);
HazelcastInstance instance = createHazelcastInstance(config);
IMap map = instance.getMap("map");
map.put(1, BOND);
}
use of com.hazelcast.config.CompactSerializationConfig 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.config.CompactSerializationConfig in project hazelcast by hazelcast.
the class GetMapConfigOperationTest method setUp.
@Before
public void setUp() {
factory = new TestHazelcastFactory();
Config config = smallInstanceConfig();
MapConfig withIndex = new MapConfig("map-with-index").addIndexConfig(new IndexConfig(IndexType.SORTED, "first"));
config.addMapConfig(withIndex);
CompactSerializationConfig compactSerializationConfig = config.getSerializationConfig().getCompactSerializationConfig();
compactSerializationConfig.setEnabled(true);
hz = factory.newHazelcastInstance(config);
ClientConfig clientConfig = new ClientConfig();
clientConfig.getSerializationConfig().getCompactSerializationConfig().setEnabled(true);
client = ((HazelcastClientProxy) factory.newHazelcastClient(clientConfig)).client;
}
use of com.hazelcast.config.CompactSerializationConfig 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);
}
}
Aggregations