def test_double_register_custom_serializer(self): config = SerializationConfig() config.set_custom_serializer(CustomClass, CustomSerializer) service = SerializationServiceV1(serialization_config=config) with self.assertRaises(ValueError): service._registry.safe_register_serializer(TheOtherCustomSerializer, CustomClass)
def test_double_register_custom_serializer(self): config = _Config() config.custom_serializers = {CustomClass: CustomSerializer} service = SerializationServiceV1(config) with self.assertRaises(ValueError): service._registry.safe_register_serializer( TheOtherCustomSerializer, CustomClass)
def test_custom_serializer(self): config = _Config() config.custom_serializers = {CustomClass: CustomSerializer} service = SerializationServiceV1(config) obj = CustomClass("uid", "some name", "description text") data = service.to_data(obj) obj2 = service.to_object(data) self.assertEqual(obj, obj2) self.assertEqual("CUSTOM", obj2.source)
def test_global_encode_decode(self): config = _Config() config.global_serializer = TestGlobalSerializer service = SerializationServiceV1(config) obj = CustomClass("uid", "some name", "description text") data = service.to_data(obj) obj2 = service.to_object(data) self.assertEqual(obj, obj2) self.assertEqual("GLOBAL", obj2.source)
def test_byte_case(self): config = _Config() config.default_int_type = IntType.BYTE service = SerializationServiceV1(config) d1 = service.to_data(byte_val) v1 = service.to_object(d1) self.assertEqual(d1.get_type(), CONSTANT_TYPE_BYTE) self.assertEqual(v1, byte_val) with self.assertRaises(HazelcastSerializationError): service.to_data(big_int)
def test_global_custom_serializer(self): config = SerializationConfig() config.set_custom_serializer(CustomClass, CustomSerializer) config.global_serializer = TestGlobalSerializer service = SerializationServiceV1(serialization_config=config) obj = CustomClass("uid", "some name", "description text") data = service.to_data(obj) obj2 = service.to_object(data) self.assertEqual(obj, obj2) self.assertEqual("CUSTOM", obj2.source)
def test_short_case(self): config = _Config() config.default_int_type = IntType.SHORT service = SerializationServiceV1(config) d1 = service.to_data(byte_val) d2 = service.to_data(short_val) v1 = service.to_object(d1) v2 = service.to_object(d2) self.assertEqual(d1.get_type(), CONSTANT_TYPE_SHORT) self.assertEqual(d2.get_type(), CONSTANT_TYPE_SHORT) self.assertEqual(v1, byte_val) self.assertEqual(v2, short_val) with self.assertRaises(HazelcastSerializationError): service.to_data(big_int)
def test_int_case(self): config = SerializationConfig() config.default_integer_type = INTEGER_TYPE.INT service = SerializationServiceV1(serialization_config=config) d1 = service.to_data(byte_val) d2 = service.to_data(short_val) d3 = service.to_data(int_val) v1 = service.to_object(d1) v2 = service.to_object(d2) v3 = service.to_object(d3) self.assertEqual(d1.get_type(), CONSTANT_TYPE_INTEGER) self.assertEqual(d2.get_type(), CONSTANT_TYPE_INTEGER) self.assertEqual(d3.get_type(), CONSTANT_TYPE_INTEGER) self.assertEqual(v1, byte_val) self.assertEqual(v2, short_val) self.assertEqual(v3, int_val) with self.assertRaises(HazelcastSerializationError): service.to_data(big_int)
def test_dynamic_case(self): config = _Config() config.default_int_type = IntType.VAR service = SerializationServiceV1(config) d1 = service.to_data(byte_val) d2 = service.to_data(short_val) d3 = service.to_data(int_val) d4 = service.to_data(long_val) v1 = service.to_object(d1) v2 = service.to_object(d2) v3 = service.to_object(d3) v4 = service.to_object(d4) self.assertEqual(d1.get_type(), CONSTANT_TYPE_BYTE) self.assertEqual(d2.get_type(), CONSTANT_TYPE_SHORT) self.assertEqual(d3.get_type(), CONSTANT_TYPE_INTEGER) self.assertEqual(d4.get_type(), CONSTANT_TYPE_LONG) self.assertEqual(v1, byte_val) self.assertEqual(v2, short_val) self.assertEqual(v3, int_val) self.assertEqual(v4, long_val)
def test_long_case(self): config = _Config() config.default_int_type = IntType.LONG service = SerializationServiceV1(config) d1 = service.to_data(byte_val) d2 = service.to_data(short_val) d3 = service.to_data(int_val) d4 = service.to_data(long_val) v1 = service.to_object(d1) v2 = service.to_object(d2) v3 = service.to_object(d3) v4 = service.to_object(d4) self.assertEqual(d1.get_type(), CONSTANT_TYPE_LONG) self.assertEqual(d2.get_type(), CONSTANT_TYPE_LONG) self.assertEqual(d3.get_type(), CONSTANT_TYPE_LONG) self.assertEqual(d4.get_type(), CONSTANT_TYPE_LONG) self.assertEqual(v1, byte_val) self.assertEqual(v2, short_val) self.assertEqual(v3, int_val) self.assertEqual(v4, long_val) with self.assertRaises(HazelcastSerializationError): service.to_data(big_int)
def setUp(self): self.service = SerializationServiceV1(_Config())
def replace_serialization_service(self, integer_type): config = _Config() config.default_int_type = integer_type new_service = SerializationServiceV1(config) self.map._wrapped._to_data = new_service.to_data self.map._wrapped._to_object = new_service.to_object
def setUp(self): config = SerializationConfig() config.default_integer_type = INTEGER_TYPE.BIG_INT self.service = SerializationServiceV1(serialization_config=config)
def setUp(self): n = random_string() self.service = SerializationServiceV1( serialization_config=SerializationConfig())