use of com.hazelcast.nio.serialization.PortableFactory in project hazelcast by hazelcast.
the class ClientAuthenticationTest method testAuthenticationWithCustomCredentials_when_singleNode.
@Test
public void testAuthenticationWithCustomCredentials_when_singleNode() {
PortableFactory factory = new CustomCredentialsPortableFactory();
// with this config, the server will authenticate any credential of type CustomCredentials
Config config = new Config();
config.getGroupConfig().setName(USERNAME).setPassword(PASSWORD);
config.getSerializationConfig().addPortableFactory(1, factory);
hazelcastFactory.newHazelcastInstance(config);
ClientConfig clientConfig = new ClientConfig();
// make sure there are no credentials sent over the wire
clientConfig.getSecurityConfig().setCredentials(new CustomCredentials());
hazelcastFactory.newHazelcastClient(clientConfig);
}
use of com.hazelcast.nio.serialization.PortableFactory in project hazelcast by hazelcast.
the class ClientMapTest method setup.
@Before
public void setup() {
Config config = getConfig();
config.getMapConfig("flushMap").setMapStoreConfig(new MapStoreConfig().setWriteDelaySeconds(1000).setImplementation(flushMapStore));
config.getMapConfig("putTransientMap").setMapStoreConfig(new MapStoreConfig().setWriteDelaySeconds(1000).setImplementation(transientMapStore));
server = hazelcastFactory.newHazelcastInstance(config);
ClientConfig clientConfig = new ClientConfig();
clientConfig.getSerializationConfig().addPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new PortableFactory() {
public Portable create(int classId) {
return new NamedPortable();
}
});
client = hazelcastFactory.newHazelcastClient(clientConfig);
}
use of com.hazelcast.nio.serialization.PortableFactory in project hazelcast by hazelcast.
the class ClientReplicatedMapTest method testClientPortableWithoutRegisteringToNode.
@Test
public void testClientPortableWithoutRegisteringToNode() {
hazelcastFactory.newHazelcastInstance(buildConfig(InMemoryFormat.BINARY, 0));
SerializationConfig serializationConfig = new SerializationConfig();
serializationConfig.addPortableFactory(5, new PortableFactory() {
public Portable create(int classId) {
return new SamplePortable();
}
});
ClientConfig clientConfig = new ClientConfig();
clientConfig.setSerializationConfig(serializationConfig);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
ReplicatedMap<Integer, SamplePortable> sampleMap = client.getReplicatedMap(randomString());
sampleMap.put(1, new SamplePortable(666));
SamplePortable samplePortable = sampleMap.get(1);
assertEquals(666, samplePortable.a);
}
use of com.hazelcast.nio.serialization.PortableFactory in project hazelcast by hazelcast.
the class DefaultSerializationServiceBuilder method buildPortableFactories.
private void buildPortableFactories(Map<Integer, PortableFactory> portableFactories, SerializationConfig config, ClassLoader cl) {
final Map<Integer, String> portableFactoryClasses = config.getPortableFactoryClasses();
for (Map.Entry<Integer, String> entry : portableFactoryClasses.entrySet()) {
int factoryId = entry.getKey();
String factoryClassName = entry.getValue();
if (factoryId <= 0) {
throw new IllegalArgumentException("PortableFactory factoryId must be positive! -> " + factoryClassName);
}
if (portableFactories.containsKey(factoryId)) {
throw new IllegalArgumentException("PortableFactory with factoryId '" + factoryId + "' is already registered!");
}
PortableFactory factory;
try {
factory = ClassLoaderUtil.newInstance(cl, factoryClassName);
} catch (Exception e) {
throw new HazelcastSerializationException(e);
}
portableFactories.put(factoryId, factory);
}
}
use of com.hazelcast.nio.serialization.PortableFactory 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());
}
Aggregations