Пример #1
0
def test_python_task_encode():
    fn, args, kwargs = sum, [range(5)], {}
    data = (fn, args, kwargs)
    dumped = cloudpickle.dumps(data)

    task = PythonTask(fn=fn,
                      args=args,
                      kwargs=kwargs,
                      id='test-id',
                      envs={'TEST': 'value'},
                      uris=['test_dependency'])

    proto = encode(task)
    assert isinstance(proto, mesos_pb2.TaskInfo)
    assert proto.data == dumped
    assert proto.task_id.value == 'test-id'
    assert proto.executor.command.uris[0].value == 'test_dependency'
    assert proto.executor.command.environment.variables[0].name == 'TEST'
    assert proto.executor.command.environment.variables[0].value == 'value'

    task = PythonTask(id=TaskID(value='test-id'))
    task.data = data
    proto = encode(task)
    assert isinstance(proto, mesos_pb2.TaskInfo)
    assert proto.data == dumped
    assert proto.task_id.value == 'test-id'
Пример #2
0
def test_python_task_execution():
    fn, args, kwargs = sum, [range(5)], {}
    task = PythonTask(fn=fn, args=args, kwargs=kwargs,
                      id='test-id')
    task = decode(encode(task))
    assert task() == 10

    def fn(lst1, lst2):
        return sum(lst1) - sum(lst2)
    args = [range(5), range(3)]
    task = PythonTask(fn=fn, args=args, id='test-id')
    task = decode(encode(task))
    assert task() == 7
Пример #3
0
def test_python_task_execution():
    fn, args, kwargs = sum, [range(5)], {}
    task = PythonTask(fn=fn, args=args, kwargs=kwargs, id='test-id')
    task = decode(encode(task))
    assert task() == 10

    def fn(lst1, lst2):
        return sum(lst1) - sum(lst2)

    args = [range(5), range(3)]
    task = PythonTask(fn=fn, args=args, id='test-id')
    task = decode(encode(task))
    assert task() == 7
Пример #4
0
def test_encode_resources():
    pb = encode(Cpus(0.1))
    assert pb.scalar.value == 0.1
    assert pb.name == 'cpus'
    assert pb.type == mesos_pb2.Value.SCALAR

    pb = encode(Mem(16))
    assert pb.scalar.value == 16
    assert pb.name == 'mem'
    assert pb.type == mesos_pb2.Value.SCALAR

    pb = encode(Disk(256))
    assert pb.scalar.value == 256
    assert pb.name == 'disk'
    assert pb.type == mesos_pb2.Value.SCALAR
Пример #5
0
def test_encode_resources():
    pb = encode(Cpus(0.1))
    assert pb.scalar.value == 0.1
    assert pb.name == 'cpus'
    assert pb.type == mesos_pb2.Value.SCALAR

    pb = encode(Mem(16))
    assert pb.scalar.value == 16
    assert pb.name == 'mem'
    assert pb.type == mesos_pb2.Value.SCALAR

    pb = encode(Disk(256))
    assert pb.scalar.value == 256
    assert pb.name == 'disk'
    assert pb.type == mesos_pb2.Value.SCALAR
Пример #6
0
def test_python_task_encode():
    fn, args, kwargs = sum, [range(5)], {}
    data = (fn, args, kwargs)
    dumped = cloudpickle.dumps(data)

    task = PythonTask(fn=fn, args=args, kwargs=kwargs, id={'value': 'test-id'})

    proto = encode(task)
    assert isinstance(proto, mesos_pb2.TaskInfo)
    assert proto.data == dumped
    assert proto.task_id.value == 'test-id'

    task = PythonTask(id=TaskID(value='test-id'))
    task.data = data
    proto = encode(task)
    assert isinstance(proto, mesos_pb2.TaskInfo)
    assert proto.data == dumped
    assert proto.task_id.value == 'test-id'
Пример #7
0
def test_python_task_status_encode():
    data = {'arbitrary': 'data', 'value': 5}
    dumped = cloudpickle.dumps(data)

    status = PythonTaskStatus(task_id='test-id', state='TASK_STAGING',
                              data=data)
    proto = encode(status)
    assert isinstance(proto, mesos_pb2.TaskStatus)
    assert proto.data == dumped
    assert proto.task_id.value == 'test-id'
    assert proto.state == mesos_pb2.TASK_STAGING

    status = PythonTaskStatus(task_id='test-id', state='TASK_RUNNING')
    status.data = data
    proto = encode(status)
    assert isinstance(proto, mesos_pb2.TaskStatus)
    assert proto.data == dumped
    assert proto.task_id.value == 'test-id'
    assert proto.state == mesos_pb2.TASK_RUNNING
Пример #8
0
def test_python_task_encode():
    fn, args, kwargs = sum, [range(5)], {}
    data = (fn, args, kwargs)
    dumped = cloudpickle.dumps(data)

    task = PythonTask(fn=fn, args=args, kwargs=kwargs,
                      id={'value': 'test-id'})

    proto = encode(task)
    assert isinstance(proto, mesos_pb2.TaskInfo)
    assert proto.data == dumped
    assert proto.task_id.value == 'test-id'

    task = PythonTask(id=TaskID(value='test-id'))
    task.data = data
    proto = encode(task)
    assert isinstance(proto, mesos_pb2.TaskInfo)
    assert proto.data == dumped
    assert proto.task_id.value == 'test-id'
Пример #9
0
def test_python_task_status_encode():
    data = {'arbitrary': 'data', 'value': 5}
    dumped = cloudpickle.dumps(data)

    status = PythonTaskStatus(task_id='test-id',
                              state='TASK_STAGING',
                              data=data)
    proto = encode(status)
    assert isinstance(proto, mesos_pb2.TaskStatus)
    assert proto.data == dumped
    assert proto.task_id.value == 'test-id'
    assert proto.state == mesos_pb2.TASK_STAGING

    status = PythonTaskStatus(task_id='test-id', state='TASK_RUNNING')
    status.data = data
    proto = encode(status)
    assert isinstance(proto, mesos_pb2.TaskStatus)
    assert proto.data == dumped
    assert proto.task_id.value == 'test-id'
    assert proto.state == mesos_pb2.TASK_RUNNING
Пример #10
0
def test_non_strict_encode_task_info():
    t = TaskInfo(name='test-task',
                 id=TaskID(value='test-task-id'),
                 resources=[Cpus(0.1), Mem(16)],
                 command=CommandInfo(value='echo 100'))
    t.result = 'some binary data'
    t.status = TaskStatus()

    p = encode(t)
    assert isinstance(p, mesos_pb2.TaskInfo)
    assert p.command.value == 'echo 100'
    with pytest.raises(AttributeError):
        p.status
Пример #11
0
def test_status_in_task_info():
    t = TaskInfo(name='test-task',
                 id=TaskID(value='test-task-id'),
                 resources=[Cpus(0.1), Mem(16)],
                 command=CommandInfo(value='echo 100'))

    assert isinstance(t.status, TaskStatus)
    assert t.status.state == 'TASK_STAGING'

    p = encode(t)
    assert isinstance(p, mesos_pb2.TaskInfo)
    with pytest.raises(AttributeError):
        p.status
Пример #12
0
def test_encode_task_info_resources():
    task = TaskInfo(name='test-task',
                    id=TaskID(value='test-task-id'),
                    resources=[Cpus(0.1), Mem(16)],
                    command=CommandInfo(value='testcmd'))
    pb = encode(task)
    assert pb.name == 'test-task'
    assert pb.task_id.value == 'test-task-id'
    assert pb.resources[0].name == 'cpus'
    assert pb.resources[0].scalar.value == 0.1
    assert pb.resources[1].name == 'mem'
    assert pb.resources[1].scalar.value == 16
    assert pb.command.value == 'testcmd'
Пример #13
0
def test_non_strict_encode_task_info():
    t = TaskInfo(name='test-task',
                 id=TaskID(value='test-task-id'),
                 resources=[Cpus(0.1), Mem(16)],
                 command=CommandInfo(value='echo 100'))
    t.result = 'some binary data'
    t.status = TaskStatus()

    p = encode(t)
    assert isinstance(p, mesos_pb2.TaskInfo)
    assert p.command.value == 'echo 100'
    with pytest.raises(AttributeError):
        p.status
Пример #14
0
def test_encode_task_info():
    t = TaskInfo(name='test-task',
                 id=TaskID(value='test-task-id'),
                 resources=[Cpus(0.1), Mem(16)],
                 command=CommandInfo(value='echo 100'))

    p = encode(t)
    assert isinstance(p, mesos_pb2.TaskInfo)
    assert p.command.value == 'echo 100'
    assert p.name == 'test-task'
    assert p.resources[0].name == 'cpus'
    assert p.resources[0].scalar.value == 0.1
    assert p.task_id.value == 'test-task-id'
Пример #15
0
def test_encode_task_info_resources():
    task = TaskInfo(name='test-task',
                    id=TaskID(value='test-task-id'),
                    resources=[Cpus(0.1), Mem(16)],
                    command=CommandInfo(value='testcmd'))
    pb = encode(task)
    assert pb.name == 'test-task'
    assert pb.task_id.value == 'test-task-id'
    assert pb.resources[0].name == 'cpus'
    assert pb.resources[0].scalar.value == 0.1
    assert pb.resources[1].name == 'mem'
    assert pb.resources[1].scalar.value == 16
    assert pb.command.value == 'testcmd'
Пример #16
0
def test_encode_task_info():
    t = TaskInfo(name='test-task',
                 id=TaskID(value='test-task-id'),
                 resources=[Cpus(0.1), Mem(16)],
                 command=CommandInfo(value='echo 100'))

    p = encode(t)
    assert isinstance(p, mesos_pb2.TaskInfo)
    assert p.command.value == 'echo 100'
    assert p.name == 'test-task'
    assert p.resources[0].name == 'cpus'
    assert p.resources[0].scalar.value == 0.1
    assert p.task_id.value == 'test-task-id'
Пример #17
0
def test_python_task_encode():
    fn, args, kwargs = sum, [range(5)], {}
    data = (fn, args, kwargs)
    dumped = cloudpickle.dumps(data)

    task = PythonTask(fn=fn, args=args, kwargs=kwargs,
                      id='test-id',
                      envs={'TEST': 'value'},
                      uris=['test_dependency'])

    proto = encode(task)
    assert isinstance(proto, mesos_pb2.TaskInfo)
    assert proto.data == dumped
    assert proto.task_id.value == 'test-id'
    assert proto.executor.command.uris[0].value == 'test_dependency'
    assert proto.executor.command.environment.variables[0].name == 'TEST'
    assert proto.executor.command.environment.variables[0].value == 'value'

    task = PythonTask(id=TaskID(value='test-id'))
    task.data = data
    proto = encode(task)
    assert isinstance(proto, mesos_pb2.TaskInfo)
    assert proto.data == dumped
    assert proto.task_id.value == 'test-id'