Example #1
0
    def test_check_heartbeat(self, mocked_init, mocked_Logger,
                             mocked_Profiler):

        rmq_params = mock.MagicMock(spec=ConnectionParameters)
        rmgr = mock.MagicMock(spec=Base_ResourceManager)
        tmgr = Tmgr('test_tmgr', ['pending_queues'], ['completed_queues'],
                    rmgr, rmq_params, 'test_rts')

        def _tmgr_side_effect(amount):
            time.sleep(amount)

        tmgr._hb_thread = mt.Thread(target=_tmgr_side_effect,
                                    name='test_tmgr',
                                    args=(1))
        tmgr._hb_thread.start()

        self.assertTrue(tmgr.check_heartbeat())
        tmgr._hb_thread.join()
        self.assertFalse(tmgr.check_heartbeat())

        tmgr._hb_thread = None
        self.assertFalse(tmgr.check_heartbeat())
Example #2
0
def test_tmgr_base_check_heartbeat():

    sid  = 'test.0007'
    rmgr = BaseRmgr({}, sid, None, {})
    tmgr = BaseTmgr(sid=sid,
                    pending_queue=['pending-1'],
                    completed_queue=['completed-1'],
                    rmgr=rmgr,
                    mq_hostname=hostname,
                    port=port,
                    rts=None)

    tmgr._hb_thread    = mt.Thread(target=tmgr._heartbeat, name='heartbeat')
    tmgr._hb_terminate = mt.Event()
    tmgr._hb_thread.start()

    assert tmgr.check_heartbeat()

    tmgr.terminate_heartbeat()
Example #3
0
def test_tmgr_base_check_heartbeat():

    rmq_conn_params = pika.ConnectionParameters(host=hostname, port=port)
    sid  = 'test.0007'
    rmgr = BaseRmgr({}, sid, None, {})
    tmgr = BaseTmgr(sid=sid,
                    pending_queue=['pending-1'],
                    completed_queue=['completed-1'],
                    rmgr=rmgr,
                    rmq_conn_params=rmq_conn_params,
                    rts=None)

    tmgr._hb_thread    = mt.Thread(target=tmgr._heartbeat, name='heartbeat')
    tmgr._hb_terminate = mt.Event()
    tmgr._hb_thread.start()

    assert tmgr.check_heartbeat()

    tmgr.terminate_heartbeat()
def test_tmgr_base_check_heartbeat():

    sid = 'test.0000'
    rmgr = BaseRmgr({}, sid, None, {})

    os.environ['ENTK_HB_INTERVAL'] = '30'

    tmgr = BaseTmgr(sid=sid,
                    pending_queue=['pending-1'],
                    completed_queue=['completed-1'],
                    rmgr=rmgr,
                    mq_hostname=hostname,
                    port=port,
                    rts=None)

    tmgr._hb_thread = threading.Thread(target=tmgr._heartbeat, name='heartbeat')
    tmgr._hb_terminate = threading.Event()
    tmgr._hb_thread.start()
    assert tmgr.check_heartbeat()
    tmgr.terminate_heartbeat()
Example #5
0
def test_tmgr_base_check_heartbeat():

    sid = 'test.0000'
    rmgr = BaseRmgr({}, sid, None, {})

    os.environ['ENTK_HB_INTERVAL'] = '30'

    tmgr = BaseTmgr(sid=sid,
                    pending_queue=['pending-1'],
                    completed_queue=['completed-1'],
                    rmgr=rmgr,
                    mq_hostname=hostname,
                    port=port,
                    rts=None)

    tmgr._hb_thread = threading.Thread(target=tmgr._heartbeat, name='heartbeat')
    tmgr._hb_terminate = threading.Event()
    tmgr._hb_thread.start()
    assert tmgr.check_heartbeat()
    tmgr.terminate_heartbeat()
Example #6
0
    def test_terminate_heartbeat(self, mocked_init, mocked_Logger,
                                 mocked_Profiler, mocked_BlockingConnection):

        mocked_BlockingConnection.channel = mock.MagicMock(
            spec=pika.BlockingConnection.channel)
        mocked_BlockingConnection.close = mock.MagicMock(return_value=None)
        mocked_BlockingConnection.channel.queue_delete = mock.MagicMock(
            return_value=None)
        mocked_BlockingConnection.channel.queue_declare = mock.MagicMock(
            return_value=None)
        mocked_BlockingConnection.close = mock.MagicMock(return_value=None)
        rmq_params = mock.MagicMock(spec=ConnectionParameters)
        rmgr = mock.MagicMock(spec=Base_ResourceManager)
        tmgr = Tmgr('test_tmgr', ['pending_queues'], ['completed_queues'],
                    rmgr, rmq_params, 'test_rts')

        tmgr._rmq_conn_params = rmq_params
        tmgr._hb_request_q = 'test_tmgr-hb-request'
        tmgr._hb_response_q = 'test_tmgr-hb-response'

        tmgr._log = mocked_Logger
        tmgr._prof = mocked_Profiler
        tmgr._uid = 'tmgr.0000'
        tmgr.check_heartbeat = mock.MagicMock(return_value=True)
        tmgr.check_manager = mock.MagicMock(return_value=True)

        tmgr._hb_terminate = mt.Event()

        tmgr._hb_thread = mt.Thread(target=_tmgr_side_effect,
                                    name='test_tmgr',
                                    args=(tmgr._hb_terminate, ))
        tmgr._hb_thread.start()

        tmgr.terminate_heartbeat()

        self.assertIsNone(tmgr._hb_thread)