Exemple #1
0
def test_send_data_segments_to_client_response_message_order(
        mocker, tmpdir, redisdb, client_task_definition_data):
    segment0 = tmpdir.join('test0.segment')
    segment0.write('content')

    segment1 = tmpdir.join('test1.segment')
    segment1.write('content')

    segment2 = tmpdir.join('test2.segment')
    segment2.write('content')

    client = Client()
    client.conn = redisdb
    client._cluster_request_data = client_task_definition_data
    client._cluster_address = str(uuid.uuid4())
    client._dataset_segments = {
        'test0': str(segment0),
        'test1': str(segment1),
        'test2': str(segment2)
    }

    client.segment_hashes = ['test1', 'test2', 'test0']

    client.send_data_segments_to_cluster()

    message_raw = redisdb.lrange(client._cluster_address, 0, -1)
    assert message_raw is not None

    messages = list(
        map(functools.partial(yaml.load, Loader=yaml.UnsafeLoader),
            message_raw))

    for key, message in zip(client.segment_hashes, messages):
        assert message['hash'] == key
Exemple #2
0
def test_obtain_cluster_segment_hash_results_valid():
    client = Client()
    hash_data = {key: 'test' for key in range(NUMBER_OF_DATASET_SEGMENTS)}
    response = {'client_id': client._client_id, 'hashes': hash_data.keys()}

    hash_data = {key: 'test' for key in range(NUMBER_OF_DATASET_SEGMENTS)}
    client._dataset_segments = hash_data

    client.get_cluster_response = MagicMock(return_value=response)

    client.obtain_cluster_segment_hash_results()
Exemple #3
0
def test_send_data_segments_to_client_cleanup_procedure(
        mocker, tmpdir, redisdb, client_task_definition_data):
    segment = tmpdir.join('test.segment')
    segment.write('content')

    client = Client()
    client.conn = redisdb
    client._cluster_request_data = client_task_definition_data
    client._cluster_address = str(uuid.uuid4())
    client._dataset_segments = {'test': str(segment)}

    client.segment_hashes = ['test']

    client.send_data_segments_to_cluster()

    assert not os.path.isfile(str(segment))
Exemple #4
0
def test_send_data_segments_to_client_response_message(
        mocker, tmpdir, redisdb, client_task_definition_data):
    segment = tmpdir.join('test.segment')
    segment.write('content')

    client = Client()
    client.conn = redisdb
    client._cluster_request_data = client_task_definition_data
    client._cluster_address = str(uuid.uuid4())
    client._dataset_segments = {'test': str(segment)}

    client.segment_hashes = ['test']

    client.send_data_segments_to_cluster()

    message_raw = redisdb.lrange(client._cluster_address, 0, -1)
    assert message_raw is not None

    messages = list(
        map(functools.partial(yaml.load, Loader=yaml.UnsafeLoader),
            message_raw))

    message = messages[0]
    assert all(key in message for key in ['hash', 'bucket', 'key'])