def serialize_for_db_gc_not_dirty(self, instance, ignore_user_types, ifacebitmaps, return_none_if_no_ref_counting=True): """ @postcondition: Serialize for flushing from GC not-dirty objects @param instance: Instance to serialize @param ignore_user_types:Indicates if user types must be ignored @param ifacebitmaps: Interface bitmaps @param return_none_if_no_ref_counting: If true, return null if object does not reference any other object except language object. This is useful during GC of not dirty objects without references. @return serialized bytes """ cur_serialized_objs = IdentityDict() reference_counting = ReferenceCounting() pending_objs = list() cur_serialized_objs[instance] = 0 obj_data = self._create_buffer_and_serialize( instance, ignore_user_types, ifacebitmaps, cur_serialized_objs, pending_objs, reference_counting, return_none_if_no_ref_counting=return_none_if_no_ref_counting) if return_none_if_no_ref_counting: if obj_data == None: return None return obj_data.obj_bytes
def serialize_dcobj_with_data(self, dc_object, pending_objs, ignore_user_types, hint, runtime, force_pending_to_register, for_update=False): """ @postcondition: Serialize DataClayObject with data. @param dc_object: DCObject @param ignore_user_types: Indicates if user types inside the instance must be ignored or not @param pending_objs: pending objects @param hint: Hint to set if needed @param runtime; Runtime managed @param force_pending_to_register: If TRUE, object is going to be set as pending to register. Take into account that this function is also called to serialize objects in 'moves','replicas',... and in that case this parameter must be FALSE to avoid overriding the actual value of the instance (actual pending or not). @param for_update whether this serialziation comes from an update operation or not """ object_with_data = None object_id = dc_object.get_object_id() runtime.lock(object_id) try: cur_serialized_objs = IdentityDict() reference_counting = ReferenceCounting() cur_serialized_objs[dc_object] = 0 """ Set flags of volatile/persisted obj. being send """ # Set Hint in object being send/persisted. Hint provided during creation of metadata # is for associated objects that are not persistent yet (currently being persisted) # This algorithm can be improved in both languages, Python and Java. if for_update is False: dc_object.set_hint(hint) dc_object.set_persistent(True) object_with_data = self._create_buffer_and_serialize( dc_object, ignore_user_types, None, cur_serialized_objs, pending_objs, reference_counting) if force_pending_to_register: dc_object.set_pending_to_register(True) finally: runtime.unlock(object_id) return object_with_data
def setUp(self): self.identity_dict = IdentityDict() self.key = 10 self.value = 20
class TestIdentityDict(ut.TestCase): def setUp(self): self.identity_dict = IdentityDict() self.key = 10 self.value = 20 def tearDown(self): pass def test_setitem(self): self.identity_dict.__setitem__(self.key, self.value) obtained_value = self.identity_dict[self.key] assert obtained_value == self.value def test_len(self): self.identity_dict.__setitem__(self.key, self.value) assert len(self.identity_dict) == 1 def test_contains(self): self.identity_dict.__setitem__(self.key, self.value) assert self.key in self.identity_dict def test_delitem(self): self.identity_dict.__setitem__(self.key, self.value) self.identity_dict.__delitem__(self.key) assert len(self.identity_dict) == 0 def test_items(self): self.identity_dict.__setitem__(self.key, self.value) iterator = self.identity_dict.items() assert len(iterator) == 1