def test_on_acknowledged(mocker): agent_addr = 'mock_addr:12345' framework_id = str(uuid.uuid4()) executor_id = str(uuid.uuid4()) env = { 'MESOS_LOCAL': 'true', 'MESOS_AGENT_ENDPOINT': agent_addr, 'MESOS_FRAMEWORK_ID': framework_id, 'MESOS_EXECUTOR_ID': executor_id, } mocker.patch('os.environ', env) exc = mocker.Mock() driver = MesosExecutorDriver(exc) driver._started = True assert driver.updates == {} assert driver.tasks == {} tid = str(uuid.uuid4()) uid = uuid.uuid4() driver.updates[uid] = mocker.Mock() driver.tasks[tid] = mocker.Mock() event = { 'type': 'ACKNOWLEDGED', 'acknowledged': { 'task_id': { 'value': tid }, 'uuid': encode_data(uid.bytes) } } driver.on_event(event) assert driver.updates == {} assert driver.tasks == {}
def test_on_launch(mocker): agent_addr = 'mock_addr:12345' framework_id = str(uuid.uuid4()) executor_id = str(uuid.uuid4()) env = { 'MESOS_LOCAL': 'true', 'MESOS_AGENT_ENDPOINT': agent_addr, 'MESOS_FRAMEWORK_ID': framework_id, 'MESOS_EXECUTOR_ID': executor_id, } mocker.patch('os.environ', env) exc = mocker.Mock() driver = MesosExecutorDriver(exc) driver._started = True task_id = str(uuid.uuid4()) framework_info = {'id': {'value': framework_id}} task_info = { "task_id": { "value": task_id }, } event = { 'type': 'LAUNCH', 'launch': { 'framework_info': framework_info, 'task': task_info } } driver.on_event(event) exc.launchTask.assert_called_once_with(driver, task_info)
def test_on_subscribed(mocker): agent_addr = 'mock_addr:12345' framework_id = str(uuid.uuid4()) executor_id = str(uuid.uuid4()) env = { 'MESOS_LOCAL': 'true', 'MESOS_AGENT_ENDPOINT': agent_addr, 'MESOS_FRAMEWORK_ID': framework_id, 'MESOS_EXECUTOR_ID': executor_id, } mocker.patch('os.environ', env) exc = mocker.Mock() driver = MesosExecutorDriver(exc) driver._started = True executor_info = { 'executor_id': { 'value': executor_id }, 'framework_id': { 'value': framework_id } } framework_info = {'id': {'value': framework_id}} event = { 'type': 'SUBSCRIBED', 'subscribed': { 'executor_info': executor_info, 'framework_info': framework_info, 'agent_info': {} } } driver.on_event(event) exc.registered.assert_called_once_with(driver, executor_info, framework_info, {})
def test_on_shutdown(mocker): agent_addr = 'mock_addr:12345' framework_id = str(uuid.uuid4()) executor_id = str(uuid.uuid4()) env = { 'MESOS_LOCAL': 'true', 'MESOS_AGENT_ENDPOINT': agent_addr, 'MESOS_FRAMEWORK_ID': framework_id, 'MESOS_EXECUTOR_ID': executor_id, } mocker.patch('os.environ', env) exc = mocker.Mock() driver = MesosExecutorDriver(exc) driver._started = True event = {'type': 'shutdown'} driver.on_event(event) exc.shutdown.assert_called_once_with(driver)
def test_on_kill(mocker): agent_addr = 'mock_addr:12345' framework_id = str(uuid.uuid4()) executor_id = str(uuid.uuid4()) env = { 'MESOS_LOCAL': 'true', 'MESOS_AGENT_ENDPOINT': agent_addr, 'MESOS_FRAMEWORK_ID': framework_id, 'MESOS_EXECUTOR_ID': executor_id, } mocker.patch('os.environ', env) exc = mocker.Mock() driver = MesosExecutorDriver(exc) driver._started = True task_id = {'value': str(uuid.uuid4())} event = {'type': 'KILL', 'kill': {'task_id': task_id}} driver.on_event(event) exc.killTask.assert_called_once_with(driver, task_id)
def test_on_error(mocker): agent_addr = 'mock_addr:12345' framework_id = str(uuid.uuid4()) executor_id = str(uuid.uuid4()) env = { 'MESOS_LOCAL': 'true', 'MESOS_AGENT_ENDPOINT': agent_addr, 'MESOS_FRAMEWORK_ID': framework_id, 'MESOS_EXECUTOR_ID': executor_id, } mocker.patch('os.environ', env) exc = mocker.Mock() driver = MesosExecutorDriver(exc) driver._started = True message = ''.join( random.choice(string.printable) for _ in range(random.randint(1, 100))) event = {'type': 'ERROR', 'error': {'message': message}} driver.on_event(event) exc.error.assert_called_once_with(driver, message)