示例#1
0
def test_cache_exists(path_to_checksum, object_exists, traverse):
    remote = RemoteBASE(None, {})

    # remote does not support traverse
    remote.CAN_TRAVERSE = False
    with mock.patch.object(remote,
                           "list_cache_paths",
                           return_value=list(range(256))):
        checksums = list(range(1000))
        remote.cache_exists(checksums)
        object_exists.assert_called_with(checksums, None, None)
        traverse.assert_not_called()

    remote.CAN_TRAVERSE = True

    # large remote, small local
    object_exists.reset_mock()
    traverse.reset_mock()
    with mock.patch.object(remote,
                           "list_cache_paths",
                           return_value=list(range(256))):
        checksums = list(range(1000))
        remote.cache_exists(checksums)
        # verify that _cache_paths_with_max() short circuits
        # before returning all 256 remote checksums
        max_checksums = math.ceil(
            remote._max_estimation_size(checksums) /
            pow(16, remote.TRAVERSE_PREFIX_LEN))
        assert max_checksums < 256
        object_exists.assert_called_with(frozenset(range(max_checksums, 1000)),
                                         None, None)
        traverse.assert_not_called()

    # large remote, large local
    object_exists.reset_mock()
    traverse.reset_mock()
    remote.JOBS = 16
    with mock.patch.object(remote,
                           "list_cache_paths",
                           return_value=list(range(256))):
        checksums = list(range(1000000))
        remote.cache_exists(checksums)
        object_exists.assert_not_called()
        traverse.assert_called_with(
            frozenset(checksums),
            set(range(256)),
            256 * pow(16, remote.TRAVERSE_PREFIX_LEN),
            None,
            None,
        )

    # default traverse
    object_exists.reset_mock()
    traverse.reset_mock()
    remote.TRAVERSE_WEIGHT_MULTIPLIER = 1
    with mock.patch.object(remote, "list_cache_paths", return_value=[0]):
        checksums = set(range(1000000))
        remote.cache_exists(checksums)
        traverse.assert_not_called()
        object_exists.assert_not_called()
示例#2
0
def test_cache_exists(path_to_checksum, object_exists, traverse):
    remote = RemoteBASE(None, {})

    # remote does not support traverse
    remote.CAN_TRAVERSE = False
    with mock.patch.object(
        remote, "list_cache_paths", return_value=list(range(256))
    ):
        checksums = list(range(1000))
        remote.cache_exists(checksums)
        object_exists.assert_called_with(checksums, None, None)
        traverse.assert_not_called()

    remote.CAN_TRAVERSE = True

    # large remote, small local
    object_exists.reset_mock()
    traverse.reset_mock()
    with mock.patch.object(
        remote, "list_cache_paths", return_value=list(range(256))
    ):
        checksums = list(range(1000))
        remote.cache_exists(checksums)
        object_exists.assert_called_with(
            frozenset(range(256, 1000)), None, None
        )
        traverse.assert_not_called()

    # large remote, large local
    object_exists.reset_mock()
    traverse.reset_mock()
    remote.JOBS = 16
    with mock.patch.object(
        remote, "list_cache_paths", return_value=list(range(256))
    ):
        checksums = list(range(1000000))
        remote.cache_exists(checksums)
        object_exists.assert_not_called()
        traverse.assert_called_with(
            frozenset(checksums),
            set(range(256)),
            256 * pow(16, remote.TRAVERSE_PREFIX_LEN),
            None,
            None,
        )

    # default traverse
    object_exists.reset_mock()
    traverse.reset_mock()
    remote.TRAVERSE_WEIGHT_MULTIPLIER = 1
    with mock.patch.object(remote, "list_cache_paths", return_value=[0]):
        checksums = set(range(1000000))
        remote.cache_exists(checksums)
        traverse.assert_not_called()
        object_exists.assert_not_called()