Search in sources :

Example 1 with JavaSerializer

use of com.nokia.dempsy.serialization.java.JavaSerializer in project Dempsy by Dempsy.

the class TestMpContainerLoadHandling method setUp.

@Before
public void setUp() throws Exception {
    ClusterId cid = new ClusterId("TestMpContainerLoadHandling", "test" + sequence++);
    dispatcher = new MockDispatcher();
    StatsCollectorCoda sc = new StatsCollectorCoda(cid, new StatsCollectorFactoryCoda().getNamingStrategy());
    stats = sc;
    JavaSerializer<Object> serializer = new JavaSerializer<Object>();
    container = new MpContainer(cid);
    container.setDispatcher(dispatcher);
    container.setStatCollector(sc);
    container.setSerializer(serializer);
    container.setPrototype(new TestMessageProcessor());
    forceOutputException = false;
}
Also used : StatsCollectorCoda(com.nokia.dempsy.monitoring.coda.StatsCollectorCoda) MpContainer(com.nokia.dempsy.container.MpContainer) ClusterId(com.nokia.dempsy.config.ClusterId) JavaSerializer(com.nokia.dempsy.serialization.java.JavaSerializer) StatsCollectorFactoryCoda(com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda) Before(org.junit.Before)

Example 2 with JavaSerializer

use of com.nokia.dempsy.serialization.java.JavaSerializer in project Dempsy by Dempsy.

the class TestInstanceManager method setupContainer.

//----------------------------------------------------------------------------
//  Test Cases
//----------------------------------------------------------------------------
public MpContainer setupContainer(Object prototype) throws ContainerException {
    DummyDispatcher dispatcher = new DummyDispatcher();
    StatsCollector stats = new StatsCollectorCoda(new ClusterId("test", "test"), new StatsCollectorFactoryCoda().getNamingStrategy());
    JavaSerializer<Object> serializer = new JavaSerializer<Object>();
    manager = new MpContainer(new ClusterId("test", "test"));
    manager.setDispatcher(dispatcher);
    manager.setStatCollector(stats);
    manager.setSerializer(serializer);
    manager.setPrototype(prototype);
    return manager;
}
Also used : StatsCollectorCoda(com.nokia.dempsy.monitoring.coda.StatsCollectorCoda) StatsCollector(com.nokia.dempsy.monitoring.StatsCollector) ClusterId(com.nokia.dempsy.config.ClusterId) JavaSerializer(com.nokia.dempsy.serialization.java.JavaSerializer) StatsCollectorFactoryCoda(com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda)

Example 3 with JavaSerializer

use of com.nokia.dempsy.serialization.java.JavaSerializer in project Dempsy by Dempsy.

the class TestDefaultSerializer method testChildClassSerializationWithRegistration.

@Test
public void testChildClassSerializationWithRegistration() throws Throwable {
    KryoSerializer<Object> ser = new KryoSerializer<Object>(defaultMock3Optimizer);
    JavaSerializer<Object> serJ = new JavaSerializer<Object>();
    KryoSerializer<Object> serR = new KryoSerializer<Object>(defaultMock3Optimizer, new Registration(MockClass.class.getName(), 10));
    KryoSerializer<Object> serRR = new KryoSerializer<Object>(defaultMock3Optimizer, new Registration(MockClass.class.getName(), 10), new Registration(Mock3.class.getName(), 11));
    KryoSerializer<Object> serRROb = new KryoSerializer<Object>(defaultMock3Optimizer, new Registration(MockClass.class.getName()), new Registration(Mock3.class.getName()), new Registration(UUID.class.getName()));
    Mock2 o = new Mock3(1, new MockClass(2, "Hello"));
    byte[] data = ser.serialize(o);
    byte[] dataJ = serJ.serialize(o);
    byte[] dataR = serR.serialize(o);
    byte[] dataRR = serRR.serialize(o);
    byte[] dataRROb = serRROb.serialize(o);
    assertTrue(dataJ.length > data.length);
    assertTrue(dataR.length < data.length);
    assertTrue(dataRR.length < dataR.length);
    assertTrue(dataRROb.length == dataRR.length);
    Mock2 o2 = (Mock2) ser.deserialize(data);
    assertEquals(1, o2.getInt());
    assertEquals(new MockClass(2, "Hello"), o2.getMockClass());
    assertTrue(o2 instanceof Mock3);
    assertEquals(1, ((Mock3) o2).myI);
    serRROb.deserialize(dataRROb);
}
Also used : Registration(com.nokia.dempsy.serialization.kryo.Registration) JavaSerializer(com.nokia.dempsy.serialization.java.JavaSerializer) KryoSerializer(com.nokia.dempsy.serialization.kryo.KryoSerializer) Test(org.junit.Test)

Example 4 with JavaSerializer

use of com.nokia.dempsy.serialization.java.JavaSerializer in project Dempsy by Dempsy.

the class TestDefaultSerializer method testChildClassSerializationWithRegistrationAndOptimization.

@Test
public void testChildClassSerializationWithRegistrationAndOptimization() throws Throwable {
    KryoSerializer<Object> ser = new KryoSerializer<Object>(defaultMock3Optimizer);
    JavaSerializer<Object> serJ = new JavaSerializer<Object>();
    KryoSerializer<Object> serR = new KryoSerializer<Object>(defaultMock3Optimizer, new Registration(MockClass.class.getName(), 10));
    KryoSerializer<Object> serRR = new KryoSerializer<Object>(defaultMock3Optimizer, new Registration(MockClass.class.getName(), 10), new Registration(Mock3.class.getName(), 11));
    KryoSerializer<Object> serRROb = new KryoSerializer<Object>(defaultMock3Optimizer, new Registration(MockClass.class.getName()), new Registration(Mock3.class.getName()));
    KryoSerializer<Object> serRRO = new KryoSerializer<Object>(new Registration(MockClass.class.getName(), 10), new Registration(Mock3.class.getName(), 11), new Registration(UUID.class.getName(), 12));
    serRRO.setKryoOptimizer(new KryoOptimizer() {

        @Override
        public void preRegister(Kryo kryo) {
            kryo.setRegistrationRequired(true);
            @SuppressWarnings("unchecked") FieldSerializer<MockClass> mockClassSer = (FieldSerializer<MockClass>) kryo.getSerializer(MockClass.class);
            mockClassSer.setFieldsCanBeNull(false);
            @SuppressWarnings("unchecked") FieldSerializer<Mock2> mock2Ser = (FieldSerializer<Mock2>) kryo.getSerializer(MockClass.class);
            mock2Ser.setFixedFieldTypes(true);
            mock2Ser.setFieldsCanBeNull(false);
        }

        @Override
        public void postRegister(Kryo kryo) {
            com.esotericsoftware.kryo.Registration reg = kryo.getRegistration(UUID.class);
            reg.setSerializer(uuidSerializer);
        }
    });
    Mock2 o = new Mock3(1, new MockClass(2, "Hello"));
    byte[] data = ser.serialize(o);
    byte[] dataJ = serJ.serialize(o);
    byte[] dataR = serR.serialize(o);
    byte[] dataRR = serRR.serialize(o);
    byte[] dataRROb = serRROb.serialize(o);
    byte[] dataRRO = serRRO.serialize(o);
    assertTrue(dataJ.length > data.length);
    assertTrue(dataR.length < data.length);
    assertTrue(dataRR.length < dataR.length);
    assertTrue(dataRROb.length == dataRR.length);
    assertTrue(dataRRO.length <= dataRR.length);
    Mock2 o2 = (Mock2) ser.deserialize(data);
    assertEquals(1, o2.getInt());
    assertEquals(new MockClass(2, "Hello"), o2.getMockClass());
    assertTrue(o2 instanceof Mock3);
    assertEquals(1, ((Mock3) o2).myI);
    assertEquals(o, serR.deserialize(dataR));
    assertEquals(o, serRR.deserialize(dataRR));
    assertEquals(o, serRRO.deserialize(dataRRO));
}
Also used : JavaSerializer(com.nokia.dempsy.serialization.java.JavaSerializer) KryoSerializer(com.nokia.dempsy.serialization.kryo.KryoSerializer) FieldSerializer(com.esotericsoftware.kryo.serializers.FieldSerializer) Registration(com.nokia.dempsy.serialization.kryo.Registration) KryoOptimizer(com.nokia.dempsy.serialization.kryo.KryoOptimizer) UUID(java.util.UUID) Kryo(com.esotericsoftware.kryo.Kryo) Test(org.junit.Test)

Aggregations

JavaSerializer (com.nokia.dempsy.serialization.java.JavaSerializer)4 ClusterId (com.nokia.dempsy.config.ClusterId)2 StatsCollectorCoda (com.nokia.dempsy.monitoring.coda.StatsCollectorCoda)2 StatsCollectorFactoryCoda (com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda)2 KryoSerializer (com.nokia.dempsy.serialization.kryo.KryoSerializer)2 Registration (com.nokia.dempsy.serialization.kryo.Registration)2 Test (org.junit.Test)2 Kryo (com.esotericsoftware.kryo.Kryo)1 FieldSerializer (com.esotericsoftware.kryo.serializers.FieldSerializer)1 MpContainer (com.nokia.dempsy.container.MpContainer)1 StatsCollector (com.nokia.dempsy.monitoring.StatsCollector)1 KryoOptimizer (com.nokia.dempsy.serialization.kryo.KryoOptimizer)1 UUID (java.util.UUID)1 Before (org.junit.Before)1