def tearDown(self):
        uow_dao = UnitOfWorkDao(self.worker.logger)
        uow_dao.remove(self.uow_id)

        for instance in self.worker.instances:
            self.conn.stop_instances(instance.id)

        # killing the worker
        del self.worker
Пример #2
0
    def test_select_reprocessing_candidates(self):
        logger = get_logger(PROCESS_UNIT_TEST)
        uow_dao = UnitOfWorkDao(logger)

        try:
            initial_candidates = uow_dao.get_reprocessing_candidates()
        except:
            initial_candidates = []

        try:
            initial_positive_candidates = uow_dao.get_reprocessing_candidates(
                '2010123123')
        except:
            initial_positive_candidates = []

        positive_timeperiods = {
            u'2010123123': PROCESS_SITE_HOURLY,  # hourly time qualifier
            u'2010123100': PROCESS_SITE_DAILY,  # daily time qualifier
            u'2010120000': PROCESS_SITE_MONTHLY,  # monthly time qualifier
            u'2010000000': PROCESS_SITE_YEARLY
        }  # yearly time qualifier

        negative_timeperiods = {
            u'2009123123': PROCESS_SITE_HOURLY,  # hourly time qualifier
            u'2009123100': PROCESS_SITE_DAILY,  # daily time qualifier
            u'2009120000': PROCESS_SITE_MONTHLY,  # monthly time qualifier
            u'2009000000': PROCESS_SITE_YEARLY
        }  # yearly time qualifier

        all_timeperiods = dict()
        all_timeperiods.update(positive_timeperiods)
        all_timeperiods.update(negative_timeperiods)

        created_uow = []
        for timeperiod, process_name in all_timeperiods.items():
            created_uow.append(
                create_and_insert_unit_of_work(
                    process_name,
                    0,
                    1,
                    timeperiod=timeperiod,
                    state=unit_of_work.STATE_INVALID))

        candidates = uow_dao.get_reprocessing_candidates('2010123123')
        self.assertEqual(
            len(candidates) - len(initial_positive_candidates),
            len(positive_timeperiods))

        candidates = uow_dao.get_reprocessing_candidates()
        self.assertEqual(
            len(candidates) - len(initial_candidates), len(all_timeperiods))

        for uow_id in created_uow:
            uow_dao.remove(uow_id)
class LogRecordingHandlerUnitTest(unittest.TestCase):
    """ Test flow:
        1. create a UOW in the database
        2. emulate mq message
        3. call _mq_callback method
        4. validate that all the messages are now found in the uow_log record
        5. remove UOW and uow_log record
    """
    def setUp(self):
        self.process_name = PROCESS_ALERT_DAILY
        self.logger = get_logger(self.process_name)
        self.uow_id = create_and_insert_unit_of_work(self.process_name,
                                                     'range_start',
                                                     'range_end')
        self.uow_id = str(self.uow_id)
        self.uow_dao = UnitOfWorkDao(self.logger)
        self.log_recording_dao = LogRecordingDao(self.logger)

    def tearDown(self):
        self.uow_dao.remove(self.uow_id)
        self.log_recording_dao.remove(self.uow_id)

    def test_logging(self):
        self.worker = ChattyWorker(self.process_name)
        message = TestMessage(process_name=self.process_name,
                              uow_id=self.uow_id)
        self.worker._mq_callback(message)

        uow_log = self.log_recording_dao.get_one(self.uow_id)
        messages = INFO_LOG_MESSAGES + WARN_LOG_MESSAGES  # + STD_MESSAGES
        self.assertLessEqual(len(messages), len(uow_log.log))

        for index, message in enumerate(messages):
            self.assertIn(message, uow_log.log[index])

    def test_exception_logging(self):
        self.worker = ExceptionWorker(self.process_name)
        message = TestMessage(process_name=self.process_name,
                              uow_id=self.uow_id)
        self.worker._mq_callback(message)

        uow_log = self.log_recording_dao.get_one(self.uow_id)
        messages = [
            'Exception: Artificially triggered exception to test Uow Exception Logging',
            'Method ExceptionWorker._process_uow returned None. Assuming happy flow.',
            'at INVALID_TIMEPERIOD: Success/Failure 0/0 entries'
        ]

        for index, message in enumerate(messages):
            self.assertIn(message, uow_log.log[index])
Пример #4
0
class UowLogHandlerUnitTest(unittest.TestCase):
    """ Test flow:
        1. create a UOW in the database
        2. emulate mq message
        3. call _mq_callback method
        4. validate that all the messages are now found in the uow_log record
        5. remove UOW and uow_log record
    """

    def setUp(self):
        self.process_name = PROCESS_ALERT_DAILY
        self.logger = get_logger(self.process_name)
        self.uow_id = create_and_insert_unit_of_work(self.process_name, 'range_start', 'range_end')
        self.uow_id = str(self.uow_id)
        self.uow_dao = UnitOfWorkDao(self.logger)
        self.uow_log_dao = UowLogDao(self.logger)

    def tearDown(self):
        self.uow_dao.remove(self.uow_id)
        self.uow_log_dao.remove(self.uow_id)

    def test_logging(self):
        self.worker = ChattyWorker(self.process_name)
        message = TestMessage(process_name=self.process_name, uow_id=self.uow_id)
        self.worker._mq_callback(message)

        uow_log = self.uow_log_dao.get_one(self.uow_id)
        messages = INFO_LOG_MESSAGES + WARN_LOG_MESSAGES  # + STD_MESSAGES
        self.assertLessEqual(len(messages), len(uow_log.log))

        for index, message in enumerate(messages):
            self.assertIn(message, uow_log.log[index])

    def test_exception_logging(self):
        self.worker = ExceptionWorker(self.process_name)
        message = TestMessage(process_name=self.process_name, uow_id=self.uow_id)
        self.worker._mq_callback(message)

        uow_log = self.uow_log_dao.get_one(self.uow_id)
        messages = ['Exception: Artificially triggered exception to test Uow Exception Logging',
                    'method ExceptionWorker._process_uow returned None. Assuming happy flow.',
                    'at INVALID_TIMEPERIOD: Success/Failure 0/0']

        for index, message in enumerate(messages):
            self.assertIn(message, uow_log.log[index])
    def test_select_reprocessing_candidates(self):
        logger = get_logger(PROCESS_UNIT_TEST)
        uow_dao = UnitOfWorkDao(logger)

        try:
            initial_candidates = uow_dao.get_reprocessing_candidates()
        except:
            initial_candidates = []

        try:
            initial_positive_candidates = uow_dao.get_reprocessing_candidates('2010123123')
        except:
            initial_positive_candidates = []

        positive_timeperiods = {u'2010123123': PROCESS_SITE_HOURLY,    # hourly time qualifier
                                u'2010123100': PROCESS_SITE_DAILY,     # daily time qualifier
                                u'2010120000': PROCESS_SITE_MONTHLY,   # monthly time qualifier
                                u'2010000000': PROCESS_SITE_YEARLY}    # yearly time qualifier

        negative_timeperiods = {u'2009123123': PROCESS_SITE_HOURLY,    # hourly time qualifier
                                u'2009123100': PROCESS_SITE_DAILY,     # daily time qualifier
                                u'2009120000': PROCESS_SITE_MONTHLY,   # monthly time qualifier
                                u'2009000000': PROCESS_SITE_YEARLY}    # yearly time qualifier

        all_timeperiods = dict()
        all_timeperiods.update(positive_timeperiods)
        all_timeperiods.update(negative_timeperiods)

        created_uow = []
        for timeperiod, process_name in all_timeperiods.items():
            created_uow.append(create_and_insert_unit_of_work(process_name,
                                                              0,
                                                              1,
                                                              timeperiod=timeperiod,
                                                              state=unit_of_work.STATE_INVALID))

        candidates = uow_dao.get_reprocessing_candidates('2010123123')
        self.assertEqual(len(candidates) - len(initial_positive_candidates), len(positive_timeperiods))

        candidates = uow_dao.get_reprocessing_candidates()
        self.assertEqual(len(candidates) - len(initial_candidates), len(all_timeperiods))

        for uow_id in created_uow:
            uow_dao.remove(uow_id)
Пример #6
0
 def tearDown(self):
     # cleaning up DB
     self.virtual_tear_down()
     uow_dao = UnitOfWorkDao(self.aggregator.logger)
     uow_dao.remove(self.uow_id)
     del self.aggregator
Пример #7
0
 def tearDown(self):
     # cleaning up DB
     self.virtual_tear_down()
     uow_dao = UnitOfWorkDao(self.aggregator.logger)
     uow_dao.remove(self.uow_id)
     del self.aggregator