def test_tmgr_base_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_terminate = threading.Event()
    tmgr._hb_thread = threading.Thread(target=tmgr._heartbeat, name='heartbeat')
    tmgr._hb_thread.start()

    proc = Process(target=func_for_heartbeat_test, args=(hostname,
                                                         port,
                                                         tmgr._hb_request_q,
                                                         tmgr._hb_response_q))
    proc.start()

    proc.join()
    tmgr._hb_thread.join()
Ejemplo n.º 2
0
    def test_start_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')

        global_boolean = False

        def _heartbeat_side_effect():
            nonlocal global_boolean
            global_boolean = True

        tmgr._log = mocked_Logger
        tmgr._prof = mocked_Profiler
        tmgr._heartbeat = mock.MagicMock(side_effect=_heartbeat_side_effect)
        tmgr._uid = 'tmgr.0000'
        tmgr._hb_terminate = None
        tmgr._hb_thread = None

        tmgr.start_heartbeat()

        try:
            self.assertTrue(global_boolean)
            self.assertIsInstance(tmgr._hb_terminate, mt.Event)
            self.assertIsInstance(tmgr._hb_thread, mt.Thread)
        finally:
            if tmgr._hb_thread.is_alive():
                tmgr._hb_thread.join()
Ejemplo n.º 3
0
def test_tmgr_base_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_terminate = threading.Event()
    tmgr._hb_thread = threading.Thread(target=tmgr._heartbeat,
                                       name='heartbeat')
    tmgr._hb_thread.start()

    proc = Process(target=func_for_heartbeat_test,
                   args=(hostname, port, tmgr._hb_request_q,
                         tmgr._hb_response_q))
    proc.start()

    proc.join()
    tmgr._hb_thread.join()
Ejemplo n.º 4
0
def test_tmgr_base_heartbeat():

    credentials = pika.PlainCredentials(username, password)
    rmq_conn_params = pika.ConnectionParameters(host=hostname,
                                                port=port,
                                                credentials=credentials)
    sid = 'test.0003'
    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_terminate = mt.Event()
    tmgr._hb_thread = mt.Thread(target=tmgr._heartbeat, name='heartbeat')
    tmgr._hb_thread.start()

    proc = mp.Process(target=func_for_heartbeat_test,
                      args=(hostname, port, username, password,
                            tmgr._hb_request_q, tmgr._hb_response_q))
    proc.start()
    proc.join()
    tmgr._hb_thread.join()
Ejemplo n.º 5
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())
Ejemplo n.º 6
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()
Ejemplo n.º 7
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()
Ejemplo n.º 9
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()
Ejemplo n.º 10
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)