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;
}
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;
}
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);
}
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));
}
Aggregations