Search in sources :

Example 1 with PortableFactory

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);
}
Also used : Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with PortableFactory

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);
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) NamedPortable(com.hazelcast.nio.serialization.NamedPortable) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) NamedPortable(com.hazelcast.nio.serialization.NamedPortable) Before(org.junit.Before)

Example 3 with PortableFactory

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);
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SerializationConfig(com.hazelcast.config.SerializationConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with PortableFactory

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);
    }
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) HashMap(java.util.HashMap) Map(java.util.Map) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException)

Example 5 with PortableFactory

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Portable(com.hazelcast.nio.serialization.Portable) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) PortableEmployee(com.hazelcast.query.SampleObjects.PortableEmployee) Collection(java.util.Collection) SqlPredicate(com.hazelcast.query.SqlPredicate) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

PortableFactory (com.hazelcast.nio.serialization.PortableFactory)18 Portable (com.hazelcast.nio.serialization.Portable)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 ClientConfig (com.hazelcast.client.config.ClientConfig)6 Config (com.hazelcast.config.Config)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 MapStoreConfig (com.hazelcast.config.MapStoreConfig)4 SerializationConfig (com.hazelcast.config.SerializationConfig)3 SqlPredicate (com.hazelcast.query.SqlPredicate)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Before (org.junit.Before)3 MapIndexConfig (com.hazelcast.config.MapIndexConfig)2 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)2 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2 PortableEmployee (com.hazelcast.query.SampleObjects.PortableEmployee)2 NightlyTest (com.hazelcast.test.annotation.NightlyTest)2 Collection (java.util.Collection)2