use of com.hazelcast.nio.serialization.PortableFactory 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.PortableFactory 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.PortableFactory in project hazelcast by hazelcast.
the class QueryAdvancedTest method testUnknownPortableField_notCausesQueryException_withIndex.
@Test
public // see: https://github.com/hazelcast/hazelcast/issues/3927
void testUnknownPortableField_notCausesQueryException_withIndex() {
String mapName = "default";
Config config = getConfig();
config.getSerializationConfig().addPortableFactory(666, new PortableFactory() {
public Portable create(int classId) {
return new PortableEmployee();
}
});
config.getMapConfig(mapName).addMapIndexConfig(new MapIndexConfig("notExist", false)).addMapIndexConfig(new MapIndexConfig("n", false));
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("n = name_2 OR notExist = name_0"));
assertEquals(1, values.size());
}
use of com.hazelcast.nio.serialization.PortableFactory in project hazelcast by hazelcast.
the class MorphingPortableReaderTest method before.
@Before
public void before() throws Exception {
service1 = (SerializationServiceV1) new DefaultSerializationServiceBuilder().addPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new PortableFactory() {
public Portable create(int classId) {
return new MorphingBasePortable();
}
}).build();
service2 = (SerializationServiceV1) new DefaultSerializationServiceBuilder().addPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new PortableFactory() {
public Portable create(int classId) {
return new MorphingPortable();
}
}).build();
Data data = service1.toData(new MorphingBasePortable((byte) 1, true, (char) 2, (short) 3, 4, 5, 1f, 2d, "test"));
BufferObjectDataInput in = service2.createObjectDataInput(data);
PortableSerializer portableSerializer = service2.getPortableSerializer();
reader = portableSerializer.createMorphingReader(in);
}
use of com.hazelcast.nio.serialization.PortableFactory in project hazelcast by hazelcast.
the class PortableSerializer method createNewPortableInstance.
private Portable createNewPortableInstance(int factoryId, int classId) {
final PortableFactory portableFactory = factories.get(factoryId);
if (portableFactory == null) {
throw new HazelcastSerializationException("Could not find PortableFactory for factory-id: " + factoryId);
}
final Portable portable = portableFactory.create(classId);
if (portable == null) {
throw new HazelcastSerializationException("Could not create Portable for class-id: " + classId);
}
return portable;
}
Aggregations