def test_fetch_journal_entry(self): future_response = gen.Future() future_response.set_result({}) flexmock(FakeDatastore()).should_receive('batch_get_entity').\ and_return(future_response) result = entity_utils.fetch_journal_entry(FakeDatastore(), 'key') self.assertEquals(result, None)
def test_fetch_journal_entry(self): flexmock(FakeDatastore()).should_receive('batch_get_entity').and_return({}) self.assertEquals(None, entity_utils.fetch_journal_entry(FakeDatastore(), 'key')) flexmock(FakeDatastore()).should_receive('batch_get_entity').\ and_return(FAKE_SERIALIZED_ENTITY) flexmock(entity_pb).should_receive('EntityProto').\ and_return()
def test_fetch_journal_entry(self): flexmock( FakeDatastore()).should_receive('batch_get_entity').and_return({}) self.assertEquals( None, entity_utils.fetch_journal_entry(FakeDatastore(), 'key')) flexmock(FakeDatastore()).should_receive('batch_get_entity').\ and_return(FAKE_SERIALIZED_ENTITY) flexmock(entity_pb).should_receive('EntityProto').\ and_return()
def process_entity(self, entity): """ Verifies entity, fetches from journal if necessary and calls dump_entity. Args: entity: The entity to be backed up. Returns: True on success, False otherwise. """ key = entity.keys()[0] kind = entity_utils.get_kind_from_entity_key(key) # Skip protected and private entities. if re.match(self.PROTECTED_KINDS, kind) or re.match(self.PRIVATE_KINDS, kind): # Do not skip blob entities. if not re.match(self.BLOB_CHUNK_REGEX, kind) and not re.match(self.BLOB_INFO_REGEX, kind): logging.debug("Skipping key: {0}".format(key)) return False one_entity = entity[key][dbconstants.APP_ENTITY_SCHEMA[0]] if one_entity == dbconstants.TOMBSTONE: return False app_id = key.split(dbconstants.KEY_DELIMITER)[0] root_key = entity_utils.get_root_key_from_entity_key(key) success = True while True: # Acquire lock. txn_id = self.zoo_keeper.get_transaction_id(app_id) try: if self.zoo_keeper.acquire_lock(app_id, txn_id, root_key): version = entity[key][dbconstants.APP_ENTITY_SCHEMA[1]] if not self.verify_entity(key, version): # Fetch from the journal. entity = entity_utils.fetch_journal_entry(self.db_access, key) if not entity: logging.error("Bad journal entry for key: {0} and result: {1}".format(key, entity)) success = False else: one_entity = entity[key][dbconstants.APP_ENTITY_SCHEMA[0]] if self.dump_entity(one_entity): logging.debug("Backed up key: {0}".format(key)) success = True else: success = False else: logging.warn("Entity with key: {0} not found".format(key)) success = False except zk.ZKTransactionException, zk_exception: logging.error("Zookeeper exception {0} while requesting entity lock".format(zk_exception)) success = False except zk.ZKInternalException, zk_exception: logging.error("Zookeeper exception {0} while requesting entity lock".format(zk_exception)) success = False
def process_entity(self, entity): """ Verifies entity, fetches from journal if necessary and calls dump_entity. Args: entity: The entity to be backed up. Returns: True on success, False otherwise. """ key = entity.keys()[0] kind = entity_utils.get_kind_from_entity_key(key) # Skip protected and private entities. if re.match(self.PROTECTED_KINDS, kind) or\ re.match(self.PRIVATE_KINDS, kind): # Do not skip blob entities. if not re.match(self.BLOB_CHUNK_REGEX, kind) and\ not re.match(self.BLOB_INFO_REGEX, kind): logging.debug("Skipping key: {0}".format(key)) return False one_entity = entity[key][dbconstants.APP_ENTITY_SCHEMA[0]] if one_entity == dbconstants.TOMBSTONE: return False app_id = key.split(dbconstants.KEY_DELIMITER)[0] root_key = entity_utils.get_root_key_from_entity_key(key) success = True while True: # Acquire lock. txn_id = self.zoo_keeper.get_transaction_id(app_id) try: if self.zoo_keeper.acquire_lock(app_id, txn_id, root_key): version = entity[key][dbconstants.APP_ENTITY_SCHEMA[1]] if not self.verify_entity(key, version): # Fetch from the journal. entity = entity_utils.fetch_journal_entry( self.db_access, key) if not entity: logging.error( "Bad journal entry for key: {0} and result: {1}" .format(key, entity)) success = False else: one_entity = entity[key][ dbconstants.APP_ENTITY_SCHEMA[0]] if self.dump_entity(one_entity): logging.debug("Backed up key: {0}".format(key)) success = True else: success = False else: logging.warn("Entity with key: {0} not found".format(key)) success = False except zk.ZKTransactionException, zk_exception: logging.error( "Zookeeper exception {0} while requesting entity lock". format(zk_exception)) success = False except zk.ZKInternalException, zk_exception: logging.error( "Zookeeper exception {0} while requesting entity lock". format(zk_exception)) success = False