Exemple #1
0
def test_on_failure(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._started = True
    executor_id = dict(value=str(uuid.uuid4()))
    agent_id = dict(value=str(uuid.uuid4()))
    status = random.randint(0, 256)
    event = {
        'type': 'FAILURE',
        'failure': {
            'executor_id': executor_id,
            'agent_id': agent_id,
            'status': status
        }
    }
    driver.on_event(event)
    sched.executorLost.assert_called_once_with(driver, executor_id,
                                               agent_id, status)

    event = {
        'type': 'FAILURE',
        'failure': {
            'agent_id': agent_id,
        }
    }
    driver.on_event(event)
    sched.slaveLost.assert_called_once_with(driver, agent_id)
def test_on_failure(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._started = True
    executor_id = dict(value=str(uuid.uuid4()))
    agent_id = dict(value=str(uuid.uuid4()))
    status = random.randint(0, 256)
    event = {
        'type': 'FAILURE',
        'failure': {
            'executor_id': executor_id,
            'agent_id': agent_id,
            'status': status
        }
    }
    driver.on_event(event)
    sched.executorLost.assert_called_once_with(driver, executor_id, agent_id,
                                               status)

    event = {
        'type': 'FAILURE',
        'failure': {
            'agent_id': agent_id,
        }
    }
    driver.on_event(event)
    sched.slaveLost.assert_called_once_with(driver, agent_id)
def test_on_error(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._started = True
    msg = 'error message'
    event = {'type': 'ERROR', 'error': {'message': msg}}
    driver.on_event(event)
    sched.error.assert_called_once_with(driver, msg)
def test_on_rescind(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._started = True
    offer_id = {'value': str(uuid.uuid4())}
    event = {'type': 'RESCIND', 'rescind': {'offer_id': offer_id}}
    driver.on_event(event)
    sched.offerRescinded.assert_called_once_with(driver, offer_id)
def test_on_offers_inverse(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._started = True
    offers = [{
        'offer_id': {
            'value': str(uuid.uuid4())
        }
    } for _ in range(random.randint(1, 10))]
    event = {'type': 'OFFERS', 'offers': {'inverse_offers': offers}}
    driver.on_event(event)
    sched.resourceOffers.assert_not_called()
    sched.inverseOffers.assert_called_once_with(driver, offers)
Exemple #6
0
def test_on_error(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._started = True
    msg = 'error message'
    event = {
        'type': 'ERROR',
        'error': {
            'message': msg
        }
    }
    driver.on_event(event)
    sched.error.assert_called_once_with(driver, msg)
Exemple #7
0
def test_on_rescind(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._started = True
    offer_id = {'value': str(uuid.uuid4())}
    event = {
        'type': 'RESCIND',
        'rescind': {
            'offer_id': offer_id
        }
    }
    driver.on_event(event)
    sched.offerRescinded.assert_called_once_with(driver, offer_id)
Exemple #8
0
def test_on_offers(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._started = True
    offers = [{
        'offer_id': {'value': str(uuid.uuid4())}
    } for _ in range(random.randint(1, 10))]
    event = {
        'type': 'OFFERS',
        'offers': {
            'offers': offers
        }
    }
    driver.on_event(event)
    sched.resourceOffers.assert_called_once_with(driver, offers)
def test_on_subscribed(mocker):
    sched = mocker.Mock()
    framework = {}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver.version = '1.0.0'
    driver._started = True
    driver._master = 'mock_addr:12345'
    framework_id = {'value': str(uuid.uuid4())}

    event = {
        'type': 'SUBSCRIBED',
        'subscribed': {
            'framework_id': framework_id
        }
    }
    driver.on_event(event)
    sched.registered.assert_called_once_with(driver, framework_id, {
        'hostname': 'mock_addr',
        'port': 12345,
        'version': '1.0.0'
    })
Exemple #10
0
def test_on_message(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._started = True
    executor_id = {'value': str(uuid.uuid4())}
    agent_id = {'value': str(uuid.uuid4())}
    message = ''.join(
        random.choice(string.printable) for _ in range(random.randint(1, 100)))
    data = encode_data(message.encode('utf8'))

    event = {
        'type': 'MESSAGE',
        'message': {
            'executor_id': executor_id,
            'agent_id': agent_id,
            'data': data
        }
    }
    driver.on_event(event)
    sched.frameworkMessage.assert_called_once_with(driver, executor_id,
                                                   agent_id, data)
Exemple #11
0
def test_on_message(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._started = True
    executor_id = {'value': str(uuid.uuid4())}
    agent_id = {'value': str(uuid.uuid4())}
    message = ''.join(random.choice(string.printable)
                      for _ in range(random.randint(1, 100)))
    data = encode_data(message.encode('utf8'))

    event = {
        'type': 'MESSAGE',
        'message': {
            'executor_id': executor_id,
            'agent_id': agent_id,
            'data': data
        }
    }
    driver.on_event(event)
    sched.frameworkMessage.assert_called_once_with(driver, executor_id,
                                                   agent_id, data)
Exemple #12
0
def test_on_subscribed(mocker):
    sched = mocker.Mock()
    framework = {}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver.version = '1.0.0'
    driver._started = True
    driver._master = 'mock_addr:12345'
    framework_id = {
        'value': str(uuid.uuid4())
    }

    event = {
        'type': 'SUBSCRIBED',
        'subscribed': {
            'framework_id': framework_id
        }
    }
    driver.on_event(event)
    sched.registered.assert_called_once_with(driver, framework_id, {
        'hostname': 'mock_addr',
        'port': 12345,
        'version': '1.0.0'
    })