Search in sources :

Example 1 with SerializerConfig

use of com.hazelcast.config.SerializerConfig in project hazelcast by hazelcast.

the class XmlClientConfigBuilderTest method testSerializationConfig.

@Test
public void testSerializationConfig() {
    final SerializationConfig serializationConfig = clientConfig.getSerializationConfig();
    assertEquals(3, serializationConfig.getPortableVersion());
    final Map<Integer, String> dsClasses = serializationConfig.getDataSerializableFactoryClasses();
    assertEquals(1, dsClasses.size());
    assertEquals("com.hazelcast.examples.DataSerializableFactory", dsClasses.get(1));
    final Map<Integer, String> pfClasses = serializationConfig.getPortableFactoryClasses();
    assertEquals(1, pfClasses.size());
    assertEquals("com.hazelcast.examples.PortableFactory", pfClasses.get(2));
    final Collection<SerializerConfig> serializerConfigs = serializationConfig.getSerializerConfigs();
    assertEquals(1, serializerConfigs.size());
    final SerializerConfig serializerConfig = serializerConfigs.iterator().next();
    assertEquals("com.hazelcast.examples.DummyType", serializerConfig.getTypeClassName());
    assertEquals("com.hazelcast.examples.SerializerFactory", serializerConfig.getClassName());
    final GlobalSerializerConfig globalSerializerConfig = serializationConfig.getGlobalSerializerConfig();
    assertEquals("com.hazelcast.examples.GlobalSerializerFactory", globalSerializerConfig.getClassName());
    assertEquals(ByteOrder.BIG_ENDIAN, serializationConfig.getByteOrder());
    assertEquals(true, serializationConfig.isCheckClassDefErrors());
    assertEquals(false, serializationConfig.isAllowUnsafe());
    assertEquals(false, serializationConfig.isEnableCompression());
    assertEquals(true, serializationConfig.isEnableSharedObject());
    assertEquals(true, serializationConfig.isUseNativeByteOrder());
}
Also used : GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) XMLConfigBuilderTest(com.hazelcast.config.XMLConfigBuilderTest)

Example 2 with SerializerConfig

use of com.hazelcast.config.SerializerConfig in project hazelcast by hazelcast.

the class TestClientApplicationContext method testClient.

@Test
public void testClient() {
    assertNotNull(client);
    assertNotNull(client2);
    assertNotNull(client3);
    ClientConfig config = client.getClientConfig();
    assertEquals("13", config.getProperty("hazelcast.client.retry.count"));
    assertEquals(3, config.getNetworkConfig().getConnectionAttemptLimit());
    assertEquals(1000, config.getNetworkConfig().getConnectionTimeout());
    assertEquals(3000, config.getNetworkConfig().getConnectionAttemptPeriod());
    ClientConfig config2 = client2.getClientConfig();
    assertEquals(credentials, config2.getSecurityConfig().getCredentials());
    client.getMap("default").put("Q", "q");
    client2.getMap("default").put("X", "x");
    IMap<Object, Object> map = instance.getMap("default");
    assertEquals("q", map.get("Q"));
    assertEquals("x", map.get("X"));
    ClientConfig config3 = client3.getClientConfig();
    SerializationConfig serConf = config3.getSerializationConfig();
    assertEquals(ByteOrder.BIG_ENDIAN, serConf.getByteOrder());
    assertEquals(false, serConf.isAllowUnsafe());
    assertEquals(false, serConf.isCheckClassDefErrors());
    assertEquals(false, serConf.isEnableCompression());
    assertEquals(false, serConf.isEnableSharedObject());
    assertEquals(false, serConf.isUseNativeByteOrder());
    assertEquals(10, serConf.getPortableVersion());
    Map<Integer, String> map1 = serConf.getDataSerializableFactoryClasses();
    assertNotNull(map1);
    assertTrue(map1.containsKey(1));
    assertEquals("com.hazelcast.spring.serialization.DummyDataSerializableFactory", map1.get(1));
    Map<Integer, String> portableFactoryClasses = serConf.getPortableFactoryClasses();
    assertNotNull(portableFactoryClasses);
    assertTrue(portableFactoryClasses.containsKey(2));
    assertEquals("com.hazelcast.spring.serialization.DummyPortableFactory", portableFactoryClasses.get(2));
    Collection<SerializerConfig> serializerConfigs = serConf.getSerializerConfigs();
    assertNotNull(serializerConfigs);
    SerializerConfig serializerConfig = serializerConfigs.iterator().next();
    assertNotNull(serializerConfig);
    assertEquals("com.hazelcast.nio.serialization.CustomSerializationTest$FooXmlSerializer", serializerConfig.getClassName());
    assertEquals("com.hazelcast.nio.serialization.CustomSerializationTest$Foo", serializerConfig.getTypeClassName());
    List<ProxyFactoryConfig> proxyFactoryConfigs = config3.getProxyFactoryConfigs();
    assertNotNull(proxyFactoryConfigs);
    ProxyFactoryConfig proxyFactoryConfig = proxyFactoryConfigs.get(0);
    assertNotNull(proxyFactoryConfig);
    assertEquals("com.hazelcast.spring.DummyProxyFactory", proxyFactoryConfig.getClassName());
    assertEquals("MyService", proxyFactoryConfig.getService());
    LoadBalancer loadBalancer = config3.getLoadBalancer();
    assertNotNull(loadBalancer);
    assertTrue(loadBalancer instanceof RoundRobinLB);
    NearCacheConfig nearCacheConfig = config3.getNearCacheConfig("default");
    assertNotNull(nearCacheConfig);
    assertEquals(1, nearCacheConfig.getTimeToLiveSeconds());
    assertEquals(70, nearCacheConfig.getMaxIdleSeconds());
    assertEquals(EvictionPolicy.LRU, nearCacheConfig.getEvictionConfig().getEvictionPolicy());
    assertEquals(4000, nearCacheConfig.getEvictionConfig().getSize());
    assertEquals(true, nearCacheConfig.isInvalidateOnChange());
    assertEquals(CACHE_ON_UPDATE, nearCacheConfig.getLocalUpdatePolicy());
}
Also used : SerializationConfig(com.hazelcast.config.SerializationConfig) LoadBalancer(com.hazelcast.client.LoadBalancer) NearCacheConfig(com.hazelcast.config.NearCacheConfig) RoundRobinLB(com.hazelcast.client.util.RoundRobinLB) SerializerConfig(com.hazelcast.config.SerializerConfig) ProxyFactoryConfig(com.hazelcast.client.config.ProxyFactoryConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with SerializerConfig

use of com.hazelcast.config.SerializerConfig in project hazelcast by hazelcast.

the class SerializerHookLoader method load.

private void load() {
    try {
        final Iterator<SerializerHook> hooks = ServiceLoader.iterator(SerializerHook.class, FACTORY_ID, classLoader);
        while (hooks.hasNext()) {
            final SerializerHook hook = hooks.next();
            final Class serializationType = hook.getSerializationType();
            if (serializationType != null) {
                serializers.put(serializationType, hook);
            }
        }
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
    if (serializerConfigs != null) {
        for (SerializerConfig serializerConfig : serializerConfigs) {
            Serializer serializer = serializerConfig.getImplementation();
            Class serializationType = serializerConfig.getTypeClass();
            if (serializationType == null) {
                try {
                    serializationType = ClassLoaderUtil.loadClass(classLoader, serializerConfig.getTypeClassName());
                } catch (ClassNotFoundException e) {
                    throw new HazelcastSerializationException(e);
                }
            }
            if (serializer == null) {
                serializer = createSerializerInstance(serializerConfig, serializationType);
            }
            register(serializationType, serializer);
        }
    }
}
Also used : SerializerConfig(com.hazelcast.config.SerializerConfig) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) SerializerHook(com.hazelcast.nio.serialization.SerializerHook) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) Serializer(com.hazelcast.nio.serialization.Serializer)

Example 4 with SerializerConfig

use of com.hazelcast.config.SerializerConfig in project hazelcast by hazelcast.

the class CardinalityEstimatorAbstractTest method params.

@Parameterized.Parameters(name = "config:{0}")
public static Collection<Object[]> params() {
    final Config config = new Config();
    final SerializerConfig serializerConfig = new SerializerConfig();
    serializerConfig.setImplementation(new CustomObjectSerializer());
    serializerConfig.setTypeClass(CustomObject.class);
    config.getSerializationConfig().addSerializerConfig(serializerConfig);
    return Arrays.asList(new Object[][] { { null }, { config } });
}
Also used : SerializerConfig(com.hazelcast.config.SerializerConfig) Config(com.hazelcast.config.Config) SerializerConfig(com.hazelcast.config.SerializerConfig)

Example 5 with SerializerConfig

use of com.hazelcast.config.SerializerConfig in project hazelcast by hazelcast.

the class SerializerHookLoaderTest method testLoad_withParametrizedConstructor.

@Test
public void testLoad_withParametrizedConstructor() throws Exception {
    SerializerConfig serializerConfig = new SerializerConfig();
    serializerConfig.setClassName("com.hazelcast.internal.serialization.impl.TestSerializerHook$TestSerializerWithTypeConstructor");
    serializerConfig.setTypeClassName("com.hazelcast.nio.serialization.SampleIdentifiedDataSerializable");
    SerializationConfig serializationConfig = getConfig().getSerializationConfig();
    serializationConfig.addSerializerConfig(serializerConfig);
    SerializerHookLoader hook = new SerializerHookLoader(serializationConfig, classLoader);
    Map<Class, Object> serializers = hook.getSerializers();
    TestSerializerHook.TestSerializerWithTypeConstructor serializer = (TestSerializerHook.TestSerializerWithTypeConstructor) serializers.get(SampleIdentifiedDataSerializable.class);
    assertEquals(SampleIdentifiedDataSerializable.class, serializer.getClazz());
}
Also used : SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) SampleIdentifiedDataSerializable(com.hazelcast.nio.serialization.SampleIdentifiedDataSerializable) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

SerializerConfig (com.hazelcast.config.SerializerConfig)17 SerializationConfig (com.hazelcast.config.SerializationConfig)14 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Test (org.junit.Test)11 ParallelTest (com.hazelcast.test.annotation.ParallelTest)6 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)5 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)3 SerializationService (com.hazelcast.spi.serialization.SerializationService)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 Config (com.hazelcast.config.Config)2 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)2 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)2 SampleIdentifiedDataSerializable (com.hazelcast.nio.serialization.SampleIdentifiedDataSerializable)2 LoadBalancer (com.hazelcast.client.LoadBalancer)1 ProxyFactoryConfig (com.hazelcast.client.config.ProxyFactoryConfig)1 RoundRobinLB (com.hazelcast.client.util.RoundRobinLB)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1 XMLConfigBuilderTest (com.hazelcast.config.XMLConfigBuilderTest)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1