Search in sources :

Example 1 with StreamSerializer

use of com.hazelcast.nio.serialization.StreamSerializer in project hazelcast by hazelcast.

the class IssuesTest method testIssue1067GlobalSerializer.

@Test
public void testIssue1067GlobalSerializer() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final Config config = getConfig();
    GlobalSerializerConfig globalSerializerConfig = new GlobalSerializerConfig();
    globalSerializerConfig.setOverrideJavaSerialization(false);
    config.getSerializationConfig().setGlobalSerializerConfig(globalSerializerConfig.setImplementation(new StreamSerializer() {

        public void write(ObjectDataOutput out, Object object) throws IOException {
        }

        public Object read(ObjectDataInput in) throws IOException {
            return new DummyValue();
        }

        public int getTypeId() {
            return 123;
        }

        public void destroy() {
        }
    }));
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    IMap<Object, Object> map = hz.getMap("test");
    for (int i = 0; i < 10; i++) {
        map.put(i, new DummyValue());
    }
    assertEquals(10, map.size());
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    IMap<Object, Object> map2 = hz2.getMap("test");
    assertEquals(10, map2.size());
    assertEquals(10, map.size());
    for (int i = 0; i < 10; i++) {
        Object o = map2.get(i);
        assertNotNull(o);
        assertTrue(o instanceof DummyValue);
    }
}
Also used : ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) HazelcastInstance(com.hazelcast.core.HazelcastInstance) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) StreamSerializer(com.hazelcast.nio.serialization.StreamSerializer) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Config (com.hazelcast.config.Config)1 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)1 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)1 StreamSerializer (com.hazelcast.nio.serialization.StreamSerializer)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1