use of com.hazelcast.nio.serialization.Portable in project hazelcast by hazelcast.
the class ClassDefinitionWriter method writePortableArray.
@Override
public void writePortableArray(String fieldName, Portable[] portables) throws IOException {
if (portables == null || portables.length == 0) {
throw new HazelcastSerializationException("Cannot write null portable array without explicitly " + "registering class definition!");
}
Portable p = portables[0];
int classId = p.getClassId();
for (int i = 1; i < portables.length; i++) {
if (portables[i].getClassId() != classId) {
throw new IllegalArgumentException("Detected different class-ids in portable array!");
}
}
int version = SerializationUtil.getPortableVersion(p, context.getVersion());
ClassDefinition nestedClassDef = createNestedClassDef(p, new ClassDefinitionBuilder(p.getFactoryId(), classId, version));
builder.addPortableArrayField(fieldName, nestedClassDef);
}
use of com.hazelcast.nio.serialization.Portable in project hazelcast by hazelcast.
the class QueryAdvancedTest method testUnknownPortableField_notCausesQueryException_withoutIndex.
@Test
public // see: https://github.com/hazelcast/hazelcast/issues/3927
void testUnknownPortableField_notCausesQueryException_withoutIndex() {
String mapName = randomMapName();
Config config = getConfig();
config.getSerializationConfig().addPortableFactory(666, new PortableFactory() {
public Portable create(int classId) {
return new PortableEmployee();
}
});
HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
IMap<Integer, PortableEmployee> map = hazelcastInstance.getMap(mapName);
for (int i = 0; i < 5; i++) {
map.put(i, new PortableEmployee(i, "name_" + i));
}
Collection values = map.values(new SqlPredicate("notExist = name_0 OR a > 1"));
assertEquals(3, values.size());
}
use of com.hazelcast.nio.serialization.Portable in project hazelcast by hazelcast.
the class MapTransactionTest method testKeySet_whenPortableKeysetAndValuesWithPredicates.
@Test
public void testKeySet_whenPortableKeysetAndValuesWithPredicates() throws Exception {
final String mapName = randomString();
final Config config = getConfig();
config.getSerializationConfig().addPortableFactory(666, new PortableFactory() {
public Portable create(int classId) {
return new SampleObjects.PortableEmployee();
}
});
final HazelcastInstance instance = createHazelcastInstance(config);
IMap map = instance.getMap(mapName);
final SampleObjects.PortableEmployee emp1 = new SampleObjects.PortableEmployee(34, "abc-123-xvz");
final SampleObjects.PortableEmployee emp2 = new SampleObjects.PortableEmployee(20, "abc-123-xvz");
map.put(emp1, emp1);
final TransactionContext context = instance.newTransactionContext();
context.beginTransaction();
final TransactionalMap txMap = context.getMap(mapName);
assertNull(txMap.put(emp2, emp2));
assertEquals(2, txMap.size());
assertEquals(2, txMap.keySet().size());
assertEquals(0, txMap.keySet(new SqlPredicate("a = 10")).size());
assertEquals(0, txMap.values(new SqlPredicate("a = 10")).size());
assertEquals(2, txMap.keySet(new SqlPredicate("a >= 10")).size());
assertEquals(2, txMap.values(new SqlPredicate("a >= 10")).size());
context.commitTransaction();
assertEquals(2, map.size());
assertEquals(2, map.values().size());
}
use of com.hazelcast.nio.serialization.Portable in project hazelcast by hazelcast.
the class AbstractNearCacheSerializationCountTest method prepareSerializationConfig.
/**
* Adds the serialization configuration for the used {@link Portable} domain object to the given {@link SerializationConfig}.
*
* @param serializationConfig the given {@link SerializationConfig} for the {@link DataStructureAdapter}
*/
protected static void prepareSerializationConfig(SerializationConfig serializationConfig) {
ClassDefinition classDefinition = new ClassDefinitionBuilder(SerializationCountingData.FACTORY_ID, SerializationCountingData.CLASS_ID).build();
serializationConfig.addClassDefinition(classDefinition);
serializationConfig.addPortableFactory(SerializationCountingData.FACTORY_ID, new PortableFactory() {
@Override
public Portable create(int classId) {
return new SerializationCountingData();
}
});
}
use of com.hazelcast.nio.serialization.Portable in project hazelcast by hazelcast.
the class DefaultPortableReaderPerformanceTest method setup.
@Setup
public void setup() throws Exception {
ss = new DefaultSerializationServiceBuilder().addPortableFactory(DefaultPortableReaderQuickTest.TestPortableFactory.ID, new DefaultPortableReaderQuickTest.TestPortableFactory()).build();
Portable primitive = new DefaultPortableReaderTestStructure.PrimitivePortable();
primitiveReader = reader(primitive);
reader = reader(PORSCHE);
}
Aggregations